/// <summary>
        /// Do a complete copy from a folder to another
        /// </summary>
        private void CompleteCopy()
        {
            if (Directory.Exists(SourcePath))
            {
                //The Source directory has succesfully been found

                //Search directory info from source and target path
                var diSource = new DirectoryInfo(SourcePath);
                var diTarget = new DirectoryInfo(DestinationPath);

                //Calculate the number of file in the source directory and the total size of it
                int  nbFiles       = EasySaveInfo.CompleteFilesNumber(diSource);
                long directorySize = EasySaveInfo.CompleteSize(diSource);

                EditLog.FileToSaveFound(this, nbFiles, diSource, directorySize);

                lock (Model.sync)
                {
                    CreateProgress(nbFiles, directorySize, nbFiles, 0, directorySize);
                    IsActive = true;
                }
                Model.OnSaveWorkUpdate();

                //initiate Copy from the source directory to the target directory
                EditLog.StartCopy(this);
                CompleteCopyAll(diSource, diTarget);


                lock (Model.sync)
                {
                    Progress.IsEncrypting = true;
                }
                Model.OnSaveWorkUpdate();

                //Start encryption file
                EditLog.StartEncryption(Index);
                EncryptFiles();
                EditLog.EndEncryption(Index);

                //Closing the complete save protocol
                lock (Model.sync)
                {
                    //DeleteProgress();
                    Progress.IsEncrypting = false;
                    IsActive = false;
                }
                Model.OnSaveWorkUpdate();

                EditLog.EndSaveProgram(Index);
            }
            else
            {
                //The Source Directory has not been found
                Model.OnUpdateModelError("directory");
            }
        }
        /// <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);
            }
        }
Example #3
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);
            }
        }
Example #4
0
        /// <summary>
        /// Do a differencial copy from a folder to another
        /// </summary>
        private void DifferencialCopy()
        {
            if (Directory.Exists(SourcePath))
            {
                //Search directory info from source and target path
                var diSource = new DirectoryInfo(SourcePath);
                var diTarget = new DirectoryInfo(DestinationPath);

                //Calculate the number of file in the source directory and the total size of it (of all )
                int  nbFiles       = EasySaveInfo.DifferencialFilesNumber(diSource, diTarget);
                long directorySize = EasySaveInfo.DifferencialSize(diSource, diTarget);

                //If there is at least one file to save then initiate the differencial saving protocol
                if (nbFiles != 0)
                {
                    EditLog.FileToSaveFound(this, nbFiles, diSource, directorySize);

                    lock (Model.sync)
                    {
                        CreateProgress(nbFiles, directorySize, nbFiles, 0, directorySize);
                        IsActive = true;
                    }

                    Model.OnSaveWorkUpdate();

                    //initiate Copy from the source directory to the target directory (only the file / directory that has been modified or are new)
                    EditLog.StartCopy(this);
                    DifferencialCopyAll(diSource, diTarget);


                    lock (Model.sync)
                    {
                        Progress.IsEncrypting = true;
                    }
                    Model.OnSaveWorkUpdate();

                    EditLog.StartEncryption(Index);
                    EncryptFiles();
                    EditLog.EndEncryption(Index);

                    lock (Model.sync)
                    {
                        //DeleteProgress();
                        Progress.IsEncrypting = false;
                        IsActive = false;
                    }
                    Model.OnSaveWorkUpdate();

                    EditLog.EndSaveProgram(Index);
                }
                //If there is no file to save then cancel the saving protocol
                else
                {
                    EditLog.NoFilesFound(Index);
                }
            }
            else
            {
                Model.OnUpdateModelError("directory");
            }
        }