/// <summary>
        /// Import games from the json file and add them to the global game dictionary.
        /// </summary>
        private static void ImportGames(ref int nGameCount)
        {
            var options = new JsonDocumentOptions
            {
                AllowTrailingCommas = true
            };

            string strDocumentData = File.ReadAllText(GAME_JSON_FILE);

            if (strDocumentData == "")            // File is empty
            {
                return;
            }

            using (JsonDocument document = JsonDocument.Parse(strDocumentData, options))
            {
                JsonElement jArrGames;
                if (!document.RootElement.TryGetProperty(GAMES_ARRAY, out jArrGames))
                {
                    return;                     // 'games' array does not exist
                }
                foreach (JsonElement jElement in jArrGames.EnumerateArray())
                {
                    string strTitle    = jElement.GetProperty(GAMES_ARRAY_TITLE).GetString();
                    string strLaunch   = jElement.GetProperty(GAMES_ARRAY_LAUNCH).GetString();
                    string strPlatform = jElement.GetProperty(GAMES_ARRAY_PLATFORM).GetString();
                    bool   bFavourite  = jElement.GetProperty(GAMES_ARRAY_FAVOURITE).GetBoolean();

                    CGameData.AddGame(strTitle, strLaunch, bFavourite, strPlatform);
                    nGameCount++;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Display menu and handle the selection
        /// </summary>
        private void MenuSwitchboard(out int nSelectionCode, out int nSelectionIndex)
        {
            // Show initial options - platforms or all
            // Take the selection as a string (we'll figure out the enum later)
            // Display the options related to the initial selection (all games will show everything)
            //	Allow cancel with escape (make sure to print that in the heading)
            //  Run selected game.

            if (m_nFirstSelection < 0)
            {
                string   strHeader     = "Select platform.\n Press [Q] to exit;\n Press [S] to rescan game collection; \n Press [H] for help";
                string[] platformArray = CGameData.GetPlatformNames().ToArray();

                nSelectionCode = m_dockConsole.DisplayMenu(strHeader, out nSelectionIndex, CGameData.GetPlatformNames().ToArray());

                if (nSelectionIndex > -1)
                {
                    nSelectionIndex = CGameData.GetPlatformEnum(platformArray[nSelectionIndex].Substring(0, platformArray[nSelectionIndex].IndexOf(':')));
                }
            }
            else if (m_nSecondSelection < 0)
            {
                string strHeader = "Select game.\n Press [Q] to exit;\n Press [R] to return to previous menu;\n Press [F] add/remove from favourites;";
                nSelectionCode = m_dockConsole.DisplayMenu(strHeader, out nSelectionIndex, CGameData.GetPlatformTitles((CGameData.GamePlatform)m_nFirstSelection).ToArray());
            }
            else
            {
                nSelectionCode  = -1;
                nSelectionIndex = -1;
            }
        }
        /// <summary>
        /// Scan the registry for games, add new games to memory and export into JSON document
        /// </summary>
        public static void ScanGames()
        {
            CGameData.CTempGameSet tempGameSet = new CGameData.CTempGameSet();
            List <CRegScanner.RegistryGameData> gameDataList = CRegScanner.GetGames();

            foreach (CRegScanner.RegistryGameData data in gameDataList)
            {
                tempGameSet.InsertGame(data.m_strTitle, data.m_strLaunch, false, data.m_strPlatform);
            }
            CGameFinder.ImportFromFolder(ref tempGameSet);
            CGameData.MergeGameSets(tempGameSet);
            CJsonWrapper.Export(CGameData.GetPlatformGameList(CGameData.GamePlatform.All).ToList());
        }
示例#4
0
        /// <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());
                    }
                }
            }
        }