[Webfunds-commits] java/webfunds/client/utils Backup.java BinaryButtons.java FileUtils.java Startup.java UpgradesManager.java

Ian Grigg iang@cypherpunks.ai
Tue, 20 Mar 2001 19:33:10 -0400 (AST)


iang        01/03/20 19:33:10

  Modified:    webfunds/client AccountBrowserImpl.java Core.java
               webfunds/client/util Backup.java BinaryButtons.java
                        FileUtils.java Startup.java UpgradesManager.java
  Removed:     webfunds/client/utils Backup.java BinaryButtons.java
                        FileUtils.java Startup.java UpgradesManager.java
  Log:
  1. reviewed and improved the messages in the Backup manager
  2. moved all webfunds.client.utils ==> webfunds.client.util

Revision  Changes    Path
1.86      +12 -6     java/webfunds/client/AccountBrowserImpl.java

Index: AccountBrowserImpl.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/AccountBrowserImpl.java,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -r1.85 -r1.86
--- AccountBrowserImpl.java	2001/03/18 03:21:05	1.85
+++ AccountBrowserImpl.java	2001/03/20 23:33:07	1.86
@@ -1,5 +1,5 @@
 /*
- * $Id: AccountBrowserImpl.java,v 1.85 2001/03/18 03:21:05 iang Exp $
+ * $Id: AccountBrowserImpl.java,v 1.86 2001/03/20 23:33:07 iang Exp $
  *
  * Copyright (c) Systemics Inc 1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -437,7 +437,7 @@
             sendAdminEvent(WalletInterface.CODE_FREEZE,
                            "backup being conducted");
             File srcDir = new File(".");
-            webfunds.client.utils.Backup.backup(ui, srcDir);
+            webfunds.client.util.Backup.backup(ui, srcDir);
             sendAdminEvent(WalletInterface.CODE_UNFREEZE, "backup complete");
           }
         };
@@ -451,10 +451,16 @@
           public void actionPerformed(ActionEvent evt)
           {
             sendAdminEvent(WalletInterface.CODE_SHUTDOWN, "recovery being attempted");
-            // Ouch!  statics...  but, recovery is "different"
-            webfunds.client.utils.Backup.recover(ui, Core.getUserDir());
-            ui.infoMessage("Exiting now, you will need to restart " + me);
-            System.exit(0);
+            /*
+             *  Ouch!  statics...  but, recovery is "different"
+             */
+            boolean restart =
+                webfunds.client.util.Backup.recover(ui, Core.getUserDir(), me);
+            if (restart)
+            {
+                ui.infoMessage("Exiting now, you will need to restart " + me);
+                System.exit(0);
+            }
           }
         };
 



1.71      +4 -4      java/webfunds/client/Core.java

Index: Core.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/Core.java,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -r1.70 -r1.71
--- Core.java	2001/03/18 03:21:06	1.70
+++ Core.java	2001/03/20 23:33:07	1.71
@@ -1,4 +1,4 @@
-/* $Id: Core.java,v 1.70 2001/03/18 03:21:06 iang Exp $
+/* $Id: Core.java,v 1.71 2001/03/20 23:33:07 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All rights reserved.
@@ -29,7 +29,7 @@
 import webfunds.client.plugins.PluginException;
 import webfunds.client.plugins.PluginManager;
 import webfunds.client.plugins.WalletManager;
-import webfunds.client.utils.Startup;
+import webfunds.client.util.Startup;
 
 import webfunds.store.Store;
 import webfunds.store.StoreException;
@@ -225,7 +225,7 @@
                              "webfunds.client.SimpleDepositFrame",
                              "webfunds.client.contracts.ContractBrowser",
                              "webfunds.client.SignContractWizard",
-                             "webfunds.client.utils.UpgradesManager"
+                             "webfunds.client.util.UpgradesManager"
                              // "webfunds.client.TransactionBrowser"
                            };
 
@@ -565,7 +565,7 @@
         boolean useDefaults = false;
         if (!userDir.exists())
         {
-            Startup startup = new Startup(userDir);
+            Startup startup = new Startup(userDir, me);
             String s = startup.showDialog();
             if (Startup.CANCEL.equals(s))
                 System.exit(0);



1.2       +49 -22    java/webfunds/client/util/Backup.java

Index: Backup.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/util/Backup.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Backup.java	2000/09/24 21:51:09	1.1
+++ Backup.java	2001/03/20 23:33:08	1.2
@@ -1,11 +1,11 @@
 /*
- * $Id: Backup.java,v 1.1 2000/09/24 21:51:09 iang Exp $
+ * $Id: Backup.java,v 1.2 2001/03/20 23:33:08 iang Exp $
  *
  * Copyright (C) 2000 Systemics Inc. on behalf of 
  * the WebFunds Development Team. All rights reserved.
  */
 
-package webfunds.client.utils;
+package webfunds.client.util;
 
 
 import java.io.*;
@@ -39,7 +39,7 @@
     {
         JFileChooser fc = new JFileChooser();
         fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
-        fc.setDialogTitle("Select Directory where you wish to Backup into");
+        fc.setDialogTitle("Select Directory where you wish to place Backup into");
 
         //
         //  Make a directory.  If we fail to make, keep trying!
@@ -48,7 +48,7 @@
         File targetDir = null;
         while (!ok)
         {
-            int res = fc.showDialog(new JFrame(), "Select Backup Dir");
+            int res = fc.showDialog(new JFrame(), "Select Dir for Backup");
             if (res != JFileChooser.APPROVE_OPTION)
                 return ;
 
@@ -64,7 +64,7 @@
                 continue ;
             }
 
-            logmsg("Chose backup dir: " + choice);
+            logmsg("backup dir chosen: " + choice);
             targetDir =
                 new File(choice, BACKUP_DIR + System.currentTimeMillis());
 
@@ -81,9 +81,11 @@
         //
         try
         {
-            webfunds.client.utils.FileUtils.copyTree(srcDir, targetDir);
+            webfunds.client.util.FileUtils.copyTree(srcDir, targetDir);
 
-            ui.infoMessage("Backup Complete");
+            ui.infoMessage("Backup Complete in:" + 
+                           "\n\n       " + targetDir +
+                           "\n\nYou can use File/Recover Backup on that name.");
             return ;
         }
         catch (IOException ex)
@@ -114,12 +116,15 @@
     }
 
     /**
-     *  Kludge attempt at recovering a backup.
+     *  XXX: Kludge attempt at recovering a backup.
      *  Note that targetDir is not the same as the backup() paramater.
      *
      *  @param targetDir is the user directory where data is stored
+     *  @return true if restart thought necessary (recovery done), else false
      */
-    public static void recover(UInterface ui, File targetDir)
+    public static boolean recover(UInterface ui,
+                                              File targetDir,
+                                              String callerName)
     {
         JFileChooser fc = new JFileChooser();
         fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
@@ -135,9 +140,10 @@
         File child = null;
         while (child == null)
         {
-            int res = fc.showDialog(new JFrame(), "Select Backup Dir");
+            int res = fc.showDialog(new JFrame(), "Select Backup " +
+                                                  BACKUP_DIR + "...");
             if (res != JFileChooser.APPROVE_OPTION)
-                return ;
+                return false;
 
             File choice = fc.getSelectedFile();
 
@@ -155,7 +161,8 @@
                 String parentName = parent.getName(); 
                 if (!parentName.startsWith(BACKUP_DIR))
                 {
-                    String q = "Parent is not recognised as a WebFunds backup?"+
+                    String q = "Parent directory is not recognised as a " +
+                                            callerName + " backup?"+
                                "\n\n" +
                                "        " + parentName +
                                "\n\n" +
@@ -167,7 +174,7 @@
             }
             else
             {
-                ui.errorMessage("not a recognised WebFunds Backup: " +
+                ui.errorMessage("not a recognised " + callerName + " Backup: " +
                                 "\n\n      " + choice.getPath() +
                                 "\n\nPlease select another!" +
                                 "");
@@ -186,15 +193,31 @@
          *  Gotta be careful here, might be a Windows user doing this.
          */
         String ouch = "\n\nPlease clean up and try again!";
+        String restartMe = "\n\n(requesting restart of " + callerName + ".)";
         String saveName = getSaveName(targetDir.getPath());
         if (saveName == null)
         {
-            ui.errorMessage("can not save existing " +
-                                  userName + " directory, " +
+            ui.errorMessage("can not save existing " + userName +
+                            " directory, there are too many prior attempts!" +
                             ouch);
-            return ;
+            return false;
         }
 
+        String targetExists = "(is a new directory)";
+        if (targetDir.exists())
+            targetExists = "(which exists, will attempt to save to " +
+                           saveName + ")";
+
+        String lastCheck = callerName + " will attempt to recover backup from" +
+                           "\n\n     " + child +
+                           "\n\nto the user directory of" +
+                           "\n\n     " + targetDir +
+                           "\n\n" + targetExists +
+                           "\n\nProceed?";
+
+        if (ui.getYesNo(lastCheck) != UInterface.YES)
+                        return false;
+
         if (targetDir.exists())
         {
             targetDir.renameTo(new File(saveName));
@@ -205,7 +228,7 @@
                                       userName + " directory to " +
                                       saveName + " ," +
                                 ouch);
-                return ;
+                return false;
             }
         }
 
@@ -223,18 +246,22 @@
             FileUtils.copyTree(child, new File(targetParentName));
 
         } catch (IOException ex) {
-            ui.errorMessage("RECOVERY FAILED!" +
+
+            ui.errorMessage("RECOVERY FAILED HALF WAY THROUGH!" +
                             "\n\n      " + ex +
                             "\n\nCheck " + targetDir.getName() +
                                            " for remnants." +
                             "\n\nCheck " + saveName +
                                            " for your pre-existing data." +
-                            ouch);
-            return ;
+                            ouch +
+                            restartMe);
+            return true;
         }
 
-        ui.infoMessage("Recovery Complete");
-        return ;
+        ui.infoMessage("Recovery Complete into " + targetDir +
+                       "(from " + child + ")" +
+                       "\n" + restartMe);
+        return true;
     }
 
 }



1.2       +2 -2      java/webfunds/client/util/BinaryButtons.java

Index: BinaryButtons.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/util/BinaryButtons.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BinaryButtons.java	2000/09/24 21:51:09	1.1
+++ BinaryButtons.java	2001/03/20 23:33:08	1.2
@@ -1,11 +1,11 @@
 /*
- * $Id: BinaryButtons.java,v 1.1 2000/09/24 21:51:09 iang Exp $
+ * $Id: BinaryButtons.java,v 1.2 2001/03/20 23:33:08 iang Exp $
  *
  * Copyright (c) 2000 Systemics Inc. on behalf of
  * the WebFunds Development Team. All rights reserved.
  */
 
-package webfunds.client.utils;
+package webfunds.client.util;
 import java.io.File;
 
 import java.awt.*;



1.3       +4 -4      java/webfunds/client/util/FileUtils.java

Index: FileUtils.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/util/FileUtils.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FileUtils.java	2000/09/24 21:48:41	1.2
+++ FileUtils.java	2001/03/20 23:33:08	1.3
@@ -1,12 +1,12 @@
 /*
- * $Id: FileUtils.java,v 1.2 2000/09/24 21:48:41 iang Exp $
+ * $Id: FileUtils.java,v 1.3 2001/03/20 23:33:08 iang Exp $
  *
  * Copyright (C) 2000 Systemics Inc. on behalf of 
  * the WebFunds Development Team. All rights reserved.
  */
 
-// here as main shows Swing usage, elsewise could be in webfunds.utils;
-package webfunds.client.utils;
+// here as main shows Swing usage, elsewise could be in webfunds.util;
+package webfunds.client.util;
 
 
 import java.io.*;
@@ -16,7 +16,7 @@
 /**
  * Helper functions dealing with File objects.
  *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  * @author  Jeroen C. van Gelderen (gelderen@systemics.com)
  */
 public final class FileUtils



1.3       +15 -10    java/webfunds/client/util/Startup.java

Index: Startup.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/util/Startup.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Startup.java	2000/10/09 17:30:04	1.2
+++ Startup.java	2001/03/20 23:33:08	1.3
@@ -1,11 +1,11 @@
 /*
- * $Id: Startup.java,v 1.2 2000/10/09 17:30:04 iang Exp $
+ * $Id: Startup.java,v 1.3 2001/03/20 23:33:08 iang Exp $
  *
  * Copyright (C) 2000 Systemics Inc. on behalf of 
  * the WebFunds Development Team. All rights reserved.
  */
 
-package webfunds.client.utils;
+package webfunds.client.util;
 
 import java.io.File;
 
@@ -39,14 +39,18 @@
     JButton buttonOK     = new JButton(OK);
     JButton buttonCancel = new JButton(CANCEL);
     File    userDir;
+    String  callerName;
 
     BinaryButtons choice = null;
 
-    public Startup(File userDir)
+    public Startup(File userDir, String callerName)
     {
-        super (new JFrame(), "Startup - Select User Recovery", true);
+        super (new JFrame(), "Startup " + callerName + ": " +
+                             " select New User or Recovery", true);
 
-        this.userDir = userDir;
+        this.userDir    = userDir;
+        this.callerName = callerName;
+
         choice = new BinaryButtons(
                            RECOVER, KeyEvent.VK_R, false,
                            NEW_USER, KeyEvent.VK_N, false
@@ -59,11 +63,11 @@
         JLabel lab = new JLabel("<html><font size='-1'><b>"+
                 "<p>"+
                 "</p><p>"+
-                "There is no user directory."+
+                "There is no user directory for " + callerName + "."+
                 "</p><p>"+
                 "</p><p>"+
-                "Do you wish to start with a new user, "+
-                "or to recover from an existing user?"+
+                "Do you wish to start with a fresh new directory, "+
+                "or to recover from an existing directory?"+
                 "</p>"+
                          "</b></font></html>");
         
@@ -97,7 +101,8 @@
                 logmsg(" recovery");
                 result = RECOVER;
                 // warning - this "knows" about the file structure.
-                Backup.recover(new webfunds.client.UInterfaceImpl(), userDir);
+                Backup.recover(new webfunds.client.UInterfaceImpl(),
+                               userDir, callerName);
             }
             else
             {
@@ -144,7 +149,7 @@
         String result = OK;
         while (!CANCEL.equals(result))
         {
-            Startup startup = new Startup(new File("."));
+            Startup startup = new Startup(new File("."), "Tester");
             result = startup.showDialog();
             System.err.println("Chosen: " + result);
         }



1.5       +2 -2      java/webfunds/client/util/UpgradesManager.java

Index: UpgradesManager.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/util/UpgradesManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- UpgradesManager.java	2001/03/17 22:09:58	1.4
+++ UpgradesManager.java	2001/03/20 23:33:08	1.5
@@ -1,10 +1,10 @@
 /*
- * $Id: UpgradesManager.java,v 1.4 2001/03/17 22:09:58 iang Exp $
+ * $Id: UpgradesManager.java,v 1.5 2001/03/20 23:33:08 iang Exp $
  *
  * Copyright (c) 2000 Systemics Inc on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
  */
-package webfunds.client.utils;
+package webfunds.client.util;
 
 import javax.swing.*;
 import java.io.*;