ソースを参照

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年前
コミット
2f189a5ff0

+ 10
- 4
src/com/dmdirc/updater/Update.java ファイルの表示

@@ -47,7 +47,8 @@ public final class Update {
47 47
         DOWNLOADING,
48 48
         INSTALLING,
49 49
         INSTALLED,
50
-        ERROR
50
+        ERROR,
51
+        RESTART_NEEDED
51 52
     }
52 53
 
53 54
     /** Update component. */
@@ -191,9 +192,14 @@ public final class Update {
191 192
                 setStatus(STATUS.INSTALLING);
192 193
 
193 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 203
                 } catch (Throwable ex) {
198 204
                     setStatus(STATUS.ERROR);
199 205
                     Logger.appError(ErrorLevel.MEDIUM,

+ 28
- 9
src/com/dmdirc/updater/UpdateChecker.java ファイルの表示

@@ -63,7 +63,7 @@ public final class UpdateChecker implements Runnable {
63 63
         /** New updates are available. */
64 64
         UPDATES_AVAILABLE
65 65
     }
66
-    
66
+
67 67
     /** Semaphore used to prevent multiple invocations. */
68 68
     private static final Semaphore mutex = new Semaphore(1);
69 69
 
@@ -82,7 +82,7 @@ public final class UpdateChecker implements Runnable {
82 82
 
83 83
     /** Our current state. */
84 84
     private static STATE status = STATE.IDLE;
85
-    
85
+
86 86
     /** A reference to the listener we use for update status changes. */
87 87
     private static final UpdateListener listener = new UpdateListener() {
88 88
         @Override
@@ -112,10 +112,10 @@ public final class UpdateChecker implements Runnable {
112 112
     public void run() {
113 113
         if (!mutex.tryAcquire()) {
114 114
             // Duplicate invocation
115
-            
115
+
116 116
             return;
117 117
         }
118
-        
118
+
119 119
         final ConfigManager config = IdentityManager.getGlobalConfig();
120 120
 
121 121
         if (!config.getOptionBool("updater", "enable", true)) {
@@ -165,7 +165,7 @@ public final class UpdateChecker implements Runnable {
165 165
         } else {
166 166
             setStatus(STATE.UPDATES_AVAILABLE);
167 167
         }
168
-        
168
+
169 169
         mutex.release();
170 170
 
171 171
         UpdateChecker.init();
@@ -255,6 +255,25 @@ public final class UpdateChecker implements Runnable {
255 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 278
      * Finds and returns the component with the specified name.
260 279
      *
@@ -346,16 +365,16 @@ public final class UpdateChecker implements Runnable {
346 365
             myListener.statusChanged(newStatus);
347 366
         }
348 367
     }
349
-    
368
+
350 369
     /**
351 370
      * Checks is a specified component is enabled.
352
-     * 
371
+     *
353 372
      * @param component Update component to check state
354
-     * 
373
+     *
355 374
      * @return true iif the update component is enabled
356 375
      */
357 376
     public static boolean isEnabled(final UpdateComponent component) {
358
-        return IdentityManager.getGlobalConfig().getOptionBool("updater", 
377
+        return IdentityManager.getGlobalConfig().getOptionBool("updater",
359 378
                 component.getName(), true);
360 379
     }
361 380
 

+ 2
- 1
src/com/dmdirc/updater/UpdateComponent.java ファイルの表示

@@ -53,8 +53,9 @@ public interface UpdateComponent {
53 53
      * file.
54 54
      * 
55 55
      * @param path The full path to the downloaded data
56
+     * @return True if a client restart is needed, false otherwise
56 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 ファイルの表示

@@ -25,6 +25,7 @@ package com.dmdirc.updater.components;
25 25
 import com.dmdirc.Main;
26 26
 import com.dmdirc.updater.UpdateComponent;
27 27
 
28
+import com.dmdirc.util.resourcemanager.ResourceManager;
28 29
 import java.io.File;
29 30
 
30 31
 /**
@@ -48,13 +49,29 @@ public class ClientComponent implements UpdateComponent {
48 49
 
49 50
     /** {@inheritDoc} */
50 51
     @Override
51
-    public void doInstall(final String path) {
52
+    public boolean doInstall(final String path) {
52 53
         final File tmpFile = new File(path);
53 54
         final File targetFile = new File(tmpFile.getParent() + File.separator + ".DMDirc.jar");
55
+        
54 56
         if (targetFile.exists()) {
55 57
             targetFile.delete();
56 58
         }
59
+        
57 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 ファイルの表示

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

+ 10
- 1
src/com/dmdirc/updater/components/LauncherComponent.java ファイルの表示

@@ -59,6 +59,15 @@ public class LauncherComponent implements UpdateComponent {
59 59
         
60 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 72
     /** {@inheritDoc} */
64 73
     @Override
@@ -74,7 +83,7 @@ public class LauncherComponent implements UpdateComponent {
74 83
 
75 84
     /** {@inheritDoc} */
76 85
     @Override
77
-    public void doInstall(final String path) throws Throwable {
86
+    public boolean doInstall(final String path) throws Throwable {
78 87
         throw new UnsupportedOperationException("Not supported yet.");
79 88
     }
80 89
 

+ 3
- 1
src/com/dmdirc/updater/components/ModeAliasesComponent.java ファイルの表示

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

+ 9
- 0
src/com/dmdirc/util/resourcemanager/ResourceManager.java ファイルの表示

@@ -91,6 +91,15 @@ public abstract class ResourceManager {
91 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 104
      * Returns an appropriate instance of ResourceManager for the specified url string.
96 105
      *

読み込み中…
キャンセル
保存