Forráskód Böngészése

izpl-0.9.0.0
[extractor] fixed some log messages messing with the progressbar containing the
progress too

LH 6 éve
szülő
commit
41195447cb

+ 7 - 38
ToolKit/src/main/java/de/nplusc/izc/tools/IOtools/FileTK.java

@@ -24,6 +24,8 @@ import java.lang.reflect.Method;
 import java.nio.CharBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.CopyOption;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import org.apache.logging.log4j.LogManager;
@@ -560,54 +562,21 @@ public class FileTK
     }
     /**
      * Fatei kopieren
-     * Code ist ausm netz: http://www.javabeginners.de/Dateien_und_Verzeichnisse/Eine_Datei_kopieren.php
+     * Kimpat-Wrapper
      * @param in Eingabefile
      * @param out Ausgabefile
      * @throws IOException 
      */
-    
+    @Deprecated
     public static void kopierpaste(File in, File out) //throws IOException
     {
-        FileChannel inChannel=null,outChannel=null;
         try
         {
-        inChannel = new FileInputStream(in).getChannel();
-        outChannel = new FileOutputStream(out).getChannel();
-
-
-
-            inChannel.transferTo(0, inChannel.size(), outChannel);
-        }
-        catch (IOException e)
-        {
-            e.printStackTrace();
-            l.error("Kopiererei geerrort");
-          //  throw e;
+            Files.copy(in.toPath(), out.toPath());
         }
-        finally
+        catch (IOException ex)
         {
-            if (inChannel != null)
-            {
-                try
-                {
-                    inChannel.close();
-                }
-                catch (IOException ex)
-                {
-                    ex.printStackTrace();
-                }
-            }
-            if (outChannel != null)
-            {
-                try
-                {
-                    outChannel.close();
-                }
-                catch (IOException ex)
-                {
-                    ex.printStackTrace();
-                }
-            }
+            l.error("Kopieren fehlgeschlagen");
         }
     }
         

+ 5 - 1
iZpl/build.gradle

@@ -3,13 +3,14 @@ evaluationDependsOn(':iZplPlugins:WMP')
 evaluationDependsOn(':iZplPlugins:Editor')
 evaluationDependsOn(':iZplPlugins:rtsslink')
 evaluationDependsOn(':iZplPlugins:JukeBox')
+evaluationDependsOn(':iZplPlugins:Extractor')
 defaultTasks 'distZip'
 
 apply plugin: 'java'
 apply plugin: 'application'
 apply from: "$rootDir/utils/IO.gradle"
 
-version = '0.9.0.0-snapshot'
+version = '0.9.0.0'
 mainClassName = 'de.nplusc.izc.iZpl.Main'
 //'de.nplusc.izc.iZpl.Main'
 
@@ -96,6 +97,7 @@ distZip {
         from project(':iZplPlugins:Editor').jar
         from project(':iZplPlugins:rtsslink').jar
 		from project(':iZplPlugins:JukeBox').jar
+        from project(':iZplPlugins:Extractor').jar
   }
 }
 
@@ -136,6 +138,8 @@ dependencies{
     compile group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '2.11.1'
     compile 'org.fusesource.jansi:jansi:1.11'
     compile 'org.jgrapht:jgrapht-core:0.9.0'
+    compile(project(':external:java-progressbar'))
+    
     compile(project(':ToolKit')) {
         transitive = false
     }

+ 45 - 7
iZplPlugins/Extractor/src/main/java/de/nplusc/izc/izpl/plugins/extractor/Extractor.java

@@ -24,7 +24,11 @@ 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 hu.ssh.progressbar.console.ConsoleProgressBar;
 import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -38,7 +42,8 @@ import org.apache.logging.log4j.Logger;
 public class Extractor implements FeaturePlugin
 {
     private static final Logger l = LogManager.getLogger(Extractor.class.getName());
-    
+    private ConsoleProgressBar progressBar;
+    private int copyIndex = 0;
     @Override
     public void parseParameter(String param)
     {
@@ -56,10 +61,34 @@ public class Extractor implements FeaturePlugin
             }
             else
             {
-                String targetDir = new File(".").getAbsolutePath();
+                String targetDir = new File("extracted").getAbsolutePath();
                 try
                 {
-                    getCopyStepList(basePath, targetDir, absoluteiZplPath);
+                    HashMap<String,String> scheduledCopyMes = getCopyStepList(basePath, targetDir, absoluteiZplPath);
+                        progressBar = ConsoleProgressBar.on(System.out)
+                        .withFormat("[:bar] :percent% :elapsed/:total :msg")
+                        .withTotalSteps(scheduledCopyMes.size());
+                    progressBar.start();
+                    final int total = scheduledCopyMes.size();
+                    progressBar.setMessage("Copying:" + 0 + "/" + total);
+                    l.info("Transferring [} files",scheduledCopyMes.size());
+                    scheduledCopyMes.forEach((source,target)->
+                    {
+
+                        FileTK.ensuredirExistence(target);
+                        try
+                        {
+                            l.trace("({}/{}) Copying {} to {}",copyIndex,total,source,target);
+                            Files.copy(new File(source).toPath(), new File(target).toPath(),StandardCopyOption.REPLACE_EXISTING);
+                            progressBar.tickOne();
+                        }
+                        catch (IOException ex)
+                        {
+                            l.warn("\n\nInvalid file {}->{}\n\n",source,target);
+                        }
+                        copyIndex++;
+                        progressBar.setMessage("Kopieren:" + copyIndex + "/" + total);
+                    });
                 }
                 catch(InvalidPlayListFileException e)
                 {
@@ -103,21 +132,30 @@ public class Extractor implements FeaturePlugin
                     for (SinglePlayListItem currentEntry : currentEntries)
                     {
                         File newItem = new File(currentEntry.getPath());
+                        String absoluteEntryPath = newItem.getAbsolutePath();
+                        String relativeEntryPath = FileTK.getRelativePath(absoluteEntryPath, baseDir);
+                        if(relativeEntryPath.equals(absoluteEntryPath)||relativeEntryPath.startsWith(".."))
+                        {
+                            l.error("File not inside base folder. Cannot continue.");
+                            IZPLApi.quickQuitWithoutSaving();
+                        }
+                        
+                        
                         if(currentEntry.isIncludeElement())
                         {
                             scheduledPaths.add(currentEntry.getPath());
+                            moreToHandle=true;
+                            results.put(baseDir+File.separator+relativeEntryPath, targetDir+File.separator+relativeEntryPath);
                         }
                         else
                         {
-                            
+                            results.put(baseDir+File.separator+relativeEntryPath, targetDir+File.separator+relativeEntryPath);
                         }
                     }
                 }
             }
-            
         }
-        
-        return null;
+        return results;
     }