private void Load(TreeNode node) { var itemdata = (ItemData)node.UserData; switch (itemdata.ItemType) { case ItemType.Folder: { var tracks = TrackIO.EnumerateTrackFiles(itemdata.Path); if (tracks.Length > 0) { LoadTrack(tracks[0], itemdata.Name); Close(); } } break; case ItemType.TrackFile: { var path = itemdata.Path; if (path.EndsWith(".sol", StringComparison.OrdinalIgnoreCase)) { var sol = SOLLoader.LoadSol(path); if (sol.Count == 0) { return; } if (sol.Count == 1) { LoadTrackSol(sol[0]); Close(); } else if (node.Children.Count == 0) { foreach (var track in sol) { var solnode = node.AddNode(track.name); solnode.UserData = new ItemData(ItemType.Sol, path, track); } node.ExpandAll(); } } else { LoadTrack(itemdata.Path, itemdata.Name); Close(); } } break; case ItemType.Sol: { LoadTrackSol(itemdata.sol); Close(); } break; } }
/// <summary> /// Displays all the tracks contained in an sol /// returns true if the window can close. /// </summary> private bool ExpandSOL(string filepath, TreeNode parent) { lock (_loadsync) { try { var tracks = SOLLoader.LoadSol(filepath); if (tracks.Count != 0) { foreach (var track in tracks) { parent.AddNode(track.name).UserData = track; } if (tracks.Count == 1) { LoadSOL(tracks[0]); return(true); } else { parent.UserData = tracks[0]; parent.ExpandAll(); return(false); } } return(false); } catch (Exception e) { PopupWindow.QueuedActions.Enqueue(() => PopupWindow.Error( "Failed to load the .sol track:" + Environment.NewLine + e.Message)); return(true); } } }
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; } }