Commit 7a73afe9 authored by tsuji's avatar tsuji

Update RunBatch.cs

・tmpフォルダからフォルダ丸ごとコピーする形に修正
・コードを整理
parent e9f2953b
......@@ -23,17 +23,17 @@
AsciiDocの雛形を作成します
</Label>
<Label x:Name="label1" Content="作成先のフォルダ:" HorizontalAlignment="Left" Margin="10,40,0,0" VerticalAlignment="Top" Height="26" Width="94"/>
<TextBox x:Name="box1" Margin="10,67,8.667,2" AllowDrop="True" Drop="textBox_Drop" DragOver="textBox_PreviewDragOver" Panel.ZIndex="6" Grid.ColumnSpan="3" GotFocus="DeleteCompLabel">
<TextBox x:Name="FolderPathBox" Margin="10,67,8.667,2" AllowDrop="True" Drop="textBox_Drop" DragOver="textBox_PreviewDragOver" Panel.ZIndex="6" Grid.ColumnSpan="3" GotFocus="DeleteCompLabel">
<フォルダ指定>
</TextBox>
<Label x:Name="label2" Content="ドキュメント名:" Grid.Row="1" HorizontalAlignment="Left" Margin="10,11,0,0" VerticalAlignment="Top" Height="26" Width="92"/>
<TextBox x:Name="box2" Margin="10,37,9.667,18" Grid.Row="1" AllowDrop="True" Panel.ZIndex="2" Grid.ColumnSpan="2" GotFocus="DeleteCompLabel"/>
<TextBox x:Name="ADocNameBox" Margin="10,37,9.667,18" Grid.Row="1" AllowDrop="True" Panel.ZIndex="2" Grid.ColumnSpan="2" GotFocus="DeleteCompLabel"/>
<Label x:Name="label3" Content="(.adoc)" HorizontalAlignment="Left" Margin="1.333,32,0,13" Grid.Row="1" Width="45" Grid.Column="2"/>
<Button x:Name="button1" Content="参照" Grid.Column="3" HorizontalAlignment="Left" Margin="12.333,66,0,0" VerticalAlignment="Top" Width="46" Click="button1_Click" Panel.ZIndex="2" Height="20" GotFocus="DeleteCompLabel"/>
<Button x:Name="button2" Content="作成" Grid.Column="3" Margin="6.333,0.667,0,0" Grid.Row="3" Panel.ZIndex="2" Click="button2_Click" Height="31" VerticalAlignment="Top" HorizontalAlignment="Left" Width="62" GotFocus="DeleteCompLabel"/>
<CheckBox x:Name="checkbox1" Content="SCREEN Logo" Grid.Row="3" Margin="7,9.667,2,-3.333" Panel.ZIndex="2" Height="53" VerticalAlignment="Top" GotFocus="DeleteCompLabel"/>
<CheckBox x:Name="checkbox2" Content="カスタムアイコン" Grid.Row="3" Margin="5,9.667,1.667,-16.333" Panel.ZIndex="2" Grid.Column="1" Height="66" VerticalAlignment="Top" GotFocus="DeleteCompLabel"/>
<CheckBox x:Name="checkbox3" Content="分割ドキュメント" Grid.Row="3" Margin="4.333,9.667,8.667,-16.333" Panel.ZIndex="2" Grid.Column="2" Height="66" VerticalAlignment="Top" GotFocus="DeleteCompLabel"/>
<CheckBox x:Name="ScreenCheckbox" Content="SCREEN Logo" Grid.Row="3" Margin="7,9.667,2,-3.333" Panel.ZIndex="2" Height="53" VerticalAlignment="Top" GotFocus="DeleteCompLabel"/>
<CheckBox x:Name="IconCheckbox" Content="カスタムアイコン" Grid.Row="3" Margin="5,9.667,1.667,-16.333" Panel.ZIndex="2" Grid.Column="1" Height="66" VerticalAlignment="Top" GotFocus="DeleteCompLabel"/>
<CheckBox x:Name="SepaDocCheckbox" Content="分割ドキュメント" Grid.Row="3" Margin="4.333,9.667,8.667,-16.333" Panel.ZIndex="2" Grid.Column="2" Height="66" VerticalAlignment="Top" GotFocus="DeleteCompLabel"/>
<TextBox x:Name="allBox" TextWrapping="Wrap" Grid.ColumnSpan="4" Grid.RowSpan="4" Opacity="0" Cursor="Arrow" Margin="0,0,0.333,-0.333"/>
<Label x:Name="CompletedLabel" Content="作成が完了しました!" Grid.Column="2" HorizontalAlignment="Left" Margin="51.333,32,0,0" Grid.Row="1" VerticalAlignment="Top" Grid.ColumnSpan="2" Width="139" Visibility="Hidden" FontWeight="Bold" Foreground="#FFD70B0B"/>
</Grid>
......
......@@ -30,16 +30,16 @@ namespace GetADoc
InitializeComponent();
//デフォルトに前回の設定を表示
box1.Text = Properties.Settings.Default.box1Setting;
checkbox1.IsChecked = Properties.Settings.Default.checkbox1Setting;
checkbox2.IsChecked = Properties.Settings.Default.checkbox2Setting;
checkbox3.IsChecked = Properties.Settings.Default.checkbox3Setting;
FolderPathBox.Text = Properties.Settings.Default.box1Setting;
ScreenCheckbox.IsChecked = Properties.Settings.Default.checkbox1Setting;
IconCheckbox.IsChecked = Properties.Settings.Default.checkbox2Setting;
SepaDocCheckbox.IsChecked = Properties.Settings.Default.checkbox3Setting;
//ドラッグ&ドロップイベントの追加
allBox.AddHandler(TextBox.DragOverEvent, new DragEventHandler(textBox_PreviewDragOver), true);
allBox.AddHandler(TextBox.DropEvent, new DragEventHandler(textBox_Drop), true);
box1.AddHandler(TextBox.DragOverEvent, new DragEventHandler(textBox_PreviewDragOver), true);
box1.AddHandler(TextBox.DropEvent, new DragEventHandler(textBox_Drop), true);
FolderPathBox.AddHandler(TextBox.DragOverEvent, new DragEventHandler(textBox_PreviewDragOver), true);
FolderPathBox.AddHandler(TextBox.DropEvent, new DragEventHandler(textBox_Drop), true);
}
//フォルダ指定のためにファイルをドラッグ
......@@ -68,9 +68,9 @@ namespace GetADoc
dropFiles[0] = dropFiles[0].Substring(0, dropFiles[0].LastIndexOf(@"\"));
}
box1.Text = dropFiles[0];
box1.Focus();
box1.Select(this.box1.Text.Length, 0);
FolderPathBox.Text = dropFiles[0];
FolderPathBox.Focus();
FolderPathBox.Select(this.FolderPathBox.Text.Length, 0);
}
//参照ボタンClickでフォルダ選択のダイアログを表示
......@@ -84,7 +84,7 @@ namespace GetADoc
{
return;
}
box1.Text = selectFile.FileName;
FolderPathBox.Text = selectFile.FileName;
}
//作成ボタンClickでチェックボックスで要求された仕様のADocファイル一式を指定先フォルダに生成
......@@ -94,21 +94,21 @@ namespace GetADoc
bool IconFlag = false;
bool SCREENFlag = false;
bool SepaFlag = false;
if (checkbox2.IsChecked == true)//Iconsチェックボックスがオンのとき
if (IconCheckbox.IsChecked == true)//Iconsチェックボックスがオンのとき
{
IconFlag = true;
}
if (checkbox1.IsChecked == true)//SCREEN Logoチェックボックスがオンのとき
if (ScreenCheckbox.IsChecked == true)//SCREEN Logoチェックボックスがオンのとき
{
SCREENFlag = true;
}
if (checkbox3.IsChecked == true)//分割ドキュチェックボックスがオンのとき
if (SepaDocCheckbox.IsChecked == true)//分割ドキュチェックボックスがオンのとき
{
SepaFlag = true;
}
//ファイルパスが指定されていない or 指定したフォルダが存在しない場合
if (box1.Text == "" || !Directory.Exists(box1.Text))
if (FolderPathBox.Text == "" || !Directory.Exists(FolderPathBox.Text))
{
CustomMsgBox.Show(mainWindow, "保存先が存在しません", "Save destination does not exist", MessageBoxButton.OK, MessageBoxImage.Warning);
Properties.Settings.Default.box1Setting = ""; //記憶していたパスを初期化
......@@ -117,13 +117,13 @@ namespace GetADoc
}
// テキストボックス2からfile名を取得
var fileName = box2.Text;
if (box2.Text == "")
var fileName = ADocNameBox.Text;
if (ADocNameBox.Text == "")
{
fileName = "t";
}
//テキストボック1から保存場所を取得
var filePath = box1.Text + @"\";
var filePath = FolderPathBox.Text + @"\";
// ファイル名に使用不可の文字が含まれている場合の処理
char[] NgChars = System.IO.Path.GetInvalidFileNameChars();
......@@ -133,7 +133,7 @@ namespace GetADoc
fileName = RunBatch.NameCalibration(fileName);
CustomMsgBox.Show(mainWindow, "ファイル名に使用できない文字が存在したため\n一部ファイル名を修正しました。" +
"\nもう一度作成ボタンをクリックしてください。", "Renamed this file", MessageBoxButton.OK, MessageBoxImage.Warning);
box2.Text = fileName;
ADocNameBox.Text = fileName;
return;
}
......@@ -165,10 +165,10 @@ namespace GetADoc
CompletedLabel.Visibility = Visibility.Visible;
//指定されたファイルパスとチェックボックスを保存
Properties.Settings.Default.box1Setting = box1.Text;
Properties.Settings.Default.checkbox1Setting = ((bool)checkbox1.IsChecked);
Properties.Settings.Default.checkbox2Setting = ((bool)checkbox2.IsChecked);
Properties.Settings.Default.checkbox3Setting = ((bool)checkbox3.IsChecked);
Properties.Settings.Default.box1Setting = FolderPathBox.Text;
Properties.Settings.Default.checkbox1Setting = ((bool)ScreenCheckbox.IsChecked);
Properties.Settings.Default.checkbox2Setting = ((bool)IconCheckbox.IsChecked);
Properties.Settings.Default.checkbox3Setting = ((bool)SepaDocCheckbox.IsChecked);
Properties.Settings.Default.Save();
}
......
......@@ -85,44 +85,17 @@ namespace GetADoc
process.Close();
//指定されたフォルダに生成物を移動
RunBatch.MoveProduct(icon, sepa, fileName, tempPath, filePath);
RunBatch.MoveDirectory(tempPath, filePath);
//テンポラリフォルダの消去
TemporaryFolder.DeleteTempFolder(tempPath);
}
//生成物を指定先フォルダへ移動
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"));
MoveDirectory(System.IO.Path.Combine(tempPath, "Images"), System.IO.Path.Combine(filePath, "Images")); // Directory.Move -> local MoveDirectory
if (icon == true)
{
MoveDirectory(System.IO.Path.Combine(tempPath, "icons"), System.IO.Path.Combine(filePath, "icons"));// Directory.Move -> local MoveDirectory
}
if (sepa == true)
{
File.Move(System.IO.Path.Combine(tempPath, "IncDoc.adoc"), System.IO.Path.Combine(filePath, "IncDoc.adoc"));
MoveDirectory(System.IO.Path.Combine(tempPath, "Sub_First"), System.IO.Path.Combine(filePath, "Sub_First"));// Directory.Move -> local MoveDirectory
MoveDirectory(System.IO.Path.Combine(tempPath, "Sub_Second"), System.IO.Path.Combine(filePath, "Sub_Second"));// Directory.Move -> local MoveDirectory
}
}
/// <summary>
/// ディレクトリを移動する。
/// </summary>
/// <param name="sourceDirName">移動するディレクトリ</param>
/// <param name="destDirName">移動先のディレクトリ</param>
/*
ref: https://johobase.com/copy-directory-csharp/ [ディレクトリ(フォルダー)をコピーする [C#]]
最後に追加して、移動元のディレクトリをサブディレクトリ、ファイルを含めて削除
Directory.Delete(sourceDirName, true);
*/
public static void MoveDirectory(string sourceDirName, string destDirName)
{
// コピー先のディレクトリがないかどうか判定する
......@@ -151,7 +124,7 @@ namespace GetADoc
string[] dirs = Directory.GetDirectories(sourceDirName);
foreach (string dir in dirs)
{
// コピー元のディレクトリのサブディレクトリで自メソッド(CopyDirectory)を再帰的に呼び出す
// コピー元のディレクトリのサブディレクトリで自メソッド(MoveDirectory)を再帰的に呼び出す
MoveDirectory(dir, destDirName + Path.GetFileName(dir));
}
Directory.Delete(sourceDirName, true);// 追加: 最後に元のフォルダを削除する
......
No preview for this file type
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment