Ejemplo n.º 1
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();
                }
            }
        }
Ejemplo n.º 2
0
        private void loadPreviousButton_Click(object sender, EventArgs e)
        {
            var loadLoc = new StringBuilder();

            if ((new LoadRulesWindow(ref loadLoc, 1)).ShowDialog() == DialogResult.OK)
            {
                var formatter   = new BinaryFormatter();
                var reader      = new FileStream(_appData + Path.DirectorySeparatorChar + loadLoc.ToString() + "_stats.bin", FileMode.Open, FileAccess.Read);
                var statsWindow = new StatsWindow((RenamingStats)formatter.Deserialize(reader));
                statsWindow.Show();
                reader.Close();
            }
        }
Ejemplo n.º 3
0
        private void loadPreviousButton_Click(object sender, EventArgs e)
        {
            var list = new List <string>();

            foreach (var item in Directory.GetFiles(Core._appData, "*_stats.bin"))
            {
                list.Add(Path.GetFileNameWithoutExtension(item).Replace("_stats", ""));
            }

            var loadStatsWindow = new CustomListDialog("Load...", list, "OK", "Cancel");

            if (loadStatsWindow.ShowDialog() == DialogResult.OK)
            {
                var formatter   = new BinaryFormatter();
                var reader      = new FileStream(_appData + Path.DirectorySeparatorChar + loadStatsWindow.SelectedItem + "_stats.bin", FileMode.Open, FileAccess.Read);
                var statsWindow = new StatsWindow((RenamingStats)formatter.Deserialize(reader));
                statsWindow.Show();
                reader.Close();
            }

            loadStatsWindow.Dispose();
        }