Esempio n. 1
0
        private void goButton_Click(object sender, EventArgs e)
        {
            if (this._path.Equals(""))
            {
                this.dirDialogButton_Click(sender, e);
            }
            if (this._path.Equals(""))
            {
                goto Quit;
            }

            if (this._rules.IsEmpty() && MessageBox.Show("No rules have been entered!", "Error", MessageBoxButtons.OK) != DialogResult.No)
            {
                goto Quit;
            }


            //Give the user the option to name the rules
            //This might be phased out later when there are RuleSet-specific options (including naming, hopefully)
            //We just want the user to be comfortable with naming rule sets, to allow for a more object-oriented paradigm with the RuleSet object in the future
            if (this._rules.SetName.Equals("Unnamed") && (MessageBox.Show("Do you want to name this rule set?", "", MessageBoxButtons.YesNo) == DialogResult.Yes))
            {
                var namingDialog = new CustomDialog("Edit Name...", "[Enter name for this set of rules]", "OK", "Cancel");
                namingDialog.EnableEditing = true;

                //goto header in case the name is invalid
Name:
                if (namingDialog.ShowDialog() == DialogResult.OK)
                {
                    var regex = new Regex("[" + Regex.Escape(new string(System.IO.Path.GetInvalidPathChars())) + "]");
                    if (namingDialog.DialogText.Equals("[Enter name for this set of rules]"))
                    {
                        MessageBox.Show("Enter a name for this set of rules!", "Error: No name!", MessageBoxButtons.OK);
                        goto Name;
                    }
                    else if (regex.IsMatch(namingDialog.DialogText))
                    {
                        MessageBox.Show("Invalid name!  Please try again.", "Error: Invalid name", MessageBoxButtons.OK);
                        goto Name;
                    }
                    else
                    {
                        this._rules.SetName = namingDialog.DialogText;
                        namingDialog.Dispose(); //Only dispose after grabbing the message text
                        this._stats = new RenamingStats(this._rules.RuleList);
                        this.Execute();
                    }
                }
            }
            else
            {
                this._stats = new RenamingStats(this._rules.RuleList);
                this.Execute();
            }
Quit:
            return;
        }
Esempio n. 2
0
        /// <summary>
        /// Executes the re-naming process.
        /// </summary>
        private void Execute()
        {
            List <string> dirArray = new List <string>();

            if (Settings.Default.RecursiveSearch) //Only add subdirectories if the user wants a recursive search
            {
                foreach (var path in Directory.EnumerateDirectories(_path, "*", SearchOption.AllDirectories))
                {
                    dirArray.Add(path);
                }
            }
            dirArray.Add(_path);

            foreach (var dir in dirArray)
            {
                this._rules.CleanNumbers();                                           //CleanNumbers handles the continuous numbering option, so call it for every directory and it will know what to do
                this._rules.AddFileList(dir, this.Search(dir, this._rules.RuleList)); //nested function calls...adds the file list from the result of the search from the result of GetRules()
            }

            if (Settings.Default.OpenDirectory)
            {
                Process.Start("explorer.exe", "\root," + _path);
            }

            if (Settings.Default.SaveStatistics)
            {   //Saves the statistics to a binary file using a DateTime format prefixed by the ruleset name to prevent any overwriting
                var formatter = new BinaryFormatter();
                var writer    = new FileStream(_appData + Path.DirectorySeparatorChar + this._rules.SetName + "_" + DateTime.Now.ToString("MM-dd-yy_[HH-mm-ss]") + "_stats.bin", FileMode.Create, FileAccess.Write);
                formatter.Serialize(writer, this._stats);
                writer.Close();
            }

            //We obviously want to show stats if the user options call for it, but also if the CopyFirst flag is set (so the user can review renamings)
            if (Settings.Default.OverallStats || Settings.Default.PerRuleStats || Settings.Default.CopyFirst)
            {
                var statsWindow = new StatsWindow(this._stats);
                statsWindow.ShowDialog();

                if (Settings.Default.CopyFirst)
                {//Code to allow for deletion after the search
                    var deleteDialog = new CustomDialog("Confirm Deletion", "Would you like to delete all old files?", "Yes", "No");
                    deleteDialog.Button1Result = DialogResult.Yes;
                    deleteDialog.Button2Result = DialogResult.No;

                    if (deleteDialog.ShowDialog() == DialogResult.Yes)
                    {
                        this.CleanupFiles(this._rules.FileListCollection);
                    }
                    deleteDialog.Dispose();
                }
            }
        }
Esempio n. 3
0
        private void saveRulesButton_Click(object sender, EventArgs e)
        {
            if (this._rules.IsEmpty())
            {
                MessageBox.Show("There are no rules to save!", "Error", MessageBoxButtons.OK);
            }
            else
            {
                var saveWindow = new CustomDialog("Save Rules As...", "[Enter a name for this set of rules]", "OK", "Cancel");
                saveWindow.EnableEditing = true;
Saving:         //Jump here if the file already exists but they don't want to overwrite

                if (saveWindow.ShowDialog() == DialogResult.OK)
                {
                    var named = saveWindow.DialogText;
                    var regex = new Regex("[" + Regex.Escape(new string(System.IO.Path.GetInvalidPathChars())) + "]");

                    if (named.Equals("[Enter a name for this set of rules]"))
                    {
                        MessageBox.Show("Enter a name for this set of rules!", "Error: No name!", MessageBoxButtons.OK);
                        goto Saving;
                    }
                    else if (regex.IsMatch(named))
                    {
                        MessageBox.Show("Invalid name!  Please try again.", "Error: Invalid name", MessageBoxButtons.OK);
                        goto Saving;
                    }
                    else if (named.Equals(""))
                    {
                        MessageBox.Show("Your name can not be empty!  Please try again.", "Error: Invalid name", MessageBoxButtons.OK);
                        goto Saving;
                    }

                    if (File.Exists(_appData + Path.DirectorySeparatorChar + named + "_rules.bin") && (MessageBox.Show("A rule set with this name already exists.  Do you want to overwrite it?", "Confirm Overwrite", MessageBoxButtons.YesNo) == DialogResult.No))
                    {
                        goto Saving;
                    }
                    if (this._rules.SetName.Equals("Unnamed")) //Set the name if it hasn't been
                    {
                        this._rules.SetName = named;
                    }
                    var formatter = new BinaryFormatter();
                    var writer    = new FileStream(_appData + Path.DirectorySeparatorChar + named + "_rules.bin", FileMode.Create, FileAccess.Write);
                    formatter.Serialize(writer, this._rules);
                    writer.Close();
                }

                saveWindow.Dispose(); //Only dispose after everything has been used
            }

            this.ruleBox.Text = this._rules.ToString();
        }