This commit is contained in:
BruceChen 2022-10-08 10:06:11 +08:00
parent c1a04fe5bf
commit 4cb95731bf
6 changed files with 82 additions and 14 deletions

View file

@ -121,7 +121,7 @@ namespace MinecraftClient
}
public static bool LoadFromFile(string filepath)
public static Tuple<bool, bool> LoadFromFile(string filepath)
{
TomlDocument document;
try
@ -141,16 +141,16 @@ namespace MinecraftClient
File.Copy(filepath, newFilePath, true);
ConsoleIO.WriteLineFormatted("§cPlease use the newly generated MinecraftClient.ini");
ConsoleIO.WriteLineFormatted("§cThe old MinecraftClient.ini has been backed up as " + newFilePath);
return true;
ConsoleIO.WriteLine(Translations.GetOrNull("mcc.run_with_default_settings") ?? "\nMCC is running with default settings.");
return new(false, true);
}
}
catch { }
ConsoleIO.WriteLineFormatted(Translations.GetOrNull("config.load.fail") ?? "§cFailed to load settings:§r");
ConsoleIO.WriteLine(ex.Message);
ConsoleIO.WriteLine(Translations.GetOrNull("mcc.run_with_default_settings") ?? "\nMCC is running with default settings.");
return false;
ConsoleIO.WriteLine(ex.GetFullMessage());
return new(false, false);
}
return false;
return new(true, false);
}
public static void WriteToFile(string filepath, bool backupOldFile)
@ -1210,4 +1210,14 @@ namespace MinecraftClient
};
}
}
public static class ExceptionExtensions
{
public static string GetFullMessage(this Exception ex)
{
return ex.InnerException == null
? ex.Message
: ex.Message + "\n --> " + ex.InnerException.GetFullMessage();
}
}
}