Sfoglia il codice sorgente

Add some missing files.

pull/302/head
Greg Holmes 9 anni fa
parent
commit
47218fad77

+ 106
- 0
mediasource_windows/src/com/dmdirc/addons/mediasource_windows/WindowsMediaSourceManager.java Vedi File

@@ -0,0 +1,106 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.mediasource_windows;
24
+
25
+import com.dmdirc.addons.nowplaying.MediaSource;
26
+import com.dmdirc.addons.nowplaying.MediaSourceManager;
27
+import com.dmdirc.plugins.PluginDomain;
28
+import com.dmdirc.plugins.PluginInfo;
29
+import com.dmdirc.plugins.PluginManager;
30
+import com.dmdirc.plugins.implementations.PluginFilesHelper;
31
+import com.dmdirc.util.io.StreamUtils;
32
+
33
+import com.google.common.io.CharStreams;
34
+
35
+import java.io.IOException;
36
+import java.io.InputStreamReader;
37
+import java.util.ArrayList;
38
+import java.util.List;
39
+
40
+import javax.inject.Inject;
41
+
42
+/**
43
+ * Manages all Windows based media sources.
44
+ */
45
+public class WindowsMediaSourceManager implements MediaSourceManager {
46
+
47
+    /** Media sources. */
48
+    private final List<MediaSource> sources;
49
+    /** Plugin files helper. */
50
+    private final PluginFilesHelper filesHelper;
51
+
52
+    @Inject
53
+    public WindowsMediaSourceManager(
54
+            final PluginManager pluginManager,
55
+            @PluginDomain(WindowsMediaSourcePlugin.class) final PluginInfo pluginInfo) {
56
+        this.filesHelper = new PluginFilesHelper(pluginManager, pluginInfo);
57
+        sources = new ArrayList<>();
58
+        sources.add(new DllSource(this, "Winamp", true));
59
+        sources.add(new DllSource(this, "iTunes", false));
60
+    }
61
+
62
+    public void onLoad() {
63
+        // Extract the .dlls and .exe
64
+        try {
65
+            filesHelper.extractResourcesEndingWith(".dll");
66
+            filesHelper.extractResourcesEndingWith(".exe");
67
+        } catch (IOException ex) {
68
+            throw new IllegalStateException("Unable to extract needed files: " + ex.getMessage(),
69
+                    ex);
70
+        }
71
+    }
72
+
73
+    @Override
74
+     public List<MediaSource> getSources() {
75
+        return sources;
76
+    }
77
+
78
+    /**
79
+     * Get the output from GetMediaInfo.exe for the given player and method
80
+     *
81
+     * @param player Player to ask about
82
+     * @param method Method to call
83
+     *
84
+     * @return a MediaInfoOutput with the results
85
+     */
86
+    protected MediaInfoOutput getOutput(final String player, final String method) {
87
+        try {
88
+            final Process myProcess = Runtime.getRuntime().exec(new String[]{
89
+                    filesHelper.getFilesDirString() + "GetMediaInfo.exe",
90
+                    player,
91
+                    method});
92
+            StreamUtils.readStream(myProcess.getErrorStream());
93
+            final String data = CharStreams
94
+                    .toString(new InputStreamReader(myProcess.getInputStream()));
95
+            try {
96
+                myProcess.waitFor();
97
+            } catch (InterruptedException e) {
98
+            }
99
+
100
+            return new MediaInfoOutput(myProcess.exitValue(), data);
101
+        } catch (SecurityException | IOException e) {
102
+        }
103
+
104
+        return new MediaInfoOutput(-1, "Error executing GetMediaInfo.exe");
105
+    }
106
+}

+ 49
- 0
mediasource_windows/src/com/dmdirc/addons/mediasource_windows/WindowsMediaSourceModule.java Vedi File

@@ -0,0 +1,49 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.mediasource_windows;
24
+
25
+import com.dmdirc.ClientModule;
26
+import com.dmdirc.plugins.PluginDomain;
27
+import com.dmdirc.plugins.PluginInfo;
28
+
29
+import dagger.Module;
30
+import dagger.Provides;
31
+
32
+/**
33
+ * DI module for the windows media source plugin.
34
+ */
35
+@Module(injects = WindowsMediaSourceManager.class, addsTo = ClientModule.class)
36
+public class WindowsMediaSourceModule {
37
+
38
+    private final PluginInfo pluginInfo;
39
+
40
+    public WindowsMediaSourceModule(final PluginInfo pluginInfo) {
41
+        this.pluginInfo = pluginInfo;
42
+    }
43
+
44
+    @Provides
45
+    @PluginDomain(WindowsMediaSourcePlugin.class)
46
+    public PluginInfo getPluginInfo() {
47
+        return pluginInfo;
48
+    }
49
+}

Loading…
Annulla
Salva