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
  *
50
  *
51
  * @author Shane 'Dataforce' McCormack
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
     /** The DcopCommand we created */
54
     /** The DcopCommand we created */
56
     private FDNotifyCommand command = null;
55
     private FDNotifyCommand command = null;
57
-    /** Files dir */
58
-    private static final String filesDir  = Main.getConfigDir() + "plugins/freedesktop_notifications_files/";
59
     /** notification timeout. */
56
     /** notification timeout. */
60
     private int timeout;
57
     private int timeout;
61
     /** notification icon. */
58
     /** notification icon. */
82
      * @return True if the notification was shown.
79
      * @return True if the notification was shown.
83
      */
80
      */
84
     public boolean showNotification(final String title, final String message) {
81
     public boolean showNotification(final String title, final String message) {
82
+        if (getFilesDir() == null) { return false; }
83
+        
85
         final ArrayList<String> args = new ArrayList<String>();
84
         final ArrayList<String> args = new ArrayList<String>();
86
         
85
         
87
         args.add("/usr/bin/env");
86
         args.add("/usr/bin/env");
88
         args.add("python");
87
         args.add("python");
89
-        args.add(filesDir+"notify.py");
88
+        args.add(getFilesDirString() + "notify.py");
90
         args.add("-a");
89
         args.add("-a");
91
         args.add("DMDirc");
90
         args.add("DMDirc");
92
         args.add("-i");
91
         args.add("-i");
157
             try {
156
             try {
158
                 final ResourceManager res = pi.getResourceManager();
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
                 try {
160
                 try {
168
-                    res.extractResoucesEndingWith(newDir, ".py");
169
-                    res.extractResoucesEndingWith(newDir, ".png");
161
+                    res.extractResoucesEndingWith(getFilesDir(), ".py");
162
+                    res.extractResoucesEndingWith(getFilesDir(), ".png");
170
                 } catch (IOException ex) {
163
                 } catch (IOException ex) {
171
                     Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for Free desktop notifications: " + ex.getMessage(), ex);
164
                     Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for Free desktop notifications: " + ex.getMessage(), ex);
172
                 }
165
                 }
188
     /** {@inheritDoc} */
181
     /** {@inheritDoc} */
189
     @Override
182
     @Override
190
     public void domainUpdated() {
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
     /** {@inheritDoc} */
187
     /** {@inheritDoc} */

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

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

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

47
     /** Media sources. */
47
     /** Media sources. */
48
     private final List<MediaSource> sources;
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
      * Creates a new instance of DcopMediaSourcePlugin.
51
      * Creates a new instance of DcopMediaSourcePlugin.
55
      */
52
      */
56
     public WindowsMediaSourcePlugin() {
53
     public WindowsMediaSourcePlugin() {
57
         super();
54
         super();
58
         sources = new ArrayList<MediaSource>();
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
     /** {@inheritDoc} */
60
     /** {@inheritDoc} */
73
      * @param method Method to call
70
      * @param method Method to call
74
      * @return a MediaInfoOutput with the results
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
         try {
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
             final StringBuffer data = new StringBuffer();
76
             final StringBuffer data = new StringBuffer();
80
             new StreamReader(myProcess.getErrorStream()).start();
77
             new StreamReader(myProcess.getErrorStream()).start();
81
             new StreamReader(myProcess.getInputStream(), data).start();
78
             new StreamReader(myProcess.getInputStream(), data).start();
107
         try {
104
         try {
108
             final ResourceManager res = pi.getResourceManager();
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
             try {
108
             try {
118
-                res.extractResoucesEndingWith(newDir, ".dll");
119
-                res.extractResoucesEndingWith(newDir, ".exe");
109
+                res.extractResoucesEndingWith(getFilesDir(), ".dll");
110
+                res.extractResoucesEndingWith(getFilesDir(), ".exe");
120
             } catch (IOException ex) {
111
             } catch (IOException ex) {
121
                 Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for windows media source: " + ex.getMessage(), ex);
112
                 Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for windows media source: " + ex.getMessage(), ex);
122
             }
113
             }

Loading…
Cancel
Save