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;
                }
            }
        }
示例#2
0
 private void AutoLoad()
 {
     try
     {
         game.Canvas.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);
             }
         }
         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);
             }
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Autoload failure: " + e.ToString());
     }
     finally
     {
         game.Canvas.Loading = false;
     }
 }
示例#3
0
 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;
     }
 }