1 2 import javax.swing.JOptionPane ; 3 4 import java.util.Date ; 5 import java.text.SimpleDateFormat ; 6 import java.io.File ; 7 8 18 public final class JarNewVersionReplacer 19 { 20 public JarNewVersionReplacer(File old, File newFile) 21 { 22 while(true) 23 { 24 try 25 { 26 Thread.sleep(1000); 27 if(old.exists()) 28 { 29 SimpleDateFormat df = new SimpleDateFormat ("MMM dd yyyy"); 30 old.renameTo(new File (old.getAbsolutePath()+"_ "+df.format(new Date (old.lastModified()))+".back")); } 32 if(newFile.renameTo(old)) 33 { 34 JOptionPane.showMessageDialog(null, "Your snowmail copy has been successfully updated.", "Snowmail updater", JOptionPane.INFORMATION_MESSAGE); 35 break; 36 } 37 } 38 catch(Exception e) { 39 e.printStackTrace(); 40 JOptionPane.showMessageDialog(null, "Can't replace "+old+":\n "+e.getMessage(), "Updater error", JOptionPane.ERROR_MESSAGE); 41 } 42 } 43 44 new File ("JarNewVersionReplacer").deleteOnExit(); 45 46 System.exit(0); 47 } 48 49 52 public static void main(String [] arguments) 53 { 54 new JarNewVersionReplacer(new File (arguments[0]), new File (arguments[1])); 55 } 56 57 } | Popular Tags |