Exemple #1
0
 public void BackupTrack(bool Crash = true)
 {
     try
     {
         if (_track.Lines.Count == 0)
         {
             return;
         }
         var saveindex  = 0;
         var trackfiles =
             TrackLoader.EnumerateTRKFiles(Program.CurrentDirectory + "Tracks" + Path.DirectorySeparatorChar +
                                           _track.Name);
         for (var i = 0; i < trackfiles.Length; i++)
         {
             var s = Path.GetFileNameWithoutExtension(trackfiles[i]);
             s = s.Remove(s.IndexOf(' '));
             if (int.TryParse(s, out saveindex))
             {
                 break;
             }
         }
         saveindex++;
         if (saveindex < 2 && !Crash)
         {
             return;
         }
         var save = Crash ? (saveindex + " " + "Crash Backup") : " Autosave";
         game.Loading = true;
         EnterTrackRead();
         {
             TrackLoader.SaveTrackTrk(_track, save, game.CurrentSong?.ToString());
         }
         ExitTrackRead();
         game.Loading = false;
         game.Invalidate();
     }
     catch
     {
         //ignored
     }
 }
Exemple #2
0
        private void savebtn_Clicked(ControlBase sender, ClickedEventArgs arguments)
        {
            var window = sender.Parent.Parent as WindowControl;

            if (window == null)
            {
                throw new Exception("Invalid window data");
            }
            if (window.UserData != null)
            {
                var tb        = (TextBox)window.FindChildByName("tb", true);
                var saveindex = 0;
                var txt       = (string)window.UserData;
                if (txt == "<create new track>")
                {
                    txt = tb.Text;
                    if (txt.Length == 0)
                    {
                        return;
                    }
                }
                if (
                    Directory.Exists(Program.CurrentDirectory + "Tracks" + Path.DirectorySeparatorChar + txt +
                                     Path.DirectorySeparatorChar))
                {
                    var trackfiles =
                        TrackLoader.EnumerateTRKFiles(Program.CurrentDirectory + "Tracks" + Path.DirectorySeparatorChar +
                                                      txt);
                    for (var i = 0; i < trackfiles.Length; i++)
                    {
                        var s     = Path.GetFileNameWithoutExtension(trackfiles[i]);
                        var index = s.IndexOf(" ", StringComparison.Ordinal);
                        if (index != -1)
                        {
                            s = s.Remove(index);
                        }
                        if (int.TryParse(s, out saveindex))
                        {
                            break;
                        }
                    }
                }
                var invalidchars = Path.GetInvalidFileNameChars();
                for (var i = 0; i < txt.Length; i++)
                {
                    if (invalidchars.Contains(txt[i]))
                    {
                        sender.SetToolTipText("Attempted to save with an invalid name");
                        return;
                    }
                }
                game.Track.Name = txt;
                saveindex++;
                var save = saveindex + " " + tb.Text;
                try
                {
                    game.Track.Save(save, game.CurrentSong);
                }
                catch
                {
                    sender.SetToolTipText("An error occured trying to save");
                    return;
                }
                savenode node = null;
                for (var i = 0; i < _nodes.Count; i++)
                {
                    if (_nodes[i].name.Equals(game.Track.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        node = _nodes[i];
                        break;
                    }
                }
                if (node == null)
                {
                    node = new savenode {
                        data = new List <savenode>(), name = game.Track.Name
                    };
                    _nodes.Add(node);
                }
                ((List <savenode>)node.data).Insert(0, new savenode {
                    name = (save), data = new[] { game.Track.Name, save }
                });
            }
            window.Close();
        }
Exemple #3
0
        private void InitSaveNodes()
        {
            if (_nodeslocked)
            {
                return;
            }
            game.Loading = true;
            lock (_nodes)
            {
                _nodeslocked = true;
                _nodes.Clear();
                var files = Program.CurrentDirectory + "Tracks";
                if (Directory.Exists(files))
                {
                    var solfiles =
                        Directory.GetFiles(files, "*.*")
                        .Where(s => s != null && s.EndsWith(".sol", StringComparison.OrdinalIgnoreCase));

                    foreach (var file in solfiles)
                    {
                        List <sol_track> tracks = null;
                        try
                        {
                            tracks = TrackLoader.LoadSol(file);
                        }
                        catch
                        {
                            //ignored
                        }
                        if (tracks != null)
                        {
                            var node = new savenode {
                                name = "[SOL] " + Path.GetFileNameWithoutExtension(file)
                            };
                            var addnode = new List <savenode>();
                            for (var i = 0; i < tracks.Count; i++)
                            {
                                addnode.Add(new savenode {
                                    name = tracks[i].name, data = tracks[i]
                                });
                            }
                            node.data = addnode;
                            _nodes.Add(node);
                        }
                    }
                    var trkfiles =
                        Directory.GetFiles(files, "*.*")
                        .Where(s => s != null && s.EndsWith(".trk", StringComparison.OrdinalIgnoreCase));
                    foreach (var trk in trkfiles)
                    {
                        var save = Path.GetFileNameWithoutExtension(trk);
                        var node = new savenode {
                            name = "[TRK] " + save
                        };
                        var addnode = new List <savenode>();
                        addnode.Add(new savenode {
                            name = (save), data = new[] { save, null }
                        });
                        node.data = addnode;
                        _nodes.Add(node);
                    }
                    var folders = Directory.GetDirectories(files);
                    foreach (var folder in folders)
                    {
                        var trackname = Path.GetFileName(folder);
                        var node      = new savenode {
                            name = trackname
                        };
                        var trackfiles = TrackLoader.EnumerateTRKFiles(folder);
                        var addnode    = new List <savenode>();
                        for (var i = 0; i < trackfiles.Length; i++)
                        {
                            var trk  = trackfiles[i];
                            var save = Path.GetFileNameWithoutExtension(trk);
                            addnode.Add(new savenode {
                                name = (save), data = new[] { trackname, save }
                            });
                        }
                        node.data = addnode;
                        _nodes.Add(node);
                    }
                }
                _nodeslocked = false;
            }
            game.Loading = false;
            game.Invalidate();
        }