diff --git a/root/gui/Code/CSRender/CSRender/CompareTIFF.cs b/root/gui/Code/CSRender/CSRender/CompareTIFF.cs
index c3de7b4873db915f817e6665c33318c04d567c2d..f8c1222a92c2921b00fd8e03d9397a7a6bdfc4a7 100644
--- a/root/gui/Code/CSRender/CSRender/CompareTIFF.cs
+++ b/root/gui/Code/CSRender/CSRender/CompareTIFF.cs
@@ -146,7 +146,8 @@ namespace CSRender
//指定先にレポートを移動
internal static void moveReport(string resultPath, string workPath)
{
- string reportPath = System.IO.Path.Combine(resultPath, "report", "Log");
+ //string reportPath = System.IO.Path.Combine(resultPath, "report", "Log");
+ string reportPath = System.IO.Path.Combine(resultPath, "Log");
if (!Directory.Exists(reportPath))//指定先にreportフォルダがあるか
{
Directory.CreateDirectory(reportPath);//なければ新規でreportフォルダを作成
diff --git a/root/gui/Code/CSRender/CSRender/FilePathSelect.cs b/root/gui/Code/CSRender/CSRender/FilePathSelect.cs
index a7ed9ef4f90204d00b42dbc5ef2224ba1cefe49c..8f057697b812917f6fba40d797f3da9db8dca5a6 100644
--- a/root/gui/Code/CSRender/CSRender/FilePathSelect.cs
+++ b/root/gui/Code/CSRender/CSRender/FilePathSelect.cs
@@ -338,5 +338,25 @@ namespace CSRender
Directory.CreateDirectory(inDirPath);//同名のディレクトリを作成
}
+ //キャンセルが実行されたときに、途中で生成したファイル群を削除
+ private void DelDirCancel(string inWorkPath)
+ {
+ try
+ {
+ if (Directory.Exists(System.IO.Path.Combine(inWorkPath, "OUT_DIFF")))
+ {
+ Directory.Delete(System.IO.Path.Combine(inWorkPath, "OUT_DIFF"), true);//OUT_DIFFを削除
+ }
+ if (Directory.Exists(System.IO.Path.Combine(inWorkPath, "work")))
+ {
+ Directory.Delete(System.IO.Path.Combine(inWorkPath, "work"), true);//作業(work)ディレクトリを削除
+ }
+ }
+ catch(Exception ex)
+ {
+ return;
+ }
+
+ }
}
}
diff --git a/root/gui/Code/CSRender/CSRender/MainWindow.xaml b/root/gui/Code/CSRender/CSRender/MainWindow.xaml
index bd9ae722cff5ac64d5fd4d97ff57b693209424ba..c4707a48d9dadb3e04a4bfc6e2460328f04e9da2 100644
--- a/root/gui/Code/CSRender/CSRender/MainWindow.xaml
+++ b/root/gui/Code/CSRender/CSRender/MainWindow.xaml
@@ -62,9 +62,9 @@
-
+
-
+
@@ -78,9 +78,10 @@
TextWrapping="Wrap" Text="1,2,4-6" VerticalAlignment="Top" FontSize="14" IsEnabled="{Binding PageRange_SelectionChanged}" Grid.ColumnSpan="3"
InputMethod.IsInputMethodSuspended="True" PreviewKeyDown="PageBox_PreviewKeyDown" PreviewTextInput="PageBox_PreviewTextInput" LostFocus="PageBox_LostFocus" CommandManager.PreviewExecuted="PageBox_PreviewExecuted" BorderBrush="#FF595959"/>
-
-
-
+
+
+
+
diff --git a/root/gui/Code/CSRender/CSRender/MainWindow.xaml.cs b/root/gui/Code/CSRender/CSRender/MainWindow.xaml.cs
index 883f0a9b1ad5bd6d3dbfa50c1d053496ca797eb1..59623d82bdcd9b02a41478c3c61d411d360bdd7c 100644
--- a/root/gui/Code/CSRender/CSRender/MainWindow.xaml.cs
+++ b/root/gui/Code/CSRender/CSRender/MainWindow.xaml.cs
@@ -18,6 +18,7 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Windows.Threading;
+using System.Threading;
namespace CSRender
{
@@ -80,6 +81,25 @@ namespace CSRender
private void CloseButton_Click(object sender, RoutedEventArgs e) =>
Close();
+ private CancellationTokenSource CancelToken = null;
+ //private CancellationToken Canceller;
+
+ //Cancelボタン実行
+ private void CancelButton_Click(object sender, RoutedEventArgs e)
+ {
+ isCanceled = true;
+ ResultConsole.Text += " 処理を中断します\r\n";
+ if (CancelToken == null) { return; }
+ else { CancelToken.Cancel(); }
+ //if (CancelToken?.IsCancellationRequested == false)
+ //{ CancelToken.Cancel(); }
+ }
+
+ ///
+ /// キャンセルフラグ
+ ///
+ private bool isCanceled = false;
+
///
/// 比較ボタンを実行する。
///
@@ -107,6 +127,17 @@ namespace CSRender
{
killButton();//メニューを非活性化
+ isCanceled = false;//Cancelフラグを初期化
+ CancelToken = new CancellationTokenSource();
+ var Canceller = CancelToken.Token;
+
+ //前回のOUT_DIFFフォルダを削除
+ string OldOutDiff = System.IO.Path.Combine(Properties.Settings.Default.workSpaceSetting, "OUT_DIFF");
+ if (Directory.Exists(OldOutDiff))
+ {
+ Directory.Delete(OldOutDiff, true);
+ }
+
//各種パスの指定先の取得
string workBoxText = workBox.Text;
string reportBoxText = reportBox.Text;
@@ -186,7 +217,7 @@ namespace CSRender
//前回のログが内部に残っていれば削除(エラー防止)
CompareTIFF.deleteOldLog(System.IO.Path.Combine(workDir, "report"));
- string workLogPath = System.IO.Path.Combine(workBoxText, "report");//reportフォルダのパス
+ string workLogPath = System.IO.Path.Combine(reportBoxText, "Log");//reportフォルダのパス
checkDirPath(workLogPath);//なければ作成
string outDiffPath = System.IO.Path.Combine(workBoxText, "OUT_DIFF");//DIFF画像の出力先パス
checkDirPath(outDiffPath);//なければ作成
@@ -195,6 +226,10 @@ namespace CSRender
{
//検版レポートの入力チェック
reportFlag = checkReportPath();
+ if (reportBoxText == "")
+ {
+ reportBoxText = reportBox.Text;
+ }
}
catch (Exception ex)
{
@@ -213,202 +248,348 @@ namespace CSRender
selectedPage = pageBox.Text;
}
- //TIFF画像の生成
- ResultConsole.Text += "< TIFF変換開始 >\r\n";
- ResultConsole.Text += " 対象ファイルをTIFF画像に変換中\r\n";
- ResultConsole.ScrollToEnd();
- DoEvents();
-
- //対象フォルダ
- string targetTIFFPath = System.IO.Path.Combine(workBoxText, "work", "targetTIFF");
- DeleteOldDir(targetTIFFPath); //指定先に古いTIFF用フォルダがあれば削除し、新たに作成(前回作業時の生成物との混同防止)
-
- //CSRenderの実行
+ //実処理スタート
try
{
- await Task.Run(() =>
+ //TIFF画像の生成
+ ResultConsole.Text += "< TIFF変換開始 >\r\n";
+ ResultConsole.Text += " 対象ファイルをTIFF画像に変換中\r\n";
+ ResultConsole.ScrollToEnd();
+ DoEvents();
+
+ //対象フォルダ
+ string targetTIFFPath = System.IO.Path.Combine(workBoxText, "work", "targetTIFF");
+ DeleteOldDir(targetTIFFPath); //指定先に古いTIFF用フォルダがあれば削除し、新たに作成(前回作業時の生成物との混同防止)
+
+ if (isCanceled)
{
- string targetTIFFResult =
- OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, targetBoxText, targetTIFFPath);
- });
- }
- catch (Exception ex)
- {
- string WorkCategory = "対象PDFのTIFF画像生成";
- ExceptionMessage(ex, workLogPath, WorkCategory);
- }
+ // キャンセルされたら終了
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DoEvents();
+ DelDirCancel(workBoxText);
+ reviveButton();
+ return;
+ }
- ResultConsole.Text += " リファレンスファイルをTIFF画像に変換中\r\n";
- ResultConsole.ScrollToEnd();
- DoEvents();
+ //CSRenderの実行
+ try
+ {
+ await Task.Run(() =>
+ //await Task.Factory.StartNew(() =>
+ {
+ //string targetTIFFResult =
+ OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, targetBoxText, targetTIFFPath, Canceller, isCanceled);
- //リファレンスフォルダ
- string referenceTIFFPath = System.IO.Path.Combine(workBoxText, "work", "referenceTIFF");
- DeleteOldDir(referenceTIFFPath); //指定先に古いTIFF用フォルダがあれば削除し、新たに作成(前回作業時の生成物との混同防止)
-
- //CSRenderの実行
- try
- {
- await Task.Run(() =>
+ }, Canceller);
+
+ //string targetTIFFResult = await OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, targetBoxText, targetTIFFPath, Canceller, isCanceled);
+ }
+ catch (OperationCanceledException)
{
- string referenceTIFFResult =
- OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, referenceBoxText, referenceTIFFPath);
- });
- }
- catch (Exception ex)
- {
- string WorkCategory = "リファレンスPDFのTIFF画像生成";
- ExceptionMessage(ex, workLogPath, WorkCategory);
- }
+ CancelToken.Dispose();
+ CancelToken = null;
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DelDirCancel(workBoxText);
+ reviveButton();
+ DoEvents();
+ return;
+ }
+ catch (Exception ex)
+ {
+ string WorkCategory = "対象PDFのTIFF画像生成";
+ ExceptionMessage(ex, workLogPath, WorkCategory);
+ }
+
+ if (!isCanceled)
+ {
+ ResultConsole.Text += " リファレンスファイルをTIFF画像に変換中\r\n";
+ ResultConsole.ScrollToEnd();
+ }
- ripTime.Stop();//RIP時間の計測終了
- TimeSpan timeResult = ripTime.Elapsed;
- var allRipTime = $"{timeResult}".Substring(0,8);
+ //リファレンスフォルダ
+ string referenceTIFFPath = System.IO.Path.Combine(workBoxText, "work", "referenceTIFF");
+ DeleteOldDir(referenceTIFFPath); //指定先に古いTIFF用フォルダがあれば削除し、新たに作成(前回作業時の生成物との混同防止)
- ResultConsole.Text += " [RIP処理時間 " + allRipTime + "]\r\n";
- ResultConsole.Text += "< TIFF変換完了 >\r\n";
- ResultConsole.ScrollToEnd();
- DoEvents();
-
- try
- {
- //レポートへの出力内容を編集
- //editReport(allRipTime, workBoxText);
- reportContentsInfo = CompareTIFF.getReportInfo(allRipTime, workBoxText,
- targetBoxText, referenceBoxText, ResolutionBox.Text, PageRange.Text, pageBox.Text);
- }
- catch (Exception ex)
- {
- string WorkCategory = "検版レポートの編集";
- ExceptionMessage(ex, workLogPath, WorkCategory);
- }
-
- //この時点での出力文字列を取得
- string tiffString = ResultConsole.Text;
- try
- {
- // 日付取得
- DateTime NowTime = DateTime.Now;
- //検版対象ファイル名の取得
- string[] inspectionTargets = CompareTIFF.GetTargetList(targetBoxText, referenceBoxText);
- allPDFNum = CompareTIFF.getNumOfTiff(inspectionTargets, targetTIFFPath);//検版する画像ファイルの総数
-
- //出力メニューの進捗表示を初期化
- resetProgressText(allPDFNum);
-
- // 並列処理オプションの設定
- ParallelOptions parallelOptions = new ParallelOptions();
- parallelOptions.MaxDegreeOfParallelism = 4;// 並行数(プロセス数)
- var logicalProcessNum = Environment.ProcessorCount;//PCの論理CPUの数
- if (logicalProcessNum >= 10)
+ if (isCanceled)
+ {
+ // キャンセルされたら終了
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DelDirCancel(workBoxText);
+ DoEvents();
+ reviveButton();
+ return;
+ }
+
+ //CSRenderの実行
+ try
+ {
+ await Task.Run(() =>
+ {
+ //string referenceTIFFResult =
+ OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, referenceBoxText, referenceTIFFPath, Canceller, isCanceled);
+ }, Canceller);
+
+ //string referenceTIFFResult = await OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, referenceBoxText, referenceTIFFPath, Canceller, isCanceled);
+ }
+ catch (OperationCanceledException)
{
- parallelOptions.MaxDegreeOfParallelism = logicalProcessNum - 4;
+ CancelToken.Dispose();
+ CancelToken = null;
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DelDirCancel(workBoxText);
+ reviveButton();
+ DoEvents();
+ return;
+ }
+ catch (Exception ex)
+ {
+ string WorkCategory = "リファレンスPDFのTIFF画像生成";
+ ExceptionMessage(ex, workLogPath, WorkCategory);
+ }
+
+ if (isCanceled)
+ {
+ // キャンセルされたら終了
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DelDirCancel(workBoxText);
+ reviveButton();
+ return;
+ }
+
+ ripTime.Stop();//RIP時間の計測終了
+ TimeSpan timeResult = ripTime.Elapsed;
+ var allRipTime = $"{timeResult}".Substring(0, 8);
+
+ ResultConsole.Text += " [RIP処理時間 " + allRipTime + "]\r\n";
+ ResultConsole.Text += "< TIFF変換完了 >\r\n";
+ ResultConsole.ScrollToEnd();
+ DoEvents();
+
+ if (isCanceled)
+ {
+ // キャンセルされたら終了
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DelDirCancel(workBoxText);
+ reviveButton();
+ return;
}
- //並列処理内で固定の引数を事前に処理
- string verifyArgs = CompareTIFF.makeFixityArg(targetTIFFPath, referenceTIFFPath,
- shiftPixel, colorMargin, removePoint, shadingOff, appDirectory);
+ try
+ {
+ //レポートへの出力内容を編集
+ //editReport(allRipTime, workBoxText);
+ reportContentsInfo = CompareTIFF.getReportInfo(allRipTime, workBoxText,
+ targetBoxText, referenceBoxText, ResolutionBox.Text, PageRange.Text, pageBox.Text);
+ }
+ catch (Exception ex)
+ {
+ string WorkCategory = "検版レポートの編集";
+ ExceptionMessage(ex, workLogPath, WorkCategory);
+ }
- await Task.Factory.StartNew(() => {
- Parallel.ForEach(inspectionTargets, parallelOptions, targetPDFName =>
+ //この時点での出力文字列を取得
+ string tiffString = ResultConsole.Text;
+ try
+ {
+ // 日付取得
+ DateTime NowTime = DateTime.Now;
+ //検版対象ファイル名の取得
+ string[] inspectionTargets = CompareTIFF.GetTargetList(targetBoxText, referenceBoxText);
+ allPDFNum = CompareTIFF.getNumOfTiff(inspectionTargets, targetTIFFPath);//検版する画像ファイルの総数
+
+ //出力メニューの進捗表示を初期化
+ resetProgressText(allPDFNum);
+
+ // 並列処理オプションの設定
+ ParallelOptions parallelOptions = new ParallelOptions();
+ parallelOptions.MaxDegreeOfParallelism = 4;// 並行数(プロセス数)
+ //parallelOptions.CancellationToken = CancelToken.Token;
+ var logicalProcessNum = Environment.ProcessorCount;//PCの論理CPUの数
+ if (logicalProcessNum >= 10)
{
- //PureVerifyの実行
- int[] NGTiffNum = CompareTIFF.runPureVerify(targetTIFFPath, referenceTIFFPath,
- shiftPixel, colorMargin, removePoint, shadingOff, reportFlag, reportBoxText,
- outDiffPath, targetPDFName, NowTime, reportContentsInfo, appDirectory, exePath, verifyArgs);
- ResultConsole.Dispatcher.Invoke(new Action(() =>
+ parallelOptions.MaxDegreeOfParallelism = logicalProcessNum - 4;
+ }
+
+ //並列処理内で固定の引数を事前に処理
+ string verifyArgs = CompareTIFF.makeFixityArg(targetTIFFPath, referenceTIFFPath,
+ shiftPixel, colorMargin, removePoint, shadingOff, appDirectory);
+
+ await Task.Factory.StartNew(() => {
+
+ if (isCanceled)
{
- outProgressToUI(tiffString, NGTiffNum, allPDFNum);
- }));
+ // キャンセルされたら終了
+ ResultConsole.Text += " 処理を中断します\r\n";
+ CancelToken.Cancel();
+ DoEvents();
+ reviveButton();
+ return;
+ }
+ Parallel.ForEach(inspectionTargets, parallelOptions, targetPDFName =>
+ {
+ //キャンセルフラグONなら終了
+ if (isCanceled)
+ {
+ return;
+ }
+ //PureVerifyの実行
+ int[] NGTiffNum = CompareTIFF.runPureVerify(targetTIFFPath, referenceTIFFPath,
+ shiftPixel, colorMargin, removePoint, shadingOff, reportFlag, reportBoxText,
+ outDiffPath, targetPDFName, NowTime, reportContentsInfo, appDirectory, exePath, verifyArgs);
+ //キャンセルフラグONなら終了
+ if (isCanceled)
+ {
+ return;
+ }
+ ResultConsole.Dispatcher.Invoke(new Action(() =>
+ {
+ outProgressToUI(tiffString, NGTiffNum, allPDFNum);
+ }));
+
+ });
});
- });
-
- }
- catch (Exception ex)
- {
- string WorkCategory = "検版処理";
- ExceptionMessage(ex, workLogPath, WorkCategory);
- }
- try
- {
- //レポートを出力
- //outputLog(System.IO.Path.Combine(workDir, "report"));
- NGPDFNum = CompareTIFF.getNGNum(System.IO.Path.Combine(workDir, "report"));
- ResultConsole.Text = tiffString;
- outResultToUI(allPDFNum, NGPDFNum, referenceTIFFPath, targetTIFFPath);
- }
- catch (Exception ex)
- {
- string WorkCategory = "検版ログの出力";
- ExceptionMessage(ex, workLogPath, WorkCategory);
- }
+ }
+ catch (OperationCanceledException)
+ {
+ CancelToken.Dispose();
+ CancelToken = null;
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DelDirCancel(workBoxText);
+ reviveButton();
+ DoEvents();
+ return;
+ }
+ catch (Exception ex)
+ {
+ string WorkCategory = "検版処理";
+ ExceptionMessage(ex, workLogPath, WorkCategory);
+ }
- string PDFName = "";
- try
- {
- //レポート名を取得
- if (reportBox.Text != ""){ PDFName = reportBoxText; }
- else { PDFName = CompareTIFF.getReportName(workDir); }
- }
- catch (Exception ex)
- {
- string WorkCategory = "レポート名の取得";
- ExceptionMessage(ex, workLogPath, WorkCategory);
- }
+ try
+ {
+ //レポートを出力
+ //outputLog(System.IO.Path.Combine(workDir, "report"));
+ NGPDFNum = CompareTIFF.getNGNum(System.IO.Path.Combine(workDir, "report"));
- try
- {
- //指定先にレポートを移動
- CompareTIFF.moveReport(workBoxText, workDir);
- }
- catch (Exception ex)
- {
- string WorkCategory = "ログファイルの移動";
- ExceptionMessage(ex, workLogPath, WorkCategory);
- }
+ if (isCanceled)
+ {
+ // キャンセルされたら終了
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DelDirCancel(workBoxText);
+ DoEvents();
+ reviveButton();
+ return;
+ }
- //レポートのパスを表示
- ResultConsole.Text += " 検版レポートのパス:";
- ResultConsole.Text += System.IO.Path.Combine(workBoxText, "report", PDFName);
- ResultConsole.Text += "\r\n";
- if(reportBox.Text == "")
- {
- reportBox.Text = System.IO.Path.Combine(workBoxText, "report", PDFName);
- }
+ //UIの更新
+ ResultConsole.Text = tiffString;
+ outResultToUI(allPDFNum, NGPDFNum, referenceTIFFPath, targetTIFFPath);
+ }
+ catch (Exception ex)
+ {
+ string WorkCategory = "検版ログの出力";
+ ExceptionMessage(ex, workLogPath, WorkCategory);
+ }
- //リファレンスファイルを発見できず検版回数0の場合、メッセージを出力して通知
- if (allPDFNum == 0)
- {
- CustomMsgBox.Show(mainWindow, "指定先のリファレンスフォルダから、対象フォルダ内のファイルと対応するファイルを発見できませんでした。",
- "検版対象を発見できませんでした。", MessageBoxButton.OK, MessageBoxImage.Warning);
- }
+ string PDFName = "";
+ try
+ {
- //生成したレポートinf.txtを全削除
- CompareTIFF.deleteReportTexts();
+ if (isCanceled)
+ {
+ // キャンセルされたら終了
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DelDirCancel(workBoxText);
+ reviveButton();
+ return;
+ }
- //生成したダミーファイルを削除
- if (dummyFlag)
- {
- CompareTIFF.deleteDummyFile(System.IO.Path.Combine(workBoxText, "Dummy", "Target"), dummyFileName);
- CompareTIFF.deleteDummyFile(System.IO.Path.Combine(workBoxText, "Dummy", "Reference"), dummyFileName);
- }
+ //レポート名を取得
+ if (reportBox.Text != "") { PDFName = reportBoxText; }
+ else { PDFName = CompareTIFF.getReportName(workDir); }
+ }
+ catch (Exception ex)
+ {
+ string WorkCategory = "レポート名の取得";
+ ExceptionMessage(ex, workLogPath, WorkCategory);
+ }
- //パラメータを次回初期値用に保存
- Properties.Settings.Default.resolutionSetting = ResolutionBox.Value;
- Properties.Settings.Default.formatSetting = FileSelect.Text;
- Properties.Settings.Default.shiftPixelSetting = PositionBox.Value;
- Properties.Settings.Default.colorMarginSetting = GradationBox.Value;
- Properties.Settings.Default.removePointSetting = SmallDiffBox.Value;
- Properties.Settings.Default.shadingOffSetting = VisualBox.Value;
- Properties.Settings.Default.workSpaceSetting = workBoxText;
- Properties.Settings.Default.targetSetting = targetBox.Text;
- Properties.Settings.Default.referenceSetting = referenceBox.Text;
- Properties.Settings.Default.reportPathSetting = reportBoxText;
- Properties.Settings.Default.Save();
+ try
+ {
+
+ if (isCanceled)
+ {
+ // キャンセルされたら終了
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DelDirCancel(workBoxText);
+ DoEvents();
+ reviveButton();
+ return;
+ }
+
+ //指定先にレポートを移動
+ CompareTIFF.moveReport(reportBoxText, workDir);
+ }
+ catch (Exception ex)
+ {
+ string WorkCategory = "ログファイルの移動";
+ ExceptionMessage(ex, workLogPath, WorkCategory);
+ }
+
+ //レポートのパスを表示
+ ResultConsole.Text += " 検版レポートのパス:";
+ ResultConsole.Text += System.IO.Path.Combine(workBoxText, PDFName);
+ ResultConsole.Text += "\r\n";
+ if (reportBox.Text == "")
+ {
+ reportBox.Text = System.IO.Path.Combine(workBoxText, "report", PDFName);
+ }
- reviveButton();
+ //リファレンスファイルを発見できず検版回数0の場合、メッセージを出力して通知
+ if (allPDFNum == 0)
+ {
+ CustomMsgBox.Show(mainWindow, "指定先のリファレンスフォルダから、対象フォルダ内のファイルと対応するファイルを発見できませんでした。",
+ "検版対象を発見できませんでした。", MessageBoxButton.OK, MessageBoxImage.Warning);
+ }
+
+ //生成したレポートinf.txtを全削除
+ CompareTIFF.deleteReportTexts();
+
+ //生成したダミーファイルを削除
+ if (dummyFlag)
+ {
+ CompareTIFF.deleteDummyFile(System.IO.Path.Combine(workBoxText, "Dummy", "Target"), dummyFileName);
+ CompareTIFF.deleteDummyFile(System.IO.Path.Combine(workBoxText, "Dummy", "Reference"), dummyFileName);
+ }
+
+ //パラメータを次回初期値用に保存
+ Properties.Settings.Default.resolutionSetting = ResolutionBox.Value;
+ Properties.Settings.Default.formatSetting = FileSelect.Text;
+ Properties.Settings.Default.shiftPixelSetting = PositionBox.Value;
+ Properties.Settings.Default.colorMarginSetting = GradationBox.Value;
+ Properties.Settings.Default.removePointSetting = SmallDiffBox.Value;
+ Properties.Settings.Default.shadingOffSetting = VisualBox.Value;
+ Properties.Settings.Default.workSpaceSetting = workBoxText;
+ Properties.Settings.Default.targetSetting = targetBox.Text;
+ Properties.Settings.Default.referenceSetting = referenceBox.Text;
+ Properties.Settings.Default.reportPathSetting = reportBoxText;
+ Properties.Settings.Default.Save();
+
+ reviveButton();
+ }
+ catch (OperationCanceledException)
+ {
+ // キャンセルされたら終了
+ ResultConsole.Text += " 処理が中断されました\r\n";
+ DelDirCancel(workBoxText);
+ CancelToken.Dispose();
+ CancelToken = null;
+ DoEvents();
+ reviveButton();
+ return;
+ }
}
///
@@ -591,6 +772,16 @@ namespace CSRender
ResultConsole.ScrollToEnd();
}
+ ///
+ /// キャンセル実行時に生成済みのファイルを削除
+ ///
+ private void canceledFile(string inWorkPath, string inReportPath)
+ {
+
+ }
+
+
+
///
/// TIFF画像化を実行する
///
@@ -598,8 +789,13 @@ namespace CSRender
/// 入力されたページ数
/// CSRenderの処理出力文
///
- private void TIFFButtonClick(object sender, RoutedEventArgs e)
+ private async void TIFFButtonClick(object sender, RoutedEventArgs e)
{
+ isCanceled = false;//Cancelフラグを初期化
+ //キャンセルトークン生成
+ //CancellationTokenSource CancelToken = new CancellationTokenSource();
+ var Canceller = CancelToken.Token;
+
//出力メニューにメッセージを出力
ResultConsole.Text += "<変換開始>\r\n";
ResultConsole.Text += " PDFを" + FileSelect.Text + "に変換します\r\n";
@@ -648,10 +844,10 @@ namespace CSRender
}
//CSRenderの実行
- string TIFFresult =
- OutputTIFF.runCSRender(ResolutionBox.Text, FileSelect.Text, pageFlag, selectedPage, targetBox.Text, workBox.Text);
+ //string TIFFresult =
+ OutputTIFF.runCSRender(ResolutionBox.Text, FileSelect.Text, pageFlag, selectedPage, targetBox.Text, workBox.Text, Canceller, isCanceled);
- ResultConsole.Text += TIFFresult;
+ //ResultConsole.Text += TIFFresult;
ResultConsole.Text += "\r\n<変換終了>\r\n";
ResultConsole.ScrollToEnd();
@@ -742,5 +938,6 @@ namespace CSRender
VisualBox.Enabled = true;
pageBox.IsEnabled = true;
}
+
}
}
diff --git a/root/gui/Code/CSRender/CSRender/OurputTIFF.cs b/root/gui/Code/CSRender/CSRender/OurputTIFF.cs
index 048f2c116b530ef74a456e27fe32b1b1de35783d..197910b66455e692a25ef4ac94038f969f1e3874 100644
--- a/root/gui/Code/CSRender/CSRender/OurputTIFF.cs
+++ b/root/gui/Code/CSRender/CSRender/OurputTIFF.cs
@@ -16,58 +16,129 @@ using System.Windows.Controls.Primitives;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.IO;
+using System.Threading;
namespace CSRender
{
- class OutputTIFF
+ partial class OutputTIFF
{
- public static string runCSRender(string resolutionNum, string outputFile,
- bool pageFlag, string filePage, string targetPath, string workPath)
+ public static void runCSRender(string resolutionNum, string outputFile,
+ bool pageFlag, string filePage, string targetPath, string workPath, CancellationToken inCanceller, bool inCanFlag)
{
- //実行用コンソール呼び出し
- ProcessStartInfo processStartInfo = new ProcessStartInfo();
- string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; //モジュールのパスを取得
- string appDirectory = appPath.Substring(0, appPath.LastIndexOf(@"\") + 1); //モジュールの存在するディレクトリを取得
- processStartInfo.FileName = System.IO.Path.Combine(appDirectory, "CSRender.Data", "CSRender.exe");
- processStartInfo.CreateNoWindow = true; // コマンドプロンプトを非表示
- processStartInfo.UseShellExecute = false; // シェル機能オフ
- processStartInfo.RedirectStandardOutput = true;//標準出力をリダイレクト
-
- //解像度の引数
- processStartInfo.Arguments = "/D ";
- processStartInfo.Arguments += resolutionNum;
-
- //出力ファイル形式の引数
- processStartInfo.Arguments += " /";
- processStartInfo.Arguments += outputFile;
- processStartInfo.Arguments += " ";
-
- //必要に応じてページ引数を指定
- if (pageFlag == true)
+
+ //string resuletString = "";
+ try
{
- processStartInfo.Arguments += "/P \"";
- processStartInfo.Arguments += filePage;
- processStartInfo.Arguments += "\" ";
- }
+ //実行用コンソール呼び出し
+ ProcessStartInfo processStartInfo = new ProcessStartInfo();
+ string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; //モジュールのパスを取得
+ string appDirectory = appPath.Substring(0, appPath.LastIndexOf(@"\") + 1); //モジュールの存在するディレクトリを取得
+ processStartInfo.FileName = System.IO.Path.Combine(appDirectory, "CSRender.Data", "CSRender.exe");
+ processStartInfo.CreateNoWindow = true; // コマンドプロンプトを非表示
+ processStartInfo.UseShellExecute = false; // シェル機能オフ
+ processStartInfo.RedirectStandardOutput = true;//標準出力をリダイレクト
+
+ //解像度の引数
+ processStartInfo.Arguments = "/D ";
+ processStartInfo.Arguments += resolutionNum;
+
+ //出力ファイル形式の引数
+ processStartInfo.Arguments += " /";
+ processStartInfo.Arguments += outputFile;
+ processStartInfo.Arguments += " ";
- //指定ファイル
- processStartInfo.Arguments += "/F ";
- processStartInfo.Arguments += targetPath;
+ //必要に応じてページ引数を指定
+ if (pageFlag == true)
+ {
+ processStartInfo.Arguments += "/P \"";
+ processStartInfo.Arguments += filePage;
+ processStartInfo.Arguments += "\" ";
+ }
- //出力フォルダ
- if (workPath != "")
+ //指定ファイル
+ processStartInfo.Arguments += "/F ";
+ processStartInfo.Arguments += targetPath;
+
+ //出力フォルダ
+ if (workPath != "")
+ {
+ processStartInfo.Arguments += " /O ";
+ processStartInfo.Arguments += workPath;
+ }
+
+ //CSRender.exeを実行
+ Process process = Process.Start(processStartInfo);
+ Boolean ProcEndFlag = false;
+ if (inCanceller.IsCancellationRequested)
+ {
+ process.Kill();
+ inCanceller.ThrowIfCancellationRequested();
+ //process.Close();
+ // if (Directory.Exists(System.IO.Path.Combine(inWorkPath, "OUT_DIFF")))
+ // {
+ // Directory.Delete(System.IO.Path.Combine(inWorkPath, "OUT_DIFF"), true);//OUT_DIFFを削除
+ // }
+ // if (Directory.Exists(System.IO.Path.Combine(inWorkPath, "work")))
+ // {
+ // Directory.Delete(System.IO.Path.Combine(inWorkPath, "work"), true);//作業(work)ディレクトリを削除
+ // }
+ return;
+ }
+ ////string resuletString = process.StandardOutput.ReadToEnd();
+ //resuletString = process.StandardOutput.ReadToEnd();
+ //resuletString = await ReadLineAsync(process, resuletString);
+ //process.WaitForExit();
+ while (!ProcEndFlag)
+ {
+ if (inCanceller.IsCancellationRequested)
+ {
+ process.Kill();
+ inCanceller.ThrowIfCancellationRequested();
+ return;
+ }
+ ProcEndFlag = process.WaitForExit(10000);
+ }
+ process.Close();
+ }
+ catch (OperationCanceledException)
{
- processStartInfo.Arguments += " /O ";
- processStartInfo.Arguments += workPath;
+ return;
}
- //CSRender.exeを実行
- Process process = Process.Start(processStartInfo);
- string resuletString = process.StandardOutput.ReadToEnd();
- process.WaitForExit();
- process.Close();
- return resuletString;
+ return;
}
+
+ private async static Task ReadLineAsync(Process inProc, string inLineStr)
+ {
+ inLineStr = await inProc.StandardOutput.ReadToEndAsync();
+
+ return inLineStr;
+ }
+
+ //public static async TaskrunExe(string resolutionNum, string outputFile,
+ // bool pageFlag, string filePage, string targetPath, string workPath, CancellationToken inCanceller)
+ //{
+
+ // string resuletString = "";
+ // try
+ // {
+ // await Task.Run(async () =>
+ // //await Task.Factory.StartNew(() =>
+ // {
+ // resuletString =
+ // OutputTIFF.runCSRender(resolutionNum, outputFile, pageFlag, filePage, targetPath, workPath, inCanceller);
+
+ // }, inCanceller);
+ // }
+ // catch(OperationCanceledException)
+ // {
+ // return "Canceled";
+ // }
+
+ // return resuletString;
+ //}
+
+
}
}