Browse Source

Update plugins to use filesDir

Change-Id: I7b86511d66a605d3f800b6d4171d65863cdae70c
Reviewed-on: http://gerrit.dmdirc.com/1216
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.4
Shane Mc Cormack 14 years ago
parent
commit
508dc526cd

+ 8
- 15
src/com/dmdirc/addons/freedesktop_notifications/FreeDesktopNotificationsPlugin.java View File

@@ -50,12 +50,9 @@ import java.util.ArrayList;
50 50
  *
51 51
  * @author Shane 'Dataforce' McCormack
52 52
  */
53
-public final class FreeDesktopNotificationsPlugin extends Plugin implements
54
-        ConfigChangeListener{
53
+public final class FreeDesktopNotificationsPlugin extends Plugin implements ConfigChangeListener {
55 54
     /** The DcopCommand we created */
56 55
     private FDNotifyCommand command = null;
57
-    /** Files dir */
58
-    private static final String filesDir  = Main.getConfigDir() + "plugins/freedesktop_notifications_files/";
59 56
     /** notification timeout. */
60 57
     private int timeout;
61 58
     /** notification icon. */
@@ -82,11 +79,13 @@ public final class FreeDesktopNotificationsPlugin extends Plugin implements
82 79
      * @return True if the notification was shown.
83 80
      */
84 81
     public boolean showNotification(final String title, final String message) {
82
+        if (getFilesDir() == null) { return false; }
83
+        
85 84
         final ArrayList<String> args = new ArrayList<String>();
86 85
         
87 86
         args.add("/usr/bin/env");
88 87
         args.add("python");
89
-        args.add(filesDir+"notify.py");
88
+        args.add(getFilesDirString() + "notify.py");
90 89
         args.add("-a");
91 90
         args.add("DMDirc");
92 91
         args.add("-i");
@@ -157,16 +156,10 @@ public final class FreeDesktopNotificationsPlugin extends Plugin implements
157 156
             try {
158 157
                 final ResourceManager res = pi.getResourceManager();
159 158
                 
160
-                // Make sure our files dir exists
161
-                final File newDir = new File(filesDir);
162
-                if (!newDir.exists()) {
163
-                    newDir.mkdirs();
164
-                }
165
-            
166
-                // Now extract the files needed
159
+                // Extract the files needed
167 160
                 try {
168
-                    res.extractResoucesEndingWith(newDir, ".py");
169
-                    res.extractResoucesEndingWith(newDir, ".png");
161
+                    res.extractResoucesEndingWith(getFilesDir(), ".py");
162
+                    res.extractResoucesEndingWith(getFilesDir(), ".png");
170 163
                 } catch (IOException ex) {
171 164
                     Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for Free desktop notifications: " + ex.getMessage(), ex);
172 165
                 }
@@ -188,7 +181,7 @@ public final class FreeDesktopNotificationsPlugin extends Plugin implements
188 181
     /** {@inheritDoc} */
189 182
     @Override
190 183
     public void domainUpdated() {
191
-        IdentityManager.getAddonIdentity().setOption(getDomain(), "general.icon", filesDir+"icon.png");
184
+        IdentityManager.getAddonIdentity().setOption(getDomain(), "general.icon", getFilesDirString() + "icon.png");
192 185
     }
193 186
     
194 187
     /** {@inheritDoc} */

+ 11
- 5
src/com/dmdirc/addons/mediasource_windows/DllSource.java View File

@@ -38,25 +38,31 @@ public class DllSource implements MediaSource {
38 38
     /** Use getArtistTitle */
39 39
     private final boolean useArtistTitle;
40 40
 
41
+    /** Parent Plugin. */
42
+    final WindowsMediaSourcePlugin parent;
43
+
41 44
     /**
42 45
      * Instantiates the media source.
43 46
      *
47
+     * @param parent The plugin that owns this DllSource
44 48
      * @param playerName Name of Player and DLL
45 49
      */
46
-    public DllSource(final String playerName) {
47
-        this(playerName, false);
50
+    public DllSource(final WindowsMediaSourcePlugin parent, final String playerName) {
51
+        this(parent, playerName, false);
48 52
     }
49 53
 
50 54
     /**
51 55
      * Instantiates the media source.
52 56
      *
57
+     * @param parent The plugin that owns this DllSource
53 58
      * @param playerName Name of Player and DLL
54 59
      * @param useArtistTitle True if getArtistTitle should be parsed rather than
55 60
      *                       using getArtist() and getTitle()
56 61
      */
57
-    public DllSource(final String playerName, final boolean useArtistTitle) {
62
+    public DllSource(final WindowsMediaSourcePlugin parent, final String playerName, final boolean useArtistTitle) {
58 63
         this.playerName = playerName;
59 64
         this.useArtistTitle = useArtistTitle;
65
+        this.parent = parent;
60 66
     }
61 67
 
62 68
     /** {@inheritDoc} */
@@ -72,13 +78,13 @@ public class DllSource implements MediaSource {
72 78
      * @return "Good" Output
73 79
      */
74 80
     private String getOutput(final String command) {
75
-        return WindowsMediaSourcePlugin.getOutput(playerName, command).getGoodOutput();
81
+        return parent.getOutput(playerName, command).getGoodOutput();
76 82
     }
77 83
 
78 84
     /** {@inheritDoc} */
79 85
     @Override
80 86
     public MediaSourceState getState() {
81
-        final MediaInfoOutput result = WindowsMediaSourcePlugin.getOutput(playerName, "getPlayState");
87
+        final MediaInfoOutput result = parent.getOutput(playerName, "getPlayState");
82 88
 
83 89
         if (result.getExitCode() == 0) {
84 90
             final String output = result.getGoodOutput();

+ 7
- 16
src/com/dmdirc/addons/mediasource_windows/WindowsMediaSourcePlugin.java View File

@@ -47,17 +47,14 @@ public class WindowsMediaSourcePlugin extends Plugin implements MediaSourceManag
47 47
     /** Media sources. */
48 48
     private final List<MediaSource> sources;
49 49
 
50
-    /** Files dir */
51
-    private static final String filesDir = Main.getConfigDir() + "plugins/windowsmediasource_files/";
52
-
53 50
     /**
54 51
      * Creates a new instance of DcopMediaSourcePlugin.
55 52
      */
56 53
     public WindowsMediaSourcePlugin() {
57 54
         super();
58 55
         sources = new ArrayList<MediaSource>();
59
-        sources.add(new DllSource("Winamp", true));
60
-        sources.add(new DllSource("iTunes", false));
56
+        sources.add(new DllSource(this, "Winamp", true));
57
+        sources.add(new DllSource(this, "iTunes", false));
61 58
     }
62 59
 
63 60
     /** {@inheritDoc} */
@@ -73,9 +70,9 @@ public class WindowsMediaSourcePlugin extends Plugin implements MediaSourceManag
73 70
      * @param method Method to call
74 71
      * @return a MediaInfoOutput with the results
75 72
      */
76
-    protected static MediaInfoOutput getOutput(final String player, final String method) {
73
+    protected MediaInfoOutput getOutput(final String player, final String method) {
77 74
         try {
78
-            final Process myProcess = Runtime.getRuntime().exec(new String[]{filesDir + "GetMediaInfo.exe", player, method});
75
+            final Process myProcess = Runtime.getRuntime().exec(new String[]{getFilesDirString() + "GetMediaInfo.exe", player, method});
79 76
             final StringBuffer data = new StringBuffer();
80 77
             new StreamReader(myProcess.getErrorStream()).start();
81 78
             new StreamReader(myProcess.getInputStream(), data).start();
@@ -107,16 +104,10 @@ public class WindowsMediaSourcePlugin extends Plugin implements MediaSourceManag
107 104
         try {
108 105
             final ResourceManager res = pi.getResourceManager();
109 106
 
110
-            // Make sure our files dir exists
111
-            final File newDir = new File(filesDir);
112
-            if (!newDir.exists()) {
113
-                newDir.mkdirs();
114
-            }
115
-
116
-            // Now extract the .dlls and .exe
107
+            // Extract the .dlls and .exe
117 108
             try {
118
-                res.extractResoucesEndingWith(newDir, ".dll");
119
-                res.extractResoucesEndingWith(newDir, ".exe");
109
+                res.extractResoucesEndingWith(getFilesDir(), ".dll");
110
+                res.extractResoucesEndingWith(getFilesDir(), ".exe");
120 111
             } catch (IOException ex) {
121 112
                 Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for windows media source: " + ex.getMessage(), ex);
122 113
             }

Loading…
Cancel
Save