private void addGameBtn_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(gameName.Text)) { MessageBox.Show("Game name cannot be empty!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } Game game; bool?steamChecked = steamRadio.IsChecked; bool newBool = steamChecked.HasValue && steamChecked.Value; if (newBool) { if (String.IsNullOrEmpty(gameAppID.Text)) { MessageBox.Show("The Steam AppID cannot be empty!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } game = new SteamGame(new[] { gameName.Text, gameAppID.Text }); } else { if (string.IsNullOrEmpty(gamePath.Text)) { MessageBox.Show("Path to the .exe file cannot be empty!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } game = new NonSteam(new[] { gameName.Text, gamePath.Text }); } _mw.AddNewGame(game); Close(); }
private void launchButton_Click(object sender, RoutedEventArgs e) { if (_games[GamesList.SelectedIndex] is SteamGame sg) { Process.Start("steam://rungameid/" + sg.appId); } else { NonSteam ns = (NonSteam)_games[GamesList.SelectedIndex]; Process.Start(ns.pathToEXE); } WindowState = WindowState.Minimized; }
private void editBtn_Click(object sender, RoutedEventArgs e) { bool?steamChecked = steamRadio.IsChecked; bool newBool = steamChecked.HasValue && steamChecked.Value; if (newBool) { SteamGame sg = new SteamGame(new[] { gameNewName.Text, gameNewAppID.Text }); _mw.SwapGameInList(sg, _index); } else { NonSteam ns = new NonSteam(new[] { gameNewName.Text, gameNewPath.Text }); _mw.SwapGameInList(ns, _index); } Close(); }
private void LoadGames(string path) { try { using (StreamReader sr = new StreamReader(path)) { while (true) { string line = sr.ReadLine(); if (string.IsNullOrEmpty(line)) { return; } string[] data = line.Split(','); Game game; if (data[0] == "steam") { game = new SteamGame(data.Skip(1).ToArray()); } else { game = new NonSteam(data.Skip(1).ToArray()); } _games.Add(game); } } } catch (Exception) { MessageBoxResult result = MessageBox.Show( "The save file is corrupted. Do you want to create a new one?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Error); if (result == MessageBoxResult.Yes) { Task.WaitAll(Task.Run(() => File.Delete(DataFile))); Task.WaitAll(Task.Run(() => File.Create(DataFile))); } else { _emergency = true; this.AppClose(this, EventArgs.Empty); } } }
public Edit(ref MainWindow mainWindow, Game game, int indexToSwap) { InitializeComponent(); _mw = mainWindow; _index = indexToSwap; if (game is SteamGame sg) { steamRadio.IsChecked = true; gameNewAppID.Text = sg.appId; gameNewName.Text = sg.tittle; } else { NonSteam ns = (NonSteam)game; classicRadio.IsChecked = true; gameNewPath.Text = ns.pathToEXE; gameNewName.Text = ns.tittle; } }
private void SaveGamesToFile() { try { using (StreamWriter sw = new StreamWriter(DataFile, false)) { foreach (Game game in _games) { string lineToWrite = ""; if (game is SteamGame) { lineToWrite += "steam,"; } else { lineToWrite += "classic,"; } lineToWrite += game.tittle; if (game is SteamGame sg) { lineToWrite += ',' + sg.appId; } else { NonSteam ns = (NonSteam)game; lineToWrite += ',' + ns.pathToEXE; } sw.WriteLine(lineToWrite); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }