Преглед изворни кода

Adds code to extract files ending with a suffix to a directory, required for some plugins

Change-Id: Icdc4e7b7d3cdf3d58248bbeb191a17b48dfe1297
Reviewed-on: http://gerrit.dmdirc.com/442
Reviewed-by: Chris Smith <chris@dmdirc.com>
Tested-by: Chris Smith <chris@dmdirc.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.3b1
Gregory Holmes пре 14 година
родитељ
комит
888b63372a
1 измењених фајлова са 29 додато и 0 уклоњено
  1. 29
    0
      src/com/dmdirc/util/resourcemanager/ResourceManager.java

+ 29
- 0
src/com/dmdirc/util/resourcemanager/ResourceManager.java Прегледај датотеку

@@ -208,6 +208,35 @@ public abstract class ResourceManager {
208 208
             final String directory) throws IOException {
209 209
         extractResources(resourcesPrefix, directory, true);
210 210
     }
211
+
212
+    /**
213
+     * Extracts files ending with the given suffix
214
+     *
215
+     * @param newDir Directory to extract to.
216
+     * @param suffix Suffix to extract
217
+     *
218
+     * @throws IOException if the resources failed to extract
219
+     */
220
+    public final void extractResoucesEndingWith(final File newDir,
221
+            final String suffix) throws IOException {
222
+        final Map<String, byte[]> resources = getResourcesEndingWithAsBytes(
223
+                suffix);
224
+        for (Entry<String, byte[]> resource : resources.entrySet()) {
225
+            final String key = resource.getKey();
226
+            final String resourceName = key.substring(key.lastIndexOf('/'), key.
227
+                    length());
228
+
229
+            final File newFile = new File(newDir, resourceName);
230
+
231
+            if (!newFile.isDirectory()) {
232
+                if (newFile.exists()) {
233
+                    newFile.delete();
234
+                }
235
+                ResourceManager.getResourceManager().resourceToFile(resource.
236
+                        getValue(), newFile);
237
+            }
238
+        }
239
+    }
211 240
     
212 241
     /**
213 242
      * Checks if a resource exists.

Loading…
Откажи
Сачувај