diff --git a/GetADoc/CustomMsgBox.cs b/GetADoc/CustomMsgBox.cs
new file mode 100644
index 0000000000000000000000000000000000000000..0530740f7f7b5e56ac11b8564afb4b9582916859
--- /dev/null
+++ b/GetADoc/CustomMsgBox.cs
@@ -0,0 +1,168 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Interop;
+using System.Runtime.InteropServices;
+
+namespace GetADoc
+{
+ //親(メイン)ウインドウの中心にメッセージを表示するためのクラス
+ class CustomMsgBox
+ {///
+ /// 親ウィンドウ
+ ///
+ private Window ownerWindow = null;
+
+ ///
+ /// フックハンドル
+ ///
+ private IntPtr hHook = IntPtr.Zero;
+
+ ///
+ /// メッセージボックスを表示する
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static MessageBoxResult Show(
+ Window owner,
+ string messageBoxText,
+ string caption,
+ MessageBoxButton button,
+ MessageBoxImage icon)
+ {
+
+ if (owner.WindowState == WindowState.Minimized)
+ {
+ return MessageBox.Show(owner, messageBoxText, caption, button, icon);
+ }
+ else
+ {
+ CustomMsgBox mbox = new CustomMsgBox(owner);
+ return mbox.Show(messageBoxText, caption, button, icon);
+ }
+ }
+
+ ///
+ /// コンストラクタ
+ ///
+ /// Owner Window
+ private CustomMsgBox(Window window)
+ {
+ ownerWindow = window;
+ }
+
+ ///
+ /// メッセージボックスを表示する
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private MessageBoxResult Show(
+ string messageBoxText,
+ string caption,
+ MessageBoxButton button,
+ MessageBoxImage icon)
+ {
+ // フックを設定する。
+ HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(ownerWindow);
+ IntPtr hInstance = WinAPI.GetWindowLong(hwndSource.Handle, WinAPI.GWL_HINSTANCE);
+ IntPtr threadId = WinAPI.GetCurrentThreadId();
+ hHook = WinAPI.SetWindowsHookEx(WinAPI.WH_CBT, new WinAPI.HOOKPROC(HookProc), hInstance, threadId);
+
+ return MessageBox.Show(ownerWindow, messageBoxText, caption, button, icon);
+ }
+
+ ///
+ /// フックプロシージャ
+ ///
+ ///
+ ///
+ ///
+ ///
+ private IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam)
+ {
+
+ if (nCode == WinAPI.HCBT_ACTIVATE)
+ {
+ WinAPI.RECT rcForm = new WinAPI.RECT(0, 0, 0, 0);
+ WinAPI.RECT rcMsgBox = new WinAPI.RECT(0, 0, 0, 0);
+
+ HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(ownerWindow);
+ WinAPI.GetWindowRect(hwndSource.Handle, out rcForm);
+ WinAPI.GetWindowRect(wParam, out rcMsgBox);
+
+ // センター位置を計算する。
+ int x = (rcForm.Left + (rcForm.Right - rcForm.Left) / 2) - ((rcMsgBox.Right - rcMsgBox.Left) / 2);
+ int y = (rcForm.Top + (rcForm.Bottom - rcForm.Top) / 2) - ((rcMsgBox.Bottom - rcMsgBox.Top) / 2);
+
+ WinAPI.SetWindowPos(wParam, 0, x, y, 0, 0, WinAPI.SWP_NOSIZE | WinAPI.SWP_NOZORDER | WinAPI.SWP_NOACTIVATE);
+
+ IntPtr result = WinAPI.CallNextHookEx(hHook, nCode, wParam, lParam);
+
+ // フックを解除する。
+ WinAPI.UnhookWindowsHookEx(hHook);
+ hHook = IntPtr.Zero;
+
+ return result;
+
+ }
+ else
+ {
+ return WinAPI.CallNextHookEx(hHook, nCode, wParam, lParam);
+ }
+ }
+ }
+
+ internal class WinAPI
+ {
+ [DllImport("user32.dll")]
+ public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
+ [DllImport("kernel32.dll")]
+ public static extern IntPtr GetCurrentThreadId();
+ [DllImport("user32.dll")]
+ public static extern IntPtr SetWindowsHookEx(int idHook, HOOKPROC lpfn, IntPtr hInstance, IntPtr threadId);
+ [DllImport("user32.dll")]
+ public static extern bool UnhookWindowsHookEx(IntPtr hHook);
+ [DllImport("user32.dll")]
+ public static extern IntPtr CallNextHookEx(IntPtr hHook, int nCode, IntPtr wParam, IntPtr lParam);
+ [DllImport("user32.dll")]
+ public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
+ [DllImport("user32.dll")]
+ public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
+
+ public delegate IntPtr HOOKPROC(int nCode, IntPtr wParam, IntPtr lParam);
+
+ public const int GWL_HINSTANCE = (-6);
+ public const int WH_CBT = 5;
+ public const int HCBT_ACTIVATE = 5;
+
+ public const int SWP_NOSIZE = 0x0001;
+ public const int SWP_NOZORDER = 0x0004;
+ public const int SWP_NOACTIVATE = 0x0010;
+
+ public struct RECT
+ {
+ public RECT(int inLeft, int inTop, int inRight, int inBottom)
+ {
+ Left = inLeft;
+ Top = inTop;
+ Right = inRight;
+ Bottom = inBottom;
+ }
+
+ public int Left;
+ public int Top;
+ public int Right;
+ public int Bottom;
+ }
+ }
+}
diff --git a/GetADoc/GetADoc.csproj b/GetADoc/GetADoc.csproj
index d4988d70d525675a12a8cfecdc45c6cc93f7ba34..92536253556abea5bc7dd26c161768d0a384718b 100644
--- a/GetADoc/GetADoc.csproj
+++ b/GetADoc/GetADoc.csproj
@@ -72,6 +72,8 @@
App.xaml
Code
+
+
MainWindow.xaml
Code
diff --git a/GetADoc/MainWindow.xaml b/GetADoc/MainWindow.xaml
index eb5ff6a649a5578beaed24e99b72a023f171b2d8..a2979fe36ad1874c384ae21939dabb0b3bf0415e 100644
--- a/GetADoc/MainWindow.xaml
+++ b/GetADoc/MainWindow.xaml
@@ -5,32 +5,35 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GetADoc"
mc:Ignorable="d"
- Title="GetADoc" Height="250" Width="400">
-
-
-
-
-
-
-
-
-
-
-
-
-
- <フォルダ指定>
-
-
-
-
-
-
-
-
-
-
-
+ Title="GetADoc" Height="260" Width="400" MinWidth="375" MinHeight="240">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <フォルダ指定>
+
+
+
+
+
+
+
+
+
+
+
diff --git a/GetADoc/MainWindow.xaml.cs b/GetADoc/MainWindow.xaml.cs
index 065d2f4b44e5f08fe26aba14fb91755fb1aa7b96..608936a973973cebc76fabf3acb56703f88af439 100644
--- a/GetADoc/MainWindow.xaml.cs
+++ b/GetADoc/MainWindow.xaml.cs
@@ -93,7 +93,7 @@ namespace GetADoc
//ファイルパスが指定されていない or 指定したフォルダが存在しない場合
if (box1.Text == "" || !Directory.Exists(box1.Text))
{
- MessageBox.Show("保存先が存在しません", "Folder not selected", MessageBoxButton.OK, MessageBoxImage.Warning);
+ CustomMsgBox.Show(mainWindow, "保存先が存在しません", "Save destination does not exist", MessageBoxButton.OK, MessageBoxImage.Warning);
Properties.Settings.Default.box1Setting = ""; //記憶していたパスを初期化
Properties.Settings.Default.Save();
return;
@@ -113,12 +113,8 @@ namespace GetADoc
char[] cutComma = { '.' };
if (fileName.IndexOfAny(NgChars) >= 0 || fileName.IndexOfAny(cutComma) >= 0)
{
- string[] charsToRemove = new string[] { @"\", ".", "/", ":", "*", "?", "<", ">", "|" };
- foreach (var allNg in charsToRemove)
- {
- fileName = fileName.Replace(allNg, string.Empty);
- }
- MessageBox.Show("ファイル名に使用できない文字が存在したため\n一部ファイル名を修正しました。" +
+ fileName = PushedButton.NameCalibration(fileName);
+ CustomMsgBox.Show(mainWindow, "ファイル名に使用できない文字が存在したため\n一部ファイル名を修正しました。" +
"\nもう一度作成ボタンをクリックしてください。", "Renamed this file", MessageBoxButton.OK, MessageBoxImage.Warning);
box2.Text = fileName;
return;
@@ -127,81 +123,43 @@ namespace GetADoc
//指定したフォルダに同名の.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("これから生成するファイルと同名のファイルが既に存在します" +
+ MessageBoxResult OverwriteADoc = CustomMsgBox.Show(mainWindow, "これから生成するファイルと同名のファイルが既に存在します" +
"\n既存のファイルを上書きしますか?",
"指定したフォルダに既存のファイルが存在します",
- MessageBoxButton.YesNo);
+ MessageBoxButton.YesNo, MessageBoxImage.None);
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);
- }
+ PushedButton.deleteFolder(filePath, fileName);
}
- else if(OverwriteADoc == MessageBoxResult.No)
+ else if (OverwriteADoc == MessageBoxResult.No)
{
- MessageBox.Show("別のフォルダを指定してください");
+ CustomMsgBox.Show(mainWindow, "別のフォルダを指定してください", "Please select another directory",
+ MessageBoxButton.OK, MessageBoxImage.None);
return;
}
}
//バッチファイルの実行
- 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 = "";
+ var tempPath = System.IO.Path.GetTempPath();
+ bool IconFlag = false;
+ bool SCREENFlag = false;
+ bool SepaFlag = false;
if (checkbox2.IsChecked == true)//Iconsチェックボックスがオンのとき
{
- processStartInfo.Arguments += "/Icons ";
+ IconFlag = true;
}
if (checkbox1.IsChecked == true)//SCREEN Logoチェックボックスがオンのとき
{
- processStartInfo.Arguments += "/SCREEN ";
+ SCREENFlag = true;
}
if (checkbox3.IsChecked == true)//分割ドキュチェックボックスがオンのとき
{
- processStartInfo.Arguments += "/SepaDoc ";
+ SepaFlag = true;
}
- processStartInfo.Arguments += fileName;
-
- //GetADoc.batを実行
- Process process = Process.Start(processStartInfo);
- process.WaitForExit();
- process.Close();
+ PushedButton.runBatch(IconFlag, SCREENFlag, SepaFlag, fileName, tempPath);
//指定されたフォルダに生成物を移動
- File.Move(System.IO.Path.Combine(stCurrentDir, fileName + ".adoc"), filePath + fileName + ".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)
- {
- Directory.Move(System.IO.Path.Combine(stCurrentDir, "icons"), System.IO.Path.Combine(filePath, "icons"));
- }
- if (checkbox3.IsChecked == true)
- {
- File.Move(System.IO.Path.Combine(stCurrentDir, "IncDoc.adoc"), System.IO.Path.Combine(filePath, "IncDoc.adoc"));
- Directory.Move(System.IO.Path.Combine(stCurrentDir, "Sub_First"), System.IO.Path.Combine(filePath, "Sub_First"));
- Directory.Move(System.IO.Path.Combine(stCurrentDir, "Sub_Second"), System.IO.Path.Combine(filePath, "Sub_Second"));
- }
+ PushedButton.MoveProduct(IconFlag, SepaFlag, fileName, tempPath, filePath);
//指定されたファイルパスとチェックボックスを保存
Properties.Settings.Default.box1Setting = box1.Text;
diff --git a/GetADoc/PushedButton.cs b/GetADoc/PushedButton.cs
new file mode 100644
index 0000000000000000000000000000000000000000..f5e89c8077a3baa560d92282a510d83e09304302
--- /dev/null
+++ b/GetADoc/PushedButton.cs
@@ -0,0 +1,100 @@
+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"));
+ }
+ }
+ }
+}
diff --git a/Release/GetADocGUI.exe b/Release/GetADocGUI.exe
index 127a7ed3e1e12ac83792987c38190f8fb973190d..7e848e8276cc9c80349e46ceeb85d8e7f988b57f 100644
Binary files a/Release/GetADocGUI.exe and b/Release/GetADocGUI.exe differ
diff --git a/Release/GetADocGUI.pdb b/Release/GetADocGUI.pdb
index d7bc35423227ec396fed5df8349366a08dab8944..71a47dff710e4a16cc78628d0744635ef5f904fb 100644
Binary files a/Release/GetADocGUI.pdb and b/Release/GetADocGUI.pdb differ