Browse Source

Update changes - components can now be marked as requiring a client restart, and client updates show a message box with manual instructions if the user isn't using a launcher

git-svn-id: http://svn.dmdirc.com/trunk@3061 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 years ago
parent
commit
2f189a5ff0

+ 10
- 4
src/com/dmdirc/updater/Update.java View File

47
         DOWNLOADING,
47
         DOWNLOADING,
48
         INSTALLING,
48
         INSTALLING,
49
         INSTALLED,
49
         INSTALLED,
50
-        ERROR
50
+        ERROR,
51
+        RESTART_NEEDED
51
     }
52
     }
52
 
53
 
53
     /** Update component. */
54
     /** Update component. */
191
                 setStatus(STATUS.INSTALLING);
192
                 setStatus(STATUS.INSTALLING);
192
 
193
 
193
                 try {
194
                 try {
194
-                    UpdateChecker.findComponent(getComponent()).doInstall(path);
195
-
196
-                    setStatus(STATUS.INSTALLED);
195
+                    final boolean restart = UpdateChecker.findComponent(getComponent()).doInstall(path);
196
+
197
+                    if (restart) {
198
+                        setStatus(STATUS.RESTART_NEEDED);
199
+                        UpdateChecker.removeComponent(getComponent());
200
+                    } else {
201
+                        setStatus(STATUS.INSTALLED);
202
+                    }
197
                 } catch (Throwable ex) {
203
                 } catch (Throwable ex) {
198
                     setStatus(STATUS.ERROR);
204
                     setStatus(STATUS.ERROR);
199
                     Logger.appError(ErrorLevel.MEDIUM,
205
                     Logger.appError(ErrorLevel.MEDIUM,

+ 28
- 9
src/com/dmdirc/updater/UpdateChecker.java View File

63
         /** New updates are available. */
63
         /** New updates are available. */
64
         UPDATES_AVAILABLE
64
         UPDATES_AVAILABLE
65
     }
65
     }
66
-    
66
+
67
     /** Semaphore used to prevent multiple invocations. */
67
     /** Semaphore used to prevent multiple invocations. */
68
     private static final Semaphore mutex = new Semaphore(1);
68
     private static final Semaphore mutex = new Semaphore(1);
69
 
69
 
82
 
82
 
83
     /** Our current state. */
83
     /** Our current state. */
84
     private static STATE status = STATE.IDLE;
84
     private static STATE status = STATE.IDLE;
85
-    
85
+
86
     /** A reference to the listener we use for update status changes. */
86
     /** A reference to the listener we use for update status changes. */
87
     private static final UpdateListener listener = new UpdateListener() {
87
     private static final UpdateListener listener = new UpdateListener() {
88
         @Override
88
         @Override
112
     public void run() {
112
     public void run() {
113
         if (!mutex.tryAcquire()) {
113
         if (!mutex.tryAcquire()) {
114
             // Duplicate invocation
114
             // Duplicate invocation
115
-            
115
+
116
             return;
116
             return;
117
         }
117
         }
118
-        
118
+
119
         final ConfigManager config = IdentityManager.getGlobalConfig();
119
         final ConfigManager config = IdentityManager.getGlobalConfig();
120
 
120
 
121
         if (!config.getOptionBool("updater", "enable", true)) {
121
         if (!config.getOptionBool("updater", "enable", true)) {
165
         } else {
165
         } else {
166
             setStatus(STATE.UPDATES_AVAILABLE);
166
             setStatus(STATE.UPDATES_AVAILABLE);
167
         }
167
         }
168
-        
168
+
169
         mutex.release();
169
         mutex.release();
170
 
170
 
171
         UpdateChecker.init();
171
         UpdateChecker.init();
255
         components.add(component);
255
         components.add(component);
256
     }
256
     }
257
 
257
 
258
+    /**
259
+     * Unregisters an update component with the specified name.
260
+     *
261
+     * @param name The name of the component to be removed
262
+     */
263
+    public static void removeComponent(final String name) {
264
+        UpdateComponent target = null;
265
+
266
+        for (UpdateComponent component : components) {
267
+            if (name.equals(component.getName())) {
268
+                target = component;
269
+            }
270
+        }
271
+
272
+        if (target != null) {
273
+            components.remove(target);
274
+        }
275
+    }
276
+
258
     /**
277
     /**
259
      * Finds and returns the component with the specified name.
278
      * Finds and returns the component with the specified name.
260
      *
279
      *
346
             myListener.statusChanged(newStatus);
365
             myListener.statusChanged(newStatus);
347
         }
366
         }
348
     }
367
     }
349
-    
368
+
350
     /**
369
     /**
351
      * Checks is a specified component is enabled.
370
      * Checks is a specified component is enabled.
352
-     * 
371
+     *
353
      * @param component Update component to check state
372
      * @param component Update component to check state
354
-     * 
373
+     *
355
      * @return true iif the update component is enabled
374
      * @return true iif the update component is enabled
356
      */
375
      */
357
     public static boolean isEnabled(final UpdateComponent component) {
376
     public static boolean isEnabled(final UpdateComponent component) {
358
-        return IdentityManager.getGlobalConfig().getOptionBool("updater", 
377
+        return IdentityManager.getGlobalConfig().getOptionBool("updater",
359
                 component.getName(), true);
378
                 component.getName(), true);
360
     }
379
     }
361
 
380
 

+ 2
- 1
src/com/dmdirc/updater/UpdateComponent.java View File

53
      * file.
53
      * file.
54
      * 
54
      * 
55
      * @param path The full path to the downloaded data
55
      * @param path The full path to the downloaded data
56
+     * @return True if a client restart is needed, false otherwise
56
      * @throws java.lang.Throwable If any error occured
57
      * @throws java.lang.Throwable If any error occured
57
      */
58
      */
58
-    void doInstall(String path) throws Throwable;
59
+    boolean doInstall(String path) throws Throwable;
59
 
60
 
60
 }
61
 }

+ 18
- 1
src/com/dmdirc/updater/components/ClientComponent.java View File

25
 import com.dmdirc.Main;
25
 import com.dmdirc.Main;
26
 import com.dmdirc.updater.UpdateComponent;
26
 import com.dmdirc.updater.UpdateComponent;
27
 
27
 
28
+import com.dmdirc.util.resourcemanager.ResourceManager;
28
 import java.io.File;
29
 import java.io.File;
29
 
30
 
30
 /**
31
 /**
48
 
49
 
49
     /** {@inheritDoc} */
50
     /** {@inheritDoc} */
50
     @Override
51
     @Override
51
-    public void doInstall(final String path) {
52
+    public boolean doInstall(final String path) {
52
         final File tmpFile = new File(path);
53
         final File tmpFile = new File(path);
53
         final File targetFile = new File(tmpFile.getParent() + File.separator + ".DMDirc.jar");
54
         final File targetFile = new File(tmpFile.getParent() + File.separator + ".DMDirc.jar");
55
+        
54
         if (targetFile.exists()) {
56
         if (targetFile.exists()) {
55
             targetFile.delete();
57
             targetFile.delete();
56
         }
58
         }
59
+        
57
         tmpFile.renameTo(targetFile);
60
         tmpFile.renameTo(targetFile);
61
+        
62
+        if (!LauncherComponent.isUsingLauncher()) {
63
+            Main.getUI().showMessageDialog("Client update downloaded", 
64
+                    "A new version of DMDirc has been downloaded, but as you\n"
65
+                    + "do not seem to be using the DMDirc launcher, it will\n"
66
+                    + "not be installed automatically.\n\n"
67
+                    + "To install this update manually, please replaces the\n"
68
+                    + "existing DMDirc.jar file, located at:\n"
69
+                    + "  " + ResourceManager.getJarPath() + "\n"
70
+                    + "with the following file:\n"
71
+                    + "  " + targetFile.getAbsolutePath());
72
+        }
73
+        
74
+        return true;
58
     }
75
     }
59
 
76
 
60
 }
77
 }

+ 3
- 1
src/com/dmdirc/updater/components/DefaultsComponent.java View File

61
      * @throws java.io.IOException On i/o exception when reading zip file
61
      * @throws java.io.IOException On i/o exception when reading zip file
62
      */
62
      */
63
     @Override
63
     @Override
64
-    public void doInstall(final String path) throws IOException {
64
+    public boolean doInstall(final String path) throws IOException {
65
         final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
65
         final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
66
         
66
         
67
         ziprm.extractResources("", IdentityManager.getDirectory());
67
         ziprm.extractResources("", IdentityManager.getDirectory());
69
         IdentityManager.loadUser();
69
         IdentityManager.loadUser();
70
         
70
         
71
         new File(path).delete();
71
         new File(path).delete();
72
+        
73
+        return false;
72
     }
74
     }
73
 
75
 
74
 }
76
 }

+ 10
- 1
src/com/dmdirc/updater/components/LauncherComponent.java View File

59
         
59
         
60
         UpdateChecker.registerComponent(new LauncherComponent());
60
         UpdateChecker.registerComponent(new LauncherComponent());
61
     }
61
     }
62
+    
63
+    /**
64
+     * Determines if the client has been run using the launcher.
65
+     * 
66
+     * @return True if the launcher has been used, false otherwise
67
+     */
68
+    public static boolean isUsingLauncher() {
69
+        return version != -1;
70
+    }
62
 
71
 
63
     /** {@inheritDoc} */
72
     /** {@inheritDoc} */
64
     @Override
73
     @Override
74
 
83
 
75
     /** {@inheritDoc} */
84
     /** {@inheritDoc} */
76
     @Override
85
     @Override
77
-    public void doInstall(final String path) throws Throwable {
86
+    public boolean doInstall(final String path) throws Throwable {
78
         throw new UnsupportedOperationException("Not supported yet.");
87
         throw new UnsupportedOperationException("Not supported yet.");
79
     }
88
     }
80
 
89
 

+ 3
- 1
src/com/dmdirc/updater/components/ModeAliasesComponent.java View File

61
      * @throws java.io.IOException On i/o exception when reading zip file
61
      * @throws java.io.IOException On i/o exception when reading zip file
62
      */
62
      */
63
     @Override
63
     @Override
64
-    public void doInstall(final String path) throws IOException {
64
+    public boolean doInstall(final String path) throws IOException {
65
         final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
65
         final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
66
         
66
         
67
         ziprm.extractResources("", IdentityManager.getDirectory());
67
         ziprm.extractResources("", IdentityManager.getDirectory());
69
         IdentityManager.loadUser();
69
         IdentityManager.loadUser();
70
         
70
         
71
         new File(path).delete();
71
         new File(path).delete();
72
+        
73
+        return false;
72
     }
74
     }
73
 
75
 
74
 }
76
 }

+ 9
- 0
src/com/dmdirc/util/resourcemanager/ResourceManager.java View File

91
         return me;
91
         return me;
92
     }
92
     }
93
     
93
     
94
+    /**
95
+     * Determines the path of DMDirc's .jar file, if possible.
96
+     * 
97
+     * @return The path to DMDirc's .jar file.
98
+     */
99
+    public static String getJarPath() {
100
+        return "<unknown location>";
101
+    }
102
+    
94
     /**
103
     /**
95
      * Returns an appropriate instance of ResourceManager for the specified url string.
104
      * Returns an appropriate instance of ResourceManager for the specified url string.
96
      *
105
      *

Loading…
Cancel
Save