Esempio n. 1
0
        /// <summary>
        /// ファイル除外ボタン押下時
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickRemove(object sender, RoutedEventArgs e)
        {
            var selectedList = new FileProperty[FileListBox.SelectedItems.Count];

            FileListBox.SelectedItems.CopyTo(selectedList, 0);

            context.RemoveFiles(selectedList);
            context.RefreshUndoButton();
        }
Esempio n. 2
0
        /// <summary>
        /// リネーム実行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickRename(object sender, RoutedEventArgs e)
        {
            var fileList = new FileProperty[context.FileList.Count];

            context.FileList.CopyTo(fileList, 0);

            core.StartRename(fileList);
            FileListBox.Items.Refresh();
        }
Esempio n. 3
0
 public void RemoveFile(FileProperty prop)
 {
     FileList.Remove(prop);
 }
Esempio n. 4
0
        // TODO: リターンで処理の結果をEnumで返す
        /// <summary>
        /// リネーム処理
        /// </summary>
        /// <param name="fileProp"></param>
        /// <param name="index"></param>
        private RenameResult Rename(FileProperty fileProp, int index)
        {
            string[] splitPathes = fileProp.Path.Split(Path.DirectorySeparatorChar);
            string   fileName, oldFilePath, extention;

            oldFilePath = fileProp.Path;
            extention   = Path.GetExtension(fileProp.Path);
            fileName    = Path.GetFileNameWithoutExtension(fileProp.Path);

            // 置換処理
            if (!string.IsNullOrEmpty(context.ReplaceSearchText))
            {
                fileName = fileName.Replace(context.ReplaceSearchText, context.ReplacedText);
            }

            // 連番処理
            string serialNumber = "";

            if (!string.IsNullOrEmpty(context.SerialNumText))
            {
                if (int.TryParse(context.SerialNumText, out int num) && int.TryParse(context.SerialNumDigit, out int digit))
                {
                    num         += index;
                    serialNumber = num.ToString("d" + digit.ToString());
                }
                else
                {
                    // テキストの指定エラーのダイアログ表示
                    MessageBox.Show("連番指定には必ず半角数字を入力してください", "確認", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return(RenameResult.Failed);
                }
            }

            // リネーム
            fileName = context.FormatText.Replace("{0}", fileName);
            fileName = fileName.Replace("{1}", serialNumber);
            if (string.IsNullOrEmpty(fileName))
            {
                return(RenameResult.EmptyName);
            }

            // 変更後の絶対パス作成
            string renamedFilePath = splitPathes[0];

            for (int i = 1; i < splitPathes.Length - 1; ++i)
            {
                renamedFilePath += Path.DirectorySeparatorChar + splitPathes[i];
            }
            renamedFilePath += Path.DirectorySeparatorChar + fileName + extention;

            // ファイルのリネーム実行
            if (renamedFilePath == fileProp.Path)
            {
                return(RenameResult.Done);
            }
            if (File.Exists(renamedFilePath))
            {
                return(RenameResult.SameFilePath);
            }

            File.Move(fileProp.Path, renamedFilePath);

            fileProp.History.Push(oldFilePath);
            fileProp.Path = renamedFilePath;

            return(RenameResult.Done);
        }