예제 #1
0
        public override StringOperation Clone()
        {
            //tạo mới 1 moveOperation trống
            var newMoveOperation = new MoveOperation()
            {
                Args = new MoveArgs()
                {
                    Size = 0,
                    Type = 0
                }
            };
            //hiện dialog để người dùng customize
            var screen = new MoveConfigDialog(newMoveOperation.Args);

            if (screen.ShowDialog() == true)
            {
            }
            //lấy args sau khi người dùng config, nếu size vẫn là 0  thì không return newMoveOperation
            //đó là trường hợp người dùng cancel
            var ArgsAfterConfiguration = newMoveOperation.Args as MoveArgs;

            if (ArgsAfterConfiguration.Size == 0)
            {
                return(null);
            }
            else
            {
                //trả về moveOperation mà người dùng đã custom
                return(newMoveOperation);
            }
        }
예제 #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //add các loại prototype mà mình có
            var prototype1 = new ReplaceOperation()
            {
                Args = new ReplaceArgs()
                {
                    From = "From",
                    To   = "To"
                }
            };
            var prototype2 = new MoveOperation()
            {
                Args = new MoveArgs()
                {
                    Size = 0,
                    Type = 0
                }
            };
            var prototype3 = new UniqueStringOperation();
            var prototype4 = new NewCaseOperation()
            {
                Args = new NewCaseArgs()
                {
                    Style = "Style"
                }
            };
            var prototype5 = new FullNameOperation();

            //add vào list prototypes
            _prototypes.Add(prototype1);
            _prototypes.Add(prototype2);
            _prototypes.Add(prototype3);
            _prototypes.Add(prototype4);
            _prototypes.Add(prototype5);
            //load các presets mà mình có
            Directory.CreateDirectory(path);
            //load presets
            var PresetsLocation = new DirectoryInfo(path);

            FileInfo[] files = PresetsLocation.GetFiles("*.txt");
            foreach (var file in files)
            {
                _presets.Add(System.IO.Path.GetFileNameWithoutExtension(file.Name));
            }
            //set source cho prototypesComboBox, filesListView, folderListView, presetsCombobox và operationListBox
            prototypesComboBox.ItemsSource = _prototypes;
            operationsListBox.ItemsSource  = _actions;
            filesListView.ItemsSource      = listFiles;
            foldersListView.ItemsSource    = listFolders;
            presetsComboBox.ItemsSource    = _presets;
        }
예제 #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var prototype1 = new ReplaceOperation()
            {
                Args = new ReplaceArgs()
                {
                    From = "From",
                    To   = "To"
                }
            };
            var prototype2 = new NewCaseOperation()
            {
                Args = new NewCaseArgs()
                {
                }
            };
            var prototype3 = new NameNormalizeOperation()
            {
                Args = new NameNormalizeArgs()
                {
                }
            };
            var prototype4 = new MoveOperation()
            {
                Args = new MoveArgs()
                {
                }
            };
            var prototype5 = new UniqueOperation()
            {
                Args = new UniqueArgs()
                {
                }
            };

            _prototypes.Add(prototype1);
            _prototypes.Add(prototype2);
            _prototypes.Add(prototype3);
            _prototypes.Add(prototype4);
            _prototypes.Add(prototype5);

            ActionsListView.ItemsSource = _prototypes;

            operationsListBox.ItemsSource = _actions;
        }
예제 #4
0
        private void Move_Button_Click(object sender, RoutedEventArgs e)
        {
            var prototype = new MoveOperation()
            {
                Args = new MoveArgs()
                {
                    Before = true,
                    Start  = 0,
                    End    = 13
                }
            };
            var action = prototype;

            if (action.Config())
            {
                _actions.Add(action.Clone());
            }
        }
예제 #5
0
        public override StringOperation Clone(string[] args)
        {
            if (args.Length != 2)
            {
                return(null);
            }
            //tạo mới 1 moveOperation, tham số là các giá trị string truyền vào
            var newMoveOperation = new MoveOperation();

            newMoveOperation.Args = new MoveArgs()
            {
                Size = int.Parse(args[0]),
                Type = int.Parse(args[1])
            };


            //trả về replaceOperation mà người dùng đã custom
            return(newMoveOperation);
        }
예제 #6
0
        private void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            //openFileDialog.InitialDirectory = @"C:\";
            openFileDialog.Title            = "Load";
            openFileDialog.DefaultExt       = "txt";
            openFileDialog.Filter           = "Text files (*.txt)|*.txt";
            openFileDialog.RestoreDirectory = true;
            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var    reader  = new StreamReader(openFileDialog.FileName);
                Preset preset  = new Preset();
                var    tokens2 = openFileDialog.FileName.Split(new string[] { "\\" }, StringSplitOptions.None);
                var    tokens3 = tokens2[tokens2.Length - 1].Split(new string[] { "." }, StringSplitOptions.None);
                preset.Name = tokens3[0];
                if (reader.ReadLine() == "BatchRename")
                {
                    var n = int.Parse(reader.ReadLine());
                    operationsList.Clear();
                    for (int i = 1; i <= n; i++)
                    {
                        var             tokens = reader.ReadLine().Split(new string[] { " - " }, StringSplitOptions.None);
                        StringOperation operation;
                        switch (tokens[0])
                        {
                        case "Replace":
                            operation = new ReplaceOperation
                            {
                                Args = new ReplaceArgs
                                {
                                    From = tokens[1],
                                    To   = tokens[2]
                                }
                            };
                            operationsList.Add(operation);
                            preset.stringOperations.Add(operation.Clone());
                            break;

                        case "Change Case":
                            operation = new NewCaseStringOperation
                            {
                                Args = new CaseArgs
                                {
                                    Case = tokens[1]
                                }
                            };
                            operationsList.Add(operation);
                            preset.stringOperations.Add(operation.Clone());
                            break;

                        case "Move":
                            operation = new MoveOperation
                            {
                                Args = new MoveArgs
                                {
                                    Mode   = tokens[1],
                                    Number = int.Parse(tokens[2])
                                }
                            };
                            operationsList.Add(operation);
                            preset.stringOperations.Add(operation.Clone());
                            break;

                        case "Fullname normalize":
                            operationsList.Add(new FullnameNormalizeOperation());
                            preset.stringOperations.Add(new FullnameNormalizeOperation());
                            break;

                        case "Unique name":
                            operationsList.Add(new UniqueNameOperation());
                            preset.stringOperations.Add(new UniqueNameOperation());
                            break;
                        }
                    }
                    loadedPresets.Add(preset);
                    PresetsList.SelectedIndex = loadedPresets.Count() - 1;
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("This txt file is not BatchRename's data");
                }
                reader.Close();
            }
        }
예제 #7
0
        private void LoadFromFile_Button_Click(object sender, RoutedEventArgs e)
        {
            string         line     = "";
            OpenFileDialog openFile = new OpenFileDialog();

            if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _actions.Clear();
                var reader = new StreamReader(openFile.FileName);
                line = reader.ReadLine();
                while (line != null)
                {
                    var tokens = line.Split(new string[] { " " }, StringSplitOptions.None);
                    {
                        if (tokens[0] == Replace)
                        {
                            string firstString  = tokens[1].Substring(0, 5).Trim();
                            string secondString = tokens[1].Substring(5).Trim();
                            tokens[1] = secondString;

                            string firstString1  = tokens[2].Substring(0, 3).Trim();
                            string secondString1 = tokens[2].Substring(3).Trim();
                            tokens[2] = secondString1;


                            bool temp = false;
                            if (tokens[3] == "True")
                            {
                                temp = true;
                            }

                            var prototype = new ReplaceOperation()
                            {
                                Args = new ReplaceArgs
                                {
                                    From        = tokens[1],
                                    To          = tokens[2],
                                    ReplaceName = temp
                                }
                            };
                            var action = prototype;
                            _actions.Add(action.Clone());
                        }
                        else
                        {
                            if (tokens[0] == Move)
                            {
                                bool temp;

                                if (tokens[3] == "True")
                                {
                                    temp = true;
                                }
                                else
                                {
                                    temp = false;
                                }
                                var prototype = new MoveOperation()
                                {
                                    Args = new MoveArgs
                                    {
                                        Start  = int.Parse(tokens[1]),
                                        End    = int.Parse(tokens[2]),
                                        Before = temp
                                    }
                                };
                                var action = prototype;
                                _actions.Add(action.Clone());
                            }
                            else
                            {
                                if (tokens[0] == Newcase)
                                {
                                    var prototype = new NewCaseOperation()
                                    {
                                        Args = new NewCaseArgs
                                        {
                                            optionNewCase = int.Parse(tokens[1])
                                        }
                                    };
                                    var action = prototype;
                                    _actions.Add(action.Clone());
                                }
                                else
                                {
                                    if (tokens[0] == Unique)
                                    {
                                        var prototype = new UniqueNameOperation()
                                        {
                                            Args = new UniqueNameArgs
                                            {
                                            }
                                        };
                                        var action = prototype;
                                        _actions.Add(action.Clone());
                                    }
                                    else
                                    {
                                        if (tokens[0] == Normalize)
                                        {
                                            var prototype = new FullnameNormalizeOperation()
                                            {
                                                Args = new FullnameNormalizeArg
                                                {
                                                }
                                            };
                                            var action = prototype;
                                            _actions.Add(action.Clone());
                                        }
                                        else
                                        {
                                            System.Windows.Forms.MessageBox.Show("Khong hop le!!!");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    line = reader.ReadLine();
                }
            }
        }
예제 #8
0
        private void presetChange(object sender, SelectionChangedEventArgs e)
        {
            InfoFile selected = presetComboBox.SelectedItem as InfoFile;

            if (selected != null)
            {
                List <StringOperation> result = new List <StringOperation>();
                var filename = selected.Name + ".txt";
                var lines    = File.ReadAllLines(filename);
                foreach (var line in lines)
                {
                    var tokens = line.Split(new string[]
                                            { "|" }, StringSplitOptions.RemoveEmptyEntries);

                    switch (tokens[0].ToString())
                    {
                    case "Replace":
                    {
                        ReplaceOperation replace = new ReplaceOperation()
                        {
                            Args = new ReplaceArgs()
                            {
                                From = tokens[1], To = tokens[2]
                            }
                        };
                        result.Add(replace);
                        break;
                    }

                    case "NewCase":
                    {
                        NewCaseOperation newcase = new NewCaseOperation()
                        {
                            Args = new NewCaseArgs()
                            {
                                From = tokens[1],
                            }
                        };
                        result.Add(newcase);
                        break;
                    }

                    case "Fullname Normalize":
                    {
                        FullnameNormalizeOperation newcase = new FullnameNormalizeOperation()
                        {
                            Args = new FullnameNormalizeArgs()
                            {
                                From = tokens[1],
                            }
                        };
                        result.Add(newcase);
                        break;
                    }

                    case "Move":
                    {
                        MoveOperation newcase = new MoveOperation()
                        {
                            Args = new MoveArgs()
                            {
                                From = tokens[1],
                            }
                        };
                        result.Add(newcase);
                        break;
                    }
                    }
                }
                foreach (StringOperation item in result)
                {
                    ActionListBox.Items.Add(item);
                }
            }
        }
예제 #9
0
        private void btnOpenPreset_Click(object sender, RoutedEventArgs e)
        {
            List <StringOperation> result = new List <StringOperation>();

            var screen = new OpenFileDialog();

            if (screen.ShowDialog() == true)
            {
                var filename = screen.FileName;
                var lines    = File.ReadAllLines(filename);
                foreach (var line in lines)
                {
                    var tokens = line.Split(new string[]
                                            { "|" }, StringSplitOptions.RemoveEmptyEntries);

                    switch (tokens[0].ToString())
                    {
                    case "Replace":
                    {
                        ReplaceOperation replace = new ReplaceOperation()
                        {
                            Args = new ReplaceArgs()
                            {
                                From = tokens[1], To = tokens[2]
                            }
                        };
                        result.Add(replace);
                        break;
                    }

                    case "NewCase":
                    {
                        NewCaseOperation newcase = new NewCaseOperation()
                        {
                            Args = new NewCaseArgs()
                            {
                                From = tokens[1],
                            }
                        };
                        result.Add(newcase);
                        break;
                    }

                    case "Fullname Normalize":
                    {
                        FullnameNormalizeOperation newcase = new FullnameNormalizeOperation()
                        {
                            Args = new FullnameNormalizeArgs()
                            {
                                From = tokens[1],
                            }
                        };
                        result.Add(newcase);
                        break;
                    }

                    case "Move":
                    {
                        MoveOperation newcase = new MoveOperation()
                        {
                            Args = new MoveArgs()
                            {
                                From = tokens[1],
                            }
                        };
                        result.Add(newcase);
                        break;
                    }
                    }
                }
            }
            foreach (StringOperation item in result)
            {
                ActionListBox.Items.Add(item);
            }
        }