Pārlūkot izejas kodu

Simplify PluginFilesHelper

Change-Id: I7494ecfeab6d588e66e569c1370fab9e485d4865
Fixes-Issue: CLIENT-394
Depends-On: Ib8d889891cf4e92d7cb1b50949d5d24f7bc8ca85
Reviewed-on: http://gerrit.dmdirc.com/2639
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.8
Greg Holmes 11 gadus atpakaļ
vecāks
revīzija
86039db832

+ 18
- 33
src/com/dmdirc/addons/freedesktop_notifications/FreeDesktopNotificationsPlugin.java Parādīt failu

@@ -35,12 +35,10 @@ import com.dmdirc.interfaces.ConfigChangeListener;
35 35
 import com.dmdirc.logger.ErrorLevel;
36 36
 import com.dmdirc.logger.Logger;
37 37
 import com.dmdirc.plugins.PluginInfo;
38
-import com.dmdirc.plugins.PluginManager;
39 38
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
40 39
 import com.dmdirc.plugins.implementations.PluginFilesHelper;
41 40
 import com.dmdirc.ui.messages.Styliser;
42 41
 import com.dmdirc.util.io.StreamReader;
43
-import com.dmdirc.util.resourcemanager.ResourceManager;
44 42
 
45 43
 import java.io.IOException;
46 44
 import java.util.ArrayList;
@@ -69,8 +67,6 @@ public final class FreeDesktopNotificationsPlugin
69 67
     private final ConfigManager config;
70 68
     /** Addon identity. */
71 69
     private final Identity identity;
72
-    /** Plugin manager instance. */
73
-    private final PluginManager pluginManager;
74 70
     /** Plugin files helper. */
75 71
     private final PluginFilesHelper filesHelper;
76 72
 
@@ -79,17 +75,14 @@ public final class FreeDesktopNotificationsPlugin
79 75
      *
80 76
      * @param pluginInfo This plugin's plugin info
81 77
      * @param identityManager Identity Manager instance
82
-     * @param pluginManager Plugin manager
83 78
      * @param commandController Command controller to register commands
84 79
      */
85 80
     public FreeDesktopNotificationsPlugin(final PluginInfo pluginInfo,
86 81
             final IdentityManager identityManager,
87
-            final PluginManager pluginManager,
88 82
             final CommandController commandController) {
89 83
         super(commandController);
90 84
         this.pluginInfo = pluginInfo;
91
-        this.pluginManager = pluginManager;
92
-        this.filesHelper = new PluginFilesHelper(pluginInfo.getMetaData());
85
+        this.filesHelper = new PluginFilesHelper(pluginInfo);
93 86
         config = identityManager.getGlobalConfiguration();
94 87
         identity = identityManager.getGlobalAddonIdentity();
95 88
         registerCommand(new FDNotifyCommand(this), FDNotifyCommand.INFO);
@@ -103,7 +96,9 @@ public final class FreeDesktopNotificationsPlugin
103 96
      * @return True if the notification was shown.
104 97
      */
105 98
     public boolean showNotification(final String title, final String message) {
106
-        if (filesHelper.getFilesDir() == null) { return false; }
99
+        if (filesHelper.getFilesDir() == null) {
100
+            return false;
101
+        }
107 102
 
108 103
         final ArrayList<String> args = new ArrayList<String>();
109 104
 
@@ -130,7 +125,10 @@ public final class FreeDesktopNotificationsPlugin
130 125
             final StringBuffer data = new StringBuffer();
131 126
             new StreamReader(myProcess.getErrorStream()).start();
132 127
             new StreamReader(myProcess.getInputStream(), data).start();
133
-            try { myProcess.waitFor(); } catch (InterruptedException e) { }
128
+            try {
129
+                myProcess.waitFor();
130
+            } catch (InterruptedException e) {
131
+            }
134 132
             return true;
135 133
         } catch (SecurityException e) {
136 134
         } catch (IOException e) {
@@ -147,7 +145,9 @@ public final class FreeDesktopNotificationsPlugin
147 145
      */
148 146
     public String prepareString(final String input) {
149 147
         String output = input;
150
-        if (stripcodes) { output = Styliser.stipControlCodes(output); }
148
+        if (stripcodes) {
149
+            output = Styliser.stipControlCodes(output);
150
+        }
151 151
         if (escapehtml) {
152 152
             if (strictescape) {
153 153
                 output = StringEscapeUtils.escapeHtml(output);
@@ -168,26 +168,12 @@ public final class FreeDesktopNotificationsPlugin
168 168
     public void onLoad() {
169 169
         config.addChangeListener(getDomain(), this);
170 170
         setCachedSettings();
171
-
172
-        // Extract required Files
173
-        final PluginInfo pi = pluginManager.getPluginInfoByName("freedesktop_notifications");
174
-
175
-        // This shouldn't actually happen, but check to make sure.
176
-        if (pi != null) {
177
-            // Now get the RM
178
-            try {
179
-                final ResourceManager res = pi.getResourceManager();
180
-
181
-                // Extract the files needed
182
-                try {
183
-                    res.extractResoucesEndingWith(filesHelper.getFilesDir(), ".py");
184
-                    res.extractResoucesEndingWith(filesHelper.getFilesDir(), ".png");
185
-                } catch (IOException ex) {
186
-                    Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for Free desktop notifications: " + ex.getMessage(), ex);
187
-                }
188
-            } catch (IOException ioe) {
189
-                Logger.userError(ErrorLevel.LOW, "Unable to open ResourceManager for freedesktop_notifications: "+ioe.getMessage(), ioe);
190
-            }
171
+        // Extract the files needed
172
+        try {
173
+            filesHelper.extractResoucesEndingWith(".py");
174
+            filesHelper.extractResoucesEndingWith(".png");
175
+        } catch (IOException ex) {
176
+            Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for Free desktop notifications: " + ex.getMessage(), ex);
191 177
         }
192 178
         super.onLoad();
193 179
     }
@@ -242,7 +228,7 @@ public final class FreeDesktopNotificationsPlugin
242 228
     private void setCachedSettings() {
243 229
         timeout = config.getOptionInt(getDomain(), "general.timeout");
244 230
         icon = config.getOption(getDomain(), "general.icon");
245
-        escapehtml = config.getOptionBool( getDomain(), "advanced.escapehtml");
231
+        escapehtml = config.getOptionBool(getDomain(), "advanced.escapehtml");
246 232
         strictescape = config.getOptionBool(getDomain(), "advanced.strictescape");
247 233
         stripcodes = config.getOptionBool(getDomain(), "advanced.stripcodes");
248 234
     }
@@ -253,4 +239,3 @@ public final class FreeDesktopNotificationsPlugin
253 239
         setCachedSettings();
254 240
     }
255 241
 }
256
-

+ 6
- 27
src/com/dmdirc/addons/mediasource_windows/WindowsMediaSourcePlugin.java Parādīt failu

@@ -30,7 +30,6 @@ import com.dmdirc.plugins.PluginInfo;
30 30
 import com.dmdirc.plugins.implementations.BasePlugin;
31 31
 import com.dmdirc.plugins.implementations.PluginFilesHelper;
32 32
 import com.dmdirc.util.io.StreamReader;
33
-import com.dmdirc.util.resourcemanager.ResourceManager;
34 33
 
35 34
 import java.io.IOException;
36 35
 import java.util.ArrayList;
@@ -44,10 +43,6 @@ public class WindowsMediaSourcePlugin extends BasePlugin
44 43
 
45 44
     /** Media sources. */
46 45
     private final List<MediaSource> sources;
47
-
48
-    /** My plugin info. */
49
-    private final PluginInfo pluginInfo;
50
-
51 46
     /** Plugin files helper. */
52 47
     private final PluginFilesHelper filesHelper;
53 48
 
@@ -58,8 +53,7 @@ public class WindowsMediaSourcePlugin extends BasePlugin
58 53
      */
59 54
     public WindowsMediaSourcePlugin(final PluginInfo pluginInfo) {
60 55
         super();
61
-        this.pluginInfo = pluginInfo;
62
-        this.filesHelper = new PluginFilesHelper(pluginInfo.getMetaData());
56
+        this.filesHelper = new PluginFilesHelper(pluginInfo);
63 57
         sources = new ArrayList<MediaSource>();
64 58
         sources.add(new DllSource(this, "Winamp", true));
65 59
         sources.add(new DllSource(this, "iTunes", false));
@@ -103,27 +97,12 @@ public class WindowsMediaSourcePlugin extends BasePlugin
103 97
     /** {@inheritDoc} */
104 98
     @Override
105 99
     public void onLoad() {
106
-        // Extract GetMediaInfo.exe and required DLLs
107
-        final PluginInfo pi = pluginInfo.getMetaData().getManager().getPluginInfoByName("windowsmediasource");
108
-
109
-        // This shouldn't actually happen, but check to make sure.
110
-        if (pi == null) {
111
-            return;
112
-        }
113
-
114
-        // Now get the RM
100
+        // Extract the .dlls and .exe
115 101
         try {
116
-            final ResourceManager res = pi.getResourceManager();
117
-
118
-            // Extract the .dlls and .exe
119
-            try {
120
-                res.extractResoucesEndingWith(filesHelper.getFilesDir(), ".dll");
121
-                res.extractResoucesEndingWith(filesHelper.getFilesDir(), ".exe");
122
-            } catch (IOException ex) {
123
-                Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for windows media source: " + ex.getMessage(), ex);
124
-            }
125
-        } catch (IOException ioe) {
126
-            Logger.userError(ErrorLevel.LOW, "Unable to open ResourceManager for windowsmediasource: " + ioe.getMessage(), ioe);
102
+            filesHelper.extractResoucesEndingWith(".dll");
103
+            filesHelper.extractResoucesEndingWith(".exe");
104
+        } catch (IOException ex) {
105
+            Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for windows media source: " + ex.getMessage(), ex);
127 106
         }
128 107
     }
129 108
 }

Notiek ielāde…
Atcelt
Saglabāt