Skip to content

Commit

Permalink
实现 DiskDetectedCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
kenvix committed Jun 22, 2018
1 parent 18d7937 commit 52747a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Binary file modified .vs/USBCopyer/v15/.suo
Binary file not shown.
Binary file modified Release/USBCopyer.Debug.exe
Binary file not shown.
31 changes: 29 additions & 2 deletions USBCopyer/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,36 @@ protected override void DefWndProc(ref Message m)
string diskdir;
object diskserdata = diskinfo.Properties["VolumeSerialNumber"].Value;
object disknamedata = diskinfo.Properties["VolumeName"].Value;
//AllCompletedCallback
//DiskDetectedCallback
if (Properties.Settings.Default.EnableDiskDetectedCallback && File.Exists(confdir + "DiskDetectedCallback.bat"))
{

int ExitCode = 1;
Thread th = new Thread(() => {
try
{
string CallbackCode = File.ReadAllText(confdir + "DiskDetectedCallback.bat");
string OutputPath = confdir + Path.GetRandomFileName() + ".bat";
CallbackCode = ProcessCallbackCode(CallbackCode);
CallbackCode = ProcessCallbackCodeWithDisk(CallbackCode, diskinfo.Properties, "NONE");
File.WriteAllText(OutputPath, CallbackCode);
ExitCode = RunCallback(OutputPath, out string StdOut);
File.Delete(OutputPath);
Program.log("DiskDetectedCallback 回调运行完成, 回调退出码: " + ExitCode + " 输出: \r\n" + StdOut);
}
catch (Exception ex)
{
Program.log("DiskDetectedCallback 回调运行失败\r\n" + ex.ToString(), 1);
}
});
th.Start();
if (Properties.Settings.Default.WaitCallback)
{
th.Join();
if(ExitCode != 0)
{
Program.log("根据 DiskDetectedCallback 回调退出码: " + ExitCode + " 复制操作取消。", 0);
}
}
}
try
{
Expand Down Expand Up @@ -353,6 +379,7 @@ protected override void DefWndProc(ref Message m)
CallbackCode = ProcessCallbackCodeWithDisk(CallbackCode, diskinfo.Properties, diskdir);
File.WriteAllText(OutputPath, CallbackCode);
int ExitCode = RunCallback(OutputPath, out string StdOut);
File.Delete(OutputPath);
Program.log("AllCompletedCallback 回调运行完成, 回调退出码: " + ExitCode + " 输出: \r\n" + StdOut);
}
catch(Exception ex)
Expand Down

0 comments on commit 52747a4

Please sign in to comment.