Example #1
0
 private string buildImageDestinationFilePath(ThreadParameters parameters, string sourcePath, System.Drawing.Image image)
 {
     if (parameters.DestinationRootDirectory.Length == 0 || parameters.DestinationSubDirectories.Length == 0 || parameters.FileNameComponent.Length == 0 || sourcePath.Length == 0)
     {
         return(null);
     }
     for (int i = 0; i < parameters.DestinationSubDirectories.Length && i < parameters.FileNameComponent.Length; i++)
     {
         string directoryPath = fillParameter(parameters.DestinationSubDirectories[i], sourcePath, image);
         if (directoryPath == null)
         {
             continue;
         }
         string fileName = fillParameter(parameters.FileNameComponent[i], sourcePath, image);
         if (fileName == null)
         {
             continue;
         }
         string destinationPath     = normalizeDirectoryPath(parameters.DestinationRootDirectory) + normalizeDirectoryPath(directoryPath) + fileName + System.IO.Path.GetExtension(sourcePath);
         string destinationFileName = System.IO.Path.GetFileNameWithoutExtension(destinationPath);
         if (destinationFileName.EndsWith(CultureStrings.MarkerSemicolon) && parameters.FileNameComponent[i].IndexOf(CultureStrings.ComponentOriginalFileName) != -1)
         {
             string newDestinationFileName = destinationFileName.Remove(destinationFileName.LastIndexOf(CultureStrings.MarkerSemicolon));
             destinationPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(destinationPath), newDestinationFileName + System.IO.Path.GetExtension(destinationPath));
         }
         return(destinationPath);
     }
     return(null);
 }
Example #2
0
        private void backgroundWorker_Filter_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            backgroundWorker_Filter.RunWorkerCompleted -= backgroundWorker_Filter_RunWorkerCompleted;
            ThreadParameters parameters = e.Result as ThreadParameters;

            if (parameters.LogFilePath_ThreadResult != null && System.IO.File.Exists(parameters.LogFilePath_ThreadResult))
            {
                richTextBox_SourcePaths.Clear();
                richTextBox_LoadFile(ref richTextBox_SourcePaths, parameters.LogFilePath_ThreadResult);
                richTextBox_SourcePaths.AppendLine(parameters.LogFilePath_ThreadResult);
            }
            richTextBox_ExcludeFileExtensions.Lines = parameters.ExcludeFileExtensions;
            richTextBox_ImageFileExtensions.Lines   = parameters.ImageFileExtensions;
            groupBox_SourcePaths.Text        = CultureStrings.TextSourcePaths;
            button_FilterSourcePaths.Enabled = true;
            progressBar.Value = 100;
            if (checkBox_AutoStart.Checked || !button_Start.Enabled)
            {
                tabControl.SelectTab(tabPage_Copy);
                lock (copyFilesJobs)
                {
                    copyFilesJobs.Push(getThreadParameters());
                }
                button_Start_Click(null, e);
            }
        }
Example #3
0
 private void DeleteDirectoryWithoutException(string directoryPath,ThreadParameters parameters)
 {
     try
     {
         FileWriterWithAppendMode.GlobalWrite(CultureStrings.TryDeleting+" "+singleQuoteText(directoryPath));
         string[]subDirectories=System.IO.Directory.GetDirectories(directoryPath);
         foreach(string subDirectory in subDirectories)
         {
             if(!parameters.SourceDirectories.Any(sourceDirectory=>sourceDirectory.StartsWith(subDirectory)))
             {
                 DeleteDirectoryWithoutException(subDirectory,parameters);
             }
         }
         subDirectories=System.IO.Directory.GetDirectories(directoryPath);
         string[]files=System.IO.Directory.GetFiles(directoryPath);
         if(onlyOneThumbsDbFile(files))
         {
             deleteFileWithoutException(files[0],parameters);
         }
         files=System.IO.Directory.GetFiles(directoryPath);
         if(subDirectories.Length==0&&files.Length==0)
         {
             System.IO.Directory.Delete(directoryPath);
             FileWriterWithAppendMode.GlobalWrite(CultureStrings.TextDeleted+" "+singleQuoteText(directoryPath));
         }
     }
     catch(System.Exception ex)
     {
         FileWriterWithAppendMode.GlobalWrite(CultureStrings.TextFailedInDeleting+" "+singleQuoteText(directoryPath));
         logException(ex);
     }
 }
Example #4
0
        private void backgroundWorker_Search_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            backgroundWorker_Search.RunWorkerCompleted -= backgroundWorker_Search_RunWorkerCompleted;
            ThreadParameters parameters = e.Result as ThreadParameters;

            if (parameters.LogFilePath_ThreadResult != null && System.IO.File.Exists(parameters.LogFilePath_ThreadResult))
            {
                richTextBox_SourcePaths.Clear();
                richTextBox_LoadFile(ref richTextBox_SourcePaths, parameters.LogFilePath_ThreadResult);
                richTextBox_SourcePaths.AppendLine(parameters.LogFilePath_ThreadResult);
            }
            groupBox_SourcePaths.Text = CultureStrings.TextSourcePaths;
            if (e.Cancelled)
            {
                richTextBox_SourceDirectories_TextChanged(sender, e);
            }
            else
            {
                previousSearchThreadParameters = parameters;
                if (isThreadParametersChanged(parameters, getThreadParameters()))
                {
                    richTextBox_SourceDirectories_TextChanged(sender, e);
                }
                else if (!button_FilterSourcePaths.Enabled && !backgroundWorker_Filter.IsBusy)
                {
                    backgroundWorker_Filter.RunWorkerCompleted += backgroundWorker_Filter_RunWorkerCompleted;
                    backgroundWorker_Filter.RunWorkerAsync(getThreadParameters());
                }
            }
        }
Example #5
0
        private ThreadParameters filterSourcePaths(ThreadParameters parameters)
        {
            System.Collections.Generic.List <string> sourcePaths = new System.Collections.Generic.List <string>();
            if (parameters.LogFilePath_ThreadResult != null)
            {
                if (System.IO.File.Exists(parameters.LogFilePath_ThreadResult))
                {
                    sourcePaths = System.IO.File.ReadAllLines(parameters.LogFilePath_ThreadResult, System.Text.Encoding.Unicode).ToList();
                }
            }
            if (sourcePaths.Count == 0)
            {
                return(parameters);
            }
            lock (copyFilesJobs)
            {
                parameters.LogFilePath_ThreadResult = buildCollectPhotoDataFilePath(parameters.DestinationRootDirectory, CultureStrings.ResultFileFilter);
            }
            FileWriterWithAppendMode logger = FileWriterWithAppendMode.Open(parameters.LogFilePath_ThreadResult);

            for (int i = 0; i < sourcePaths.Count; i++)
            {
                string filePath = sourcePaths[i];
                if (backgroundWorker_Filter.IsBusy)
                {
                    backgroundWorker_Filter.ReportProgress(calculatePercentage(sourcePaths.Count, i), filePath);
                }
                if (isMatchingFilePath(filePath, parameters.IncludeFileExtensions) || isMatchingFilePath(filePath, parameters.IncludeFileExtensionAndFileNameMap))
                {
                    logger.WriteLine(filePath);
                    continue;
                }
                if (isMatchingFilePath(filePath, parameters.ExcludeFileExtensions) || isMatchingFilePath(filePath, parameters.IncludeFileExtensionAndFileNameMap.Keys.ToArray()))
                {
                    continue;
                }
                if (isMatchingFilePath(filePath, parameters.ImageFileExtensions))
                {
                    logger.WriteLine(filePath);
                    continue;
                }
                string extension = System.IO.Path.GetExtension(filePath);
                if (extension.Length == 0)
                {
                    continue;
                }
                if (parameters.AutoDetermine && isImageFile(filePath))
                {
                    parameters.ImageFileExtensions = parameters.ImageFileExtensions.Concat(new string[] { extension }).ToArray();
                    logger.WriteLine(filePath);
                    continue;
                }
                parameters.ExcludeFileExtensions = parameters.ExcludeFileExtensions.Concat(new string[] { extension }).ToArray();
            }
            logger.Close();
            return(parameters);
        }
Example #6
0
        private void backgroundWorker_Search_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            ThreadParameters parameters = e.Argument as ThreadParameters;

            if (previousSearchThreadParameters != null)
            {
                if (!isThreadParametersChanged(parameters, previousSearchThreadParameters))
                {
                    e.Result = previousSearchThreadParameters;
                    return;
                }
            }
            e.Result = searchDirectories(parameters);
        }
Example #7
0
 private ThreadParameters[] splitCopyFilesJob(ThreadParameters threadParameters)
 {
     System.Collections.Generic.List <ThreadParameters> jobs = new System.Collections.Generic.List <ThreadParameters>();
     foreach (string sourceDirectory in threadParameters.SourceDirectories)
     {
         ThreadParameters newJob = deepCopy(threadParameters);
         newJob.SourceDirectories = threadParameters.SourceDirectories.Where(directory => sourceDirectory == directory).ToArray();
         if (threadParameters.CreateSubDestinationRootDirectory)
         {
             newJob.DestinationRootDirectory = string.Copy(newJob.DestinationRootDirectory);
             string subDestinationRootDirectory = sourceDirectory.Replace(System.IO.Path.AltDirectorySeparatorChar, '_').Replace(System.IO.Path.DirectorySeparatorChar, '_').Replace(System.IO.Path.VolumeSeparatorChar, '_');
             newJob.DestinationRootDirectory = System.IO.Path.Combine(newJob.DestinationRootDirectory, subDestinationRootDirectory.Trim(new char[] { '_' }));
         }
         jobs.Add(newJob);
     }
     return(jobs.ToArray());
 }
Example #8
0
 private ThreadParameters searchDirectories(ThreadParameters parameters)
 {
     try
     {
         lock (copyFilesJobs)
         {
             parameters.LogFilePath_ThreadResult = buildCollectPhotoDataFilePath(parameters.DestinationRootDirectory, CultureStrings.ResultFileSearch);
         }
         foreach (string directory in parameters.SourceDirectories)
         {
             getFiles(normalizeDirectoryPath(directory), "*", System.IO.SearchOption.AllDirectories, parameters.SearchDirectoryDeepnessLimitation > 0?parameters.SearchDirectoryDeepnessLimitation:int.MaxValue, parameters);
         }
     }
     catch (System.Exception cancellation)
     {
         logException(cancellation);
     }
     return(parameters);
 }
Example #9
0
 private void DeleteFileAndRelatedDirectoriesWithoutException(string filePath,ThreadParameters parameters)
 {
     try
     {
         deleteFileWithoutException(filePath,parameters);
         string directoryPath=System.IO.Path.GetDirectoryName(filePath);
         while(System.IO.Directory.GetFiles(directoryPath).Length<=1)
         {
             DeleteDirectoryWithoutException(directoryPath,parameters);
             directoryPath=System.IO.Path.GetDirectoryName(directoryPath);
             if(parameters.SourceDirectories.Any(sourceDirectory=>sourceDirectory.StartsWith(directoryPath)))
             {
                 break;
             }
         }
     }
     catch(System.Exception ex)
     {
         logException(ex);
     }
 }
Example #10
0
 private void deleteFileWithoutException(string filePath,ThreadParameters parameters)
 {
     try
     {
         System.IO.FileInfo fileInfo=new System.IO.FileInfo(filePath);
         if(fileInfo.IsReadOnly&&parameters.DeleteReadOnly)
         {
             fileInfo.IsReadOnly=false;
         }
         if(fileInfo.Exists)
         {
             fileInfo.Delete();
         }
         FileWriterWithAppendMode.GlobalWrite(CultureStrings.TextDeleted+" "+singleQuoteText(filePath));
     }
     catch(System.Exception ex)
     {
         FileWriterWithAppendMode.GlobalWrite(CultureStrings.TextFailedInDeleting+" "+singleQuoteText(filePath));
         logException(ex);
     }
 }
Example #11
0
 private void button_Start_Click(object sender, System.EventArgs e)
 {
     lock (copyFilesJobs)
     {
         button_Start.Enabled = false;
         ClearImageViewer();
         if (sender is System.Windows.Forms.Button)
         {
             ThreadParameters threadParameters = getThreadParameters();
             if (checkBox_MultipleJobs.Checked == true)
             {
                 ThreadParameters[] jobs = splitCopyFilesJob(threadParameters);
                 for (int i = jobs.Length - 1; i >= 0; i--)
                 {
                     copyFilesJobs.Push(jobs[i]);
                 }
             }
             else
             {
                 copyFilesJobs.Push(threadParameters);
             }
         }
         if (!backgroundWorker_Copy.IsBusy && copyFilesJobs.Count > 0)
         {
             richTextBox_CollectedSourcePaths.Clear();
             richTextBox_CollectedDestinationPaths.Clear();
             backgroundWorker_Copy.DoWork += backgroundWorker_Copy_DoWork;
             if (checkBox_MultipleJobs.Checked == true)
             {
                 backgroundWorker_Copy.RunWorkerAsync(null);
             }
             else
             {
                 backgroundWorker_Copy.RunWorkerAsync(copyFilesJobs.Pop());
             }
         }
     }
 }
Example #12
0
 private void preCopyFile(ThreadParameters parameters,string sourcePath,ref string destinationPath,ref bool alreadyExists,ref bool isCopy)
 {
     isCopy=false;
     alreadyExists=false;
     string alreadyExistsDestinationPath=getDuplicateAutoRenamedFile(sourcePath,destinationPath);
     if(alreadyExistsDestinationPath!=null)
     {
         destinationPath=alreadyExistsDestinationPath;
         alreadyExists=true;
     }
     else if(isOneCopy(sourcePath,destinationPath))
     {
     }
     else if(parameters.AutoRename)
     {
         destinationPath=getUnusedFilePath(destinationPath);
         isCopy=true;
     }
     else
     {
         isCopy=true;
     }
 }
Example #13
0
        private string buildUniqueDestinationFilePath(ThreadParameters parameters, string sourcePath)
        {
            MediaInfoLib.MediaInfo mediaInfo = new MediaInfoLib.MediaInfo();
            string taggedDate = null;

            if (mediaInfo.Open(sourcePath) == 1)
            {
                taggedDate = mediaInfo.Get(MediaInfoLib.StreamKind.General, 0, CultureStrings.TextTaggedDate);
            }
            mediaInfo.Close();
            string uniqueDestinationFilePath = null;

            if (taggedDate != null && taggedDate.Length > 0)
            {
                try
                {
                    System.DateTime dateTime = parseTaggedDate(taggedDate);
                    uniqueDestinationFilePath = normalizeDirectoryPath(parameters.DestinationRootDirectory) + normalizeDirectoryPath(System.IO.Path.GetExtension(sourcePath).ToUpper().Substring(1)) + normalizeDirectoryPath(dateTime.ToString("yyyy")) + normalizeDirectoryPath(dateTime.ToString("MMMM")) + getCollectPhotoOriginalFileName(sourcePath);
                }
                catch (System.Exception ex)
                {
                    logException(ex);
                }
            }
            if (uniqueDestinationFilePath == null)
            {
                uniqueDestinationFilePath = normalizeDirectoryPath(parameters.DestinationRootDirectory) + normalizeDirectoryPath(System.IO.Path.GetExtension(sourcePath).ToUpper().Substring(1)) + getCollectPhotoOriginalFileName(sourcePath);
            }
            if (getDuplicateAutoRenamedFile(sourcePath, uniqueDestinationFilePath) != null)
            {
                return(getDuplicateAutoRenamedFile(sourcePath, uniqueDestinationFilePath));
            }
            else
            {
                return(getUnusedFilePath(uniqueDestinationFilePath));
            }
        }
Example #14
0
        private void getFiles(string directoryPath, string searchPattern, System.IO.SearchOption searchOption, int deepnessLimitation, ThreadParameters parameters)
        {
            FileWriterWithAppendMode.GlobalWrite(string.Format("getFiles, directory path: {0}, deepness limitation: {1}.", doubleQuoteText(directoryPath), deepnessLimitation));
            string[] fileExtensions = parameters.FilterWhileSearching?parameters.ImageFileExtensions.Concat(parameters.IncludeFileExtensions).ToArray():null;
            string   resultFilePath = parameters.LogFilePath_ThreadResult;

            if (backgroundWorker_Search.CancellationPending)
            {
                throw new System.Exception("Cancel getFiles!");
            }
            if (backgroundWorker_Search.IsBusy)
            {
                backgroundWorker_Search.ReportProgress(0, directoryPath);
            }
            if (deepnessLimitation <= 0)
            {
                return;
            }
            string[] topDirectoryFiles = getFiles(directoryPath, searchPattern);
            if (topDirectoryFiles != null)
            {
                appendLines(resultFilePath, filterFilePaths(topDirectoryFiles, fileExtensions));
            }
            if (searchOption == System.IO.SearchOption.AllDirectories)
            {
                string[] directories = getDirectories(directoryPath);
                if (directories != null)
                {
                    foreach (string directory in directories)
                    {
                        if (isMatchingDirectoryPath(directory, parameters.BypassRegexes))
                        {
                            continue;
                        }
                        getFiles(directory, searchPattern, searchOption, deepnessLimitation - 1, parameters);
                    }
                }
            }
        }
Example #15
0
        private ThreadParameters executeCommands(ThreadParameters parameters)
        {
            System.Collections.Generic.List <string> sourcePaths = new System.Collections.Generic.List <string>();
            if (parameters.SourcePaths != null)
            {
                sourcePaths.AddRange(parameters.SourcePaths);
            }
            if (parameters.LogFilePath_ThreadResult != null && System.IO.File.Exists(parameters.LogFilePath_ThreadResult))
            {
                sourcePaths.AddRange(System.IO.File.ReadAllLines(parameters.LogFilePath_ThreadResult, System.Text.Encoding.Unicode));
            }
            else if (parameters.SourceDirectories != null && parameters.SourceDirectories.Length > 0)
            {
                parameters = filterSourcePaths(searchDirectories(parameters));
                sourcePaths.AddRange(System.IO.File.ReadAllLines(parameters.LogFilePath_ThreadResult, System.Text.Encoding.Unicode));
            }
            lock (copyFilesJobs)
            {
                parameters.LogFilePath_ThreadResult = buildCollectPhotoDataFilePath(parameters.DestinationRootDirectory, CultureStrings.LogFileExecuteCommandsResult);
            }
            FileWriterWithAppendMode logger = FileWriterWithAppendMode.Open(parameters.LogFilePath_ThreadResult);
            string sourcePathTemplate       = fillCommandParameter(fillCommandParameter(parameters.CommandOptions, CommandParameterKey_Command, parameters.Command, 0), CommandParameterKey_DestinationRootDirectory, parameters.DestinationRootDirectory, 0);
            string commandName = System.IO.Path.GetFileNameWithoutExtension(parameters.Command);

            if (sourcePathTemplate.IndexOf(commandName, System.StringComparison.InvariantCultureIgnoreCase) == -1)
            {
                sourcePathTemplate = doubleQuoteText(parameters.Command) + " " + sourcePathTemplate;
            }
            for (int i = 0; i < sourcePaths.Count; i++)
            {
                string command = fillCommandParameter(sourcePathTemplate, CommandParameterKey_SourcePath, sourcePaths[i], 0);
                command = fillCommandParameter(fillCommandParameter(command, fileSizeId, getFileSize(sourcePaths[i]).ToString(), 0), originalFileNameId, getCollectPhotoOriginalFileName(sourcePaths[i]), 0);
                if (backgroundWorker_ExecuteCommands.CancellationPending)
                {
                    return(parameters);
                }
                else
                {
                    logger.WriteLine(command);
                    if (backgroundWorker_ExecuteCommands.IsBusy)
                    {
                        backgroundWorker_ExecuteCommands.ReportProgress(calculatePercentage(sourcePaths.Count, i), command);
                    }
                    try
                    {
                        System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(command);
                        info.CreateNoWindow         = true;
                        info.UseShellExecute        = false;
                        info.RedirectStandardOutput = true;
                        info.RedirectStandardError  = true;
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = info;
                        process.Start();
                        string stdout = process.StandardOutput.ReadToEnd();
                        string stderr = process.StandardError.ReadToEnd();
                        backgroundWorker_ExecuteCommands.ReportProgress(calculatePercentage(sourcePaths.Count, i), stdout);
                        backgroundWorker_ExecuteCommands.ReportProgress(calculatePercentage(sourcePaths.Count, i), stderr);
                        logger.WriteLine(stdout);
                        logger.WriteLine(stderr);
                    }
                    catch (System.Exception ex)
                    {
                        logException(ex);
                    }
                }
            }
            logger.Close();
            return(parameters);
        }
Example #16
0
        private ThreadParameters copyFiles(ThreadParameters parameters)
        {
            System.Collections.Generic.List <string> sourcePaths = new System.Collections.Generic.List <string>();
            if (parameters.SourcePaths != null)
            {
                sourcePaths.AddRange(parameters.SourcePaths);
            }
            FileWriterWithAppendMode sourcePathLogger        = null;
            FileWriterWithAppendMode deletedSourcePathLogger = null;
            FileWriterWithAppendMode destinationPathLogger   = null;

            lock (copyFilesJobs)
            {
                sourcePathLogger = FileWriterWithAppendMode.Open(buildCollectPhotoLogFilePath(parameters.DestinationRootDirectory, CultureStrings.LogFileCopiedSourcePaths));
            }
            lock (copyFilesJobs)
            {
                destinationPathLogger = FileWriterWithAppendMode.Open(buildCollectPhotoLogFilePath(parameters.DestinationRootDirectory, CultureStrings.LogFileCopiedDestinationPaths));
            }
            lock (copyFilesJobs)
            {
                deletedSourcePathLogger = FileWriterWithAppendMode.Open(buildCollectPhotoLogFilePath(parameters.DestinationRootDirectory, CultureStrings.LogFileToBeDeletedSourcePaths));
            }
            ThreadProgress threadProgress = new ThreadProgress();

            resetThreadProgress(ref threadProgress, sourcePaths.Count, sourcePathLogger.FilePath, deletedSourcePathLogger.FilePath, destinationPathLogger.FilePath);
            if (parameters.LogFilePath_ThreadResult == null)
            {
                threadProgress.ProgressBarStyle = System.Windows.Forms.ProgressBarStyle.Marquee;
                backgroundWorker_Copy.ReportProgress(0, threadProgress);
                parameters = filterSourcePaths(searchDirectories(parameters));
            }
            if (System.IO.File.Exists(parameters.LogFilePath_ThreadResult))
            {
                sourcePaths.AddRange(System.IO.File.ReadAllLines(parameters.LogFilePath_ThreadResult, System.Text.Encoding.Unicode).ToList());
            }
            threadProgress.CountTotal       = sourcePaths.Count;
            threadProgress.ProgressBarStyle = System.Windows.Forms.ProgressBarStyle.Blocks;
            for (int i = 0; i < sourcePaths.Count; i++)
            {
                string sourcePath      = sourcePaths[i];
                string destinationPath = null;
                threadProgress.SourcePath = sourcePath;
                bool isCopy          = false;
                bool isOverwriteCopy = false;
                bool alreadyExists   = false;
                try
                {
                    if (isMatchingFilePath(sourcePath, parameters.IncludeFileExtensions) || isMatchingFilePath(sourcePath, parameters.IncludeFileExtensionAndFileNameMap))
                    {
                        destinationPath = buildImageDestinationFilePath(parameters, sourcePath, null);
                        preCopyFile(parameters, sourcePath, ref destinationPath, ref alreadyExists, ref isCopy);
                    }
                    else if (isMatchingFilePath(sourcePath, parameters.ExcludeFileExtensions) || isMatchingFilePath(sourcePath, parameters.IncludeFileExtensionAndFileNameMap.Keys.ToArray()))
                    {
                    }
                    else if (isImageFile(sourcePath))
                    {
                        bool isLowGradeImage = false;
                        using (System.Drawing.Image image = getImage(sourcePath))
                        {
                            isLowGradeImage = !isImageLargerThanMinDimension(parameters.FileNameComponent, image);
                            destinationPath = buildImageDestinationFilePath(parameters, sourcePath, image);
                        }
                        if (parameters.CopyLowGradeImage && (isLowGradeImage || destinationPath == null))
                        {
                            destinationPath = buildUniqueDestinationFilePath(parameters, sourcePath);
                            preCopyFile(parameters, sourcePath, ref destinationPath, ref alreadyExists, ref isCopy);
                        }
                        else if (destinationPath != null)
                        {
                            preCopyFile(parameters, sourcePath, ref destinationPath, ref alreadyExists, ref isCopy);
                            if (!alreadyExists && isCopy && System.IO.File.Exists(destinationPath) && getFileSize(destinationPath) < getFileSize(sourcePath))
                            {
                                isOverwriteCopy = true;
                            }
                        }
                    }
                    if (parameters.DeleteSourceIfDestinationAlreadyExists && alreadyExists && areTwoCopies(sourcePath, destinationPath))
                    {
                        deletedSourcePathLogger.WriteLine(sourcePath);
                        deletedSourcePathLogger.WriteLine(destinationPath);
                        DeleteFileAndRelatedDirectoriesWithoutException(sourcePath, parameters);
                        reportSkippedCopy(ref threadProgress, destinationPath, i);
                    }
                    else if (isCopy)
                    {
                        if (isOverwriteCopy)
                        {
                            overwriteFile(sourcePath, destinationPath);
                        }
                        else if (parameters.DeleteAfterCopy)
                        {
                            createDirectoryForFile(destinationPath);
                            System.IO.File.Move(sourcePath, destinationPath);
                            DeleteFileAndRelatedDirectoriesWithoutException(sourcePath, parameters);
                        }
                        else
                        {
                            copyFile(sourcePath, destinationPath);
                        }
                        sourcePathLogger.WriteLine(sourcePath);
                        destinationPathLogger.WriteLine(destinationPath);
                        reportSuccessCopy(ref threadProgress, destinationPath, i);
                    }
                    else
                    {
                        reportSkippedCopy(ref threadProgress, destinationPath, i);
                    }
                }
                catch (System.Exception ex)
                {
                    logException(ex);
                    reportSkippedCopy(ref threadProgress, destinationPath, i);
                }
                sourcePathLogger.Flush();
                destinationPathLogger.Flush();
                deletedSourcePathLogger.Flush();
            }
            sourcePathLogger.Close();
            destinationPathLogger.Close();
            deletedSourcePathLogger.Close();
            FileWriterWithAppendMode.GlobalWrite(threadProgress.ToString());
            return(parameters);
        }
Example #17
0
        private void backgroundWorker_ExecuteCommands_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            ThreadParameters parameters = e.Argument as ThreadParameters;

            e.Result = executeCommands(parameters);
        }
Example #18
0
 private bool isThreadParametersChanged(ThreadParameters p1, ThreadParameters p2)
 {
     return(GetConfigContent(p1) != GetConfigContent(p2));
 }
Example #19
0
 private string GetConfigContent(ThreadParameters parameters)
 {
     return(("*** Source Directories ***\r\n" + convertStringsToText(parameters.SourceDirectories)) + ("\r\n*** Image File Extensions ***\r\n" + convertStringsToText(parameters.ImageFileExtensions)) + ("\r\n*** Exclude File Extensions ***\r\n" + convertStringsToText(parameters.ExcludeFileExtensions)) + ("\r\n*** Include File Extensions ***\r\n" + convertStringsToText(parameters.IncludeFileExtensions)) + ("\r\n*** Search Directories Bypass Patterns ***\r\n" + convertStringsToText(parameters.SearchDirectoriesBypassPatterns)) + ("\r\n*** Source Paths ***\r\n" + convertStringsToText(parameters.SourcePaths)) + ("\r\n*** Destination Root Directory ***\r\n" + parameters.DestinationRootDirectory) + ("\r\n*** Destination Sub Directories ***\r\n" + parameters.DestinationSubDirectories) + ("\r\n*** File Name Component ***\r\n" + parameters.FileNameComponent) + ("\r\n*** Search Directory Deepness Limitation ***\r\n" + parameters.SearchDirectoryDeepnessLimitation.ToString()) + ("\r\n*** Auto Start ***\r\n" + parameters.AutoStart.ToString()) + ("\r\n*** Auto Determine ***\r\n" + parameters.AutoDetermine.ToString()) + ("\r\n*** Filter While Searching ***\r\n" + parameters.FilterWhileSearching.ToString()) + ("\r\n*** Copy Low Grade Image ***\r\n" + parameters.CopyLowGradeImage.ToString()) + ("\r\n*** Delete After Copy ***\r\n" + parameters.DeleteAfterCopy.ToString()) + ("\r\n*** Delete Already Exists ***\r\n" + parameters.DeleteSourceIfDestinationAlreadyExists.ToString()) + ("\r\n*** Delete Read Only ***\r\n" + parameters.DeleteReadOnly.ToString()) + ("\r\n*** Auto Rename ***\r\n" + parameters.AutoRename.ToString()) + ("\r\n*** Multiple Jobs ***\r\n" + parameters.MultipleJobs.ToString()) + ("\r\n*** Create Sub Destination Root Directory ***\r\n" + parameters.CreateSubDestinationRootDirectory.ToString()));
 }
Example #20
0
        private ThreadParameters getThreadParameters()
        {
            ThreadParameters parameters = new ThreadParameters();

            parameters.SourceDirectories     = stripBlankLines(richTextBox_SourceDirectories.Lines);
            parameters.ImageFileExtensions   = stripBlankLines(richTextBox_ImageFileExtensions.Lines);
            parameters.ExcludeFileExtensions = stripBlankLines(richTextBox_ExcludeFileExtensions.Lines);
            System.Collections.Generic.List <string> includeFileExtensions     = new System.Collections.Generic.List <string>();
            System.Collections.Generic.List <string> includeFileNameExtensions = new System.Collections.Generic.List <string>();
            foreach (string line in richTextBox_IncludeFileExtensions.Lines)
            {
                if (line.Length > 0 && fileExtensionPattern.IsMatch(line))
                {
                    includeFileExtensions.Add(line);
                }
                else
                {
                    includeFileNameExtensions.Add(line);
                }
            }
            parameters.IncludeFileExtensions = includeFileExtensions.ToArray();
            parameters.IncludeFileExtensionAndFileNameMap = new System.Collections.Generic.Dictionary <string, System.Text.RegularExpressions.Regex>();
            foreach (string includeFileName in includeFileNameExtensions)
            {
                string pattern = System.IO.Path.GetFileNameWithoutExtension(includeFileName);
                if (pattern == "*")
                {
                    includeFileExtensions.Add(System.IO.Path.GetExtension(includeFileName));
                    parameters.IncludeFileExtensions = includeFileExtensions.ToArray();
                    continue;
                }
                else if (pattern.Length == 0)
                {
                    continue;
                }
                if (!parameters.IncludeFileExtensionAndFileNameMap.ContainsKey(System.IO.Path.GetExtension(includeFileName)))
                {
                    parameters.IncludeFileExtensionAndFileNameMap.Add(System.IO.Path.GetExtension(includeFileName), new System.Text.RegularExpressions.Regex(pattern));
                }
            }
            parameters.SearchDirectoriesBypassPatterns = stripBlankLines(richTextBox_SearchDirectoriesBypassPatterns.Lines);
            System.Collections.Generic.List <System.Text.RegularExpressions.Regex> regexList = new System.Collections.Generic.List <System.Text.RegularExpressions.Regex>();
            foreach (string bypassPattern in parameters.SearchDirectoriesBypassPatterns)
            {
                regexList.Add(new System.Text.RegularExpressions.Regex(bypassPattern));
            }
            parameters.BypassRegexes = regexList.ToArray();
            if (richTextBox_SourcePaths.Text.EndsWith(getCollectPhotoDataExtension()))
            {
                parameters.LogFilePath_ThreadResult = richTextBox_SourcePaths.Lines[richTextBox_SourcePaths.Lines.Length - 1];
            }
            else
            {
                parameters.SourcePaths = richTextBox_SourcePaths.Lines;
            }
            parameters.DestinationRootDirectory  = richTextBox_DestinationRootDirectory.Text;
            parameters.DestinationSubDirectories = stripBlankLines(richTextBox_DestinationSubDirectories.Lines);
            parameters.FileNameComponent         = stripBlankLines(richTextBox_FileNameComponent.Lines);
            parameters.Command        = richTextBox_Command.Text;
            parameters.CommandOptions = richTextBox_CommandOptions.Text;
            parameters.SearchDirectoryDeepnessLimitation = getSearchDirectoryDeepnessLimitation();
            parameters.AutoStart            = checkBox_AutoStart.Checked;
            parameters.AutoDetermine        = checkBox_AutoDetermine.Checked;
            parameters.FilterWhileSearching = checkBox_FilterWhileSearching.Checked;
            parameters.CopyLowGradeImage    = checkBox_CopyLowGradeImage.Checked;
            parameters.DeleteAfterCopy      = checkBox_DeleteAfterCopy.Checked;
            parameters.DeleteSourceIfDestinationAlreadyExists = checkBox_DeleteAlreadyExists.Checked;
            parameters.DeleteReadOnly = checkBox_DeleteReadOnly.Checked;
            parameters.AutoRename     = checkBox_AutoRename.Checked;
            parameters.MultipleJobs   = checkBox_MultipleJobs.Checked;
            parameters.CreateSubDestinationRootDirectory = checkBox_CreateSubDestinationRootDirectory.Checked;
            try
            {
                FileWriterWithAppendMode logger = FileWriterWithAppendMode.Open(buildCollectPhotoLogFilePath(richTextBox_DestinationRootDirectory.Text, CultureStrings.TextTaskParameters));
                string configContent            = GetConfigContent(parameters);
                logger.Write(configContent);
                logger.Close();
            }
            catch (System.Exception ex)
            {
                logException(ex);
            }
            return(parameters);
        }