diff --git a/GetADoc/MainWindow.xaml.cs b/GetADoc/MainWindow.xaml.cs index 2c2eef7b263710cdd741d3d03aee401ddab57b91..f2c0b9a0d3c04e5266cc9146c2ee7c1354c65702 100644 --- a/GetADoc/MainWindow.xaml.cs +++ b/GetADoc/MainWindow.xaml.cs @@ -116,11 +116,48 @@ namespace GetADoc { fileName = fileName.Replace(allNg, string.Empty); } - MessageBox.Show("ファイル名に使用できない文字が存在したため\n一部ファイル名を修正しました。\nもう一度作成ボタンをクリックしてください。", "Renamed this file", MessageBoxButton.OK, MessageBoxImage.Warning); + MessageBox.Show("ファイル名に使用できない文字が存在したため\n一部ファイル名を修正しました。" + + "\nもう一度作成ボタンをクリックしてください。", "Renamed this file", MessageBoxButton.OK, MessageBoxImage.Warning); box2.Text = fileName; return; } + //指定したフォルダに同名の.adocや既存の付属ファイル(config.adocなど)がある場合の処理 + if (File.Exists(System.IO.Path.Combine(filePath, fileName + ".adoc")) || File.Exists(System.IO.Path.Combine(filePath, "config.adoc"))) + { + MessageBoxResult OverwriteADoc = MessageBox.Show("これから生成するファイルと同名のファイルが既に存在します" + + "\n既存のファイルを上書きしますか?", + "指定したフォルダに既存のファイルが存在します", + MessageBoxButton.YesNo); + if (OverwriteADoc == MessageBoxResult.Yes) + { + File.Delete(filePath + fileName + ".adoc"); + File.Delete(System.IO.Path.Combine(filePath, "config.adoc")); + File.Delete(System.IO.Path.Combine(filePath, "IncDoc.adoc")); + if (Directory.Exists(System.IO.Path.Combine(filePath, "Images"))) + { + Directory.Delete(System.IO.Path.Combine(filePath, "Images"), true); + } + if (Directory.Exists(System.IO.Path.Combine(filePath, "icons"))) + { + Directory.Delete(System.IO.Path.Combine(filePath, "icons"), true); + } + if (Directory.Exists(System.IO.Path.Combine(filePath, "Sub_First"))) + { + Directory.Delete(System.IO.Path.Combine(filePath, "Sub_First"), true); + } + if (Directory.Exists(System.IO.Path.Combine(filePath, "Sub_Second"))) + { + Directory.Delete(System.IO.Path.Combine(filePath, "Sub_Second"), true); + } + } + else if(OverwriteADoc == MessageBoxResult.No) + { + MessageBox.Show("別のフォルダを指定してください"); + return; + } + } + //バッチファイルの実行 ProcessStartInfo processStartInfo = new ProcessStartInfo(); string stCurrentDir = System.IO.Directory.GetCurrentDirectory(); @@ -151,7 +188,7 @@ namespace GetADoc //指定されたフォルダに生成物を移動 File.Move(System.IO.Path.Combine(stCurrentDir, fileName + ".adoc"), filePath + fileName + ".adoc"); - File.Move(System.IO.Path.Combine(stCurrentDir, "config.adoc"), filePath + "/config.adoc"); + File.Move(System.IO.Path.Combine(stCurrentDir, "config.adoc"), System.IO.Path.Combine(filePath, "config.adoc")); Directory.Move(System.IO.Path.Combine(stCurrentDir, "Images"), System.IO.Path.Combine(filePath, "Images")); if (checkbox2.IsChecked == true) {