Commit d84f1dbd authored by tsuji's avatar tsuji

GetADocGUIの以下を修正

・既存の生成物がテンポラリフォルダに存在するとアプリケーションが停止する
・横に広げると「作成ボタンが押せない」
・作成できたか分からない
parent 123afddb
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="TemporaryFolder.cs" />
<Page Include="MainWindow.xaml"> <Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
...@@ -72,7 +73,7 @@ ...@@ -72,7 +73,7 @@
<DependentUpon>App.xaml</DependentUpon> <DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="PushedButton.cs" /> <Compile Include="RunBatch.cs" />
<Compile Include="CustomMsgBox.cs" /> <Compile Include="CustomMsgBox.cs" />
<Compile Include="MainWindow.xaml.cs"> <Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GetADoc" xmlns:local="clr-namespace:GetADoc"
mc:Ignorable="d" mc:Ignorable="d"
Title="GetADoc" Height="260" Width="400" MinWidth="375" MinHeight="240"> Title="GetADoc" Height="260" Width="430" MinWidth="400" MinHeight="245">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="100*"/> <ColumnDefinition Width="104*"/>
<ColumnDefinition Width="99*"/> <ColumnDefinition Width="103*"/>
<ColumnDefinition Width="111*"/> <ColumnDefinition Width="108*"/>
<ColumnDefinition Width="83*"/> <ColumnDefinition Width="79*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="88"/> <RowDefinition Height="88"/>
...@@ -19,21 +19,22 @@ ...@@ -19,21 +19,22 @@
<RowDefinition Height="8*"/> <RowDefinition Height="8*"/>
<RowDefinition Height="51*"/> <RowDefinition Height="51*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label FontWeight="Bold" FontSize="18" Grid.RowSpan="4" Grid.ColumnSpan="4" Margin="0,0,76.583,-3.333"> <Label FontWeight="Bold" FontSize="18" Grid.RowSpan="4" Grid.ColumnSpan="4" Margin="0,0,78.333,-3.333">
AsciiDocの雛形を作成します AsciiDocの雛形を作成します
</Label> </Label>
<Label x:Name="label1" Content="作成先のフォルダ:" HorizontalAlignment="Left" Margin="10,40,0,0" VerticalAlignment="Top" Height="26" Width="94" Grid.ColumnSpan="2"/> <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,9.512,2" AllowDrop="True" Drop="textBox_Drop" DragOver="textBox_PreviewDragOver" Panel.ZIndex="6" Grid.ColumnSpan="3"> <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> </TextBox>
<Label x:Name="label2" Content="ドキュメント名:" Grid.Row="1" HorizontalAlignment="Left" Margin="10,11,0,0" VerticalAlignment="Top" Height="26" Width="92" Grid.ColumnSpan="2"/> <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,10.418,18" Grid.Row="1" AllowDrop="True" Panel.ZIndex="2" Grid.ColumnSpan="2"/> <TextBox x:Name="box2" 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="0.582,32,0,13" Grid.Row="1" Width="45" Grid.Column="2"/> <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="11.488,66,0,0" VerticalAlignment="Top" Width="46" Click="button1_Click" Panel.ZIndex="2" Height="20"/> <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" HorizontalAlignment="Left" Margin="11,5,0,0" Grid.Row="2" Width="62" Panel.ZIndex="2" Click="button2_Click" Grid.RowSpan="2" Height="38" VerticalAlignment="Top"/> <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="12,9.667,76.333,-16.333" Panel.ZIndex="2" Grid.ColumnSpan="4" Height="66" VerticalAlignment="Top"/> <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="10,9.667,15,-16.333" Panel.ZIndex="2" Grid.ColumnSpan="2" Grid.Column="1" Height="66" VerticalAlignment="Top"/> <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="9.333,9.667,64.333,-16.333" Panel.ZIndex="2" Grid.Column="2" Grid.ColumnSpan="2" Height="66" VerticalAlignment="Top"/> <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"/>
<TextBox x:Name="allBox" TextWrapping="Wrap" Grid.ColumnSpan="4" Grid.RowSpan="4" Opacity="0" Cursor="Arrow" Margin="0,0,0.333,-0.333"/> <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> </Grid>
</Window> </Window>
...@@ -90,6 +90,23 @@ namespace GetADoc ...@@ -90,6 +90,23 @@ namespace GetADoc
//作成ボタンClickでチェックボックスで要求された仕様のADocファイル一式を指定先フォルダに生成 //作成ボタンClickでチェックボックスで要求された仕様のADocファイル一式を指定先フォルダに生成
private void button2_Click(object sender, RoutedEventArgs e) private void button2_Click(object sender, RoutedEventArgs e)
{ {
bool IconFlag = false;
bool SCREENFlag = false;
bool SepaFlag = false;
if (checkbox2.IsChecked == true)//Iconsチェックボックスがオンのとき
{
IconFlag = true;
}
if (checkbox1.IsChecked == true)//SCREEN Logoチェックボックスがオンのとき
{
SCREENFlag = true;
}
if (checkbox3.IsChecked == true)//分割ドキュチェックボックスがオンのとき
{
SepaFlag = true;
}
//ファイルパスが指定されていない or 指定したフォルダが存在しない場合 //ファイルパスが指定されていない or 指定したフォルダが存在しない場合
if (box1.Text == "" || !Directory.Exists(box1.Text)) if (box1.Text == "" || !Directory.Exists(box1.Text))
{ {
...@@ -113,7 +130,7 @@ namespace GetADoc ...@@ -113,7 +130,7 @@ namespace GetADoc
char[] cutComma = { '.' }; char[] cutComma = { '.' };
if (fileName.IndexOfAny(NgChars) >= 0 || fileName.IndexOfAny(cutComma) >= 0) if (fileName.IndexOfAny(NgChars) >= 0 || fileName.IndexOfAny(cutComma) >= 0)
{ {
fileName = PushedButton.NameCalibration(fileName); fileName = RunBatch.NameCalibration(fileName);
CustomMsgBox.Show(mainWindow, "ファイル名に使用できない文字が存在したため\n一部ファイル名を修正しました。" + CustomMsgBox.Show(mainWindow, "ファイル名に使用できない文字が存在したため\n一部ファイル名を修正しました。" +
"\nもう一度作成ボタンをクリックしてください。", "Renamed this file", MessageBoxButton.OK, MessageBoxImage.Warning); "\nもう一度作成ボタンをクリックしてください。", "Renamed this file", MessageBoxButton.OK, MessageBoxImage.Warning);
box2.Text = fileName; box2.Text = fileName;
...@@ -121,7 +138,9 @@ namespace GetADoc ...@@ -121,7 +138,9 @@ namespace GetADoc
} }
//指定したフォルダに同名の.adocや既存の付属ファイル(config.adocなど)がある場合の処理 //指定したフォルダに同名の.adocや既存の付属ファイル(config.adocなど)がある場合の処理
if (File.Exists(System.IO.Path.Combine(filePath, fileName + ".adoc")) || File.Exists(System.IO.Path.Combine(filePath, "config.adoc"))) if (File.Exists(System.IO.Path.Combine(filePath, fileName + ".adoc")) || File.Exists(System.IO.Path.Combine(filePath, "config.adoc"))
|| Directory.Exists(System.IO.Path.Combine(filePath, "Images")) || Directory.Exists(System.IO.Path.Combine(filePath, "icons"))
|| Directory.Exists(System.IO.Path.Combine(filePath, "Sub_First")) || Directory.Exists(System.IO.Path.Combine(filePath, "Sub_Second")))
{ {
MessageBoxResult OverwriteADoc = CustomMsgBox.Show(mainWindow, "これから生成するファイルと同名のファイルが既に存在します" + MessageBoxResult OverwriteADoc = CustomMsgBox.Show(mainWindow, "これから生成するファイルと同名のファイルが既に存在します" +
"\n既存のファイルを上書きしますか?", "\n既存のファイルを上書きしますか?",
...@@ -129,7 +148,7 @@ namespace GetADoc ...@@ -129,7 +148,7 @@ namespace GetADoc
MessageBoxButton.YesNo, MessageBoxImage.None); MessageBoxButton.YesNo, MessageBoxImage.None);
if (OverwriteADoc == MessageBoxResult.Yes) if (OverwriteADoc == MessageBoxResult.Yes)
{ {
PushedButton.deleteFolder(filePath, fileName); RunBatch.deleteFolder(filePath, fileName, IconFlag, SepaFlag);
} }
else if (OverwriteADoc == MessageBoxResult.No) else if (OverwriteADoc == MessageBoxResult.No)
{ {
...@@ -140,26 +159,10 @@ namespace GetADoc ...@@ -140,26 +159,10 @@ namespace GetADoc
} }
//バッチファイルの実行 //バッチファイルの実行
var tempPath = System.IO.Path.GetTempPath(); RunBatch.runBatch(IconFlag, SCREENFlag, SepaFlag, fileName, filePath);
bool IconFlag = false;
bool SCREENFlag = false;
bool SepaFlag = false;
if (checkbox2.IsChecked == true)//Iconsチェックボックスがオンのとき
{
IconFlag = true;
}
if (checkbox1.IsChecked == true)//SCREEN Logoチェックボックスがオンのとき
{
SCREENFlag = true;
}
if (checkbox3.IsChecked == true)//分割ドキュチェックボックスがオンのとき
{
SepaFlag = true;
}
PushedButton.runBatch(IconFlag, SCREENFlag, SepaFlag, fileName, tempPath);
//指定されたフォルダに生成物を移動 //処理の完了を知らせるラベルを表示
PushedButton.MoveProduct(IconFlag, SepaFlag, fileName, tempPath, filePath); CompletedLabel.Visibility = Visibility.Visible;
//指定されたファイルパスとチェックボックスを保存 //指定されたファイルパスとチェックボックスを保存
Properties.Settings.Default.box1Setting = box1.Text; Properties.Settings.Default.box1Setting = box1.Text;
...@@ -168,6 +171,12 @@ namespace GetADoc ...@@ -168,6 +171,12 @@ namespace GetADoc
Properties.Settings.Default.checkbox3Setting = ((bool)checkbox3.IsChecked); Properties.Settings.Default.checkbox3Setting = ((bool)checkbox3.IsChecked);
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
} }
//コントロール(テキストボックスなど)がフォーカスされたら処理完了のラベルを非表示にする
private void DeleteCompLabel(object sender, RoutedEventArgs e)
{
CompletedLabel.Visibility = Visibility.Hidden;
}
} }
} }
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 RunBatch
{
//ファイル名に使用不可の文字が含まれている場合の処理
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, bool icon, bool sepa)
{
File.Delete(filePath + fileName + ".adoc");
File.Delete(System.IO.Path.Combine(filePath, "config.adoc"));
if(sepa == true)
{
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")) && icon == true)
{
Directory.Delete(System.IO.Path.Combine(filePath, "icons"), true);
}
if (Directory.Exists(System.IO.Path.Combine(filePath, "Sub_First")) && sepa == true)
{
Directory.Delete(System.IO.Path.Combine(filePath, "Sub_First"), true);
}
if (Directory.Exists(System.IO.Path.Combine(filePath, "Sub_Second")) && sepa == true)
{
Directory.Delete(System.IO.Path.Combine(filePath, "Sub_Second"), true);
}
}
//バッチファイルの実行
public static void runBatch(bool icon, bool screen, bool sepa, string fileName, string filePath)
{
//テンポラリフォルダの作成
var tempPath = TemporaryFolder.MakeTempFolder();
//コンソール呼び出し
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();
//指定されたフォルダに生成物を移動
RunBatch.MoveProduct(icon, sepa, fileName, 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"));
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"));
}
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GetADoc
{
//テンポラリフォルダの作成/削除
class TemporaryFolder
{
//テンポラリフォルダの作成
public static string MakeTempFolder()
{
var TempFile = Path.GetTempFileName();
if (File.Exists(TempFile))
{
File.Delete(TempFile);
Directory.CreateDirectory(TempFile);
}
return TempFile;
}
//テンポラリフォルダの削除
public static void DeleteTempFolder(string TempFolderPath)
{
if (Directory.Exists(TempFolderPath))
{
Directory.Delete(TempFolderPath);
}
}
}
}
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