Example #1
0
    public static void Init()
    {
        RenameTool window = (RenameTool)EditorWindow.GetWindow(typeof(RenameTool));

        window.titleContent = new GUIContent("Rename");
        window.Show();
    }
Example #2
0
        // Ready to rename now the selected files
        public void RenameNow()
        {
            if (renameNowEvent != null)
            {
                renameNowEvent(ProcessCode.ON_RENAME_INIT);
            }
            // Renaming now so set busy to true for the MainWindowViewModel and OptionsModel
            _option.Busy = true;


            // Validation before renaming happens here
            // No renaming to happen if theres no suffix or prefix involved
            if (string.IsNullOrEmpty(_option.Prefix) && string.IsNullOrEmpty(_option.Suffix))
            {
                MessageBox.Show("Prefix and Suffix can't be empty!", "Error", MessageBoxButton.OK);
                _option.Busy = false;
                return;
            }

            if (_option.RemoveFilename)
            {
                string[] apOptions = RenameTool.GetCapturedOptions(_option.Prefix);
                string[] asOptions = RenameTool.GetCapturedOptions(_option.Suffix);

                // Get all increment values using lambda select and where
                bool bSuffixi = RenameTool.IsContains(apOptions);
                bool bPrefixi = RenameTool.IsContains(asOptions);
                if (!bSuffixi && !bPrefixi)
                {
                    MessageBox.Show("Remove filename only works if you have [i] option set!", "Error", MessageBoxButton.OK);
                    _option.Busy = false;
                    return;
                }
            }



            // Done validating continue to rename now
            bool yes = RenameTool.AskToConfirm();

            if (yes && !_bgworker.IsBusy)
            {
                _bgworker.RunWorkerAsync();
                _wprogress = new ProgressWindow(_option, ref _bgworker);
                _wprogress.ShowDialog();
            }


            _option.Busy = false;
        }
Example #3
0
        // Pop the browse multiple files dialog
        // and return the folder path they all live
        private string BrowseMultipleFilesPop(string paramFolder)
        {
            string        tempFolder = paramFolder;
            List <string> sFiles     = RenameTool.BrowseByMultipleFiles(tempFolder);

            if (sFiles.Count > 0)
            {
                // Set the folder path after selection

                tempFolder            = Path.GetDirectoryName(sFiles.FirstOrDefault());
                _option.FilesSelected = sFiles;
            }
            return(tempFolder);
        }
Example #4
0
        // Pop the dialog box to select a folder
        private string BrowseByFolderPop(string paramFolder)
        {
            string tempFolder = RenameTool.BrowseByFolder(paramFolder);
            Object tempObj    = null;

            // If folder is empty string return zero list
            if (string.IsNullOrEmpty(tempFolder))
            {
                tempObj = new List <string>();
            }
            else // Otherwise get the files in folder
            {
                tempObj = RenameTool.SelectFilesInFolder(tempFolder, _option.FileTypes.GetFilters());
            }

            if (tempObj is List <string> )
            {
                _option.FilesSelected = tempObj as List <string>;
            }
            return(tempFolder);
        }
Example #5
0
        // Initialize files selection coming from context menu
        private void InitializeFilesSelected(ref ErrorCode enErr)
        {
            if (_option.IsFromContextMenu)
            {
                int isDirOrDoesntExist = RenameTool.isDirectory(_option.FolderPath);
                // Get the files in folder and folder is 1
                if (_option.ArgumentProperty == "-folder" && isDirOrDoesntExist == 1)
                {
                    var tempObj = RenameTool.SelectFilesInFolder(_option.FolderPath, _option.FileTypes.GetFilters());
                    if (tempObj is List <string> )
                    {
                        _option.FilesSelected = tempObj as List <string>;
                    }
                }
                // Get files from the temp file with list of path in it from context menu
                // int code for 0 means its a file and it exist
                else if (_option.ArgumentProperty == "-files" && isDirOrDoesntExist == 0)
                {
                    // read the temp file and fill up the files selected
                    var           lines = File.ReadLines(_option.FolderPath);
                    List <string> Files = new List <string>();
                    foreach (var line in lines)
                    {
                        Files.Add(line.ToString());
                    }
                    _option.FilesSelected = Files;

                    // must delete the file afterwards
                    // File.Delete(_option.FolderPath);
                }

                // int value is -1 File or folder doesnt exist
                if (isDirOrDoesntExist < 0)
                {
                    enErr = ErrorCode.NO_FOLDER_EXIST;
                }
            }
        }
Example #6
0
 static void RenameAllScenes()
 {
     RenameTool.RenameAllScenes();
 }
Example #7
0
 static void RenameAsset()
 {
     //TODO
     //EditorWindow.GetWindow<>
     RenameTool.RenameAsset();
 }
Example #8
0
        // This is the main rename worker to do all the grun work

        void _bgworker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Check if files selected
            int filecount = _option.FilesSelected.Count;

            if (filecount > 0)
            {
                // Initialize and get dates
                int day   = DateTime.Now.Day;
                int month = DateTime.Now.Month;
                int year  = DateTime.Now.Year;

                int   increment   = 1;
                float percentDone = 0;

                List <string> newList = new List <string>();

                foreach (string v in _option.FilesSelected)
                {
                    // Check first if theres any cancellation of action otherwise just keep going.
                    if (_bgworker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }
                    string filename    = Path.GetFileNameWithoutExtension(v);
                    string folder      = Path.GetDirectoryName(v);
                    string ext         = Path.GetExtension(v);
                    string newfilename = filename;
                    string prefix2     = _option.Prefix;
                    string suffix2     = _option.Suffix;


                    // Replace i option with increment and add 0 padding
                    int    iPadNum = filecount.ToString().Length;
                    string sPad    = increment.ToString().PadLeft(iPadNum, '0');
                    prefix2 = Regex.Replace(prefix2, @"\[i\]", sPad);
                    suffix2 = Regex.Replace(suffix2, @"\[i\]", sPad);

                    // Replace date
                    prefix2 = Regex.Replace(prefix2, @"\[d\]", day.ToString());
                    prefix2 = Regex.Replace(prefix2, @"\[m\]", month.ToString());
                    prefix2 = Regex.Replace(prefix2, @"\[y\]", year.ToString());

                    suffix2 = Regex.Replace(suffix2, @"\[d\]", day.ToString());
                    suffix2 = Regex.Replace(suffix2, @"\[m\]", month.ToString());
                    suffix2 = Regex.Replace(suffix2, @"\[y\]", year.ToString());


                    // Set the progress window control
                    percentDone = (float)increment / (float)filecount;
                    int totaldone = (int)Math.Ceiling(percentDone * 100);

                    _option.ProgressWindowPercentage = string.Format("{0}%", totaldone);
                    _option.ProgressWindowStatus     = string.Format("Renaming {0}", newfilename);
                    _option.ProgressWindowWidth      = (int)(percentDone * 170);

                    // If the prefix or suffix is the same as the first or last occurence remove them!
                    if (_option.RemovePrefixFirst)
                    {
                        string pmatch = string.Format("^{0}", prefix2);
                        newfilename = Regex.Replace(newfilename, pmatch, "");
                    }
                    if (_option.RemoveSuffixFirst)
                    {
                        string smatch = string.Format("{0}$", suffix2);
                        newfilename = Regex.Replace(newfilename, smatch, "");
                    }
                    // reconstruct newfilename
                    newfilename = string.Format("{0}{1}{2}", prefix2, newfilename, suffix2);

                    // Only remove file name if there is an [i] increment option in the suffix/prefix
                    if (_option.RemoveFilename)
                    {
                        newfilename = string.Format("{0}{1}", prefix2, suffix2);
                    }

                    // Remove any unwanted character
                    newfilename = RenameTool.RemoveSpecialCharacters(newfilename);

                    // Lastly rename now
                    string fullpath = string.Format(@"{0}\{1}{2}", folder, newfilename, ext);

                    try
                    {
                        System.IO.File.Move(v, fullpath); // This will throw exception if file not found
                        newList.Add(fullpath);
                    }
                    catch (FileNotFoundException)
                    {
                        MessageBox.Show(string.Format("{0} does not exist. Skipping to the next one.", v), "Notification", MessageBoxButton.OK);
                    }
                    increment++;
                }

                // successfully renaming
                _option.FilesSelected = newList;
                e.Result = true;
                return;
            }

            // nothings been renamed
            e.Result = false;
            return;
        }
Example #9
0
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string presuff = (string)value;

            return(RenameTool.RemoveSpecialCharacters(presuff));
        }