/// <summary> /// Start the game process /// </summary> /// <param name="game"></param> private bool StartGame(CGameData.CGame game) { Console.Clear(); Console.WriteLine("Starting game: {0} ...", game.Title); try { if (game.PlatformString == "GOG") { ProcessStartInfo gogProcess = new ProcessStartInfo(); string clientPath = game.Launch.Substring(0, game.Launch.IndexOf('.') + 4); string arguments = game.Launch.Substring(game.Launch.IndexOf('.') + 4); gogProcess.FileName = clientPath; gogProcess.Arguments = arguments; Process.Start(gogProcess); return(true); } Process.Start(game.Launch); return(true); } catch (Exception e) { Logger.CLogger.LogError(e, "Cannot start game. Was game removed?"); Console.WriteLine("Cannot launch game. Make sure that the game is installed."); Console.WriteLine("{0} will be removed from the list.", game.Title); return(false); } }
/// <summary> /// Create a game JSON object and add write it with JsonWriter /// </summary> /// <param name="writer">JsonWriter object</param> /// <param name="stream">MemoryStream object</param> /// <param name="options">JsonWriter options struct</param> /// <param name="data">Game data</param> private static void WriteGame(Utf8JsonWriter writer, MemoryStream stream, JsonWriterOptions options, CGameData.CGame data) { writer.WriteStartObject(); writer.WriteString(GAMES_ARRAY_TITLE, data.Title); writer.WriteString(GAMES_ARRAY_LAUNCH, data.Launch); writer.WriteString(GAMES_ARRAY_PLATFORM, data.PlatformString); writer.WriteBoolean(GAMES_ARRAY_FAVOURITE, data.IsFavourite); writer.WriteEndObject(); }
/// <summary> /// Run the main program loop. /// Return when game is launched or the user decided to exit. /// </summary> public void MainLoop() { CJsonWrapper.ImportFromJSON(); CGameFinder.CheckCustomFolder(); int nSelectionCode, nSelectionIndex; for (; ;) { MenuSwitchboard(out nSelectionCode, out nSelectionIndex); switch ((DockSelection)nSelectionCode) { case DockSelection.cSel_Help: DisplayHelp(); continue; case DockSelection.cSel_Exit: // Exit application return; case DockSelection.cSel_Back: // Go back to first menu m_nFirstSelection = -1; continue; case DockSelection.cSel_Fav: // Toggle game favourite if (m_nFirstSelection > -1) { CGameData.ToggleFavourite((CGameData.GamePlatform)m_nFirstSelection, nSelectionIndex); CJsonWrapper.Export(CGameData.GetPlatformGameList(CGameData.GamePlatform.All).ToList()); } continue; case DockSelection.cSel_Rescan: // Rescan the game list if (m_nFirstSelection < 0) { Console.Clear(); Console.Write("Scanning for games..."); Logger.CLogger.LogInfo("Scanning for games..."); CRegScanner.ScanGames(); } continue; case DockSelection.cSel_Default: // Possible valid platform/game selection default: break; } if (nSelectionIndex > -1) { if (m_nFirstSelection < 0) { m_nFirstSelection = nSelectionIndex; } else if (m_nSecondSelection < 0) { m_nSecondSelection = nSelectionIndex; } } if (m_nSecondSelection > -1) { CGameData.CGame selectedGame = CGameData.GetPlatformGame((CGameData.GamePlatform)m_nFirstSelection, m_nSecondSelection); if (StartGame(selectedGame)) { return; } else { CGameData.RemoveGame(selectedGame); CJsonWrapper.Export(CGameData.GetPlatformGameList(CGameData.GamePlatform.All).ToList()); } } } }