Small changes usability changes
authorMaximilian Quellmalz <maximilian.quellmalz@mailbox.tu-dresden.de>
Fri, 12 Dec 2014 14:03:14 +0000 (15:03 +0100)
committerMaximilian Quellmalz <maximilian.quellmalz@mailbox.tu-dresden.de>
Fri, 12 Dec 2014 14:03:14 +0000 (15:03 +0100)
Splitter-ng-filesplitter/src/Filesplitter.java

index b4fc770..9f358fa 100644 (file)
@@ -5,16 +5,16 @@ import java.nio.file.Files;
 import java.nio.file.LinkOption;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Scanner;
-import java.util.Set;
+import java.util.SortedSet;
 import java.util.TreeMap;
+import java.util.TreeSet;
 
 import org.ini4j.Ini;
 import org.ini4j.Profile.Section;
@@ -159,7 +159,7 @@ public class Filesplitter implements SplitterCallback {
                        }
                        Scanner in = new Scanner(commandline);
                        switch (in.next()) {
-                       case "EOF":
+                       //case "EOF":
                        case "q":
                        case "quit":
                        case "exit":
@@ -286,16 +286,6 @@ public class Filesplitter implements SplitterCallback {
 
                                break;
                        case "enc":
-                               int splitternr;
-                               Splitter splitter;
-                               try {
-                                       splitternr = in.nextInt();
-                                       splitter = splitters.get(splitternr);
-                               } catch (Exception e1) {
-                                       // TODO Auto-generated catch block
-                                       println_err("no valid Splitter-Infex. Use 'ls splitter' to show valid indices");
-                                       break;
-                               }
                                String filename;
                                Path srcfile = null;
                                try {
@@ -306,7 +296,17 @@ public class Filesplitter implements SplitterCallback {
                                                throw new Exception();
                                        }
                                } catch (Exception e1) {
-                                       println_err("no valid Filename. Use 'enc <splitternr> <Filename>'");
+                                       println_err("no valid Filename. Use 'enc <Filename> <splitternr>'");
+                                       break;
+                               }
+                               int splitternr;
+                               Splitter splitter;
+                               try {
+                                       splitternr = in.nextInt();
+                                       splitter = splitters.get(splitternr);
+                               } catch (Exception e1) {
+                                       // TODO Auto-generated catch block
+                                       println_err("no valid Splitter-Infex. Use 'ls splitter' to show valid indices");
                                        break;
                                }
                                try {
@@ -447,6 +447,7 @@ public class Filesplitter implements SplitterCallback {
                                }
                        }
                }
+               Collections.sort(codeclist);
        }
 
        private boolean isInConfig(String id) {
@@ -523,6 +524,7 @@ public class Filesplitter implements SplitterCallback {
                        return;
                }
                config.remove(config.get(id));
+               config.remove(config.get(id+"_MetadataTemplate"));
                saveconfig();
                if (codeclist_configured.contains(id)){
                        codeclist_configured.remove(id);
@@ -559,28 +561,64 @@ public class Filesplitter implements SplitterCallback {
                                        }
                                        print_codecdescription(p, c);
                                        println_std(id + " Configuration:");
-                                       for (Entry<String, Integer[]> entry : c
-                                                       .getCodecParameterMinMax().entrySet()) {
-                                               print_std(entry.getKey());
-                                               print_std("\tmin="+ c.getCodecParameterMinMax().get(entry.getKey())[0]);
-                                               print_std("\tmax="+ c.getCodecParameterMinMax().get(entry.getKey())[1]);
-                                               if (c.getCodecParameterDefaults().get(entry.getKey()) != null) {
-                                                       print_std("\tdefault="
-                                                                       + c.getCodecParameterDefaults().get(
-                                                                                       entry.getKey()));
-                                                       section.put(entry.getKey(), readCommandline("\t"+entry.getKey()+"=",true));
-                                               }
-                                               else {
-                                                       section.put(entry.getKey(), readCommandline("\t"+entry.getKey()+"=",false));
+                                       Map<String, Integer[]> mapminmax = c.getCodecParameterMinMax();
+                                       Map<String, Integer> mapdefault = c.getCodecParameterDefaults();
+                                       SortedSet<String> keyset = new TreeSet<>(mapminmax.keySet());
+                                       Integer[] minmax;
+                                       Integer defaultval;
+                                       
+                                       String key = "k";
+                                       minmax = mapminmax.get(key);
+                                       print_std(key);
+                                       print_std("\tmin="+ minmax[0]);
+                                       print_std("\tmax="+ minmax[1]);
+                                       section.put(key, readCommandline("\t"+key+"=",false));
+                                       
+                                       key = "m";
+                                       minmax = mapminmax.get(key);
+                                       print_std(key);
+                                       print_std("\tmin="+ minmax[0]);
+                                       print_std("\tmax="+ minmax[1]);
+                                       section.put(key, readCommandline("\t"+key+"=",false));
+                                       
+                                       for ( String key1 : keyset) {
+                                               if (key1 != "k" && key1 != "m") {
+                                                       print_std(key1);
+                                                       minmax = mapminmax.get(key1);
+                                                       defaultval = mapdefault.get(key1);
+                                                       print_std("\tmin=" + minmax[0]);
+                                                       print_std("\tmax=" + minmax[1]);
+                                                       if (defaultval != null) {
+                                                               print_std("\tdefault=" + defaultval);
+                                                               section.put(
+                                                                               key1,
+                                                                               readCommandline("\t" + key1 + "=", true));
+                                                       } else {
+                                                               section.put(
+                                                                               key1,
+                                                                               readCommandline("\t" + key1 + "=",
+                                                                                               false));
+                                                       }
+
                                                }
-                                       }
-                                       println_std("");
+                               }
 
                                        section = config.get(id + "_MetadataTemplate");
                                        if (section == null) {
                                                section = config.add(id + "_MetadataTemplate");
                                        }
-                                       section.put("fragmentsize", "4096");
+                                       key = "fragmentsize";
+                                       defaultval = 4096;
+                                       print_std(key);
+                                       print_std("\tdefault=" + defaultval);
+                                       String result = readCommandline("\t" + key + "=",true);
+                                       try {
+                                               section.put(key, Integer.parseInt(result));
+                                       } catch (Exception e) {
+                                               section.put(key, defaultval);
+                                       }
+                                       
+                                       println_std("");
                                        saveconfig();
                                        init_codec(id);
                                }
@@ -713,17 +751,18 @@ public class Filesplitter implements SplitterCallback {
                println_std("Bedienung:");
                println_std("init");
                println_std("reset");
-               println_std( "ls splitter\tlistet alle initialisierten Splitter auf");
-               println_std( "ls codec\t\tlistet alle codecs auf");
-               println_std("ls enc\t\tlistet alle fertig encodierten Tasks auf");
-               println_std("ls dec\t\tlistet alle fertig decodierten Tasks auf");
-               println_std("ls frag <nr>\tlistet die Fragmentdateien zu Encoding-Task <nr> auf");
-               println_std("rm <nr> <frac_nr>\tlöscht aus Encoding-Task <nr> die Fragmentdatei <frac_nr>");
-               println_std("dec <nr>\twiederherstellen der Originaldatei aus Encoding-Task <nr> in das Verzeichnis restoreDir");
-               println_std("enc <splitternr> <filename>\tencodieren files with a splitter");
-               println_std("meta enc <nr>\tgibt metadaten zu encodingtask <nr> aus");
-               println_std("meta dec <nr>\tgibt metadaten zu decodingtask <nr> aus");
-               println_std("q, quit oder exit\tbeenden das Programm");
+               println_std("ls splitters           list all initiated splitters");
+               println_std("ls codecs              list all available codecs");
+               println_std("ls enc                 list all encoded Tasks");
+               println_std("ls dec                 list all decoded Tasks");
+               println_std("ls frag <nr>           list fragments of encoded task <nr>");
+               println_std("rm <nr> <frac_nr>      delete fragment <frac_nr> of encoded task <nr>");
+               println_std("dec <nr>               recover original file from encoded task <nr> into ./restoreDir");
+               //println_std("enc <file>             encode file with all splitters");
+               println_std("enc <file> <sp_nr>     encode file with a specific splitter");
+               println_std("meta enc <nr>          show metada of encoded task <nr>");
+               println_std("meta dec <nr>          show metada of decoded task <nr>");
+               println_std("q, quit oder exit      Exit");
                // +" \nh oder help\tzeigt die Hilfe an"
                println_std("");
        }