Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //process switch, set property value
            if (args.Length > 0)
            {
                int argpos = 1;
                foreach (string arg in args)
                {
                    if (arg.Length > 0)
                    {
                        ProcessArgument(arg, argpos);
                    }
                    argpos++;
                }
                if (SaveAndExit)
                {
                    ConfigManager.WriteConfig();
                    OutputManager.AppendToConsole("Config Stored.", ConsoleColor.White);
                    System.Environment.Exit(0);
                }
            }
            if (ConfigManager.ConfigData.SyncPaths.Length > 0)
            {
                if (string.IsNullOrEmpty(ConfigManager.ConfigData.SyncPaths[0].dest_folder))
                {
                    OutputManager.WriteError("Destination path is required.");
                    System.Environment.Exit(ConfigManager.ERROR_BAD_ARGUMENTS);
                }
                if (string.IsNullOrEmpty(ConfigManager.ConfigData.SyncPaths[0].src_folder))
                {
                    OutputManager.WriteError("Source path is required.");
                    System.Environment.Exit(ConfigManager.ERROR_BAD_ARGUMENTS);
                }
            }
            else
            {
                OutputManager.WriteError("Both source and destination paths are required.");
                System.Environment.Exit(ConfigManager.ERROR_BAD_ARGUMENTS);
            }
            if (ConfigManager.ConfigData.SyncPaths[0].dest_folder.Contains(ConfigManager.ConfigData.SyncPaths[0].src_folder))
            {
                OutputManager.WriteError("Destination cannot be inside source due to recursion.");
                System.Environment.Exit(ConfigManager.ERROR_BAD_ARGUMENTS);
            }

            // Begin the File Sync.
            SyncCopy Synchronizer = new SyncCopy(ConfigManager, OutputManager);

            Synchronizer.SourcePath    = ConfigManager.ConfigData.SyncPaths[0].src_folder;
            Synchronizer.DestPath      = ConfigManager.ConfigData.SyncPaths[0].dest_folder;
            Synchronizer.UserExclusion = UserExcludes;
            Synchronizer.CopyFolder();

            string final_notice = string.Format("> Synchronization Completed at {0}\n\r", DateTime.Now);

            OutputManager.Clear(3); OutputManager.Clear(2); OutputManager.Clear(1);
            OutputManager.hWriteToConsole(final_notice, 0, ConsoleColor.Green);
            Synchronizer.LogOutput(final_notice, 1);

            OutputManager.AppendToConsole("               Total processed: "); OutputManager.AppendLineToConsole(Synchronizer.result_data.total_items.ToString().Trim(), ConsoleColor.White);
            OutputManager.AppendToConsole("                 Total updated: "); OutputManager.AppendLineToConsole(Synchronizer.result_data.total_updated.ToString().Trim(), ConsoleColor.White);
            OutputManager.AppendToConsole("       Total older than source: "); OutputManager.AppendLineToConsole(Synchronizer.result_data.total_older.ToString().Trim(), ConsoleColor.White);
            OutputManager.AppendToConsole("       Total newer than source: "); OutputManager.AppendLineToConsole(Synchronizer.result_data.total_newer.ToString().Trim(), ConsoleColor.White);
            OutputManager.AppendToConsole("Total missing from destination: "); OutputManager.AppendLineToConsole(Synchronizer.result_data.total_missingdest.ToString().Trim(), ConsoleColor.White);
            OutputManager.AppendToConsole("     Total missing from source: "); OutputManager.AppendLineToConsole(Synchronizer.result_data.total_missingsrc.ToString().Trim(), ConsoleColor.White);
            OutputManager.AppendToConsole("  Total invalid on destination: "); OutputManager.AppendLineToConsole(Synchronizer.result_data.total_removed.ToString().Trim(), ConsoleColor.White);
            OutputManager.AppendToConsole("       Total Zero Size Skipped: "); OutputManager.AppendLineToConsole(Synchronizer.result_data.total_zerosize.ToString().Trim(), ConsoleColor.White);
            OutputManager.AppendToConsole("");
        }
Exemplo n.º 2
0
        public void CopyFolder(string SourceFolder = "")
        {
            string tsrc = "", tdst = "", locOnDest, tsource;

            string[] SourceFiles;
            DateTime lastWriteTime;
            bool     copyCurFile;

            if (SourceFolder == string.Empty)
            {
                SourceFolder = SourcePath;
            }

            try
            {
                SourceFiles = Directory.GetFiles(SourceFolder);
                ScreenPrinter.hWriteToConsole("Scanning...", 0);
                foreach (string cFile in SourceFiles)
                {
                    copyCurFile   = true;
                    lastWriteTime = File.GetLastWriteTime(cFile);
                    tsrc          = cFile;
                    if (cFile.Length > 0 && !StopCopy && !exclusionCheck(cFile, true))
                    {
                        result_data.total_items++;
                        //Get destination path
                        locOnDest = DestPath;
                        tsource   = SanitizeSource(SourcePath);

                        //append destination
                        if (locOnDest[locOnDest.Length - 1] != folder_delimiter)
                        {
                            locOnDest += folder_delimiter;
                        }
                        tdst = SanitizeDestination(cFile, tsource);
                        if (object.ReferenceEquals(null, tdst))
                        {
                            ScreenPrinter.WriteError(string.Format("Destination path issue: {0}", tdst));
                            System.Environment.Exit(0);
                        }
                        locOnDest += tdst;

                        if (cFile.Length > 120)
                        {
                            Console.Write("");
                        }
                        //update display
                        ScreenPrinter.hWriteToConsole(cFile, 1, ConsoleColor.White);

                        //check for destination
                        copyCurFile = true;
                        if (File.Exists(locOnDest))
                        {
                            copyCurFile = NeedToCopyValidator(cFile, locOnDest);
                        }
                        else
                        {
                            result_data.total_missingdest++;
                        }

                        if (copyCurFile && !ToExcludeFile(cFile))
                        {
                            if (!AnalyzeOnly)
                            {
                                LogOutput("Starting Copy " + cFile + " to " + locOnDest + " @ " + DateTime.Now);
                                SafeCopy(cFile, locOnDest);
                            }
                            else if (AnalyzeOnly && this.configHandler.ConfigData.LogAction)
                            {
                                LogOutput("Synchronization would update:", 1);
                                LogFileData(cFile, locOnDest);
                            }
                        }
                    }

                    if (StopCopy)
                    {
                        break;
                    }
                }
            }
            catch (Exception _e)
            {
                if (tsrc.Length > 0)
                {
                    ScreenPrinter.WriteError(string.Format("Path/File issue with exception {0}", _e.Message));
                }
            }

            // Copy the subfolders
            if (StopCopy == false && configHandler.ConfigData.nofolders == false)
            {
                ScanFolders(SourceFolder);
            }
        }