using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace GetADoc { class PushedButton { //ファイル名に使用不可の文字が含まれている場合の処理 public static string NameCalibration(string inFileName) { string[] charsToRemove = new string[] { @"\", ".", "/", ":", "*", "?", "<", ">", "|" }; foreach (var allNg in charsToRemove) { inFileName = inFileName.Replace(allNg, string.Empty); } return inFileName; } //先に同名フォルダが存在すれば削除(エラー回避のため) public static void deleteFolder(string filePath, string fileName) { 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); } } //バッチファイルの実行 public static void runBatch(bool icon, bool screen, bool sepa, string fileName, string tempPath) { ProcessStartInfo processStartInfo = new ProcessStartInfo(); string stCurrentDir = System.IO.Directory.GetCurrentDirectory(); processStartInfo.FileName = System.IO.Path.Combine(stCurrentDir, "getADoc.Data", "getADoc.bat"); processStartInfo.CreateNoWindow = true; // コマンドプロンプトを非表示 processStartInfo.UseShellExecute = false; // シェル機能オフ //チェックボックスの状況に応じて引数を指定 processStartInfo.Arguments = ""; if (icon == true)//Iconsチェックボックスがオンのとき { processStartInfo.Arguments += "/Icons "; } if (screen == true)//SCREEN Logoチェックボックスがオンのとき { processStartInfo.Arguments += "/SCREEN "; } if (sepa == true)//分割ドキュチェックボックスがオンのとき { processStartInfo.Arguments += "/SepaDoc "; } var pathAndName = System.IO.Path.Combine(tempPath, fileName); processStartInfo.Arguments += pathAndName; //GetADoc.batを実行 Process process = Process.Start(processStartInfo); process.WaitForExit(); process.Close(); } //生成物を指定先フォルダへ移動 static public void MoveProduct(bool icon, bool sepa, string fileName, string tempPath, string filePath) { File.Move(System.IO.Path.Combine(tempPath, fileName + ".adoc"), filePath + fileName + ".adoc"); File.Move(System.IO.Path.Combine(tempPath, "config.adoc"), System.IO.Path.Combine(filePath, "config.adoc")); Directory.Move(System.IO.Path.Combine(tempPath, "Images"), System.IO.Path.Combine(filePath, "Images")); if (icon == true) { Directory.Move(System.IO.Path.Combine(tempPath, "icons"), System.IO.Path.Combine(filePath, "icons")); } if (sepa == true) { File.Move(System.IO.Path.Combine(tempPath, "IncDoc.adoc"), System.IO.Path.Combine(filePath, "IncDoc.adoc")); Directory.Move(System.IO.Path.Combine(tempPath, "Sub_First"), System.IO.Path.Combine(filePath, "Sub_First")); Directory.Move(System.IO.Path.Combine(tempPath, "Sub_Second"), System.IO.Path.Combine(filePath, "Sub_Second")); } } } }