Просмотр исходного кода

added code for optimizing of the wallpaper-cache file-structure

LH 9 лет назад
Родитель
Сommit
5b09356858
1 измененных файлов с 132 добавлено и 6 удалено
  1. 132 6
      WPCMGr/src/main/java/de/nplusc/izc/Utilities/WPCMgr/Synchronizer.java

+ 132 - 6
WPCMGr/src/main/java/de/nplusc/izc/Utilities/WPCMgr/Synchronizer.java

@@ -51,6 +51,7 @@ public class Synchronizer
         
         try
         {
+            folderOptimize(path);
             LinkedHashMap<String,Object> data = (LinkedHashMap<String,Object>) new Yaml().load(new FileInputStream(path+"\\00_meta\\state.yml"));
             if(data.get("HEAD")==null)
             {
@@ -108,7 +109,7 @@ public class Synchronizer
                 String fn = FileTK.getFileName(entry);
                 FileTK.kopierpaste(new File(entry),new File(targetDir+"\\"+fn));
                 pos++;
-                if(pos%1000==0)
+                if(pos%100==0)
                 {
                     System.out.print(pos+" Dateien kopiert");
                 }
@@ -215,13 +216,31 @@ public class Synchronizer
         String[][] mergedList = new String[c1+c2][2];
         for (int i = 0; i < c1 ; i++)
         {
-            mergedList[i][0] = availablePackagesNormal[i];
-            mergedList[i][1] = "proc";
+            String pth = availablePackagesNormal[i];
+            String dst = "proc";
+
+            String fex = FileTK.getFileExt(pth);
+            if(fex!=null&&fex.equals("loc"))
+            {
+                dst ="src";
+                pth=pth.substring(0, pth.length()-4);
+            }
+            mergedList[i][0] = pth;
+            mergedList[i][1] = dst;
         }
         for (int i = 0; i < c2; i++)
         {
-            mergedList[i+c1][0] = availablePackagesNoResize[i];
-            mergedList[i+c1][1] = "k-i-p";
+            String pth = availablePackagesNoResize[i];
+            String dst = "k-i-p";
+
+            String fex = FileTK.getFileExt(pth);
+            if(fex!=null&&fex.equals("loc"))
+            {
+                dst ="src";
+                pth=pth.substring(0, pth.length()-4);
+            }
+            mergedList[i+c1][0] = pth;
+            mergedList[i+c1][1] = dst;
         }
                             //main inited_b's b_loop
         int[] cntr = new int[]{0,0,0};//HAX
@@ -252,9 +271,17 @@ public class Synchronizer
                 if (cntr[1] < availablePackagesBFrames.length)
                 {
                     String bp = path+"\\p\\b\\"+cntr[1]+".jpg";
+                    String dst = "b-frames";
+                    String pth = availablePackagesBFrames[cntr[1]];
+                    String fex = FileTK.getFileExt(pth);
+                    if(fex!=null&fex.equals("loc"))
+                    {
+                        dst="src";
+                        pth=pth.substring(0, pth.length()-4);
+                    }
                     commandQueue.add(new String[]
                     {
-                        "C:\\Program Files\\ImageMagick-6.8.8-Q16\\convert.exe", path + "\\b-frames\\" + availablePackagesBFrames[cntr[1]], "-resize", res + "!", bp
+                        "C:\\Program Files\\ImageMagick-6.8.8-Q16\\convert.exe", path + "\\"+dst+"\\" + pth, "-resize", res + "!", bp
                     });
                     availablePackagesBFrames[cntr[1]]=bp;
                     cntr[1]++;
@@ -280,4 +307,103 @@ public class Synchronizer
         //convert in.image -resize res+">" -background black -gravity center -extent res out.image
         return new Object[]{commandQueue,resultFiles};
     }
+    
+    private static void folderOptimize(String basepath)
+    {
+        String[] dirsExist = FileTK.getDirectoryContent(/*args[0]*/basepath,true);
+        
+        Arrays.stream(dirsExist).filter(t -> !t.startsWith("00_") && new File(basepath+"\\" + t).isDirectory()).forEach(t ->
+        {
+            
+            System.out.println("Optimieren: Verzeichnis "+t+"(@"+pos+")");
+            String path = basepath+"\\" + t;
+            FileTK.verzeichnisKillen(new File(path+"\\p"));
+            
+            List<String> availablePackagesNormal = Arrays.asList(FileTK.getDirectoryContent(path+"\\proc",true));
+            List<String> availablePackagesNoResize = Arrays.asList(FileTK.getDirectoryContent(path+"\\k-i-p",true));
+            List<String> availablePackagesBFrames = Arrays.asList(FileTK.getDirectoryContent(path+"\\b-frames",true));
+            
+            String[] sourceFiles = FileTK.getDirectoryContent(path+"\\src",true);
+            
+            for (String sourceFile : sourceFiles)
+            {
+
+                String fex = FileTK.getFileExt(sourceFile);
+                if(fex!=null&&fex.equals("loc"))
+                {
+                    continue;
+                }
+                String fp = path+"\\src\\"+sourceFile;
+                File src = new File(fp);
+                if(!src.isFile())
+                {
+                    continue;
+                }
+                long fs = src.length();
+                if(availablePackagesNormal.contains(sourceFile))
+                {
+                    String tfp = path+"\\proc\\"+sourceFile;
+                    File cp = new File(tfp);
+                    if(cp.exists()&&(!cp.isDirectory())&&cp.length()==fs)
+                    {
+                        //System.out.println("DELETE "+tfp);
+                        cp.delete();
+                        //System.out.println("CREATE "+tfp+".loc");
+                        try
+                        {
+                            new File(tfp+".loc").createNewFile();
+                        }
+                        catch (IOException ex)
+                        {
+                            ex.printStackTrace();
+                        }/**/
+                        
+                    }  
+                }
+                if(availablePackagesNoResize.contains(sourceFile))
+                {
+                    String tfp = path+"\\k-i-p\\"+sourceFile;
+                    File cp = new File(tfp);
+                    if(cp.exists()&&(!cp.isDirectory())&&cp.length()==fs)
+                    {
+                        //System.out.println("DELETE "+tfp);
+                        cp.delete();
+                        //System.out.println("CREATE "+tfp+".loc");
+                        try
+                        {
+                            new File(tfp+".loc").createNewFile();
+                        }
+                        catch (IOException ex)
+                        {
+                            ex.printStackTrace();
+                        }/**/
+                        
+                    }  
+                }
+                if(availablePackagesBFrames.contains(sourceFile))
+                {
+                    String tfp = path+"\\b-frames\\"+sourceFile;
+                    File cp = new File(tfp);
+                    if(cp.exists()&&(!cp.isDirectory())&&cp.length()==fs)
+                    {
+                        //System.out.println("DELETE "+tfp);
+                        cp.delete();
+                        //System.out.println("CREATE "+tfp+".loc");
+                        try
+                        {
+                            new File(tfp+".loc").createNewFile();
+                        }
+                        catch (IOException ex)
+                        {
+                            ex.printStackTrace();
+                        }/**/
+                        
+                    }  
+                }
+            }
+            
+        });
+    }
+    
+    
 }