Exemplo n.º 1
0
        private void Rename(FileNameStyle style, TextMode textMode)
        {
            if (!Verify())
            {
                return;
            }
            var voiceRoot   = exVoicePathTextBox.Text;
            var voiceList   = _Voices[exVoiceSelector.SelectedIndex];
            int renameCount = 0;

            foreach (var item in voiceList.Items)
            {
                var current = item.GetCurrentFilePath(voiceRoot);
                var newPath = item.GetNewFilePath(voiceRoot, style);
                if (current != null)
                {
                    var result = RenameFile(current, newPath);
                    if (result)
                    {
                        renameCount++;
                    }
                }

                current = item.GetCurrentFilePath(voiceRoot, "txt");
                newPath = item.GetNewFilePath(voiceRoot, style, "txt");
                switch (textMode)
                {
                case TextMode.Generate:
                    if (current != null)
                    {
                        RenameFile(current, newPath);
                    }
                    Encoding encoding = _Encodings[encodingSelector.SelectedIndex];
                    bool     newline  = newlineCheckBox.IsChecked ?? true;
                    item.CreateTextFile(voiceRoot, style, encoding, newline);
                    break;

                case TextMode.Delete:
                    if (current != null)
                    {
                        File.Delete(current);
                    }
                    break;
                }
            }

            MessageBox.Show($"{renameCount}個のファイルをリネームしました");
        }
Exemplo n.º 2
0
        public string GetNewFilePath(string root, FileNameStyle style, string ext = "wav")
        {
            switch (style)
            {
            case FileNameStyle.VoiceId:
                return(Path.Combine(root, FolderName, $"{VoiceId}.{ext}"));

            case FileNameStyle.VoiceId_Line:
                string filename = $"{VoiceId}_{Line}.{ext}";
                filename = filename.ConvertInvalidFileNameChars();
                return(Path.Combine(root, FolderName, filename));

            default:
                throw new ArgumentException($"スタイル{style}は不正です");
            }
        }
Exemplo n.º 3
0
        public bool CreateTextFile(string root, FileNameStyle style, Encoding encoding, bool newline)
        {
            string filename = GetNewFilePath(root, style, "txt");

            using (var sw = new StreamWriter(filename, false, encoding))
            {
                if (newline)
                {
                    sw.WriteLine(Line);
                }
                else
                {
                    sw.Write(Line);
                }
            }
            return(true);
        }