X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2FMain.java;h=53c4a8629f952075f4519131f5541363f5701f45;hb=85493b380b07146e2b36c0ffe40d2dc17a4ebdf2;hp=70f71ed58a17be21ba36cb5505adcc52056e8596;hpb=62c63b0724f4bc45999cb2e7186b4b3ada479a0a;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/Main.java b/src/be/nikiroo/fanfix/Main.java index 70f71ed..53c4a86 100644 --- a/src/be/nikiroo/fanfix/Main.java +++ b/src/be/nikiroo/fanfix/Main.java @@ -21,11 +21,9 @@ import be.nikiroo.fanfix.reader.BasicReader; import be.nikiroo.fanfix.reader.Reader; import be.nikiroo.fanfix.reader.Reader.ReaderType; import be.nikiroo.fanfix.supported.BasicSupport; -import be.nikiroo.fanfix.supported.BasicSupport.SupportType; +import be.nikiroo.fanfix.supported.SupportType; import be.nikiroo.utils.Progress; -import be.nikiroo.utils.TraceHandler; import be.nikiroo.utils.Version; -import be.nikiroo.utils.serial.server.ConnectActionClientObject; import be.nikiroo.utils.serial.server.ServerObject; /** @@ -201,9 +199,8 @@ public class Main { } else if (port == null) { port = Integer.parseInt(args[i]); - File remoteCacheDir = Instance.getRemoteDir(host); BasicLibrary lib = new RemoteLibrary(key, host, port); - lib = new CacheLibrary(remoteCacheDir, lib); + lib = new CacheLibrary(Instance.getRemoteDir(host), lib); BasicReader.setDefaultLibrary(lib); @@ -224,6 +221,9 @@ public class Main { int diff = progress.getProgress() - current; current += diff; + if (diff <= 0) + return; + StringBuilder builder = new StringBuilder(); for (int i = 0; i < diff; i++) { builder.append('.'); @@ -312,8 +312,8 @@ public class Main { case VERSION: System.out .println(String.format("Fanfix version %s" - + "\nhttps://github.com/nikiroo/fanfix/" - + "\n\tWritten by Nikiroo", + + "%nhttps://github.com/nikiroo/fanfix/" + + "%n\tWritten by Nikiroo", Version.getCurrentVersion())); updates.ok(); // we consider it read break; @@ -334,8 +334,8 @@ public class Main { } try { ServerObject server = new RemoteLibraryServer(key, port); - server.setTraceHandler(new TraceHandler(true, true, true)); - server.start(); + server.setTraceHandler(Instance.getTraceHandler()); + server.run(); } catch (IOException e) { Instance.getTraceHandler().error(e); } @@ -346,22 +346,7 @@ public class Main { break; } - try { - final String fkey = key; - new ConnectActionClientObject(host, port, true) { - @Override - public void action(Version serverVersion) - throws Exception { - try { - send(new Object[] { fkey, "EXIT" }); - } catch (Exception e) { - Instance.getTraceHandler().error(e); - } - } - }.connect(); - } catch (IOException e) { - Instance.getTraceHandler().error(e); - } + new RemoteLibrary(key, host, port).exit(); break; case REMOTE: exitCode = 255; // should not be reachable (REMOTE -> START) @@ -369,6 +354,20 @@ public class Main { } } + // We cannot do it when in GUI mode, because it is async... + // So if we close the temp files before it is actually used, + // we have a problem... + // TODO: close it at the correct time (for now, finalize try to do it) + if (false) { + try { + Instance.getTempFiles().close(); + } catch (IOException e) { + Instance.getTraceHandler().error( + new IOException( + "Cannot dispose of the temporary files", e)); + } + } + if (exitCode == 255) { syntax(false); } @@ -524,10 +523,11 @@ public class Main { * * @return the exit return code (0 = success) */ - private static int convert(String urlString, String typeString, + public static int convert(String urlString, String typeString, String target, boolean infoCover, Progress pg) { int exitCode = 0; + Instance.getTraceHandler().trace("Convert: " + urlString); String sourceName = urlString; try { URL source = BasicReader.getUrl(urlString); @@ -548,6 +548,7 @@ public class Main { BasicSupport support = BasicSupport.getSupport(source); if (support != null) { + Instance.getTraceHandler().trace("Support found: " + support.getClass()); Progress pgIn = new Progress(); Progress pgOut = new Progress(); if (pg != null) { @@ -556,11 +557,11 @@ public class Main { pg.addProgress(pgOut, 1); } - Story story = support.process(source, pgIn); + Story story = support.process(pgIn); try { target = new File(target).getAbsolutePath(); - BasicOutput.getOutput(type, infoCover).process( - story, target, pgOut); + BasicOutput.getOutput(type, infoCover, infoCover) + .process(story, target, pgOut); } catch (IOException e) { Instance.getTraceHandler().error( new IOException(trans(StringId.ERR_SAVING,