Beispiel #1
0
        static void Main()
        {
            bool mutexCreated = true;
            using (System.Threading.Mutex mutex = new System.Threading.Mutex(true, "PushApp", out mutexCreated))
            {
                if (mutexCreated)
                {
                    // This loads the properties, defined in AppSettings, with values...
                    //		If the value of a property has not been defined, all properties will be set to null...
                    try
                    {
                        var ConfigFilePath = Itenso.Configuration.ApplicationSettings.UserConfigurationFilePath;
                        appSettings.Load();
                    }
                    catch (System.Configuration.ConfigurationErrorsException e)
                    {
                        File.Delete(e.Filename);
                    }

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    MainForm mainForm = new MainForm(appSettings);

                    // Assign the FormClosed Event handler...
                    mainForm.FormClosed += FormClosed;

                    // This handles the first-run + cancel scenario...
                    if (mainForm.IsDisposed)
                        return;

                    Application.Run(mainForm);

                    #region [ Comments ]
                    /* When the form is closed, the Form.OnClosing and Form.OnFormClosed
                     *		events is executed.
                     *
                     *	The Form.OnClosing event calls Itenso.Configuration.FormSettings.FormClosing( ).
                     *	This method takes care of writing the form properties to the XML File.
                     *
                     *	Next the Form.OnFormClosed event calls Program.FormClosed( ).
                     *	This method copies the PushSettings properties into the
                     *		AppSettings collection.   */
                    #endregion

                    // Save the AppSettings to the same XML file that holds the form properties...
                    appSettings.Save();
                }
                else
                {
                    // If we get here Push is already running. Don't let another copy start...
                    System.Diagnostics.Process current = System.Diagnostics.Process.GetCurrentProcess();
                    foreach (System.Diagnostics.Process process in System.Diagnostics.Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            MessageBox.Show("Another instance of Push is already running.", "Push already running",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;
                        }
                    }
                } //END_MUTEX-CREATED
            } // END_USING_MUTEX
        }
Beispiel #2
0
        public void CopyFiles(MainForm mainForm)
        {
            AppSettings appSettings = mainForm.appSettings;

            Helper.commandResult DuplicateAction;

            bgWorker = new BackgroundWorker();
            bgWorker.ProgressChanged += new ProgressChangedEventHandler(mainForm.bgProgressChangedEventHandler);
            bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(mainForm.bgRunWorkerCompletedEventHandler);
            bgWorker.WorkerReportsProgress = true;
            bgWorker.WorkerSupportsCancellation = true;

            // File extension types...
            List<string> FileExtensionArrayList = Helper.LoadFileExtensions(appSettings);

            #region [ BUILD LIST OF SOURCE FILES ]
            List<string> all_FileSourceList = new List<string>();
            all_FileSourceList = GetFiles(appSettings.SourcePath, FileExtensionArrayList, all_FileSourceList, mainForm.ignorePattern);

            if (all_FileSourceList.Count == 0)
            {
                // If we get here, there are not files in the source folder to process...
                bgWorker.DoWork += new DoWorkEventHandler(CopyFile_BackGround);
                bgWorker.RunWorkerAsync();
                return;
            }
            #endregion

            #region [ BUILD LIST OF TARGET FILES ]
            List<string> all_FileTargetList = new List<string>();
            all_FileTargetList = GetFiles(appSettings.TargetPath, FileExtensionArrayList, all_FileTargetList);

            // Build a list of files on the target folder...
            int dupeFileCount = 0;

            // OUTER LOOP -- Iterate over each file in the target list...
            foreach (string t in all_FileTargetList)
            {
                FileInfo targetFileInfo = new FileInfo(t);

                // INNER_LOOP -- Iterate over each file in the source list...
                foreach (string s in all_FileSourceList)
                {
                    FileInfo sourceFileInfo = new FileInfo(s);

                    // Compare the fileName.ext (ignore the path)...
                    if (!targetFileInfo.Name.Equals(sourceFileInfo.Name, StringComparison.Ordinal))
                    {
                        continue;
                    }
                    ++dupeFileCount;
                    break; // Exit innter loop...

                } // END_FOREACH_INNER
            } // END_FOREACH_OUTER
            #endregion

            if (dupeFileCount <= 0)
            {
                bgWorker.DoWork += new DoWorkEventHandler(CopyFileOverwrite.CopyOverwrite_BackGround);
                List<object> args = new List<object>() { all_FileSourceList, appSettings };
                bgWorker.RunWorkerAsync(args);
            }
            else
            {
                if (appSettings.HideDupeMessage.GetValueOrDefault(false))
                {
                    //---------------------------------------------------------
                    // If we get here, perform whatever Dupe File Action has been configured...

                    List<object> args;

                    // Save the Dupe Action. We need this for the statusing return value...
                    DuplicateAction = (Helper.commandResult)Enum.Parse(typeof(Helper.commandResult), appSettings.DuplicateFileAction);

                    #region [ AUTO DUPE ACTION ]
                    switch (DuplicateAction)
                    {
                        case Helper.commandResult.Rename:
                            // Assign the correct event handler to the worker...
                            bgWorker.DoWork += new DoWorkEventHandler(CopyFileRename.RenameDuplicates_BackGround);
                            // Load DoWorkEvent Arguments
                            args = new List<object>() { all_FileSourceList, all_FileTargetList, appSettings };
                            // Start the worker...
                            bgWorker.RunWorkerAsync(args);
                            break;

                        case Helper.commandResult.Skip:
                            bgWorker.DoWork += new DoWorkEventHandler(CopyFileSkip.SkipDuplicates_BackGround);
                            args = new List<object>() { all_FileSourceList, all_FileTargetList, appSettings };
                            bgWorker.RunWorkerAsync(args);
                            break;

                        case Helper.commandResult.Cancel:
                            bgWorker.DoWork += new DoWorkEventHandler(CopyFileCancel.CopyCancel_BackGround);
                            args = new List<object>() { null, null, null, };
                            bgWorker.RunWorkerAsync(args);
                            break;

                        case Helper.commandResult.Overwrite:
                        default:
                            bgWorker.DoWork += new DoWorkEventHandler(CopyFileOverwrite.CopyOverwrite_BackGround);
                            args = new List<object>() { all_FileSourceList, appSettings };
                            bgWorker.RunWorkerAsync(args);
                            break;

                    } // END SWITCH
                    #endregion

                }
                else
                {
                    //---------------------------------------------------------
                    // If we get here, Hide Dupe Message checkbox is false.

                    #region [ TASK DIALOG ]
                    cTaskDialog.ForceEmulationMode = true;
                    cTaskDialog.EmulatedFormWidth = 450;

                    cTaskDialog.ShowTaskDialogBox(
                            mainForm,
                            "Duplicate Files Found",
                            string.Format("There were {0} duplicate files found in the Target Folder.", dupeFileCount),
                            "What would you like to do?",
                            "Renamed files will have the format: original_File_Name(n).ext, where (n) is a numeric value. " +
                                "When multiple copies exist the latest duplicate will always have the highest value.\n\n" +
                                "These settings may be modified in the Configuration Dialog.",
                            string.Empty,
                            "Don't show me this message again",
                            string.Empty,
                            "Overwrite All Duplicates|Copy/Rename All Duplicates|Skip All Duplicates|Cancel Copy",
                            eTaskDialogButtons.None,
                            eSysIcons.Information,
                            eSysIcons.Warning);
                    #endregion

                    //-------------------------------------------------------------
                    // Based on the configuration above, DialogResult and RadioButtonResult is ignored...

                    if (cTaskDialog.VerificationChecked)
                    {
                        // If we get here, the Display Dupe Message checkbox
                        //		has been deselected. Save the currently selected
                        //		action to settings...
                        appSettings.HideDupeMessage = cTaskDialog.VerificationChecked;
                        appSettings.DuplicateFileAction = Enum.GetName(typeof(Helper.commandResult), cTaskDialog.CommandButtonResult);
                    }

                    #region [ MANUAL DUPE ACTION ]

                    List<object> args;

                    // Fetch the Dupe Action. We need this for the statusing return value...
                    DuplicateAction = (Helper.commandResult)cTaskDialog.CommandButtonResult;

                    switch (DuplicateAction)
                    {

                        case Helper.commandResult.Rename:
                            // Assign the correct event handler to the worker...
                            bgWorker.DoWork += new DoWorkEventHandler(CopyFileRename.RenameDuplicates_BackGround);
                            // Load DoWorkEvent Arguments
                            args = new List<object>() { all_FileSourceList, all_FileTargetList, appSettings };
                            // Start the worker...
                            bgWorker.RunWorkerAsync(args);
                            break;

                        case Helper.commandResult.Skip:
                            bgWorker.DoWork += new DoWorkEventHandler(CopyFileSkip.SkipDuplicates_BackGround);
                            args = new List<object>() { all_FileSourceList, all_FileTargetList, appSettings };
                            bgWorker.RunWorkerAsync(args);
                            break;

                        case Helper.commandResult.Cancel:
                            bgWorker.DoWork += new DoWorkEventHandler(CopyFileCancel.CopyCancel_BackGround);
                            args = new List<object>() { null, null, null, };
                            bgWorker.RunWorkerAsync(args);
                            break;

                        case Helper.commandResult.Overwrite:
                        default:
                            bgWorker.DoWork += new DoWorkEventHandler(CopyFileOverwrite.CopyOverwrite_BackGround);
                            args = new List<object>() { all_FileSourceList, appSettings };
                            bgWorker.RunWorkerAsync(args);
                            break;

                    } // END SWITCH
                    #endregion

                } // END_IF_ELSE HideDupeMessage

            } // END_IF_ELSE DupeFileCount
        }