diff --git a/CreamInstaller/Forms/UpdateForm.cs b/CreamInstaller/Forms/UpdateForm.cs index a36f151..8b8eef7 100644 --- a/CreamInstaller/Forms/UpdateForm.cs +++ b/CreamInstaller/Forms/UpdateForm.cs @@ -205,23 +205,31 @@ internal sealed partial class UpdateForm : CustomForm string directory = Path.GetDirectoryName(path); string file = Path.GetFileName(path); StringBuilder commands = new(); - _ = commands.AppendLine(CultureInfo.InvariantCulture, $"\nTASKKILL /F /T /PID {Program.CurrentProcessId}"); + _ = commands.AppendLine(CultureInfo.InvariantCulture, $"chcp 65001"); _ = commands.AppendLine(CultureInfo.InvariantCulture, $":LOOP"); - _ = commands.AppendLine(CultureInfo.InvariantCulture, $"TASKLIST | FIND \" {Program.CurrentProcessId}\" "); + _ = commands.AppendLine(CultureInfo.InvariantCulture, $"TASKKILL /F /T /PID {Program.CurrentProcessId}"); + _ = commands.AppendLine(CultureInfo.InvariantCulture, $"TASKLIST | FIND \" {Program.CurrentProcessId} \""); _ = commands.AppendLine(CultureInfo.InvariantCulture, $"IF NOT ERRORLEVEL 1 ("); _ = commands.AppendLine(CultureInfo.InvariantCulture, $" TIMEOUT /T 1"); _ = commands.AppendLine(CultureInfo.InvariantCulture, $" GOTO LOOP"); _ = commands.AppendLine(CultureInfo.InvariantCulture, $")"); _ = commands.AppendLine(CultureInfo.InvariantCulture, $"MOVE /Y \"{ExecutablePath}\" \"{path}\""); _ = commands.AppendLine(CultureInfo.InvariantCulture, $"START \"\" /D \"{directory}\" \"{file}\""); +#if DEBUG + _ = commands.AppendLine(CultureInfo.InvariantCulture, $"PAUSE"); +#endif _ = commands.AppendLine(CultureInfo.InvariantCulture, $"EXIT"); - UpdaterPath.WriteFile(commands.ToString(), true, this); + UpdaterPath.WriteFile(commands.ToString(), true, this, Encoding.Default); Process process = new(); ProcessStartInfo startInfo = new() { WorkingDirectory = ProgramData.DirectoryPath, FileName = "cmd.exe", Arguments = $"/C START \"UPDATER\" /B {Path.GetFileName(UpdaterPath)}", +#if DEBUG + CreateNoWindow = false +#else CreateNoWindow = true +#endif }; process.StartInfo = startInfo; _ = process.Start(); diff --git a/CreamInstaller/Utility/SafeIO.cs b/CreamInstaller/Utility/SafeIO.cs index 79b568b..e3035c3 100644 --- a/CreamInstaller/Utility/SafeIO.cs +++ b/CreamInstaller/Utility/SafeIO.cs @@ -174,14 +174,14 @@ internal static class SafeIO } } - internal static string ReadFile(this string filePath, bool crucial = false, Form form = null) + internal static string ReadFile(this string filePath, bool crucial = false, Form form = null, Encoding encoding = null) { if (!filePath.FileExists()) return null; while (!Program.Canceled) try { - return File.ReadAllText(filePath, Encoding.UTF8); + return File.ReadAllText(filePath, encoding ?? Encoding.UTF8); } catch (Exception e) { @@ -212,12 +212,12 @@ internal static class SafeIO return null; } - internal static void WriteFile(this string filePath, string text, bool crucial = false, Form form = null) + internal static void WriteFile(this string filePath, string text, bool crucial = false, Form form = null, Encoding encoding = null) { while (!Program.Canceled) try { - File.WriteAllText(filePath, text, Encoding.UTF8); + File.WriteAllText(filePath, text, encoding ?? Encoding.UTF8); return; } catch (Exception e)