diff --git a/.gitignore b/.gitignore index 000a9aa..15949b6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ target .idea/workspace.xml dist/Fastcopy(1.0.4).app/ dist/tmp_make_exe/ +dist/Fastcopy(1.1).app/ diff --git a/.idea/ant.xml b/.idea/ant.xml index ef072ef..d19c68e 100644 --- a/.idea/ant.xml +++ b/.idea/ant.xml @@ -2,8 +2,8 @@ - - + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6a9cd7..4d19c60 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,9 @@ - - - + + + - - - - - - - - - - - + \ No newline at end of file diff --git a/FastCopy.iml b/FastCopy.iml index 1810470..7f7515f 100644 --- a/FastCopy.iml +++ b/FastCopy.iml @@ -1,6 +1,6 @@ - + @@ -9,7 +9,7 @@ - + diff --git a/build.xml b/build.xml index db8c7ed..af136bf 100644 --- a/build.xml +++ b/build.xml @@ -5,7 +5,7 @@ - + diff --git a/dist/fastcopy-console.jar b/dist/fastcopy-console.jar index f0de07d..ac83750 100644 Binary files a/dist/fastcopy-console.jar and b/dist/fastcopy-console.jar differ diff --git a/dist/fastcopy-ui.exe b/dist/fastcopy-ui.exe index a80e36a..c510dcd 100644 Binary files a/dist/fastcopy-ui.exe and b/dist/fastcopy-ui.exe differ diff --git a/dist/fastcopy-ui.jar b/dist/fastcopy-ui.jar index 0d27ba3..e719a3a 100644 Binary files a/dist/fastcopy-ui.jar and b/dist/fastcopy-ui.jar differ diff --git a/dist/fc.exe b/dist/fc.exe index 2511129..9ef1def 100644 Binary files a/dist/fc.exe and b/dist/fc.exe differ diff --git a/src/main/java/org/mhisoft/fc/CopyFileThread.java b/src/main/java/org/mhisoft/fc/CopyFileThread.java index e48ad45..f36bc93 100644 --- a/src/main/java/org/mhisoft/fc/CopyFileThread.java +++ b/src/main/java/org/mhisoft/fc/CopyFileThread.java @@ -34,7 +34,6 @@ public class CopyFileThread implements Runnable { static final int TRIGGER_MULTI_THREAD_THRESHHOLD = 20; private String dir; - private boolean verbose; private FileCopyStatistics statistics; private UI rdProUI; @@ -42,10 +41,9 @@ public class CopyFileThread implements Runnable { File targetFile; - public CopyFileThread(UI rdProUI, File sourceFile, File targetFile, boolean verbose, FileCopyStatistics frs) { + public CopyFileThread(UI rdProUI, File sourceFile, File targetFile, FileCopyStatistics frs) { this.sourceFile = sourceFile; this.targetFile = targetFile; - this.verbose = verbose; this.statistics = frs; this.rdProUI = rdProUI; } diff --git a/src/main/java/org/mhisoft/fc/FastCopy.java b/src/main/java/org/mhisoft/fc/FastCopy.java index 7a8effe..2eec00c 100644 --- a/src/main/java/org/mhisoft/fc/FastCopy.java +++ b/src/main/java/org/mhisoft/fc/FastCopy.java @@ -35,7 +35,7 @@ */ public class FastCopy { public static boolean debug = Boolean.getBoolean("debug"); - public static final int DEFAULT_THREAD_NUM =5; + public static final int DEFAULT_THREAD_NUM = 5; FileCopyStatistics frs = new FileCopyStatistics(); Workers workerPool; @@ -54,7 +54,7 @@ public FileCopyStatistics getStatistics() { return frs; } - public static boolean stopThreads=false; + public static boolean stopThreads = false; private boolean running; public static boolean isStopThreads() { @@ -87,15 +87,15 @@ public void run(RunTimeProperties props) { FileWalker fw = new FileWalker(rdProUI, workerPool, props, frs); long t1 = System.currentTimeMillis(); - running= true; + running = true; String[] files = props.sourceDir.split(";"); - fw.walk( files, props.getDestDir()); + fw.walk(files, props.getDestDir()); workerPool.shutDownandWaitForAllThreadsToComplete(); //reset the flags - running= false; + running = false; stopThreads = false; rdProUI.println(""); @@ -109,11 +109,14 @@ public void run(RunTimeProperties props) { public static void main(String[] args) { FastCopy fastCopy = new FastCopy(new ConsoleRdProUIImpl()); RunTimeProperties props = fastCopy.getRdProUI().parseCommandLineArguments(args); + if (!props.isSuccess()) { + System.exit(-1); + } if (props.isDebug()) fastCopy.getRdProUI().dumpArguments(args, props); - if (props.getSourceDir()!=null) { + if (props.getSourceDir() != null) { Path path = Paths.get(props.getSourceDir()); if (Files.notExists(path)) { fastCopy.getRdProUI().printError("The source dir does not exist:" + props.getSourceDir()); @@ -123,7 +126,7 @@ public static void main(String[] args) { boolean b = fastCopy.getRdProUI().isAnswerY( "Start to copy everything under \"" + props.getSourceDir() + "\"" + - "to \"" + props.getDestDir() + "\"" + + " to \"" + props.getDestDir() + "\"" + " (y/n/q or h for help)?"); @@ -131,11 +134,8 @@ public static void main(String[] args) { System.exit(-2); } - - if (props.isSuccess()) { - fastCopy.getRdProUI().print("working."); - fastCopy.run(props); - } + fastCopy.getRdProUI().print("working."); + fastCopy.run(props); } } diff --git a/src/main/java/org/mhisoft/fc/FileUtils.java b/src/main/java/org/mhisoft/fc/FileUtils.java index 0b1a775..48bc692 100644 --- a/src/main/java/org/mhisoft/fc/FileUtils.java +++ b/src/main/java/org/mhisoft/fc/FileUtils.java @@ -41,8 +41,6 @@ */ public class FileUtils { - - public static void createDir(final File theDir, final UI ui, final FileCopyStatistics frs) { // if the directory does not exist, create it if (!theDir.exists()) { @@ -55,7 +53,8 @@ public static void createDir(final File theDir, final UI ui, final FileCopyStati ui.println(String.format("[error] Failed to create directory: %s", theDir.getName())); } if (result) { - ui.println(String.format("Directory created: %s", theDir.getName())); + if (RunTimeProperties.instance.isVerbose()) + ui.println(String.format("Directory created: %s", theDir.getName())); frs.setDirCount(frs.getDirCount() + 1); } } @@ -76,7 +75,7 @@ private static void copyFileUsingFileChannels(File source, File dest) } } - private static final int BUFFER = 4096*16; + private static final int BUFFER = 4096 * 16; static final DecimalFormat df = new DecimalFormat("#,###.##"); public static void showPercent(final UI rdProUI, double digital) { @@ -99,21 +98,22 @@ public static void nioBufferCopy(final File source, final File target, FileCopyS out = new FileOutputStream(target).getChannel(); totalFileSize = in.size(); //double size2InKB = size / 1024 ; - rdProUI.print(String.format("\nCopying file %s-->%s, size:%s KBytes", source.getAbsolutePath(), - target.getAbsolutePath(), df.format(totalFileSize/1024))); + if (RunTimeProperties.instance.isVerbose()) + rdProUI.print(String.format("\n\tCopying file %s-->%s, size:%s KBytes", source.getAbsolutePath(), + target.getAbsolutePath(), df.format(totalFileSize / 1024))); ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFER); int readSize = in.read(buffer); long totalRead = 0; int progress = 0; - long startTime, endTime ; + long startTime, endTime; while (readSize != -1) { if (FastCopy.isStopThreads()) { - rdProUI.println("[warn]Cancelled by user. Stoping copying."); - rdProUI.println("\t" + Thread.currentThread().getName() + "is stopped."); + rdProUI.println("[warn]Cancelled by user. Stoping copying.", true); + rdProUI.println("\t" + Thread.currentThread().getName() + "is stopped.", true); return; } startTime = System.currentTimeMillis(); @@ -137,7 +137,7 @@ public static void nioBufferCopy(final File source, final File target, FileCopyS statistics.addToTotalFileSizeAndTime(totalFileSize, readSize / 1024, (endTime - startTime)); } - statistics.setFilesCount(statistics.getFilesCount()+1); + statistics.setFilesCount(statistics.getFilesCount() + 1); } catch (IOException e) { @@ -146,7 +146,7 @@ public static void nioBufferCopy(final File source, final File target, FileCopyS close(in); close(out); try { - boolean b = target.setLastModified( source.lastModified()); + boolean b = target.setLastModified(source.lastModified()); //rdProUI.println("modify file date to: " + b + "," + new Timestamp(target.lastModified())); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/org/mhisoft/fc/FileWalker.java b/src/main/java/org/mhisoft/fc/FileWalker.java index 585341b..5f02d2e 100644 --- a/src/main/java/org/mhisoft/fc/FileWalker.java +++ b/src/main/java/org/mhisoft/fc/FileWalker.java @@ -32,7 +32,6 @@ */ public class FileWalker { - RunTimeProperties props; //Integer threads; boolean lastAnsweredDeleteAll = false; boolean initialConfirmation = false; @@ -46,16 +45,16 @@ public FileWalker(UI rdProUI, , FileCopyStatistics frs ) { this.workerPool = workerPool; - this.props = props; this.rdProUI = rdProUI; this.statistics = frs; rdProUI.reset(); } - public void walk(final String[] sourceFileDirs, final String destDir) { + public void walk(final String[] sourceFileDirs, String destDir) { FileUtils.createDir(new File(destDir), rdProUI, statistics); + rdProUI.println("Copying files under directory " + destDir); for (String source : sourceFileDirs) { @@ -69,17 +68,24 @@ public void walk(final String[] sourceFileDirs, final String destDir) { String sTarget = destDir + File.separator + fSource.getName(); File targetFile = new File(sTarget); if (overrideTargetFile(fSource, targetFile)) { - CopyFileThread t = new CopyFileThread(rdProUI, fSource, targetFile, props.verbose, statistics); + CopyFileThread t = new CopyFileThread(rdProUI, fSource, targetFile, statistics); workerPool.addTask(t); - } else + } else { + if (RunTimeProperties.instance.isVerbose()) rdProUI.println(String.format("\tFile %s exists on the target dir. Skip. ", sTarget)); + } } else if (fSource.isDirectory()) { // get the last dir of the source and make it under dest //ext /Users/me/doc --> /Users/me/target make /Users/me/target/doc String _targetDir =destDir; - if (props.isCreateTheSameSourceFolderUnderTarget()) { - _targetDir=destDir+File.separator+fSource.getName() ; - FileUtils.createDir(new File(_targetDir), rdProUI, statistics); + if (RunTimeProperties.instance.isCreateTheSameSourceFolderUnderTarget()) { + //String sourceDirName = + + _targetDir=destDir+File.separator + fSource.getName() ; + if (!new File(_targetDir).exists()) + FileUtils.createDir(new File(_targetDir), rdProUI, statistics); + destDir = _targetDir; + RunTimeProperties.instance.setDestDir(destDir); } walkSubDir(fSource, destDir); } @@ -90,9 +96,9 @@ public void walk(final String[] sourceFileDirs, final String destDir) { private boolean overrideTargetFile(final File srcFile, final File targetFile) { if (targetFile.exists()) { //target file exists - if (props.overwrite) { + if (RunTimeProperties.instance.overwrite) { return true; - } else if (props.isOverwriteIfNewerOrDifferent()) { + } else if (RunTimeProperties.instance.isOverwriteIfNewerOrDifferent()) { if (srcFile.lastModified() > targetFile.lastModified() || (srcFile.length() != targetFile.length()) ) @@ -113,8 +119,10 @@ private boolean overrideTargetFile(final File srcFile, final File targetFile) { public void walkSubDir(final File rootDir, final String destRootDir) { + + if (FastCopy.isStopThreads()) { - rdProUI.println("[warn]Cancelled by user. stop walk. "); + rdProUI.println("[warn]Cancelled by user. stop walk. ", true); return; } @@ -140,22 +148,24 @@ public boolean accept(File dir, String name) { return; + rdProUI.println("Copying files under directory " + destRootDir); + for (File childFile : list) { if (FastCopy.isStopThreads()) { - rdProUI.println("[warn]Cancelled by user. stop walk. "); + rdProUI.println("[warn]Cancelled by user. stop walk. ", true); return; } if (childFile.isDirectory()) { //keep walking down - if (!props.flatCopy) { + if (!RunTimeProperties.instance.flatCopy) { //create the mirror child dir targetDir = destRootDir + File.separator + childFile.getName(); FileUtils.createDir(new File(targetDir), rdProUI, statistics); } else { - targetDir = props.getDestDir(); + targetDir = RunTimeProperties.instance.getDestDir(); } walkSubDir(childFile, targetDir); @@ -164,19 +174,20 @@ public boolean accept(File dir, String name) { else { - if (!props.flatCopy) { + if (!RunTimeProperties.instance.flatCopy) { targetDir = destRootDir ; } else { - targetDir = props.getDestDir(); + targetDir = RunTimeProperties.instance.getDestDir(); } String newDestFile = targetDir + File.separator + childFile.getName(); File targetFile = new File(newDestFile); if (overrideTargetFile(childFile, targetFile)) { - CopyFileThread t = new CopyFileThread(rdProUI, childFile, targetFile, props.verbose, statistics); + CopyFileThread t = new CopyFileThread(rdProUI, childFile, targetFile, statistics); workerPool.addTask(t); } else { + if (RunTimeProperties.instance.isVerbose()) rdProUI.println(String.format("\tFile %s exists on the target dir. Skip based on the input. ", newDestFile)); } diff --git a/src/main/java/org/mhisoft/fc/RunTimeProperties.java b/src/main/java/org/mhisoft/fc/RunTimeProperties.java index a824e68..efa3625 100644 --- a/src/main/java/org/mhisoft/fc/RunTimeProperties.java +++ b/src/main/java/org/mhisoft/fc/RunTimeProperties.java @@ -4,6 +4,13 @@ * Run time properties */ public class RunTimeProperties { + + public static RunTimeProperties instance = new RunTimeProperties(); + + private RunTimeProperties() { + // + } + String sourceDir = null; String destDir = null; boolean success; diff --git a/src/main/java/org/mhisoft/fc/ui/ConsoleRdProUIImpl.java b/src/main/java/org/mhisoft/fc/ui/ConsoleRdProUIImpl.java index 369dfc6..ba3734a 100644 --- a/src/main/java/org/mhisoft/fc/ui/ConsoleRdProUIImpl.java +++ b/src/main/java/org/mhisoft/fc/ui/ConsoleRdProUIImpl.java @@ -41,12 +41,20 @@ public void print(final String msg) { System.out.print(msg); } + @Override + public void print(String msg, boolean force) { + print(msg); + } + @Override public void printError(String msg) { System.err.print("[error]" + msg); } @Override + public void println(final String msg, boolean force) { + println(msg); + } public void println(final String msg) { System.out.println(msg); } @@ -105,13 +113,16 @@ public Confirmation getConfirmation(String question, String... options) { if (a.equalsIgnoreCase("all")) { return Confirmation.YES_TO_ALL; } - else if (!a.equalsIgnoreCase("y")) { + else if (a.equalsIgnoreCase("y")) { + return Confirmation.YES; + } + else if (a.equalsIgnoreCase("n")) { return Confirmation.NO; } - else if (!a.equalsIgnoreCase("q")) { + else if (a.equalsIgnoreCase("q")) { return Confirmation.QUIT; } - return Confirmation.YES; + return Confirmation.NO; } public void help() { @@ -126,16 +137,16 @@ public void help() { println("\t\t -o override"); println("\t\t -f flat copy, copy everything to one flat target directory"); println("\t\t -n override if new or different"); - /*println("\t -w number of worker threads, default 5");*/ + println("\t\t -w number of worker threads, default 5"); println("Examples:"); - println("\t\t fastcopy t:\\backup"); - println("\t\t fastcopy s:\\projects\\dir1;s:\\projects\\dir2 t:\\backup"); + println("\t\t copy from current dir to the backup directory: fastcopy t:\\backup"); + println("\t\t fastcopy -from s:\\projects\\dir1;s:\\projects\\dir2 -to t:\\backup"); } public RunTimeProperties parseCommandLineArguments(String[] args) { - RunTimeProperties props = new RunTimeProperties(); + RunTimeProperties props = RunTimeProperties.instance; List noneHyfenArgs = new ArrayList(); if (args==null || args.length==0) { @@ -174,16 +185,30 @@ else if (arg.equalsIgnoreCase("-w")) { } catch (NumberFormatException e) { props.setNumOfThreads( 1 ); } - } else if (arg.equalsIgnoreCase("-from") ) { - props.setSourceDir(args[i + 1]); + + if (args.length>i+1) + props.setSourceDir(args[i + 1]); + else { + System.err.println("No value for -from is specified"); + props.setSuccess(false); + return props; + } i++; //skip the next arg } else if (arg.equalsIgnoreCase("-to") ) { - props.setDestDir(args[i + 1]); - i++; //skip the next arg else { + if (args.length>i+1) + props.setDestDir(args[i + 1]); + else { + System.err.println("No value for -to is specified"); + props.setSuccess(false); + return props; + } + + i++; //skip the next arg + } else { if (arg.startsWith("-")) { - System.err.println("The argument is not recognized:" + arg); + System.err.println("The option argument is not recognized:" + arg); props.setSuccess(false); return props; } else @@ -194,38 +219,26 @@ else if (arg.equalsIgnoreCase("-w")) { } - if (noneHyfenArgs.size() == 0) { - props.setSourceDir(System.getProperty("user.dir")); - } - else if (noneHyfenArgs.size() == 1) { - //fc d:\temp -dest classes - if (props.getDestDir() != null) - props.setSourceDir(noneHyfenArgs.get(0)); - - else { - //rdpro classes - props.setSourceDir(System.getProperty("user.dir")); - props.setDestDir(noneHyfenArgs.get(0)); - } + //use the none hyfen args to fill in the source and dest if needed. + //when -from and -to are not specified. + if (props.getSourceDir()==null && noneHyfenArgs.size()>=1) + props.setSourceDir(noneHyfenArgs.get(0)); - } - else { - props.setSourceDir(noneHyfenArgs.get(0)); + if (props.getDestDir()==null && noneHyfenArgs.size()>=2) { props.setDestDir(noneHyfenArgs.get(1)); } - if (props.getSourceDir() == null) + //now default to user current directory for source + // fc -to target_dir + if (props.getSourceDir()==null || props.getSourceDir().length()==0) props.setSourceDir(System.getProperty("user.dir")); - println(""); - - if (props.getDestDir() == null) { - if (!isAnswerY("Specify a destination directory:")) - props.setSuccess(false); + if (props.getDestDir()==null) { + System.err.println("Specify the target directory to copy to by using -to dest_dir"); + props.setSuccess(false); return props; - } props.setSuccess(true); diff --git a/src/main/java/org/mhisoft/fc/ui/FastCopyMainForm.form b/src/main/java/org/mhisoft/fc/ui/FastCopyMainForm.form index 5c1c78d..5b4e0b3 100644 --- a/src/main/java/org/mhisoft/fc/ui/FastCopyMainForm.form +++ b/src/main/java/org/mhisoft/fc/ui/FastCopyMainForm.form @@ -14,6 +14,7 @@ + @@ -249,6 +250,7 @@ + @@ -256,14 +258,14 @@ - + - - + + diff --git a/src/main/java/org/mhisoft/fc/ui/FastCopyMainForm.java b/src/main/java/org/mhisoft/fc/ui/FastCopyMainForm.java index 28722e9..c811cbd 100644 --- a/src/main/java/org/mhisoft/fc/ui/FastCopyMainForm.java +++ b/src/main/java/org/mhisoft/fc/ui/FastCopyMainForm.java @@ -64,7 +64,7 @@ public class FastCopyMainForm { JFrame frame; FastCopy fastCopy; - RunTimeProperties props; + RunTimeProperties props= RunTimeProperties.instance; JCheckBox chkMultiThread; @@ -127,7 +127,8 @@ public void actionPerformed(ActionEvent e) { chkShowInfo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - showHideInfo(chkShowInfo.isSelected()); + //showHideInfo(chkShowInfo.isSelected()); + RunTimeProperties.instance.setVerbose(chkShowInfo.isSelected()); } }); diff --git a/src/main/java/org/mhisoft/fc/ui/GraphicsUIImpl.java b/src/main/java/org/mhisoft/fc/ui/GraphicsUIImpl.java index 103c86b..f5aec08 100644 --- a/src/main/java/org/mhisoft/fc/ui/GraphicsUIImpl.java +++ b/src/main/java/org/mhisoft/fc/ui/GraphicsUIImpl.java @@ -42,6 +42,8 @@ public class GraphicsUIImpl extends AbstractUIImpl { JTextArea outputTextArea; JLabel labelStatus; JProgressBar progressBar; + public static int bufferLineThreshold = 9999; + private int lineNumber = 0; public GraphicsUIImpl(JTextArea outputTextArea) { this.outputTextArea = outputTextArea; @@ -71,7 +73,12 @@ public void setProgressBar(JProgressBar progressBar) { } @Override - public void print(final String msg) { + public void print(String msg) { + print(msg, false); + } + + @Override + public void print(final String msg, boolean force) { //invokeLater() //This method allows us to post a "job" to Swing, which it will then run // on the event dispatch thread at its next convenience. @@ -81,8 +88,14 @@ public void run() { // Here, we can safely update the GUI // because we'll be called from the // event dispatch thread + if (lineNumber >= bufferLineThreshold) { + outputTextArea.setText(""); + lineNumber = 0; + } outputTextArea.append(msg); outputTextArea.setCaretPosition(outputTextArea.getDocument().getLength()); + lineNumber++; + //labelStatus.setText(msg); } }); @@ -91,21 +104,27 @@ public void run() { @Override public void printError(String msg) { - print("[Error] " + msg) ; + print("[Error] " + msg, true); } @Override - public void println(final String msg) { - print(msg+"\n"); + public void println(final String msg) { + print(msg + "\n"); + } + + + @Override + public void println(final String msg, boolean force) { + print(msg + "\n", force); } @Override - public void printf(final String msg, Object args) { + public void printf(final String msg, Object args) { // } @Override - public boolean isAnswerY(String question) { + public boolean isAnswerY(String question) { int dialogResult = JOptionPane.showConfirmDialog(null, question, "Please confirm", JOptionPane.YES_NO_OPTION); return dialogResult == JOptionPane.YES_OPTION; } @@ -113,11 +132,10 @@ public boolean isAnswerY(String question) { @Override public Confirmation getConfirmation(String question, String... options) { int dialogResult = JOptionPane.showConfirmDialog(null, question, "Please confirm", JOptionPane.YES_NO_OPTION); - if (JOptionPane.YES_OPTION==dialogResult) { - return Confirmation.YES; - } - else - return Confirmation.NO; + if (JOptionPane.YES_OPTION == dialogResult) { + return Confirmation.YES; + } else + return Confirmation.NO; //todo support presend a check box to check Yes for all future confirmations //return Confirmation.YES_TO_ALL @@ -133,15 +151,14 @@ public RunTimeProperties parseCommandLineArguments(String[] args) { List noneHyfenArgs = new ArrayList(); - RunTimeProperties props= new RunTimeProperties(); + RunTimeProperties props = RunTimeProperties.instance; - if (args.length<1 || args[0]==null || args[0].trim().length()==0) { + if (args.length < 1 || args[0] == null || args[0].trim().length() == 0) { //JOptionPane.showMessageDialog(null, "The root dir to start with can't be determined from args[].", "Error" // , JOptionPane.ERROR_MESSAGE); //props.setSuccess(false); props.setSourceDir(null); - } - else { + } else { // if (args.length>=1) // props.setSourceDir(args[0]); // if (args.length>=2) @@ -152,23 +169,21 @@ public RunTimeProperties parseCommandLineArguments(String[] args) { help(); } else if (arg.equalsIgnoreCase("-v")) { props.setVerbose(true); - } - else if (arg.equalsIgnoreCase("-debug")) { + } else if (arg.equalsIgnoreCase("-debug")) { props.setDebug(true); - } - else if (arg.equalsIgnoreCase("-w")) { + } else if (arg.equalsIgnoreCase("-w")) { try { props.setNumOfThreads(Integer.parseInt(args[i + 1])); i++; //skip the next arg, it is the target. } catch (NumberFormatException e) { - props.setNumOfThreads( 1 ); + props.setNumOfThreads(1); } - } else if (arg.equalsIgnoreCase("-from") ) { + } else if (arg.equalsIgnoreCase("-from")) { props.setSourceDir(args[i + 1]); i++; //skip the next arg - } else if (arg.equalsIgnoreCase("-to") ) { + } else if (arg.equalsIgnoreCase("-to")) { props.setDestDir(args[i + 1]); i++; //skip the next arg @@ -179,21 +194,19 @@ else if (arg.equalsIgnoreCase("-w")) { return props; } else //not start with "-" - if (arg!=null && arg.trim().length()>0) + if (arg != null && arg.trim().length() > 0) noneHyfenArgs.add(arg); } } - } if (noneHyfenArgs.size() == 0) { - if (props.getSourceDir()==null || props.getSourceDir().length()==0) + if (props.getSourceDir() == null || props.getSourceDir().length() == 0) props.setSourceDir(System.getProperty("user.dir")); - } - else if (noneHyfenArgs.size() == 1) { + } else if (noneHyfenArgs.size() == 1) { //fc d:\temp -dest classes if (props.getDestDir() != null) props.setSourceDir(noneHyfenArgs.get(0)); @@ -204,8 +217,7 @@ else if (noneHyfenArgs.size() == 1) { props.setDestDir(noneHyfenArgs.get(0)); } - } - else { + } else { props.setSourceDir(noneHyfenArgs.get(0)); props.setDestDir(noneHyfenArgs.get(1)); } @@ -214,7 +226,6 @@ else if (noneHyfenArgs.size() == 1) { props.setSourceDir(System.getProperty("user.dir")); - if (props.getSourceDir() == null) props.setSourceDir(System.getProperty("user.dir")); @@ -225,16 +236,16 @@ else if (noneHyfenArgs.size() == 1) { @Override public void reset() { - lastProgressTime=-1; + lastProgressTime = -1; labelStatus.setText(""); progressBar.setValue(0); } //0..100 public void showProgress(int value, FileCopyStatistics statistics) { - if (lastProgressTime==-1 || (System.currentTimeMillis()-lastProgressTime)>1000) { + if (lastProgressTime == -1 || (System.currentTimeMillis() - lastProgressTime) > 1000) { progressBar.setValue(value); - labelStatus.setText( statistics.printOverallProgress()); + labelStatus.setText(statistics.printOverallProgress()); lastProgressTime = System.currentTimeMillis(); } } diff --git a/src/main/java/org/mhisoft/fc/ui/UI.java b/src/main/java/org/mhisoft/fc/ui/UI.java index ce592a2..f007c3b 100644 --- a/src/main/java/org/mhisoft/fc/ui/UI.java +++ b/src/main/java/org/mhisoft/fc/ui/UI.java @@ -30,8 +30,8 @@ */ public interface UI { - public static final String version = "1.0.4"; - public static final String build = "09172017"; + public static final String version = "1.1"; + public static final String build = "06-29-2018"; public enum Confirmation { YES, NO, YES_TO_ALL, HELP, QUIT @@ -43,6 +43,7 @@ public enum Confirmation { * @param msg */ void print(String msg); + void print(String msg, boolean force); /** * log the msg @@ -50,6 +51,8 @@ public enum Confirmation { */ void println(String msg); + void println(String msg, boolean force); + public void printf(final String msg, Object args); public void printError(final String msg) ;