/// <summary>
        /// Copy each files from a directory and do the same for each subdirectory using recursion
        /// </summary>
        /// <param name="_nb">Index of the save work</param>
        /// <param name="_source">source directory path</param>
        /// <param name="_target">target destination directory path</param>
        private void CompleteCopyAll(DirectoryInfo _source, DirectoryInfo _target)
        {
            //Check of the different parameter that can stop or cancel the work (parameters stored in the Progress Update)
            if (Progress.Cancelled)
            {
                return;
            }
            bool softwareIsLaunched = false;

            while (Progress.IsPaused || EasySaveInfo.CheckIfSoftwareIsLaunched(Setting.softwareString))
            {
                if (Progress.Cancelled)
                {
                    return;
                }
                if (EasySaveInfo.CheckIfSoftwareIsLaunched(Setting.softwareString) && !softwareIsLaunched)
                {
                    Model.OnUpdateModelError("software");
                    softwareIsLaunched = true;
                }
            }
            if (softwareIsLaunched)
            {
                Model.OnUpdateModelError("resume");
            }

            //First create the new target directory where all the files are saved later on
            EditLog.CreateDirectoryLogLine(this, _target);
            Directory.CreateDirectory(_target.FullName);

            // Copy each file into the new directory.
            foreach (FileInfo fi in _source.GetFiles())
            {
                lock (Model.sync)
                {
                    Progress.CurrentSourceFilePath      = fi.FullName;
                    Progress.CurrentDestinationFilePath = Path.Combine(_target.FullName, fi.Name);
                }
                Model.OnSaveWorkUpdate();

                string elapsedTime = "";

                if (fi.Length >= Setting.maxTransferSize)
                {
                    lock (SaveProgress.taken)
                    {
                        EditLog.StartCopyFileLogLine(this, fi);

                        //Copy the file and measure execution time
                        Stopwatch watch = new Stopwatch();
                        watch.Start();
                        fi.CopyTo(Path.Combine(_target.FullName, fi.Name), true);
                        watch.Stop();
                        elapsedTime = watch.Elapsed.TotalSeconds.ToString();
                    }
                }
                else
                {
                    EditLog.StartCopyFileLogLine(this, fi);

                    //Copy the file and measure execution time
                    Stopwatch watch = new Stopwatch();
                    watch.Start();
                    fi.CopyTo(Path.Combine(_target.FullName, fi.Name), true);
                    watch.Stop();
                    elapsedTime = watch.Elapsed.TotalSeconds.ToString();
                }



                lock (Model.sync)
                {
                    Progress.FilesRemaining--;
                    Progress.SizeRemaining -= fi.Length;
                    Progress.UpdateProgressState();
                }

                Model.OnSaveWorkUpdate();
                EditLog.FinishCopyFileLogLine(this, fi, elapsedTime);

                //Check of the different parameter that can stop or cancel the work (parameters stored in the Progress Update)
                if (Progress.Cancelled)
                {
                    return;
                }
                softwareIsLaunched = false;
                while (Progress.IsPaused || EasySaveInfo.CheckIfSoftwareIsLaunched(Setting.softwareString))
                {
                    if (Progress.Cancelled)
                    {
                        return;
                    }
                    if (EasySaveInfo.CheckIfSoftwareIsLaunched(Setting.softwareString) && !softwareIsLaunched)
                    {
                        Model.OnUpdateModelError("software");
                        softwareIsLaunched = true;
                    }
                }
                if (softwareIsLaunched)
                {
                    Model.OnUpdateModelError("resume");
                }
            }

            // Copy each subdirectory using recursion.
            foreach (DirectoryInfo diSourceSubDir in _source.GetDirectories())
            {
                DirectoryInfo nextTargetSubDir =
                    _target.CreateSubdirectory(diSourceSubDir.Name);
                EditLog.EnterSubdirectoryLogLine(this, diSourceSubDir);
                CompleteCopyAll(diSourceSubDir, nextTargetSubDir);
                EditLog.ExitSubdirectoryLogLine(this, diSourceSubDir);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Copy each files (that has been modified since the last save) from a directory, and do the same for each subdirectory using recursion
        /// </summary>
        /// <param name="_nb">Index of the save work</param>
        /// <param name="_source">source directory path</param>
        /// <param name="_target">target destination directory path</param>
        private void DifferencialCopyAll(DirectoryInfo _source, DirectoryInfo _target)
        {
            if (Progress.Cancelled)
            {
                return;
            }
            bool softwareIsLaunched = false;

            while (Progress.IsPaused || EasySaveInfo.CheckIfSoftwareIsLaunched(Setting.softwareString))
            {
                if (Progress.Cancelled)
                {
                    return;
                }
                if (EasySaveInfo.CheckIfSoftwareIsLaunched(Setting.softwareString) && !softwareIsLaunched)
                {
                    Model.OnUpdateModelError("software");
                    softwareIsLaunched = true;
                }
            }
            if (softwareIsLaunched)
            {
                Model.OnUpdateModelError("resume");
            }

            Directory.CreateDirectory(_target.FullName);
            EditLog.CreateDirectoryLogLine(this, _target);

            // Copy each file into the new directory.
            foreach (FileInfo fi in _source.GetFiles())
            {
                //Calculate the path of the future file we need to save
                string targetPath = Path.Combine(_target.FullName, fi.Name);

                //Check if the file already exist or not (new one), and verify if it has been modified or not
                if (!File.Exists(targetPath) || fi.LastWriteTime != File.GetLastWriteTime(targetPath))
                {
                    lock (Model.sync)
                    {
                        Progress.CurrentSourceFilePath      = fi.FullName;
                        Progress.CurrentDestinationFilePath = Path.Combine(_target.FullName, fi.Name);
                    }
                    Model.OnSaveWorkUpdate();
                    EditLog.StartCopyFileLogLine(this, fi);

                    string elapsedTime = "";

                    if (fi.Length >= Setting.maxTransferSize)
                    {
                        lock (SaveProgress.taken)
                        {
                            EditLog.StartCopyFileLogLine(this, fi);

                            //Copy the file and measure execution time
                            Stopwatch watch = new Stopwatch();
                            watch.Start();
                            fi.CopyTo(Path.Combine(_target.FullName, fi.Name), true);
                            watch.Stop();
                            elapsedTime = watch.Elapsed.TotalSeconds.ToString();
                        }
                    }
                    else
                    {
                        EditLog.StartCopyFileLogLine(this, fi);

                        //Copy the file and measure execution time
                        Stopwatch watch = new Stopwatch();
                        watch.Start();
                        fi.CopyTo(Path.Combine(_target.FullName, fi.Name), true);
                        watch.Stop();
                        elapsedTime = watch.Elapsed.TotalSeconds.ToString();
                    }

                    lock (Model.sync)
                    {
                        Progress.FilesRemaining--;
                        Progress.SizeRemaining -= fi.Length;
                        Progress.UpdateProgressState();
                    }
                    Model.OnSaveWorkUpdate();
                    EditLog.FinishCopyFileLogLine(this, fi, elapsedTime);

                    if (Progress.Cancelled)
                    {
                        return;
                    }
                    softwareIsLaunched = false;
                    while (Progress.IsPaused || EasySaveInfo.CheckIfSoftwareIsLaunched(Setting.softwareString))
                    {
                        if (Progress.Cancelled)
                        {
                            return;
                        }
                        if (EasySaveInfo.CheckIfSoftwareIsLaunched(Setting.softwareString) && !softwareIsLaunched)
                        {
                            Model.OnUpdateModelError("software");
                            softwareIsLaunched = true;
                        }
                    }
                    if (softwareIsLaunched)
                    {
                        Model.OnUpdateModelError("resume");
                    }
                }
            }

            // Copy each subdirectory using recursion.
            foreach (DirectoryInfo diSourceSubDir in _source.GetDirectories())
            {
                string targetDirectoryPath = Path.Combine(_target.FullName, diSourceSubDir.Name);
                EditLog.EnterSubdirectoryLogLine(this, diSourceSubDir);

                //Check if the directory already exist to decide if it is required to create a new one or not
                if (!Directory.Exists(targetDirectoryPath))
                {
                    DirectoryInfo nextTargetSubDir = _target.CreateSubdirectory(diSourceSubDir.Name);
                    DifferencialCopyAll(diSourceSubDir, nextTargetSubDir);
                }
                else
                {
                    DirectoryInfo nextTargetSubDir = new DirectoryInfo(targetDirectoryPath);
                    DifferencialCopyAll(diSourceSubDir, nextTargetSubDir);
                }

                EditLog.ExitSubdirectoryLogLine(this, diSourceSubDir);
            }
        }