Browse Source

Add some methods to update components to indicate if a restart of the client is needed before the user updates

fixes issue 642

Change-Id: I64f23ddcd75e97700a02e1c65d97ae91e48734f5
Reviewed-on: http://gerrit.dmdirc.com/1057
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.6.4rc1
Simon Mott 14 years ago
parent
commit
05c46ce373

+ 37
- 9
src/com/dmdirc/updater/UpdateComponent.java View File

@@ -26,25 +26,25 @@ package com.dmdirc.updater;
26 26
  * The update component interface defines the methods needed to be implemented
27 27
  * by updatable components. The components handle determining the current
28 28
  * version and installing updated files.
29
- * 
29
+ *
30 30
  * @author chris
31 31
  */
32 32
 public interface UpdateComponent {
33
-    
33
+
34 34
     /**
35 35
      * Retrieves the name of this component.
36
-     * 
36
+     *
37 37
      * @return This component's name
38 38
      */
39 39
     String getName();
40
-    
40
+
41 41
     /**
42 42
      * A user-friendly name displayed for the component.
43
-     * 
43
+     *
44 44
      * @return This component's user-friendly name
45 45
      */
46 46
     String getFriendlyName();
47
-    
47
+
48 48
     /**
49 49
      * A user-friendly version displayed for the component.
50 50
      *
@@ -55,17 +55,45 @@ public interface UpdateComponent {
55 55
 
56 56
     /**
57 57
      * Retrieves the currently installed version of this component.
58
-     * 
58
+     *
59 59
      * @return This component's current version
60 60
      * @since 0.6.3m1
61 61
      */
62 62
     Version getVersion();
63
-    
63
+
64
+    /**
65
+     * Provisionally indicates if this component will require a client
66
+     * restart. The result of {@link #doInstall(java.lang.String)} ultimately
67
+     * decides if the client requires a restart.
68
+     *
69
+     * @return True if the client requires a restart
70
+     * @since 0.6.4
71
+     */
72
+    boolean requiresRestart();
73
+
74
+    /**
75
+     * Indicates if this component will require a manual install.
76
+     *
77
+     * @return True if the component requires a manual install
78
+     * @since 0.6.4
79
+     */
80
+    boolean requiresManualInstall();
81
+
82
+    /**
83
+     * Generates manual installation instructions given that the update has been
84
+     * downloaded to the specified temporary path.
85
+     *
86
+     * @param path The full path to the downloaded data
87
+     * @return Return manual instructions for this plugin
88
+     * @since 0.6.4
89
+     */
90
+    String getManualInstructions(final String path);
91
+
64 92
     /**
65 93
      * Installs the updated version of this component. After the update has
66 94
      * been installed, the component is responsible for deleting the specified
67 95
      * file.
68
-     * 
96
+     *
69 97
      * @param path The full path to the downloaded data
70 98
      * @return True if a client restart is needed, false otherwise
71 99
      * @throws java.lang.Exception If any error occured

+ 23
- 5
src/com/dmdirc/updater/components/ActionGroupComponent.java View File

@@ -30,22 +30,22 @@ import com.dmdirc.updater.Version;
30 30
 
31 31
 /**
32 32
  * Update component for action groups.
33
- * 
33
+ *
34 34
  * @author chris
35 35
  */
36 36
 public class ActionGroupComponent implements UpdateComponent {
37
-    
37
+
38 38
     /** The group that this component represents. */
39 39
     private ActionGroup group;
40
-    
40
+
41 41
     /**
42 42
      * Creates a new ActionGroupComponent for the specified action group.
43
-     * 
43
+     *
44 44
      * @param group The action group this component is for
45 45
      */
46 46
     public ActionGroupComponent(final ActionGroup group) {
47 47
         this.group = group;
48
-        
48
+
49 49
         if (group.getComponent() != -1 && group.getVersion() != null) {
50 50
             UpdateChecker.removeComponent(getName());
51 51
             UpdateChecker.registerComponent(this);
@@ -76,6 +76,24 @@ public class ActionGroupComponent implements UpdateComponent {
76 76
         return String.valueOf(getVersion());
77 77
     }
78 78
 
79
+    /** {@inheritDoc} */
80
+    @Override
81
+    public boolean requiresRestart() {
82
+        return false;
83
+    }
84
+
85
+    /** {@inheritDoc} */
86
+    @Override
87
+    public boolean requiresManualInstall() {
88
+        return false;
89
+    }
90
+
91
+    /** {@inheritDoc} */
92
+    @Override
93
+    public String getManualInstructions(final String path) {
94
+        return "";
95
+    }
96
+
79 97
     /** {@inheritDoc} */
80 98
     @Override
81 99
     public boolean doInstall(final String path) throws Exception {

+ 42
- 20
src/com/dmdirc/updater/components/ClientComponent.java View File

@@ -32,7 +32,7 @@ import java.io.File;
32 32
 
33 33
 /**
34 34
  * Represents the client component, which covers the core client resources.
35
- * 
35
+ *
36 36
  * @author chris
37 37
  */
38 38
 public class ClientComponent implements UpdateComponent {
@@ -42,7 +42,7 @@ public class ClientComponent implements UpdateComponent {
42 42
     public String getName() {
43 43
         return "client";
44 44
     }
45
-    
45
+
46 46
     /** {@inheritDoc} */
47 47
     @Override
48 48
     public String getFriendlyName() {
@@ -57,26 +57,24 @@ public class ClientComponent implements UpdateComponent {
57 57
 
58 58
     /** {@inheritDoc} */
59 59
     @Override
60
-    public String getFriendlyVersion() {
61
-        return IdentityManager.getGlobalConfig().getOption("version", "version");
60
+    public boolean requiresRestart() {
61
+        return true;
62 62
     }
63 63
 
64 64
     /** {@inheritDoc} */
65 65
     @Override
66
-    public boolean doInstall(final String path) {
67
-        final File tmpFile = new File(path);
68
-        final File targetFile = new File(tmpFile.getParent() + File.separator + ".DMDirc.jar");
69
-        
70
-        if (targetFile.exists()) {
71
-            targetFile.delete();
72
-        }
73
-        
74
-        tmpFile.renameTo(targetFile);
75
-        
76
-        if (!LauncherComponent.isUsingLauncher()) {
77
-            final String message;
66
+    public boolean requiresManualInstall() {
67
+        return !LauncherComponent.isUsingLauncher();
68
+    }
69
+
70
+    /** {@inheritDoc} */
71
+    @Override
72
+    public String getManualInstructions(final String path) {
73
+        final File targetFile = new File(new File(path).getParent() + File.separator + ".DMDirc.jar");
74
+
75
+        if (requiresManualInstall()) {
78 76
             if (DMDircResourceManager.isRunningFromJar()) {
79
-                message = "A new version of DMDirc has been downloaded, but as you\n"
77
+                return "A new version of DMDirc has been downloaded, but as you\n"
80 78
                     + "do not seem to be using the DMDirc launcher, it will\n"
81 79
                     + "not be installed automatically.\n\n"
82 80
                     + "To install this update manually, please replace the\n"
@@ -85,7 +83,7 @@ public class ClientComponent implements UpdateComponent {
85 83
                     + "with the following file:\n"
86 84
                     + "  " + targetFile.getAbsolutePath();
87 85
             } else {
88
-                message = "A new version of DMDirc has been downloaded, but as you\n"
86
+                return "A new version of DMDirc has been downloaded, but as you\n"
89 87
                     + "do not seem to be using the DMDirc launcher, it will\n"
90 88
                     + "not be installed automatically.\n\n"
91 89
                     + "To install this update manually, please extract the\n"
@@ -94,10 +92,34 @@ public class ClientComponent implements UpdateComponent {
94 92
                     + "over your existing DMDirc install located in:\n"
95 93
                     + "  " + DMDircResourceManager.getCurrentWorkingDirectory();
96 94
             }
97
-            
95
+        }
96
+        return "";
97
+    }
98
+
99
+    /** {@inheritDoc} */
100
+    @Override
101
+    public String getFriendlyVersion() {
102
+        return IdentityManager.getGlobalConfig().getOption("version", "version");
103
+    }
104
+
105
+    /** {@inheritDoc} */
106
+    @Override
107
+    public boolean doInstall(final String path) {
108
+        final File tmpFile = new File(path);
109
+        final File targetFile = new File(tmpFile.getParent() + File.separator + ".DMDirc.jar");
110
+
111
+        if (targetFile.exists()) {
112
+            targetFile.delete();
113
+        }
114
+
115
+        tmpFile.renameTo(targetFile);
116
+
117
+         // @deprecated Should be removed when updater UI changes are implemented.
118
+        final String message = this.getManualInstructions(path);
119
+        if (requiresManualInstall()) {
98 120
             Main.getUI().showMessageDialog("Client update downloaded", message);
99 121
         }
100
-        
122
+
101 123
         return true;
102 124
     }
103 125
 

+ 28
- 10
src/com/dmdirc/updater/components/DefaultsComponent.java View File

@@ -33,7 +33,7 @@ import java.io.IOException;
33 33
 
34 34
 /**
35 35
  * Represents the default identities.
36
- * 
36
+ *
37 37
  * @author chris
38 38
  */
39 39
 public class DefaultsComponent implements UpdateComponent {
@@ -43,12 +43,12 @@ public class DefaultsComponent implements UpdateComponent {
43 43
     public String getName() {
44 44
         return "defaultsettings";
45 45
     }
46
-    
46
+
47 47
     /** {@inheritDoc} */
48 48
     @Override
49 49
     public String getFriendlyName() {
50 50
         return "Default settings";
51
-    }    
51
+    }
52 52
 
53 53
     /** {@inheritDoc} */
54 54
     @Override
@@ -57,10 +57,10 @@ public class DefaultsComponent implements UpdateComponent {
57 57
     }
58 58
 
59 59
     /** {@inheritDoc} */
60
-    @Override    
60
+    @Override
61 61
     public Version getVersion() {
62 62
         final ConfigManager globalConfig = IdentityManager.getGlobalConfig();
63
-        
63
+
64 64
         if (globalConfig.hasOptionString("identity", "defaultsversion")) {
65 65
             return new Version(globalConfig.getOption("identity", "defaultsversion"));
66 66
         } else {
@@ -68,21 +68,39 @@ public class DefaultsComponent implements UpdateComponent {
68 68
         }
69 69
     }
70 70
 
71
+    /** {@inheritDoc} */
72
+    @Override
73
+    public boolean requiresRestart() {
74
+        return false;
75
+    }
76
+
77
+    /** {@inheritDoc} */
78
+    @Override
79
+    public boolean requiresManualInstall() {
80
+        return false;
81
+    }
82
+
83
+    /** {@inheritDoc} */
84
+    @Override
85
+    public String getManualInstructions(final String path) {
86
+        return "";
87
+    }
88
+
71 89
     /**
72 90
      * {@inheritDoc}
73
-     * 
91
+     *
74 92
      * @throws java.io.IOException On i/o exception when reading zip file
75 93
      */
76 94
     @Override
77 95
     public boolean doInstall(final String path) throws IOException {
78 96
         final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
79
-        
97
+
80 98
         ziprm.extractResources("", IdentityManager.getDirectory());
81
-        
99
+
82 100
         IdentityManager.loadUser();
83
-        
101
+
84 102
         new File(path).delete();
85
-        
103
+
86 104
         return false;
87 105
     }
88 106
 

+ 23
- 4
src/com/dmdirc/updater/components/LauncherComponent.java View File

@@ -88,12 +88,12 @@ public class LauncherComponent implements UpdateComponent, OptionsComponent {
88 88
     public String getName() {
89 89
         return "launcher-" + platform;
90 90
     }
91
-    
91
+
92 92
     /** {@inheritDoc} */
93 93
     @Override
94 94
     public String getFriendlyName() {
95 95
         return "Launcher";
96
-    }    
96
+    }
97 97
 
98 98
     /** {@inheritDoc} */
99 99
     @Override
@@ -113,6 +113,25 @@ public class LauncherComponent implements UpdateComponent, OptionsComponent {
113 113
         return options;
114 114
     }
115 115
 
116
+
117
+    /** {@inheritDoc} */
118
+    @Override
119
+    public boolean requiresRestart() {
120
+        return true;
121
+    }
122
+
123
+    /** {@inheritDoc} */
124
+    @Override
125
+    public boolean requiresManualInstall() {
126
+        return false;
127
+    }
128
+
129
+    /** {@inheritDoc} */
130
+    @Override
131
+    public String getManualInstructions(final String path) {
132
+        return "";
133
+    }
134
+
116 135
     /** {@inheritDoc} */
117 136
     @Override
118 137
     public boolean doInstall(final String path) throws Exception {
@@ -126,13 +145,13 @@ public class LauncherComponent implements UpdateComponent, OptionsComponent {
126 145
 
127 146
             tmpFile.renameTo(targetFile);
128 147
             targetFile.setExecutable(true);
129
-            return true;
148
+
130 149
         } else {
131 150
             final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
132 151
             ziprm.extractResources("", tmpFile.getParent()+ File.separator);
133 152
             new File(path).delete();
134
-            return true;
135 153
         }
154
+        return true;
136 155
     }
137 156
 
138 157
 }

+ 28
- 10
src/com/dmdirc/updater/components/ModeAliasesComponent.java View File

@@ -33,7 +33,7 @@ import java.io.IOException;
33 33
 
34 34
 /**
35 35
  * Represents the mode alias identities.
36
- * 
36
+ *
37 37
  * @author chris
38 38
  */
39 39
 public class ModeAliasesComponent implements UpdateComponent {
@@ -43,12 +43,12 @@ public class ModeAliasesComponent implements UpdateComponent {
43 43
     public String getName() {
44 44
         return "modealiases";
45 45
     }
46
-    
46
+
47 47
     /** {@inheritDoc} */
48 48
     @Override
49 49
     public String getFriendlyName() {
50 50
         return "Mode aliases";
51
-    }    
51
+    }
52 52
 
53 53
     /** {@inheritDoc} */
54 54
     @Override
@@ -57,10 +57,10 @@ public class ModeAliasesComponent implements UpdateComponent {
57 57
     }
58 58
 
59 59
     /** {@inheritDoc} */
60
-    @Override    
60
+    @Override
61 61
     public Version getVersion() {
62 62
         final ConfigManager globalConfig = IdentityManager.getGlobalConfig();
63
-        
63
+
64 64
         if (globalConfig.hasOptionString("identity", "modealiasversion")) {
65 65
             return new Version(globalConfig.getOption("identity", "modealiasversion"));
66 66
         } else {
@@ -68,21 +68,39 @@ public class ModeAliasesComponent implements UpdateComponent {
68 68
         }
69 69
     }
70 70
 
71
+    /** {@inheritDoc} */
72
+    @Override
73
+    public boolean requiresRestart() {
74
+        return false;
75
+    }
76
+
77
+    /** {@inheritDoc} */
78
+    @Override
79
+    public boolean requiresManualInstall() {
80
+        return false;
81
+    }
82
+
83
+    /** {@inheritDoc} */
84
+    @Override
85
+    public String getManualInstructions(final String path) {
86
+        return "";
87
+    }
88
+
71 89
     /**
72 90
      * {@inheritDoc}
73
-     * 
91
+     *
74 92
      * @throws java.io.IOException On i/o exception when reading zip file
75 93
      */
76 94
     @Override
77 95
     public boolean doInstall(final String path) throws IOException {
78 96
         final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
79
-        
97
+
80 98
         ziprm.extractResources("", IdentityManager.getDirectory());
81
-        
99
+
82 100
         IdentityManager.loadUser();
83
-        
101
+
84 102
         new File(path).delete();
85
-        
103
+
86 104
         return false;
87 105
     }
88 106
 

+ 30
- 12
src/com/dmdirc/updater/components/PluginComponent.java View File

@@ -34,26 +34,26 @@ import java.io.File;
34 34
 
35 35
 /**
36 36
  * An update component for plugins.
37
- * 
37
+ *
38 38
  * @author chris
39 39
  */
40 40
 public class PluginComponent implements UpdateComponent, FileComponent {
41
-    
41
+
42 42
     /** The plugin this component is for. */
43 43
     private final PluginInfo plugin;
44
-    
44
+
45 45
     /** The config to use. */
46 46
     private static final ConfigManager config = IdentityManager.getGlobalConfig();
47 47
 
48 48
     /**
49 49
      * Creates a new PluginComponent for the specified plugin, to enable it to
50 50
      * be updated automatically.
51
-     * 
51
+     *
52 52
      * @param plugin The plugin to be added to the updater
53 53
      */
54 54
     public PluginComponent(final PluginInfo plugin) {
55 55
         this.plugin = plugin;
56
-        
56
+
57 57
         if ((plugin.getAddonID() > 0 && plugin.getVersion().isValid())
58 58
                 || (config.hasOptionInt("plugin-addonid", plugin.getName()))) {
59 59
             UpdateChecker.removeComponent(getName());
@@ -72,7 +72,7 @@ public class PluginComponent implements UpdateComponent, FileComponent {
72 72
     }
73 73
 
74 74
     /** {@inheritDoc} */
75
-    @Override    
75
+    @Override
76 76
     public String getFriendlyName() {
77 77
         return plugin.getNiceName();
78 78
     }
@@ -84,13 +84,31 @@ public class PluginComponent implements UpdateComponent, FileComponent {
84 84
     }
85 85
 
86 86
     /** {@inheritDoc} */
87
-    @Override    
87
+    @Override
88 88
     public Version getVersion() {
89 89
         return plugin.getVersion();
90 90
     }
91 91
 
92 92
     /** {@inheritDoc} */
93
-    @Override    
93
+    @Override
94
+    public boolean requiresRestart() {
95
+        return !plugin.isUnloadable() && plugin.isLoaded();
96
+    }
97
+
98
+    /** {@inheritDoc} */
99
+    @Override
100
+    public boolean requiresManualInstall() {
101
+        return false;
102
+    }
103
+
104
+    /** {@inheritDoc} */
105
+    @Override
106
+    public String getManualInstructions(final String path) {
107
+        return "";
108
+    }
109
+
110
+    /** {@inheritDoc} */
111
+    @Override
94 112
     public boolean doInstall(final String path) throws Exception {
95 113
         final File target = new File(plugin.getFullFilename());
96 114
 
@@ -110,14 +128,14 @@ public class PluginComponent implements UpdateComponent, FileComponent {
110 128
         // If it doesn't work then keep the plugin in a .update file untill
111 129
         // the next restart.
112 130
         // If it does, update the metadata.
113
-        if ((!plugin.isUnloadable() && plugin.isLoaded()) || !new File(path).renameTo(target)) {
131
+        if (requiresRestart() || !new File(path).renameTo(target)) {
114 132
             // Windows rocks!
115 133
             final File newTarget = new File(plugin.getFullFilename() + ".update");
116
-            
134
+
117 135
             if (newTarget.exists()) {
118 136
                 newTarget.delete();
119 137
             }
120
-            
138
+
121 139
             new File(path).renameTo(newTarget);
122 140
             returnCode = true;
123 141
         } else {
@@ -126,7 +144,7 @@ public class PluginComponent implements UpdateComponent, FileComponent {
126 144
 
127 145
         // If the plugin was loaded before, load it again.
128 146
         if (wasLoaded) { plugin.loadPlugin(); }
129
-        
147
+
130 148
         return returnCode;
131 149
     }
132 150
 

Loading…
Cancel
Save