Quellcode durchsuchen

Optimized File detection
Updated Profile handling for allowing to process all profiles at onced
Added Error-wallpaper

LH vor 7 Jahren
Ursprung
Commit
315e5e9d56

+ 143 - 31
WPCMGr/src/main/java/de/nplusc/izc/Utilities/WPCMgr/Synchronizer.java

@@ -16,7 +16,6 @@
  */
 package de.nplusc.izc.Utilities.WPCMgr;
 
-import static de.nplusc.izc.Utilities.WPCMgr.WPCUtils.ensureProfileExists;
 import de.nplusc.izc.tools.IOtools.FileTK;
 import de.nplusc.izc.tools.baseTools.Tools;
 import hu.ssh.progressbar.console.ConsoleProgressBar;
@@ -32,6 +31,7 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.apache.commons.cli.ParseException;
@@ -68,11 +68,44 @@ public class Synchronizer
     private static final String wallpaperRegex = "([0-9]{4})_([AaBb])_([0-9]{6})([Bb]?)\\.jpg";
     public static void wpcToFlatFolder(String targetCache, boolean debugmode,boolean dryRun,String profile) throws FileNotFoundException
     {
+        final LinkedHashMap<String, Object> data = (LinkedHashMap<String, Object>) WPCUtils.getConfig(targetCache);
+            HashMap<String,Object> profiles_storage = (HashMap<String,Object>) data.get("profiles");
+            Set<String> profile_ids = profiles_storage.keySet();
+        
+        
+        
         if(dryRun)
         {
             l.info("DRY");
         }
-        new Synchronizer().handleWPC(targetCache, debugmode, dryRun,profile); 
+        
+        List<String> profiles = new ArrayList<>();
+        
+        if(profile.equals("__ALL__"))
+        {
+            profiles.addAll(profile_ids);
+        }
+        else
+        {
+            if(profile_ids.contains(profile))
+            {
+                 profiles.add(profile);
+            }
+            else
+            {
+                l.error("Invalid ProfileID, profile not existing");
+            }
+        }
+        int i=1;
+        int count = profiles.size();
+        l.trace(new Yaml().dump(profiles));
+        for(String id:profiles)
+        {
+            l.info("Converting Profile {} ({}/{})",id,i,count);
+            new Synchronizer().handleWPC(targetCache, debugmode, dryRun,id); 
+            i++;
+        }
+        
     }
     public static void getSourcePathForID(String targetCache,String wallpaperID) throws ParseException, FileNotFoundException
     {
@@ -196,6 +229,9 @@ public class Synchronizer
         }
         //install hack for using certain ratio multiscreen WPs in other multiscreen ratios
         //int[][] tri
+        l.trace(new Yaml().dump(profiles));
+        l.trace("PROFILE_SELECTED->{}",profile);
+         l.trace(new Yaml().dump(profile_data));
         HashMap<String, List<Integer>> monitors = (HashMap<String, List<Integer>>) profile_data.get("MONITORS");
         HashMap<String, List<String>> monstrips = (HashMap<String, List<String>>) profile_data.get("MONITORSTRIPS");
         if(monstrips==null)
@@ -296,7 +332,10 @@ public class Synchronizer
         });
         l.trace("finalize pre");
         //progressBar.complete();
-
+        
+        identifyAll(theState);
+        
+        
         progressBar = progressBar.withTotalSteps(totalFiles + 1);
         progressBar.setMessage("Dateien:0/" + totalFiles);
         progressBar.start();
@@ -308,6 +347,9 @@ public class Synchronizer
             WPCUtils.saveCacheState(cachedir, theState);
         }
         int packNR = 0;
+        
+        
+        
         List<ResultWallpaper> copylist = new ArrayList<>();
         l.trace(new Yaml().dump(existingPKGs));
         for (String pak : existingPKGs)
@@ -357,6 +399,10 @@ public class Synchronizer
         System.out.println();
     }
 
+    
+    
+    
+    
     private  void preProcessPackage(PackageState theState)
     {
         String path = cachedir + File.separator + theState.getPath();
@@ -471,7 +517,7 @@ public class Synchronizer
             lastSingleWP = wallpaper;
 
             String targetfile = bframedir + "bframe_" + i + ".jpg";
-            processWallpaper(wallpaper, lastSingleWP, targetfile, true, lastPicIsSquashable, true);
+            processWallpaper(wallpaper, lastSingleWP, targetfile, true, lastPicIsSquashable, true,packageOffset,i);
             bframes.add(targetfile);
             i++;
             progressBar.tickOne();
@@ -488,7 +534,7 @@ public class Synchronizer
             progressBar.setMessage("Dateien:" + currentFile + "/" + totalFiles);
             String targetFilenameBase = String.format("%04d", packageOffset) + "_a_" + String.format("%06d", i);
             String targetfile = outdir + targetFilenameBase + ".jpg";
-            boolean[] swp = processWallpaper(wallpaper, lastSingleWP, targetfile, true, lastPicIsSquashable, false);
+            boolean[] swp = processWallpaper(wallpaper, lastSingleWP, targetfile, true, lastPicIsSquashable, false,packageOffset,i);
             i++;
             if (swp[0])
             {
@@ -515,7 +561,7 @@ public class Synchronizer
             progressBar.setMessage("Dateien:" + currentFile + "/" + totalFiles);
             String targetFilenameBase = String.format("%04d", packageOffset) + "_b_" + String.format("%06d", i);
             String targetfile = outdir + targetFilenameBase + ".jpg";
-            boolean[] swp = processWallpaper(wallpaper, lastSingleWP, targetfile, false, lastPicIsSquashable, false);
+            boolean[] swp = processWallpaper(wallpaper, lastSingleWP, targetfile, false, lastPicIsSquashable, false,packageOffset,i);
             i++;
             if (swp[0])
             {
@@ -541,12 +587,36 @@ public class Synchronizer
         //proc & BFrame= WxH!
     }
 
-    private  boolean[] processWallpaper(Wallpaper wallpaper, Wallpaper fallback, String targetfile, boolean allowStretch, boolean fallbackSquashable, boolean isBFrame)
+    private void identifyAll(CacheState st)
     {
-        l.trace(wallpaper.getFilepath());
-        l.trace(currentFile);
-        boolean wallpaperIsSingle = false;
-        boolean skipped = true;
+        progressBar = progressBar.withTotalSteps(totalFiles + 1);
+        progressBar.setMessage("Analysisere:0/" + totalFiles);
+        progressBar.start();
+        currentFile=1;
+        HashMap<String,PackageState> packages = st.getPackages();
+        packages.forEach((id,pkg)->{
+            pkg.getB_frames().forEach(this::identify);
+            pkg.getFixedRatioPics().forEach(this::identify);
+            pkg.getStretchablePics().forEach(this::identify);
+        });
+        progressBar.complete();
+    }
+    
+    
+    private void identify(Wallpaper wallpaper)
+    {
+        progressBar.setMessage("Analysiere:" + currentFile + "/" + totalFiles);
+        progressBar.tickOne();
+        currentFile++;
+        File wallpaperfile = new File(wallpaper.getFilepath());
+        long wallpapersize = wallpaperfile.length();
+        if(wallpaper.isValid()
+                &&wallpaperfile.exists()
+                &&wallpapersize==wallpaper.getFilesize()
+        )
+        {
+            return; //assumeing the file did not change
+        }
         String content ="1 1";
         if(!debug)
         {
@@ -567,27 +637,34 @@ public class Synchronizer
         {
             wpX = Integer.parseInt(r[0].trim());
             wpY = Integer.parseInt(r[1].trim());
+            wallpaper.setHeight(wpY);
+            wallpaper.setWidth(wpX);
+            wallpaper.setFilesize(wallpapersize);
+            wallpaper.setValid(true);
         }
         catch(NumberFormatException bonkers)
         {
             System.out.println();
             l.error("Got a invalid \"identify\" response:\n{} \nwhile processing {}",content,wallpaper.getFilepath());
-            if(!dryRun)
-            {
-                throw bonkers;
-                
-            }
-            else
-            {
-                System.out.println();
-                
-            }
-            
+            wallpaper.setValid(false);
         }
+    }
+    
+    
+    
+    private  boolean[] processWallpaper(Wallpaper wallpaper, Wallpaper fallback, String targetfile, boolean allowStretch, boolean fallbackSquashable, boolean isBFrame,int packageid,int fileoffset)
+    {
+        l.trace(wallpaper.getFilepath());
+        l.trace(currentFile);
+        boolean wallpaperIsSingle = false;
+        boolean skipped = true;
+
         if(dryRun)
         {
             return new boolean[]{false,false};
         }
+        int wpX=wallpaper.getWidth();
+        int wpY=wallpaper.getHeight();
         int[] ratio = WPCUtils.getRatio(wpX, wpY);
         int screensofWP = WPCUtils.getScreensInRatio(ratio);
         if (screensofWP == 1 || wpX < 1500 || (wpX < 2500 && !allowStretch) || isBFrame)//to prevent too small wallpapers from entering Multiscreen handling
@@ -602,13 +679,37 @@ public class Synchronizer
             List<String> convertCmd = new ArrayList<>();
             String[] convertPrefix =
             {
-                imagemagickPath+File.separator+"convert.exe", "-respect-parentheses", "-size", width + "x" + height, "xc:black"
+                imagemagickPath+File.separator+"convert.exe", "-respect-parentheses"
             };
             convertCmd.addAll(Arrays.asList(convertPrefix));
+            if(wallpaper.isValid())
+            {
+            String[] convertFiles =
+            {
+                wallpaper.getFilepath(),"+write","mpr:wallpaper","+delete"
+            };
+            convertCmd.addAll(Arrays.asList(convertFiles));
+            }
+            else
+            {
+                int seed = (packageid<<16)+fileoffset;
+                String[] convertFiles =
+                {
+                    "(", "(", "-size" ,"2000x3000", "xc:" ,"-seed" ,""+seed ,"+noise" ,"Random" ,"-write" ,"mpr:rand" ,"-extent", "2000x3000" ,"-page" ,
+                    "+50-40", "mpr:rand", "-page" ,"+50+40" ,"mpr:rand", "-flatten", ")", "-virtual-pixel", "tile", "-paint" ,"40", "-shade" ,
+                    "60x1",  "+write", "mpr:chalkboard", ")", "+delete"
+                };
+                convertCmd.addAll(Arrays.asList(convertFiles));
+            }
+            String[] convertSetupSize =
+            {
+                "-size", width + "x" + height, "xc:black"
+            };
+            convertCmd.addAll(Arrays.asList(convertSetupSize));
             // identify rose.jpg
             // rose.jpg JPEG 70x46 70x46+0+0 8-bit sRGB 2.36KB 0.000u 0:00.000
-
-            if (wallpaperIsSingle)
+            
+            if (wallpaperIsSingle||!wallpaper.isValid())
             {
                 l.trace("1");
                 for (Screen screen : screens)
@@ -617,11 +718,22 @@ public class Synchronizer
                     int y = screen.getY();
                     int sw = screen.getW();
                     int sh = screen.getH();//page +5+10  balloon.gif
-                    String[] core =
+                    String[] core = null;
+                    if(wallpaper.isValid())
+                        core = new String[]{
+                            "(", "-size", sw + "x" + sh, debug ? "xc:red" : "xc:black", "-gravity", "center",
+                            "mpr:wallpaper", "-resize", sw + "x" + sh + (allowStretch ? "!" : ">"), "-composite", ")"
+                        };
+                    else
                     {
-                        "(", "-size", sw + "x" + sh, debug ? "xc:red" : "xc:black", "-gravity", "center",
-                        wallpaper.getFilepath(), "-resize", sw + "x" + sh + (allowStretch ? "!" : ">"), "-composite", ")"
-                    };
+                        
+                        String filename = FileTK.getFileName(targetfile);
+                        core=new String[]{
+                            "(","(","-size",sw+"x"+sh, "tile:mpr:chalkboard", ")"
+                                ,"-font", "Comic-Sans-MS", "-fill", "red", "-draw", "\"gravity center  font-size 80 text 0,0 'ERROR'\"", 
+                            "-draw", "\"gravity south-east  font-size 15 text 0,0 '"+filename+"'\"", ")"
+                        };
+                    }
                     insertIntoConvert(x, y, convertCmd, core);
                 }
             }
@@ -705,7 +817,7 @@ public class Synchronizer
                                     "(",
                                         "(",
                                             "-size", targetWidth + "x" + targetHeight, "xc:" + wpreplacements[i % wpreplacements.length], "-gravity", "center",
-                                            wallpaper.getFilepath(), "-resize", targetWidth + "x" + targetHeight + (allowStretch ? "!" : ">"), "-composite",
+                                            "mpr:wallpaper", "-resize", targetWidth + "x" + targetHeight + (allowStretch ? "!" : ">"), "-composite",
                                         ")",
                                         "-gravity", "northwest", "-crop", sw + "x" + sh + "+" + baseX + "+0",
                                     ")"
@@ -742,7 +854,7 @@ public class Synchronizer
                         }
                     }
                 }
-                //--seed <numeric_seed> to feed randomizer
+                //-seed <numeric_seed> to feed randomizer
                 workingSet.forEach((nothing, screen) ->
                 {
                     int x = screen.getX();

+ 70 - 4
WPCMGr/src/main/java/de/nplusc/izc/Utilities/WPCMgr/Wallpaper.java

@@ -30,16 +30,24 @@ public class Wallpaper
     private String filepath;
     private boolean upgradeToProfiles=false;
     private HashMap<String,Integer> screenhashs = new HashMap<>();
+    private long filesize = -1;
     
-    public int getScreenHash()
+    private int width=-1;
+    private int height=-1;
+    
+    private boolean valid=false;
+
+    public boolean isValid()
     {
-        return screenHash;
+        return valid;
     }
 
-    public void setScreenHash(int screenHash)
+    public void setValid(boolean valid)
     {
-        this.screenHash = screenHash;
+        this.valid = valid;
     }
+    
+    
     public void upgrade()
     {
         if(!upgradeToProfiles)
@@ -47,7 +55,65 @@ public class Wallpaper
             screenhashs.put("default", screenHash);
         }
         upgradeToProfiles=true;
+        
+    }
+    
+    
+    public int getWidth()
+    {
+        return width;
+    }
+
+    public void setWidth(int width)
+    {
+        this.width = width;
+    }
+
+    public int getHeight()
+    {
+        return height;
+    }
+
+    public void setHeight(int height)
+    {
+        this.height = height;
     }
+ 
+    
+    
+    
+   
+
+    /**
+     * Get the value of filesize
+     *
+     * @return the value of filesize
+     */
+    public long getFilesize()
+    {
+        return filesize;
+    }
+
+    /**
+     * Set the value of filesize
+     *
+     * @param filesize new value of filesize
+     */
+    public void setFilesize(long filesize)
+    {
+        this.filesize = filesize;
+    }
+
+    public int getScreenHash()
+    {
+        return screenHash;
+    }
+
+    public void setScreenHash(int screenHash)
+    {
+        this.screenHash = screenHash;
+    }
+
     public int getScreenHash(String profile)
     {