private void AutoLoad() { try { game.Loading = true; var lasttrack = Settings.LastSelectedTrack; var trdr = Constants.TracksDirectory; if (!lasttrack.StartsWith(trdr)) { return; } if (string.Equals( Path.GetExtension(lasttrack), ".trk", StringComparison.InvariantCultureIgnoreCase)) { var trackname = TrackIO.GetTrackName(lasttrack); lock (LoadSync) { var track = TRKLoader.LoadTrack(lasttrack, trackname); ChangeTrack(track); } } } catch (Exception e) { Debug.WriteLine("Autoload failure: " + e.ToString()); } finally { game.Loading = false; } }
private void LoadTrackWorker(string file, string name) { lock (_loadsync) { try { _canvas.Loading = true; Track track; if (file.EndsWith(".trk", StringComparison.InvariantCultureIgnoreCase)) { track = TRKLoader.LoadTrack(file, name); } else if (file.EndsWith(".json", StringComparison.InvariantCultureIgnoreCase)) { track = JSONLoader.LoadTrack(file); } else { throw new Exception("Filetype unknown"); } _editor.ChangeTrack(track); Settings.LastSelectedTrack = file; Settings.Save(); } #if CATCHERRORS catch (TrackIO.TrackLoadException e) { GameCanvas.QueuedActions.Enqueue(() => _canvas.ShowError( "Failed to load the track:" + Environment.NewLine + e.Message)); return; } catch (Exception e) { GameCanvas.QueuedActions.Enqueue(() => _canvas.ShowError( "An unknown error occured while loading the track:\n" + Environment.NewLine + e.Message)); return; } #endif finally { _canvas.Loading = false; } } }
private void LoadTrack(string file, string name) { lock (_loadsync) { try { game.Loading = true; Track track; if (file.EndsWith(".trk", StringComparison.InvariantCultureIgnoreCase)) { track = TRKLoader.LoadTrack(file, name); } else { throw new Exception("Filetype unknown"); } game.Track.ChangeTrack(track); Settings.LastSelectedTrack = file; Settings.Save(); } catch (TrackIO.TrackLoadException e) { PopupWindow.QueuedActions.Enqueue(() => PopupWindow.Error( "Failed to load the track:" + Environment.NewLine + e.Message)); return; } catch (Exception e) { PopupWindow.QueuedActions.Enqueue(() => PopupWindow.Error( "An unknown error occured while loading the track." + Environment.NewLine + e.Message)); return; } finally { game.Loading = false; } } }
private void AutoLoad() { try { game.Canvas.Loading = true; string lasttrack; if (Program.args.Length > 0) { Settings.LastSelectedTrack = Program.args[0]; lasttrack = Settings.LastSelectedTrack; } else { lasttrack = Settings.LastSelectedTrack; var trdr = Constants.TracksDirectory; if (!lasttrack.StartsWith(trdr)) { return; } } if (lasttrack.Contains("Crash Backup")) { if (!GameCanvas.ShowLoadCrashBackup(game.Canvas, lasttrack)) { game.Canvas.Loading = false; return; } } if (string.Equals( Path.GetExtension(lasttrack), ".trk", StringComparison.InvariantCultureIgnoreCase)) { var trackname = TrackIO.GetTrackName(lasttrack); lock (LoadSync) { var track = TRKLoader.LoadTrack(lasttrack, trackname); ChangeTrack(track); } } else if (string.Equals( Path.GetExtension(lasttrack), ".json", StringComparison.InvariantCultureIgnoreCase)) { var trackname = TrackIO.GetTrackName(lasttrack); lock (LoadSync) { var track = JSONLoader.LoadTrack(lasttrack); if (track.Name == Constants.DefaultTrackName || string.IsNullOrEmpty(track.Name)) { track.Name = trackname; } ChangeTrack(track); } } else if (string.Equals( Path.GetExtension(lasttrack), ".sol", StringComparison.InvariantCultureIgnoreCase)) { var trackname = TrackIO.GetTrackName(lasttrack); var sol = SOLLoader.LoadSol(lasttrack); if (sol.Count == 0) { return; } lock (LoadSync) { var track = SOLLoader.LoadTrack(sol[0]); ChangeTrack(track); } } } catch (Exception e) { Debug.WriteLine("Autoload failure: " + e.ToString()); } finally { game.Canvas.Loading = false; } }