diff --git a/assets/version.txt b/assets/version.txt index 01e4338..77159eb 100644 --- a/assets/version.txt +++ b/assets/version.txt @@ -1 +1 @@ -1.0.3.3-alpha \ No newline at end of file +1.0.3.4-alpha \ No newline at end of file diff --git a/src/SingleExe.Tool/SingleExe.Tool.csproj b/src/SingleExe.Tool/SingleExe.Tool.csproj index a067769..5749dc1 100644 --- a/src/SingleExe.Tool/SingleExe.Tool.csproj +++ b/src/SingleExe.Tool/SingleExe.Tool.csproj @@ -17,7 +17,7 @@ MIT True True - 1.0.3.3-alpha + 1.0.3.4-alpha False Nuget.md single-exe diff --git a/src/SingleExe/MainWindow.xaml.cs b/src/SingleExe/MainWindow.xaml.cs index 399de40..5b28175 100644 --- a/src/SingleExe/MainWindow.xaml.cs +++ b/src/SingleExe/MainWindow.xaml.cs @@ -14,49 +14,51 @@ public MainWindow() StartAsync(); } - async void StartAsync() + void StartAsync() { - await Task.Yield(); - try + Task.Factory.StartNew(() => { - var tempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), $"{App.Name}\\{App.Version}"); - var integrityFile = Path.Combine(tempFolder, "integrity.txt"); - var exePath = Path.Combine(tempFolder, App.EntryPoint); - if (!File.Exists(integrityFile) || !File.Exists(exePath)) + try { - if (Directory.Exists(tempFolder)) Directory.Delete(tempFolder, true); - if (!Directory.Exists(tempFolder)) Directory.CreateDirectory(tempFolder); - var zipFile = Path.Combine(tempFolder, "Source.zip"); - if (File.Exists(zipFile)) File.Delete(zipFile); + var tempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), $"{App.Name}\\{App.Version}"); + var versionFile = Path.Combine(tempFolder, "version.txt"); + var exePath = Path.Combine(tempFolder, App.EntryPoint); + if (!File.Exists(versionFile) || !File.Exists(exePath)) + { + if (Directory.Exists(tempFolder)) Directory.Delete(tempFolder, true); + if (!Directory.Exists(tempFolder)) Directory.CreateDirectory(tempFolder); + var zipFile = Path.Combine(tempFolder, "Source.zip"); + if (File.Exists(zipFile)) File.Delete(zipFile); - var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"SingleExe.Source.zip"); - var zipStream = new FileStream(zipFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); - stream.CopyTo(zipStream); - zipStream.Flush(); - zipStream.Dispose(); - stream.Dispose(); - ZipFile.ExtractToDirectory(zipFile, tempFolder); - File.Delete(zipFile); - } + var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"SingleExe.Source.zip"); + var zipStream = new FileStream(zipFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); + stream.CopyTo(zipStream); + zipStream.Flush(); + zipStream.Dispose(); + stream.Dispose(); + ZipFile.ExtractToDirectory(zipFile, tempFolder); + File.Delete(zipFile); + } - if (!File.Exists(exePath)) throw new Exception($"file not found:{exePath}"); - var process = new Process - { - StartInfo = new ProcessStartInfo(exePath, string.Join(" ", Environment.GetCommandLineArgs())) + if (!File.Exists(exePath)) throw new Exception($"file not found:{exePath}"); + var process = new Process { - WorkingDirectory = new FileInfo(exePath).DirectoryName, - CreateNoWindow = true - } - }; - process.Start(); + StartInfo = new ProcessStartInfo(exePath, string.Join(" ", Environment.GetCommandLineArgs())) + { + WorkingDirectory = new FileInfo(exePath).DirectoryName, + CreateNoWindow = true + } + }; + process.Start(); - if (!File.Exists(integrityFile)) File.Create(integrityFile).Close(); - Application.Current.Shutdown(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - Application.Current.Shutdown(1); - } + if (!File.Exists(versionFile)) File.WriteAllText(versionFile, App.Version); + Application.Current.Shutdown(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + Application.Current.Shutdown(1); + } + }); } } \ No newline at end of file