Example #1
0
        /// <param name="task">Task to be backed up/restored.</param>
        /// <param name="expectedNumOutputLines">
        /// Expected total number of output lines for progress estimation, e.g.,
        /// obtained by a prior simulation run.
        /// Required for the ProgressChanged event to be fired.
        /// </param>
        public RobocopyProcess(MirrorTask task, string sourceFolder, string destinationFolder, int expectedNumOutputLines = -1)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (string.IsNullOrEmpty(sourceFolder))
            {
                throw new ArgumentNullException("sourceFolder");
            }
            if (string.IsNullOrEmpty(destinationFolder))
            {
                throw new ArgumentNullException("destinationFolder");
            }

            if (!Directory.Exists(sourceFolder))
            {
                throw new InvalidOperationException(string.Format("The source folder {0} does not exist.", PathHelper.Quote(sourceFolder)));
            }
            if (!Directory.Exists(destinationFolder))
            {
                throw new InvalidOperationException(string.Format("The destination folder {0} does not exist.", PathHelper.Quote(destinationFolder)));
            }

            // only use the bundled Robocopy version if the system does not ship with one
            string exePath = Path.Combine(Environment.SystemDirectory, "Robocopy.exe");

            if (!File.Exists(exePath))
            {
                exePath = Path.Combine(System.Windows.Forms.Application.StartupPath, @"Tools\Robocopy.exe");

                if (!File.Exists(exePath))
                {
                    throw new InvalidOperationException(string.Format("{0} does not exist.", PathHelper.Quote(exePath)));
                }
            }

#if DEBUG
            exePath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "DummyConsoleProcess.exe");
#endif

            SourceFolder      = sourceFolder;
            DestinationFolder = destinationFolder;
            PurgeExtraItems   = task.DeleteExtraItems;

            _expectedNumOutputLines = expectedNumOutputLines;

            StartInfo.FileName  = exePath;
            StartInfo.Arguments = string.Format("{0} {1} {2}", PathHelper.QuoteForRobocopy(SourceFolder),
                                                PathHelper.QuoteForRobocopy(DestinationFolder), BuildSwitches(task, SourceFolder));
        }
Example #2
0
        private static void AppendPathOrWildcard(StringBuilder arguments, string folder, string pathOrWildcard)
        {
            // paths begin with a directory separator character
            if (pathOrWildcard[0] == Path.DirectorySeparatorChar)
            {
                pathOrWildcard = Path.Combine(folder, pathOrWildcard.Substring(1));
            }

            arguments.Append(' ');

            // enforce enclosing double-quotes because if a volume shadow copy is used,
            // the source volume will be replaced by the mount point which may contain spaces
            arguments.Append(PathHelper.QuoteForRobocopy(pathOrWildcard, force: true));
        }