// Path: FileSync/src/de/loskutov/fs/FileSyncPlugin.java
// public class FileSyncPlugin extends AbstractUIPlugin {
// 
//     private static FileSyncPlugin plugin;
// 
//     public static final String PLUGIN_ID = "de.loskutov.FileSync";
// 
//     /**
//      * The constructor.
//      */
//     public FileSyncPlugin() {
//         super();
//         if(plugin != null){
//             throw new IllegalStateException("FileSync plugin is singleton!");
//         }
//         plugin = this;
//     }
// 
//     /**
//      * Returns the shared instance.
//      */
//     public static FileSyncPlugin getDefault() {
//         return plugin;
//     }
// 
//     public static void error(String message, Throwable error) {
//         Shell shell = FileSyncPlugin.getShell();
//         if(message == null){
//             message = "";
//         }
//         if (error != null) {
//             message = message + " " + error.getMessage();
//         }
//         IPreferenceStore store = getDefault().getPreferenceStore();
//         if (store.getBoolean(FileSyncConstants.KEY_ASK_USER)) {
//             MessageDialog.openError(shell, "FileSync error", message);
//         }
//         log(message, error, IStatus.ERROR);
//     }
// 
//     /**
//      * @param statusID
//      *            one of IStatus. constants like IStatus.ERROR etc
//      * @param error
//      */
//     public static void log(String messageID, Throwable error, int statusID) {
//         if (messageID == null) {
//             messageID = error.getMessage();
//             if (messageID == null) {
//                 messageID = error.toString();
//             }
//         }
//         Status status = new Status(statusID, PLUGIN_ID, 0, messageID, error);
//         getDefault().getLog().log(status);
//         if(getDefault().isDebugging()){
//             System.out.println(status);
//         }
//     }
// 
//     public static Shell getShell() {
//         return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
//     }
// 
//     /**
//      * Returns an image descriptor for the image file at the given plug-in
//      * relative path.
//      *
//      * @param path
//      *            the path
//      * @return the image descriptor
//      */
//     public static ImageDescriptor getImageDescriptor(String path) {
//         if (path == null) {
//             return null;
//         }
//         ImageRegistry imageRegistry = getDefault().getImageRegistry();
//         ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(path);
//         if (imageDescriptor == null) {
//             imageDescriptor = imageDescriptorFromPlugin(PLUGIN_ID, path);
//             imageRegistry.put(path, imageDescriptor);
//         }
//         return imageDescriptor;
//     }
// 
//     public static Image getImage(String path) {
//         if (path == null) {
//             return null;
//         }
//         // prefetch image, if not jet there
//         ImageDescriptor imageDescriptor = getImageDescriptor(path);
//         if (imageDescriptor != null) {
//             return getDefault().getImageRegistry().get(path);
//         }
//         // TODO error message
//         return null;
//     }
// }


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import org.eclipse.core.runtime.IStatus;
import de.loskutov.fs.FileSyncPlugin;

/*******************************************************************************
 * Copyright (c) 2009 Andrey Loskutov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributor:  Andrey Loskutov - initial API and implementation
 *******************************************************************************/
package de.loskutov.fs.command;




/**
 * Utility class for file system related operations.
 * @author Andrey
 */
public final class FS {

    private static final String OS_NAME = System.getProperty("os.name").toLowerCase();

    // not final for tests only
    public static boolean enableLogging = true;


    private FS() {
        // don't instantiate me
    }

    public static boolean isWin32() {
        return OS_NAME.indexOf("windows") >= 0;
    }



    /**
     * Single file/directory create operation.
     * @param destination
     * @param isFile
     * @return true if source was successfully created or if it was already existing
     */
    public static boolean create(File destination, boolean isFile) {
        if (destination == null) {
            return true;
        }
        if (isFile && destination.isFile()) {
            return true;
        } else if (!isFile && destination.isDirectory()) {
            return true;
        }

        boolean result = false;

        if (isFile) {
            File dir = destination.getParentFile();
            if (!dir.exists()) {
                result = dir.mkdirs();
                if (!result) {
                    if (enableLogging) {

// Path: FileSync/src/de/loskutov/fs/FileSyncPlugin.java
// public class FileSyncPlugin extends AbstractUIPlugin {
// 
//     private static FileSyncPlugin plugin;
// 
//     public static final String PLUGIN_ID = "de.loskutov.FileSync";
// 
//     /**
//      * The constructor.
//      */
//     public FileSyncPlugin() {
//         super();
//         if(plugin != null){
//             throw new IllegalStateException("FileSync plugin is singleton!");
//         }
//         plugin = this;
//     }
// 
//     /**
//      * Returns the shared instance.
//      */
//     public static FileSyncPlugin getDefault() {
//         return plugin;
//     }
// 
//     public static void error(String message, Throwable error) {
//         Shell shell = FileSyncPlugin.getShell();
//         if(message == null){
//             message = "";
//         }
//         if (error != null) {
//             message = message + " " + error.getMessage();
//         }
//         IPreferenceStore store = getDefault().getPreferenceStore();
//         if (store.getBoolean(FileSyncConstants.KEY_ASK_USER)) {
//             MessageDialog.openError(shell, "FileSync error", message);
//         }
//         log(message, error, IStatus.ERROR);
//     }
// 
//     /**
//      * @param statusID
//      *            one of IStatus. constants like IStatus.ERROR etc
//      * @param error
//      */
//     public static void log(String messageID, Throwable error, int statusID) {
//         if (messageID == null) {
//             messageID = error.getMessage();
//             if (messageID == null) {
//                 messageID = error.toString();
//             }
//         }
//         Status status = new Status(statusID, PLUGIN_ID, 0, messageID, error);
//         getDefault().getLog().log(status);
//         if(getDefault().isDebugging()){
//             System.out.println(status);
//         }
//     }
// 
//     public static Shell getShell() {
//         return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
//     }
// 
//     /**
//      * Returns an image descriptor for the image file at the given plug-in
//      * relative path.
//      *
//      * @param path
//      *            the path
//      * @return the image descriptor
//      */
//     public static ImageDescriptor getImageDescriptor(String path) {
//         if (path == null) {
//             return null;
//         }
//         ImageRegistry imageRegistry = getDefault().getImageRegistry();
//         ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(path);
//         if (imageDescriptor == null) {
//             imageDescriptor = imageDescriptorFromPlugin(PLUGIN_ID, path);
//             imageRegistry.put(path, imageDescriptor);
//         }
//         return imageDescriptor;
//     }
// 
//     public static Image getImage(String path) {
//         if (path == null) {
//             return null;
//         }
//         // prefetch image, if not jet there
//         ImageDescriptor imageDescriptor = getImageDescriptor(path);
//         if (imageDescriptor != null) {
//             return getDefault().getImageRegistry().get(path);
//         }
//         // TODO error message
//         return null;
//     }
// }


// Path: FileSync/src/de/loskutov/fs/command/FS.java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import org.eclipse.core.runtime.IStatus;
import de.loskutov.fs.FileSyncPlugin;

/*******************************************************************************
 * Copyright (c) 2009 Andrey Loskutov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributor:  Andrey Loskutov - initial API and implementation
 *******************************************************************************/
package de.loskutov.fs.command;




/**
 * Utility class for file system related operations.
 * @author Andrey
 */
public final class FS {

    private static final String OS_NAME = System.getProperty("os.name").toLowerCase();

    // not final for tests only
    public static boolean enableLogging = true;


    private FS() {
        // don't instantiate me
    }

    public static boolean isWin32() {
        return OS_NAME.indexOf("windows") >= 0;
    }



    /**
     * Single file/directory create operation.
     * @param destination
     * @param isFile
     * @return true if source was successfully created or if it was already existing
     */
    public static boolean create(File destination, boolean isFile) {
        if (destination == null) {
            return true;
        }
        if (isFile && destination.isFile()) {
            return true;
        } else if (!isFile && destination.isDirectory()) {
            return true;
        }

        boolean result = false;

        if (isFile) {
            File dir = destination.getParentFile();
            if (!dir.exists()) {
                result = dir.mkdirs();
                if (!result) {
                    if (enableLogging) {

                        FileSyncPlugin.log("Could not create directory '" + dir + "'",
