fix updater batch file encoding & code page
This commit is contained in:
parent
4927a079c7
commit
0b1d8e7937
2 changed files with 15 additions and 7 deletions
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue