|
@@ -23,6 +23,7 @@ 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.shared.InvalidPlayListFileException;
|
|
|
+import de.nplusc.izc.iZpl.API.shared.SinglePlayListItem;
|
|
|
import de.nplusc.izc.iZpl.Utils.shared.PLFileIO;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
@@ -38,6 +39,8 @@ import java.util.HashMap;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
+
|
|
|
+import de.nplusc.izc.tools.baseTools.Detectors;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
import org.yaml.snakeyaml.Yaml;
|
|
@@ -48,6 +51,8 @@ import org.yaml.snakeyaml.Yaml;
|
|
|
*/
|
|
|
public class PlProcessorV2 implements HttpHandler
|
|
|
{
|
|
|
+ private boolean FileChooserMode = false;
|
|
|
+ private boolean winpath = false;
|
|
|
private static final Logger l = LogManager.getLogger();
|
|
|
private HashMap<String,PlayListItem> pool;
|
|
|
private String path;
|
|
@@ -152,6 +157,37 @@ public class PlProcessorV2 implements HttpHandler
|
|
|
|
|
|
public void InitializeOnPath(String PlPath)
|
|
|
{
|
|
|
+ if(PlPath.equals("///")) //abusing a invalid path for
|
|
|
+ {
|
|
|
+ FileChooserMode = true;
|
|
|
+ if(Detectors.getSystemClassification()[0].equals("windows"))
|
|
|
+ {
|
|
|
+ winpath = true; //used only for handling filechooser logic
|
|
|
+ }
|
|
|
+ String lastchooserpath = Main.CONFIG.getProperty("lastchooserpath");
|
|
|
+ if(lastchooserpath == null)
|
|
|
+ {
|
|
|
+ lastchooserpath = System.getProperty("user.home");
|
|
|
+ File tmp = new File(lastchooserpath);
|
|
|
+ if(!(tmp.exists()&&tmp.isDirectory()))
|
|
|
+ {
|
|
|
+ lastchooserpath=winpath?"C:/":"/";
|
|
|
+ }
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ File tmp = new File(lastchooserpath);
|
|
|
+ if(!(tmp.exists()&&tmp.isDirectory()))
|
|
|
+ {
|
|
|
+ lastchooserpath = System.getProperty("user.home");
|
|
|
+ tmp = new File(lastchooserpath);
|
|
|
+ if(!(tmp.exists()&&tmp.isDirectory()))
|
|
|
+ {
|
|
|
+ lastchooserpath=winpath?"C:/":"/";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PlPath = lastchooserpath;
|
|
|
+ }
|
|
|
Thread t = new Thread(this::FSWatch);
|
|
|
t.setName("FS-Observer");
|
|
|
t.setDaemon(true);
|
|
@@ -166,7 +202,71 @@ public class PlProcessorV2 implements HttpHandler
|
|
|
{
|
|
|
reloadLists(false);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ private boolean fileIsRoot(File f)
|
|
|
+ {
|
|
|
+ for(File iter:File.listRoots())
|
|
|
+ {
|
|
|
+ if(iter.equals(f))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<PlayListItem> synthesizeChooserData(String path)
|
|
|
+ {
|
|
|
+ Main.CONFIG.setProperty("lastchooserpath",path);
|
|
|
+ List<PlayListItem> lst = new ArrayList<>();
|
|
|
+ if(winpath&&path.equals("/")) //simulating root dir for showing drive letters
|
|
|
+ {
|
|
|
+ for(File iter:File.listRoots())
|
|
|
+ {
|
|
|
+ SinglePlayListItem itm = new SinglePlayListItem(iter.getAbsolutePath(),"0,"+iter.getAbsolutePath(),1);
|
|
|
+ lst.add(itm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ File f = new File(path).getAbsoluteFile();
|
|
|
+ if(winpath&&fileIsRoot(f))
|
|
|
+ {
|
|
|
+ SinglePlayListItem itm = new SinglePlayListItem("/","0,"+"../",1);
|
|
|
+ lst.add(itm);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(!(path.equals("/"))) //no .. entry on rootdir
|
|
|
+ {
|
|
|
+ SinglePlayListItem itm = new SinglePlayListItem(f.getParent(),"0,"+"../",1);
|
|
|
+ lst.add(itm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(File iter: f.listFiles())
|
|
|
+ {
|
|
|
+ String fname = iter.getName();
|
|
|
+ String[] fextinternal = fname.split("\\.");
|
|
|
+ String fext = fextinternal[fextinternal.length-1];
|
|
|
+
|
|
|
+ if(iter.isDirectory())
|
|
|
+ {
|
|
|
+ SinglePlayListItem itm = new SinglePlayListItem(iter.getAbsolutePath(),"0,"+fname+"/",1);
|
|
|
+ lst.add(itm);
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(fext.equalsIgnoreCase("izpl")||fext.equalsIgnoreCase("izcont")||fext.equalsIgnoreCase("m3u"))
|
|
|
+ {
|
|
|
+ SinglePlayListItem itm = new SinglePlayListItem(iter.getAbsolutePath(),"0,"+fname,1);
|
|
|
+ lst.add(itm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ l.trace(yp.dump(lst));
|
|
|
+ return lst;
|
|
|
+ }
|
|
|
+
|
|
|
public void reloadLists(boolean reload)
|
|
|
{
|
|
|
|
|
@@ -175,15 +275,51 @@ public class PlProcessorV2 implements HttpHandler
|
|
|
List<PlayListItem> inp;
|
|
|
try
|
|
|
{
|
|
|
- inp = PLFileIO.parseFullList(path,this::registerChangedFolders);
|
|
|
+ if(FileChooserMode)
|
|
|
+ {
|
|
|
+ if((new File(path).isDirectory()||path.equals("/")))
|
|
|
+ {
|
|
|
+ inp = synthesizeChooserData(path);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ String[] fextinternal = new File(path).getName().split("\\.");
|
|
|
+ String fext = fextinternal[fextinternal.length-1];
|
|
|
+ if(fext.equalsIgnoreCase("izcont"))
|
|
|
+ {
|
|
|
+ FileChooserMode = false;
|
|
|
+ PlProcessorV2 copysrc = Main.reloadFromFile(path);
|
|
|
+ this.options = copysrc.options;
|
|
|
+ this.pool = copysrc.pool;
|
|
|
+ this.forceList = copysrc.forceList;
|
|
|
+ this.history = copysrc.history;
|
|
|
+ this.path = copysrc.path;
|
|
|
+ inp = PLFileIO.parseFullList(path,this::registerChangedFolders);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FileChooserMode = false;
|
|
|
+ inp = PLFileIO.parseFullList(path,this::registerChangedFolders);
|
|
|
+ }
|
|
|
+ Main.saveConfig();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ inp = PLFileIO.parseFullList(path,this::registerChangedFolders);
|
|
|
+ }
|
|
|
}
|
|
|
catch (InvalidPlayListFileException ex)
|
|
|
{
|
|
|
l.error("invalid playlist file");
|
|
|
Main.quickQuit();
|
|
|
return;
|
|
|
+ } catch (IOException e) {
|
|
|
+ l.error("invalid playlist file");
|
|
|
+ Main.quickQuit();
|
|
|
+ return;
|
|
|
}
|
|
|
- int clampPlayCount = 0;
|
|
|
+ int clampPlayCount = 0;
|
|
|
if(options.containsKey("PLAYCOUNTLIMIT"))
|
|
|
{
|
|
|
try
|
|
@@ -372,8 +508,18 @@ public class PlProcessorV2 implements HttpHandler
|
|
|
|
|
|
public void addElementToForcedList(PlayListItem i)
|
|
|
{
|
|
|
- forceList.add(i);
|
|
|
- IZPLApi.refreshScheduledItemList();
|
|
|
+ if(FileChooserMode)
|
|
|
+ {
|
|
|
+ path = i.getPath();
|
|
|
+ reloadLists();
|
|
|
+ IZPLApi.getUIPlugin().reloadPlayList();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ forceList.add(i);
|
|
|
+ IZPLApi.refreshScheduledItemList();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public int getPoolSize()
|