示例#1
0
        public static void Configure()
        {
            string       source      = Prompt("Enter the path to the source folder");
            string       destination = Prompt("Enter the path to the destination folder");
            MasucoConfig config      = new MasucoConfig();

            config.Source      = source;
            config.Destination = destination;
            config.ToJsonFile(_configFile);
            if (Confirm("Start copying?"))
            {
                CopyMatchingSubfolders();
            }
        }
示例#2
0
 public static void ShowConfiguration()
 {
     if (!File.Exists(_configFile))
     {
         OutLineFormat("Config file {0} not found.", ConsoleColor.Yellow, _configFile);
         OutLine("Starting configuration...", ConsoleColor.Cyan);
         Configure();
     }
     else
     {
         MasucoConfig config = _configFile.SafeReadFile().FromJson <MasucoConfig>();
         OutLineFormat("Source: {0}", ConsoleColor.Cyan, config.Source);
         OutLineFormat("Destination: {0}", ConsoleColor.Cyan, config.Destination);
     }
 }
示例#3
0
        public static void CopyMatchingSubfolders()
        {
            if (!File.Exists(_configFile))
            {
                OutLineFormat("Config file {0} not found.", ConsoleColor.Yellow, _configFile);
                OutLine("Starting configuration...", ConsoleColor.Cyan);
                Configure();
            }
            else
            {
                MasucoConfig  config         = _configFile.SafeReadFile().FromJson <MasucoConfig>();
                DirectoryInfo sourceDir      = new DirectoryInfo(config.Source);
                DirectoryInfo destinationDir = new DirectoryInfo(config.Destination);

                if (Exists(sourceDir) && Exists(destinationDir))
                {
                    DirectoryInfo[] dirsToMatch = destinationDir.GetDirectories();
                    for (int i = 0; i < dirsToMatch.Length; i++)
                    {
                        DirectoryInfo currentDirToMatch = dirsToMatch[i];
                        string        sourcePath        = Path.Combine(sourceDir.FullName, currentDirToMatch.Name);
                        DirectoryInfo currentSource     = new DirectoryInfo(sourcePath);
                        if (currentSource.Exists)
                        {
                            currentSource.Copy(currentDirToMatch.FullName, true,
                                               (srcFile, destFile) =>
                            {
                                FileInfo d = new FileInfo(destFile);
                                if (d.Exists)
                                {
                                    if (d.IsReadOnly)
                                    {
                                        d.IsReadOnly = false;
                                    }
                                    d.Delete();
                                    d.Refresh();
                                }

                                OutLineFormat("Copying {0} -> {1}", ConsoleColor.Yellow, srcFile, destFile);
                            });
                        }
                    }
                }
            }
        }