소스 검색

quick and dirty hack for avoiding skipped folders
first version of copy&extract added

LH 6 년 전
부모
커밋
a446f78db4

+ 4 - 0
iZpl/src/main/java/de/nplusc/izc/iZpl/API/IZPLApi.java

@@ -22,6 +22,9 @@ import de.nplusc.izc.iZpl.API.shared.PlayListFile;
 import de.nplusc.izc.iZpl.API.shared.SinglePlayListItem;
 import de.nplusc.izc.iZpl.API.shared.PlayListItem;
 import de.nplusc.izc.iZpl.Main;
+import de.nplusc.izc.iZpl.PLServer;
+import de.nplusc.izc.iZpl.PlProcessor;
+import de.nplusc.izc.iZpl.PlProcessorV2;
 import de.nplusc.izc.iZpl.Utils.shared.PLFileIO;
 import java.awt.Image;
 import java.io.File;
@@ -86,6 +89,7 @@ public class IZPLApi
     {
         return Main.getPluginManager().getSelectedSkinPath();
     }
+    
     /**
      * Exits the program without saving the statefile for the current session. Recommended in case of a error
      */

+ 21 - 0
iZpl/src/main/java/de/nplusc/izc/iZpl/API/PlayListEditAPI.java

@@ -9,6 +9,8 @@ import de.nplusc.izc.iZpl.API.shared.SinglePlayListItem;
 import de.nplusc.izc.iZpl.API.shared.PlayListItem;
 import de.nplusc.izc.iZpl.API.shared.MultiPlayListItem;
 import de.nplusc.izc.iZpl.Main;
+import de.nplusc.izc.iZpl.PLServer;
+import de.nplusc.izc.iZpl.PlProcessorV2;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
@@ -49,6 +51,25 @@ public class PlayListEditAPI
     private static List<String> playListItemKeys = new ArrayList<>();//wird genutzt um idx auf hasmap zu linkern
     
     
+    /**
+     * Obtains the path of the current playlist loaded. May be empty if nothing is loaded
+     */
+    public static String getCurrentPlaylist()
+    {
+        PLServer p = Main.getPLServer();
+        if(p==null)
+        {
+            return "";
+        }
+        PlProcessorV2 ppp = p.getPlProcessorV2();
+        if(ppp==null)
+        {
+            return "";
+        }  
+        
+        return ppp.getPath();
+    }
+    
     /**
      * reloads the data from the Playlist managment. Use after any change
      */

+ 17 - 48
iZpl/src/main/java/de/nplusc/izc/iZpl/PlProcessorV2.java

@@ -22,7 +22,6 @@ import com.sun.net.httpserver.Headers;
 import com.sun.net.httpserver.HttpExchange;
 import com.sun.net.httpserver.HttpHandler;
 import de.nplusc.izc.iZpl.API.IZPLApi;
-import de.nplusc.izc.iZpl.API.UIPlugin;
 import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
 import de.nplusc.izc.iZpl.Utils.shared.PLFileIO;
 import java.io.File;
@@ -38,7 +37,6 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -374,25 +372,18 @@ public class PlProcessorV2 implements HttpHandler
     
     private void registerChangedFolders(String folder)
     {
-        
-        synchronized(registeredFolders)
+        Path p = new File(folder).toPath();
+        try
         {
-            if(!registeredFolders.containsKey(folder)&&observer != null)
-            {
-                Path p = new File(folder).toPath();
-                try
-                {
-                    WatchKey k = p.register(observer,
-                            StandardWatchEventKinds.ENTRY_CREATE,
-                            StandardWatchEventKinds.ENTRY_DELETE,
-                            StandardWatchEventKinds.ENTRY_MODIFY);
-                    registeredFolders.put(path, k);
-                } 
-                catch (IOException ex)
-                {
-                    l.info("Failed to register the observer");
-                }
-            }
+            WatchKey k = p.register(observer,
+                    StandardWatchEventKinds.ENTRY_CREATE,
+                    StandardWatchEventKinds.ENTRY_DELETE,
+                    StandardWatchEventKinds.ENTRY_MODIFY);
+            registeredFolders.put(path, k);
+        } 
+        catch (IOException ex)
+        {
+            l.info("Failed to register the observer");
         }
     }
     
@@ -418,31 +409,12 @@ public class PlProcessorV2 implements HttpHandler
                 return;
             }
             l.trace("Incoming Changeset");
-            synchronized(registeredFolders)
+            //
+            if(key.isValid())
             {
-                if(registeredFolders.containsValue(key))
-                {
-                    //
-                    if(key.isValid())
-                    {
-                        synchronized(refreshLock)
-                        {
-                            requiresRefresh=true;
-                        }
-                    }
-                    else
-                    {
-                        List<String> removeMes = new LinkedList<>();
-                        registeredFolders.entrySet().stream().filter((entry) -> (entry.getValue().equals(key))).forEach((entry) ->
-                        {
-                            removeMes.add(entry.getKey());
-                        });
-                        removeMes.forEach((x)->{registeredFolders.remove(x);});
-                    }
-                }
-                else
+                synchronized(refreshLock)
                 {
-                    l.trace("Unexpected Notification");
+                    requiresRefresh=true;
                 }
             }
             key.pollEvents();
@@ -450,7 +422,8 @@ public class PlProcessorV2 implements HttpHandler
             l.trace(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Notification parsed");
         }
     }
-    @SuppressWarnings("SleepWhileInLoop")
+    
+    @SuppressWarnings({"SleepWhileInLoop", "CallToPrintStackTrace"})
     private void FSWatchFilter()
     {
         try
@@ -482,9 +455,5 @@ public class PlProcessorV2 implements HttpHandler
             e.printStackTrace();
         }
     }
-    
-    
-               
-    
 }
 

+ 1 - 0
iZplPlugins/Extractor/.gitignore

@@ -0,0 +1 @@
+auxy

+ 12 - 0
iZplPlugins/Extractor/build.gradle

@@ -0,0 +1,12 @@
+apply plugin:'java'
+task distZip(dependsOn: 'jar') {
+	//NO-OPtask als redirect
+}
+
+dependencies
+{
+	compile fileTree(dir: 'lib', include: '*.jar')
+	compile project(':iZpl')
+}
+
+

+ 161 - 0
iZplPlugins/Extractor/src/main/java/de/nplusc/izc/izpl/plugins/extractor/Extractor.java

@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2018 iZc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.nplusc.izc.izpl.plugins.extractor;
+
+import de.nplusc.izc.iZpl.API.FeaturePlugin;
+import de.nplusc.izc.iZpl.API.IZPLApi;
+import de.nplusc.izc.iZpl.API.PlayListEditAPI;
+import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
+import de.nplusc.izc.iZpl.API.shared.RawPlayListFile;
+import de.nplusc.izc.iZpl.API.shared.SinglePlayListItem;
+import de.nplusc.izc.iZpl.Utils.shared.PLFileIO;
+import de.nplusc.izc.tools.IOtools.FileTK;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ *
+ * @author iZc <nplusc.de>
+ */
+public class Extractor implements FeaturePlugin
+{
+    private static final Logger l = LogManager.getLogger(Extractor.class.getName());
+    
+    @Override
+    public void parseParameter(String param)
+    {
+        File base = new File(param);
+        String basePath = base.getAbsolutePath();
+        if(base.exists()&&base.isDirectory())
+        {
+            String iZplPath = PlayListEditAPI.getCurrentPlaylist();
+            File izplFile = new File(iZplPath);
+            String absoluteiZplPath = izplFile.getAbsolutePath();
+            String relativizediZplPath = FileTK.getRelativePath(absoluteiZplPath, basePath);
+            if(relativizediZplPath.equals(absoluteiZplPath)||relativizediZplPath.startsWith(".."))
+            {
+                l.error("IZPL-Folder not inside base folder. Cannot continue.");
+            }
+            else
+            {
+                String targetDir = new File(".").getAbsolutePath();
+                try
+                {
+                    getCopyStepList(basePath, targetDir, absoluteiZplPath);
+                }
+                catch(InvalidPlayListFileException e)
+                {
+                    l.error("Cannot continue, Invalid playlist file");
+                    e.printStackTrace();
+                }
+            }
+        }
+        else
+        {
+            l.error("Invalid path given for the plugin.");
+        }
+        
+        //intentionally quick quitting since the statefile should never get changed
+        IZPLApi.quickQuitWithoutSaving();
+    }
+
+    private HashMap<String,String> getCopyStepList(String baseDir,String targetDir,String startList) throws InvalidPlayListFileException
+    {
+        HashMap<String,String> results = new HashMap<>();
+        boolean moreToHandle = true;
+        List<String> processedRootPaths = new ArrayList<String>();
+        List<String> scheduledPaths = new ArrayList<>();
+        scheduledPaths.add(startList);
+        l.trace("basedir|targetDir|startList:{}|{}|{}",baseDir,targetDir,startList);
+        while(moreToHandle)
+        {
+            ArrayList<String> temp = new ArrayList(scheduledPaths);
+            scheduledPaths.clear(); //resetting for the second part of the loop;
+            moreToHandle=false;
+            for (String currentList : temp)
+            {
+                if(processedRootPaths.contains(currentList))
+                {
+                    continue;
+                }
+                else
+                {
+                    RawPlayListFile currentData = PLFileIO.readSingleList(currentList);
+                    List<SinglePlayListItem> currentEntries = currentData.getData();
+                    for (SinglePlayListItem currentEntry : currentEntries)
+                    {
+                        File newItem = new File(currentEntry.getPath());
+                        if(currentEntry.isIncludeElement())
+                        {
+                            
+                        }
+                        else
+                        {
+                            
+                        }
+                    }
+                }
+            }
+            
+        }
+        
+        return null;
+    }
+    
+    
+    @Override
+    public boolean hasUserInterface()
+    {
+        return false;
+    }
+
+    @Override
+    public void openUserInterface()
+    {
+        return; //TODO UI?
+    }
+
+    @Override
+    public boolean requiresLoadedPlayList()
+    {
+        return true;
+    }
+
+    @Override
+    public String getPluginName()
+    {
+        return "Extractor";
+    }
+
+    @Override
+    public void initializePlugin()
+    {
+        return;
+    }
+
+    @Override
+    public void prepareUpgrade()
+    {
+        return;
+    }
+    
+}
+

+ 11 - 0
iZplPlugins/Extractor/src/main/resources/plugin.yml

@@ -0,0 +1,11 @@
+pluginbaseclass: de.nplusc.izc.izpl.plugins.extractor.Extractor
+supportedoses:
+  - 'windows'
+  - 'mac'
+  - 'linux'
+# can be windows, mac or linux
+supportedarchitectures:
+  - 'x86'
+  - 'x64'
+  - 'arm'
+# x86 or x64 valid

+ 2 - 1
settings.gradle

@@ -1,3 +1,4 @@
 include 'ToolKit','iZpl',  'IZSetup','WPCMGr','UpidTK', 'izstreamer', 'LogBlockHeatMapper','iZlaunch',
 'iZpaqSFX','MazeViewer','TWPUtil',"iZplPlugins:WMP","iZplPlugins:foobar2000_others","iZplPlugins:itunes","iZplPlugins:GameRadio",
-"iZplPlugins:Editor","izpl-shared","iZpl-server","iZplPlugins:Smartphonizer","QuickStuff","external:java-progressbar","iZplPlugins:rtsslink","iZplPlugins:JukeBox"
+"iZplPlugins:Editor","izpl-shared","iZpl-server","iZplPlugins:Smartphonizer","QuickStuff","external:java-progressbar","iZplPlugins:rtsslink","iZplPlugins:JukeBox",
+"iZplPlugins:Extractor"