/*
 * Copyright (c) 2006-2014 DMDirc Developers
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.util.io;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.CopyOption;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

/**
 * Utility class to deal with files.
 */
public final class FileUtils {

    private FileUtils() {
        // Shouldn't be instansiated.
    }

    /**
     * Recursively copies the resources specified by the given URL to the destination folder.
     * Existing files will be replaced.
     *
     * @param source The resource to be copied (file or folder).
     * @param destination The destination folder to copy the resource to.
     * @throws IOException If the resource couldn't be copied.
     */
    public static void copyResources(final URL source, final Path destination) throws IOException {
        try {
            copyRecursively(Paths.get(source.toURI()), destination,
                    StandardCopyOption.REPLACE_EXISTING);
        } catch (URISyntaxException ex) {
            throw new IOException("Unable to get source URI", ex);
        }
    }

    /**
     * Recursively copies one path to another. Once complete, a deep copy of the source file or
     * folder will be present in the destination directory.
     *
     * @param source The path that should be copied.
     * @param destination The directory to place copied files in.
     * @param options Options to use when copying.
     * @throws IOException If any files couldn't be copied.
     */
    public static void copyRecursively(final Path source, final Path destination,
            final CopyOption... options) throws IOException {
        final Path destinationPath = destination.resolve(source.getFileName().toString());

        if (Files.isDirectory(source)) {
            Files.createDirectories(destinationPath);
            try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(source)) {
                for (Path path : directoryStream) {
                    copyRecursively(path, destinationPath, options);
                }
            }
        } else {
            Files.copy(source, destinationPath, options);
        }
    }

}

@@ -1170,32 +1170,53 @@
 io.IOException;%0A
+import java.net.URI;%0A
 import java.net.
@@ -1227,32 +1227,32 @@
 yntaxException;%0A
-
 import java.net.
@@ -1327,16 +1327,83 @@
 Stream;%0A
+import java.nio.file.FileSystem;%0Aimport java.nio.file.FileSystems;%0A
 import j
@@ -1517,16 +1517,64 @@
 yOption;
+%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0A/**%0A *
@@ -2188,16 +2188,574 @@
   try %7B%0A
+            final String path = source.toURI().toString();%0A            final int index = path.indexOf(%22!/%22);%0A            if (index %3E -1) %7B%0A                final String file = path.substring(0, index);%0A                final Map%3CString, String%3E env = new HashMap%3C%3E();%0A                try (final FileSystem fs = FileSystems.newFileSystem(URI.create(file), env)) %7B%0A                    copyRecursively(fs.getPath(path.substring(index + 2)), destination,%0A                            StandardCopyOption.REPLACE_EXISTING);%0A                %7D%0A            %7D else %7B%0A    
         
@@ -2826,32 +2826,36 @@
                 
+    
 StandardCopyOpti
@@ -2868,32 +2868,46 @@
 LACE_EXISTING);%0A
+            %7D%0A
         %7D catch 

Fix copying resources from zip files.