Skip to content

Commit

Permalink
GUI: Don't crash if unable to open logfile in General Logs tab
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Apr 23, 2021
1 parent ffa147c commit 00ed83e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CLI/Program.cs
Expand Up @@ -28,7 +28,7 @@ public static class Program {
public static void Main(string[] args) {
Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

// If MCGalaxy_.dll is missing, .NET will throw a FileNotFoundException for MCGalaxy dll
// If MCGalaxy_.dll is missing, a FileNotFoundException will get thrown for MCGalaxy dll
try {
EnableCLIMode();
} catch (FileNotFoundException) {
Expand Down
16 changes: 8 additions & 8 deletions GUI/Window/Window.Log.cs
Expand Up @@ -23,18 +23,18 @@ namespace MCGalaxy.Gui {
public partial class Window : Form {

void logs_dateGeneral_Changed(object sender, EventArgs e) {
string day = logs_dateGeneral.Value.Day.ToString().PadLeft(2, '0');
string year = logs_dateGeneral.Value.Year.ToString();
string month = logs_dateGeneral.Value.Month.ToString().PadLeft(2, '0');

string date = year + "-" + month + "-" + day;
string date = logs_dateGeneral.Value.ToString("yyyy-MM-dd").Replace("/", "-");
string path = Path.Combine("logs", date + ".txt");

if (!File.Exists(path)) {
try {
logs_txtGeneral.Text = File.ReadAllText(path);
} catch (FileNotFoundException) {
logs_txtGeneral.Text = "No logs found for: " + date;
} else {
} catch (Exception ex) {
logs_txtGeneral.Text = null;
logs_txtGeneral.Text = File.ReadAllText(path);

Logger.LogError("Opening " + path, ex);
Popup.Error("Failed to open logfile " + path);
}
}
}
Expand Down

0 comments on commit 00ed83e

Please sign in to comment.