How can I show folder size and number of items in folder detail in Alfresco? - alfresco-share

I want to show folder size and number of all the subordinate files(not sub-folders) for each folder in Alfresco Share.
How can I show this information on Folder Details as the following?
Name: Alfresco
Title: Alfresco Share
Description: Alfresco Discussion
Creator: admin
Size: 128,08 MB
Files: 12
Sub-Folders: 2

Try with this:
System.IO.DirectoryInfo info = new DirectoryInfo("c:\\");
int NumerSubDirs = info.GetDirectories().Length;
int NumFiles = info.GetFiles().Length;
FileInfo[] fileinfos = info.GetFiles();
float totalSize =0;
foreach (FileInfo infof in fileinfos)
{
totalSize += (infof.Length / 1024 / 1024);
}
Console.WriteLine("Number of subdirs -> " + NumerSubDirs.ToString());
Console.WriteLine("Numer of files -> " + NumFiles.ToString());
Console.Write("Size of files -> " + totalSize.ToString());

Related

Replace variable in text file with sbt

I have legacy SBT build file. As a part of build process I need to replace one specific string in text file.
Specifically in Play Framework application in public/index.html file I need to replace placeholder string to GA UUID code.
Actually an additional "in Compile" is missing from the confirmed solution (contributed by Aki):
resourceGenerators in Compile += Def.task {
val content = IO.read((resourceDirectory in Compile).value / "index.html")
val out = (resourceManaged in Compile).value / "index.html"
IO.write(out, content.replace("<build-time>", System.currentTimeMillis.toString))
Seq(out)
}
I would have added a comment but I don't have enough "reputation" :)
You can write a custom resource generator that reads your file, replaces the placeholder and writes it to a file.
resourceGenerators in Compile += Def.task {
val content = IO.read(resourceDirectory.value / "index.html")
val out = (resourceManaged in Compile).value / "index.html"
IO.write(out, content.replace("<build-time>", System.currentTimeMillis.toString))
Seq(out)
}

How to set version number in sbt when building & publishing akka-http

I'm trying to experiment with a local copy of the akka-http library. I can publish it locally with sbt publishLocal, but I can't figure out how to change the version number. build.sbt contains an organization field but no simple version field - that seems to be generated from somewhere else and I can't figure out where. It's currently at 10.0.5but grepping that string in the source doesn't turn up anything obvious.
Seems like a simple question, but where is version defined? Thanks.
(I'm asking this because sbt docs tell me I should name my local version something like 0.1-SNAPSHOT. I assume there must be a simpler way to do this than by disabling the auto-generation logic and hardcoding it into build.sbt)
It seems that Akka-HTTP generates its version at run-time.
If you look at akka-http/akka-http-core/src/main/resources/reference.conf:
Akka HTTP version, checked against the runtime version of Akka HTTP.
Loaded from generated conf file.
And then look at akka-http/project/Version.scala:
/**
* Generate version.conf and akka/Version.scala files based on the version setting.
*/
object Version {
def versionSettings: Seq[Setting[_]] = inConfig(Compile)(Seq(
resourceGenerators += generateVersion(resourceManaged, _ / "akka-http-version.conf",
"""|akka.http.version = "%s"
|""").taskValue,
sourceGenerators += generateVersion(sourceManaged, _ / "akka" / "http" / "Version.scala",
"""|package akka.http
|
|import com.typesafe.config.Config
|
|object Version {
| val current: String = "%s"
| def check(config: Config): Unit = {
| val configVersion = config.getString("akka.http.version")
| if (configVersion != current) {
| throw new akka.ConfigurationException(
| "Akka JAR version [" + current + "] does not match the provided " +
| "config version [" + configVersion + "]")
| }
| }
|}
|""").taskValue
))
def generateVersion(dir: SettingKey[File], locate: File => File, template: String) = Def.task[Seq[File]] {
val file = locate(dir.value)
val content = template.stripMargin.format(version.value)
if (!file.exists || IO.read(file) != content) IO.write(file, content)
Seq(file)
}
}
I'm assuming after generating the current version you should see a akka-http-version.conf file somewhere in your filesystem.

Preserving recursive directory structure in zips with Java 8

I have the following directory on my laptop:
/tmp/
myapp/
assets/
config.yml
models/
troll.ply
tree.ply
textures/
troll-skin.png
tree-skin.png
I would like to zip /tmp/myapp/assets (and all its recursive contents) up into a ZIP named assets.zip, such that, when I unzip it (via unzip assets.zip), it preserves the directory structure under the assets folder. Hence, when unzipped, it would show config.yml in the "root" of the ZIP, and 2 directories inside the ZIP (models and textures). The rest of the files would be inside these respective subdirectories, etc.
When I run this code:
File sourceDir = new File("/tmp/myapp/assets");
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream("/Users/myuser/archives/assets.zip"));
File[] contents = sourceDir.listFiles();
for(File file : contents) {
zip.putNextEntry(new ZipEntry(file.name));
InputStream isteam = new FileInputStream(file);
Files.copy(isteam, zip);
zip.closeEntry();
isteam.close();
}
zip.close();
The code correctly creates a ZIP at /Users/myuser/archives/assets.zip.
However, when I unzip it (unzip /Users/myuser/archives/assets.zip) and then run ls -al /Users/myuser/archives, my output is:
-rw-r--r-- 1 myuser 1754083733 492 Dec 30 14:14 assets.zip
-rw-r--r-- 1 myuser 1754083733 10 Dec 30 14:14 config.yml
-rw-r--r-- 1 myuser 1754083733 7 Dec 30 14:14 models
-rw-r--r-- 1 myuser 1754083733 9 Dec 30 14:14 textures
So both models and textures are being treated like files (not as directories). Furthermore, when I take a peek at the contents of the "models file", it appears that the contents of troll.ply and tree.ply have been concatenated inside of it, and ditto for the "tree file" with the 2 PNGs.
How can I tweak this so that directory structure (no matter how deep/nested) is always preserved in the resultant ZIP?
you can probably use the recursive method call to preserve the sub directories structure:
private static void addDir(File sourceDir, ZipOutputStream zip) throws IOException {
File[] contents = sourceDir.listFiles();
for(File file : contents) {
if(file.isDirectory()){
addDir(file, zip);
} else {
zip.putNextEntry(new ZipEntry(file.getAbsolutePath().replace("/tmp/myapp/","")));
System.out.println("file name " + file.getAbsolutePath().replace("/tmp/myapp/",""));
Path rn_demo = Paths.get(String.valueOf(file));
Files.copy(rn_demo, zip);
}
}
zip.closeEntry();
}
and you call in main method as below:
public static void main(String[] args) throws IOException {
File sourceDir = new File("/tmp/myapp/assets");
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream("/Users/myuser/archives/assets.zip"));
addDir(sourceDir, zip);
zip.close();
}
Zipping through Java Zip seems to work differently on different OS's. I had the issue that it was working fine on Windows 7. But on Linux (RHEL6) the files were before the folders. This caused tests to fail.
A way to solve it is to sort the files and folders. folders first and then files. So the..
File[] contents = sourceDir.listFiles();
...File array should be sorted via path. Create a List<> from the Files and sort.
Collections.sort(newFiles, (a, b) ->
b.getAbsolutePath().compareTo(a.getAbsolutePath())
);
Note, I created an InputFile object to store the absolute path of the file.

qmake and generated qm files

What is the best (proper) way to organize compiled translations (*.qm) into resources?
*.qm files referred in qrc file and generated by two (three) extra targets this way:
trans_update.commands = lupdate $$_PRO_FILE_
trans_update.depends = $$_PRO_FILE_
trans_release.commands = lrelease $$_PRO_FILE_
trans_release.depends = trans_update $$TRANSLATIONS
translate.depends = trans_release
QMAKE_EXTRA_TARGETS += trans_update trans_release translate deploy
CONFIG(release, debug|release) {
DESTDIR=release
PRE_TARGETDEPS += translate
}
but the problem is at the moment qmake runs first time, there're no qm files generated yet and make prints errors like:
RCC: Error in 'qml.qrc': Cannot find file ...
I don't like an idea of saving compiled qm files into VSC.
Is there a way to organize it nicely?
I like to point out a solution which I use in some projects. It might be far from perfect, but it works out nicely.
CONFIG(release, debug|release) {
TRANSLATION_TARGET_DIR = $${OUT_PWD}/release/translations
LANGUPD_OPTIONS = -locations relative -no-ui-lines
LANGREL_OPTIONS = -compress -nounfinished -removeidentical
} else {
TRANSLATION_TARGET_DIR = $${OUT_PWD}/debug/translations
LANGUPD_OPTIONS =
LANGREL_OPTIONS = -markuntranslated "MISS_TR "
}
isEmpty(QMAKE_LUPDATE) {
win32:LANGUPD = $$[QT_INSTALL_BINS]\lupdate.exe
else:LANGUPD = $$[QT_INSTALL_BINS]/lupdate
}
isEmpty(QMAKE_LRELEASE) {
win32:LANGREL = $$[QT_INSTALL_BINS]\lrelease.exe
else:LANGREL = $$[QT_INSTALL_BINS]/lrelease
}
langupd.command = \
$$LANGUPD $$LANGUPD_OPTIONS $$shell_path($$_PRO_FILE_) -ts $$_PRO_FILE_PWD_/$$TRANSLATIONS
langrel.depends = langupd
langrel.input = TRANSLATIONS
langrel.output = $$TRANSLATION_TARGET_DIR/${QMAKE_FILE_BASE}.qm
langrel.commands = \
$$LANGREL $$LANGREL_OPTIONS ${QMAKE_FILE_IN} -qm $$TRANSLATION_TARGET_DIR/${QMAKE_FILE_BASE}.qm
langrel.CONFIG += no_link
QMAKE_EXTRA_TARGETS += langupd
QMAKE_EXTRA_COMPILERS += langrel
PRE_TARGETDEPS += langupd compiler_langrel_make_all
There might be a sensful tweak to lupdate options because the various builds (release and debug) generate different *.ts files which then trigger a change in the used VCS.
I also like to guide the tended reader to an example where experts use it.
The recommended way -- which may not have been available at the time this question was originally asked would be to use
TRANSLATIONS += <your *.ts files>
CONFIG += lrelease embed_translations
If you really need/want to build the qm files separately, I'd point to what qmake does with the above config and adapt it according to your needs. See https://github.com/qt/qtbase/blob/5.15.2/mkspecs/features/lrelease.prf
(Basically, it creates and adds a list of resources to RESOURCES).

Zip Files using PeopleCode in Application Engine

I have a requirment to zip multiple folders inside parent folder and display the file in App Engine ouput. The folder structure in Unix File Server -
Parent Folder
- Folder1 (contains files)
- Folder2 (contains files)
How to zip the folders and store it in parent folder using PeopleCode in AE (Final folder structure will be as follows
Parent Folder
-Folder1
-Folder2
-ParentFolder.Zip.
Note: Process runs on Unix Server.
Actually we were calling java code to zip files.
Such as:
&buffer = CreateJavaArray("byte[]", 18024);
&zipStream = CreateJavaObject("java.util.zip.ZipOutputStream", CreateJavaObject("java.io.FileOutputStream", &outDir | &outZip));
For &i = 1 To &inFiles.Len
&zipStream.putNextEntry(CreateJavaObject("java.util.zip.ZipEntry", &inFiles [&i]));
&inStream = CreateJavaObject("java.io.FileInputStream", &outDir | &inFiles [&i]);
&len = &inStream.read(&buffer);
While &len > 0;
&zipStream.write(&buffer, 0, &len);
&len = &inStream.read(&buffer);
End-While;
&zipStream.closeEntry();
&inStream.close();
End-For;
&zipStream.close();

Resources