private static void FindCustomLinkFiles(ref CTempGameSet tempGameSet) { List <string> fileList = Directory.EnumerateFiles(Path.Combine(CDock.currentPath, CUSTOM_GAME_FOLDER), "*", SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".lnk")).ToList(); string strPlatform = GetPlatformString(ENUM); foreach (string file in fileList) { string strPathOnly = Path.GetDirectoryName(file); strPathOnly = Path.GetFullPath(strPathOnly); string strFilenameOnly = Path.GetFileName(file); Shell32.Shell shell = new(); Shell32.Folder folder = shell.NameSpace(strPathOnly); Shell32.FolderItem folderItem = folder.ParseName(strFilenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; string strID = Path.GetFileNameWithoutExtension(file); string strTitle = strID; CLogger.LogDebug($"- {strTitle}"); string strLaunch = link.Path; string strUninstall = ""; // N/A string strAlias = GetAlias(strTitle); if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } tempGameSet.InsertGame(strID, strTitle, strLaunch, strLaunch, strUninstall, true, false, true, false, strAlias, strPlatform, new List <string>(), DateTime.MinValue, 0, 0, 0f); } } }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { string dir = Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), EPIC_ITEMS); if (!Directory.Exists(dir)) { CLogger.LogInfo("{0} games not found in ProgramData.", _name.ToUpper()); return; } string[] files = Directory.GetFiles(dir, "*.item", SearchOption.TopDirectoryOnly); CLogger.LogInfo("{0} {1} games found", files.Length, _name.ToUpper()); foreach (string file in files) { string strDocumentData = File.ReadAllText(file); if (string.IsNullOrEmpty(strDocumentData)) { continue; } try { using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); string strID = GetStringProperty(document.RootElement, "AppName"); if (string.IsNullOrEmpty(strID)) { strID = Path.GetFileName(file); } string strTitle = GetStringProperty(document.RootElement, "DisplayName"); CLogger.LogDebug($"- {strTitle}"); string strLaunch = GetStringProperty(document.RootElement, "LaunchExecutable"); // DLCs won't have this set string strAlias = ""; string strPlatform = GetPlatformString(ENUM); if (!string.IsNullOrEmpty(strLaunch)) { strLaunch = Path.Combine(GetStringProperty(document.RootElement, "InstallLocation"), strLaunch); strAlias = GetAlias(GetStringProperty(document.RootElement, "MandatoryAppFolderName")); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } gameDataList.Add(new ImportGameData(strID, strTitle, strLaunch, strLaunch, "", strAlias, true, strPlatform)); } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } } CLogger.LogDebug("--------------------"); }
/// <summary> /// Function overload /// Display either the insert or navigate menu, depending on the console state. /// Returns selection code and selection index /// </summary> /// <param name="strMenuTitle">Helper heading text block displayed on top of the console.</param> /// <param name="nSelectionIndex">Index of the selected option - reference</param> /// <param name="options">String array representing the available options</param> /// <returns>Selection code</returns> public int DisplayMenu(string strMenuTitle, out int nSelectionIndex, params string[] options) { Console.Clear(); int nSelectionCode = -1; do { nSelectionCode = HandleNavigationMenu(strMenuTitle, out nSelectionIndex, true, options); CLogger.LogDebug("Current Selection = {0}", nSelectionCode); if (nSelectionIndex == 0 && options.Length == 0) { nSelectionIndex = -1; return(nSelectionCode); } } while(!IsSelectionValid(nSelectionIndex, options.Length)); return(nSelectionCode); }
/// <summary> /// Display either the insert or navigate menu, depending on the console state /// </summary> /// <param name="strMenuTitle">Helper heading text block displayed on top of the console.</param> /// <param name="options">String array representing the available options</param> /// <returns>Index of the selection array, or any other valid integer</returns> public int DisplayMenu(string strMenuTitle, params string[] options) { Console.Clear(); int nSelection = 0; do { if (m_ConsoleState == ConsoleState.cState_Navigate) { nSelection = HandleNavigationMenu(strMenuTitle, true, options); } else if (m_ConsoleState == ConsoleState.cState_Insert) { nSelection = HandleInsertMenu(strMenuTitle, options); } CLogger.LogDebug("Current Selection = {0}", nSelection); } while(!IsSelectionValid(nSelection, options.Length)); return(nSelection); }
/// <summary> /// Import games from the game.json config file /// </summary> /// <returns>True if successful, otherwise false</returns> public static bool ImportFromJSON() { int nGameCount = 0; if (!DoesFileExist()) { CLogger.LogDebug("JSON file missing - create file and scan..."); Console.WriteLine("games.json missing. Creating new..."); CreateEmptyFile(); } else { ImportGames(ref nGameCount); } if (nGameCount < 1) { CLogger.LogDebug("JSON file is empty - scanning for games..."); Console.WriteLine("games.json is empty. Scanning for games..."); CRegScanner.ScanGames(); } return(true); }
/// <summary> /// Search the "CustomGames" folder for binaries (.exe) files to import /// </summary> private static void FindCustomBinaries(ref CTempGameSet tempGameSet) { string strPlatform = GetPlatformString(ENUM); List <string> fileList = Directory.EnumerateFiles(Path.Combine(CDock.currentPath, CUSTOM_GAME_FOLDER), "*", SearchOption.AllDirectories).Where(s => s.EndsWith(".exe")).ToList(); // Big Fish Games may use .bfg for executables //fileList.AddRange(Directory.EnumerateFiles(Path.Combine(CDock.currentPath, CUSTOM_GAME_FOLDER), "*", SearchOption.AllDirectories).Where(s => s.EndsWith(".bfg")).ToList()); foreach (string file in fileList) { string strID = Path.GetFileNameWithoutExtension(file); string strTitle = strID; CLogger.LogDebug($"- {strTitle}"); string strLaunch = Path.GetFullPath(file); string strUninstall = ""; // N/A string strAlias = GetAlias(strTitle); if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } tempGameSet.InsertGame(strID, strTitle, strLaunch, strLaunch, strUninstall, true, false, true, false, strAlias, strPlatform, new List <string>(), DateTime.MinValue, 0, 0, 0f); } }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { List <RegistryKey> keyList; string launcherPath = ""; using (RegistryKey launcherKey = Registry.LocalMachine.OpenSubKey(ROCKSTAR_REG, RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 { if (launcherKey == null) { CLogger.LogInfo("{0} client not found in the registry.", _name.ToUpper()); return; } launcherPath = Path.Combine(GetRegStrVal(launcherKey, ROCKSTAR_FOLDER), ROCKSTAR_UNINST); } using (RegistryKey key = Registry.LocalMachine.OpenSubKey(NODE32_REG, RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 { keyList = FindGameKeys(key, launcherPath, GAME_UNINSTALL_STRING, new string[] { ROCKSTAR_LAUNCHER, ROCKSTAR_SOCIAL }); CLogger.LogInfo("{0} {1} games found", keyList.Count, _name.ToUpper()); foreach (var data in keyList) { string strID = ""; string strTitle = ""; string strLaunch = ""; string strUninstall = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); try { strTitle = GetRegStrVal(data, GAME_DISPLAY_NAME); CLogger.LogDebug($"- {strTitle}"); strLaunch = GetRegStrVal(data, GAME_DISPLAY_ICON).Trim(new char[] { ' ', '"' }); strUninstall = GetRegStrVal(data, GAME_UNINSTALL_STRING); strID = strUninstall[(strUninstall.IndexOf(" -uninstall=") + 12)..];
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { List <string> dirs = new(); // Get installed games if (OperatingSystem.IsWindows()) { using RegistryKey key = Registry.LocalMachine.OpenSubKey(PARADOX_REG, RegistryKeyPermissionCheck.ReadSubTree); // HKLM32 if (key == null) { CLogger.LogInfo("{0} client not found in the registry.", _name.ToUpper()); } else { string path = GetRegStrVal(key, PARADOX_PATH); try { if (!path.Equals(null) && Directory.Exists(path)) { dirs.AddRange(Directory.GetDirectories(Path.Combine(Directory.GetParent(Directory.GetParent(path).ToString()).ToString(), "games"), "*.*", SearchOption.TopDirectoryOnly)); foreach (string dir in dirs) { CultureInfo ci = new("en-GB"); TextInfo ti = ci.TextInfo; string strID = Path.GetFileName(dir); string strTitle = ""; string strLaunch = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); strTitle = ti.ToTitleCase(strID.Replace('_', ' ')); CLogger.LogDebug($"- {strTitle}"); strLaunch = CGameFinder.FindGameBinaryFile(dir, strTitle); strAlias = GetAlias(Path.GetFileNameWithoutExtension(strLaunch)); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } if (!(string.IsNullOrEmpty(strLaunch))) { gameDataList.Add( new ImportGameData(strID, strTitle, strLaunch, strLaunch, "", strAlias, true, strPlatform)); } } } } catch (Exception e) { CLogger.LogError(e); } } } // Get not-installed games if (!(bool)CConfig.GetConfigBool(CConfig.CFG_INSTONLY)) { string folder = Path.Combine(GetFolderPath(SpecialFolder.LocalApplicationData), PARADOX_JSON); if (!Directory.Exists(folder)) { CLogger.LogInfo("{0} games not found in Local AppData.", _name.ToUpper()); } else { CLogger.LogDebug("{0} not-installed games:", _name.ToUpper()); string[] files = Directory.GetFiles(folder, "*.json", SearchOption.TopDirectoryOnly); foreach (string file in files) { if (file.EndsWith("_installableGames.json") && !(file.StartsWith("_noUser"))) { string strDocumentData = File.ReadAllText(file); if (string.IsNullOrEmpty(strDocumentData)) { continue; } try { using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); document.RootElement.TryGetProperty("content", out JsonElement content); if (!content.Equals(null)) { foreach (JsonElement game in content.EnumerateArray()) { game.TryGetProperty("_name", out JsonElement id); // Check if game is already installed bool found = false; foreach (string dir in dirs) { if (id.ToString().Equals(Path.GetFileName(dir))) { found = true; } } if (!found) { game.TryGetProperty("_displayName", out JsonElement title); game.TryGetProperty("_owned", out JsonElement owned); if (!id.Equals(null) && !title.Equals(null) && owned.ToString().ToLower().Equals("true")) { string strID = id.ToString(); string strTitle = title.ToString(); CLogger.LogDebug($"- *{strTitle}"); string strPlatform = GetPlatformString(ENUM); gameDataList.Add(new ImportGameData(strID, strTitle, "", "", "", "", false, strPlatform)); } } } } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } } } } } CLogger.LogDebug("--------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { List <string> epicIds = new(); string strPlatform = GetPlatformString(ENUM); string dir = Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), EPIC_ITEMS); if (!Directory.Exists(dir)) { CLogger.LogInfo("{0} games not found in ProgramData.", _name.ToUpper()); return; } string[] files = Directory.GetFiles(dir, "*.item", SearchOption.TopDirectoryOnly); CLogger.LogInfo("{0} {1} games found", files.Length, _name.ToUpper()); foreach (string file in files) { string strDocumentData = File.ReadAllText(file); if (string.IsNullOrEmpty(strDocumentData)) { continue; } try { using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); string strID = GetStringProperty(document.RootElement, "AppName"); if (string.IsNullOrEmpty(strID)) { strID = Path.GetFileName(file); } string strTitle = GetStringProperty(document.RootElement, "DisplayName"); CLogger.LogDebug($"- {strTitle}"); string strLaunch = GetStringProperty(document.RootElement, "LaunchExecutable"); // DLCs won't have this set string strUninstall = ""; string strAlias = ""; if (!string.IsNullOrEmpty(strLaunch)) { epicIds.Add(strID); strUninstall = GetStringProperty(document.RootElement, "InstallLocation"); strLaunch = Path.Combine(strUninstall, strLaunch); strUninstall += ";" + Path.GetFileName(file); // rather than an uninstaller like most platforms, for Epic, strUninstall holds two fields: the install location and the manifest file strAlias = GetAlias(GetStringProperty(document.RootElement, "MandatoryAppFolderName")); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } gameDataList.Add(new ImportGameData(strID, strTitle, strLaunch, strLaunch, strUninstall, strAlias, true, strPlatform)); } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } } // Get not-installed games (requires Legendary) if (!(bool)CConfig.GetConfigBool(CConfig.CFG_INSTONLY)) { bool useLeg = (bool)CConfig.GetConfigBool(CConfig.CFG_USELEG); string pathLeg = CConfig.GetConfigString(CConfig.CFG_PATHLEG); if (string.IsNullOrEmpty(pathLeg)) { useLeg = false; } if (!pathLeg.Contains(@"\") && !pathLeg.Contains("/")) // legendary.exe in current directory { pathLeg = Path.Combine(Directory.GetCurrentDirectory(), pathLeg); } if (useLeg && File.Exists(pathLeg)) { try { Process ps; string tmpfile = $"tmp_{_name}.json"; string errfile = $"tmp_{_name}.err"; if (OperatingSystem.IsWindows()) { CLogger.LogInfo("Launch: cmd.exe /c \"" + pathLeg + "\" list --json 1> " + tmpfile + " 2> " + errfile); ps = CDock.StartAndRedirect("cmd.exe", "/c \"" + pathLeg + "\" list --json 1> " + tmpfile + " 2> " + errfile); } else { CLogger.LogInfo("Launch: " + pathLeg + " list 1> " + tmpfile + " 2> " + errfile); ps = Process.Start(pathLeg, "list 1> " + tmpfile + " 2> " + errfile); } ps.WaitForExit(30000); if (File.Exists(tmpfile)) { if (ps.ExitCode != 0) { if (File.Exists(errfile)) { string strErrorData = File.ReadAllText(errfile); if (!string.IsNullOrEmpty(strErrorData)) { using StreamReader reader = new(errfile); string line; while ((line = reader.ReadLine()) != null) { if (line.Trim().EndsWith("No saved credentials")) { CLogger.LogInfo("Error getting not-installed {0} games. Is Legendary authenticated?\n" + $"To login, enter: \"{pathLeg}\" auth", _name.ToUpper()); } } } } } string strDocumentData = File.ReadAllText(tmpfile); if (!string.IsNullOrEmpty(strDocumentData)) { CLogger.LogDebug("{0} not-installed games:", _name.ToUpper()); using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); foreach (JsonElement element in document.RootElement.EnumerateArray()) { string strID = GetStringProperty(element, "app_name"); if (epicIds.Contains(strID)) // Check if game is already installed { continue; } string strTitle = GetStringProperty(element, "app_title"); CLogger.LogDebug($"- *{strTitle}"); string strAlias = GetAlias(strTitle); if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } gameDataList.Add(new ImportGameData(strID, strTitle, "", "", "", strAlias, false, strPlatform)); } } #if !DEBUG File.Delete(tmpfile); File.Delete(errfile); #endif } else { CLogger.LogInfo("Can't get not-installed {0} games. Error running Legendary.", _name.ToUpper()); } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} output.", _name.ToUpper())); } } else { CLogger.LogInfo("Can't get not-installed {0} games. Legendary must be installed.\n" + "Go to <https://legendary.gl/release/latest>.", _name.ToUpper()); } } CLogger.LogDebug("--------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { List <string> igcIds = new(); string strPlatform = GetPlatformString(ENUM); // Get installed games string file = Path.Combine(GetFolderPath(SpecialFolder.ApplicationData), IG_JSON); if (!File.Exists(file)) { CLogger.LogInfo("{0} installed games not found in AppData", _name.ToUpper()); return; } else { string strDocumentData = File.ReadAllText(file); if (string.IsNullOrEmpty(strDocumentData)) { CLogger.LogWarn(string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } else { try { using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); foreach (JsonElement element in document.RootElement.EnumerateArray()) { string strID = ""; string strTitle = ""; string strLaunch = ""; string strAlias = ""; element.TryGetProperty("target", out JsonElement target); if (!target.Equals(null)) { target.TryGetProperty("item_data", out JsonElement item); if (!item.Equals(null)) { strID = GetStringProperty(item, "id_key_name"); igcIds.Add(strID); strTitle = GetStringProperty(item, "name"); } } element.TryGetProperty("path", out JsonElement paths); if (!paths.Equals(null)) { foreach (JsonElement path in paths.EnumerateArray()) { strLaunch = CGameFinder.FindGameBinaryFile(path.ToString(), strTitle); } } CLogger.LogDebug($"- {strTitle}"); if (!string.IsNullOrEmpty(strLaunch)) { strAlias = GetAlias(Path.GetFileNameWithoutExtension(strLaunch)); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } gameDataList.Add(new ImportGameData(strID, strTitle, strLaunch, strLaunch, "", strAlias, true, strPlatform)); } } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } } } // Get not-installed games if (!(bool)CConfig.GetConfigBool(CConfig.CFG_INSTONLY)) { file = Path.Combine(GetFolderPath(SpecialFolder.ApplicationData), IG_OWN_JSON); if (!File.Exists(file)) { CLogger.LogInfo("{0} not-installed games not found in AppData", _name.ToUpper()); } else { CLogger.LogDebug("{0} not-installed games:", _name.ToUpper()); string strDocumentData = File.ReadAllText(file); if (string.IsNullOrEmpty(strDocumentData)) { CLogger.LogWarn(string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } else { try { using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); bool exists = false; bool found = false; JsonElement coll = new(); document.RootElement.TryGetProperty("gala_data", out JsonElement gData); if (!gData.Equals(null)) { gData.TryGetProperty("data", out JsonElement data); if (!data.Equals(null)) { data.TryGetProperty("showcase_content", out JsonElement sContent); if (!sContent.Equals(null)) { sContent.TryGetProperty("content", out JsonElement content); if (!content.Equals(null)) { content.TryGetProperty("user_collection", out coll); if (!coll.Equals(null)) { exists = true; } } } } } if (exists) { foreach (JsonElement prod in coll.EnumerateArray()) { string strID = GetStringProperty(prod, "prod_id_key_name"); if (!string.IsNullOrEmpty(strID)) { foreach (string id in igcIds) { if (id.Equals(strID)) { found = true; } } if (!found) { string strTitle = GetStringProperty(prod, "prod_name"); CLogger.LogDebug($"- *{strTitle}"); gameDataList.Add(new ImportGameData(strID, strTitle, "", "", "", "", false, strPlatform)); // Use prod_dev_image to download not-installed icons if (!(bool)(CConfig.GetConfigBool(CConfig.CFG_IMGDOWN))) { string devName = GetStringProperty(prod, "prod_dev_namespace"); string image = GetStringProperty(prod, "prod_dev_image"); if (!string.IsNullOrEmpty(devName) && !string.IsNullOrEmpty(image)) { string iconUrl = $"https://www.indiegalacdn.com/imgs/devs/{devName}/products/{strID}/prodmain/{image}"; CDock.DownloadCustomImage(strTitle, iconUrl); } } } } } } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } } } } CLogger.LogDebug("--------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { Dictionary <string, string> installDict = new(); List <RegistryKey> keyList; /* * string launcherPath = ""; * * using (RegistryKey launcherKey = Registry.CurrentUser.OpenSubKey(Path.Combine(NODE64_REG, WARGAMING_UNREG), RegistryKeyPermissionCheck.ReadSubTree)) // HKCU64 * { * if (launcherKey == null) * { * CLogger.LogInfo("{0} client not found in the registry.", _name.ToUpper()); * return; * } * launcherPath = GetRegStrVal(launcherKey, GAME_DISPLAY_ICON); * int pathIndex = launcherPath.IndexOf(","); * if (pathIndex > -1) * launcherPath = launcherPath.Substring(0, pathIndex); * } */ string dataPath = Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), WARGAMING_DATA); try { if (Directory.Exists(dataPath)) { foreach (var dir in Directory.EnumerateDirectories(dataPath)) { foreach (var file in Directory.EnumerateFiles(dir)) { foreach (string line in File.ReadLines(file)) { installDict.Add(Path.GetFileName(dir).ToUpper(), line.Trim()); break; } break; } } } } catch (Exception e) { CLogger.LogError(e); } using (RegistryKey key = Registry.CurrentUser.OpenSubKey(NODE64_REG, RegistryKeyPermissionCheck.ReadSubTree)) // HKCU64 { keyList = FindGameKeys(key, "Wargaming.net", "Publisher", new string[] { WARGAMING_UNREG }); CLogger.LogInfo("{0} {1} games found", keyList.Count, _name.ToUpper()); foreach (var data in keyList) { string strID = ""; string strTitle = ""; string strLaunch = ""; string strIconPath = ""; string strUninstall = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); try { strID = Path.GetFileName(data.Name).ToUpper(); strTitle = GetRegStrVal(data, GAME_DISPLAY_NAME); CLogger.LogDebug($"- {strTitle}"); string installPath = GetRegStrVal(data, GAME_INSTALL_LOCATION); installDict.Remove(strID); //installDict.Remove(installPath); strLaunch = FindGameBinaryFile(installPath, strTitle); strIconPath = GetRegStrVal(data, GAME_DISPLAY_ICON); int iconIndex = strIconPath.IndexOf(','); if (iconIndex > -1) { strIconPath = strIconPath.Substring(0, iconIndex); } strUninstall = GetRegStrVal(data, GAME_UNINSTALL_STRING); strAlias = GetAlias(Path.GetFileNameWithoutExtension(strLaunch.Trim(new char[] { ' ', '\'', '"' }))); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } } catch (Exception e) { CLogger.LogError(e); } if (!(string.IsNullOrEmpty(strLaunch))) { gameDataList.Add( new ImportGameData(strID, strTitle, strLaunch, strIconPath, strUninstall, strAlias, true, strPlatform)); } } } foreach (var kv in installDict) { string path = kv.Value; string strID = kv.Key; string strTitle = ""; string strLaunch = ""; string strIconPath = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); try { string xmlPath = Path.Combine(path, "game_metadata", "metadata.xml"); if (File.Exists(xmlPath)) { XmlDocument doc = new(); doc.Load(xmlPath); foreach (XmlNode exeNode in doc.SelectSingleNode("/protocol/predefined_section/executables").ChildNodes) { XmlAttribute arch = exeNode.Attributes["arch"]; if (arch != null && arch.Value.Equals("x64", CDock.IGNORE_CASE)) { strLaunch = Path.Combine(path, exeNode.InnerText); } if (string.IsNullOrEmpty(strLaunch)) { strLaunch = exeNode.InnerText; } } XmlNode name = doc.SelectSingleNode("/protocol/predefined_section/name"); if (name != null && !string.IsNullOrEmpty(name.InnerText)) { strTitle = name.InnerText; } } if (string.IsNullOrEmpty(strLaunch)) { strLaunch = FindGameBinaryFile(path, strID); } if (string.IsNullOrEmpty(strTitle)) { strTitle = Path.GetFileNameWithoutExtension(strLaunch); } CLogger.LogDebug($"- {strTitle}"); if (expensiveIcons) { strIconPath = Path.Combine(path, "game_metadata", "game.ico"); if (!File.Exists(strIconPath)) { strIconPath = strLaunch; } } else { strIconPath = strLaunch; } strAlias = GetAlias(Path.GetFileNameWithoutExtension(strLaunch.Trim(new char[] { ' ', '\'', '"' }))); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } if (!(string.IsNullOrEmpty(strLaunch))) { gameDataList.Add( new ImportGameData(strID, strTitle, strLaunch, strIconPath, "", strAlias, true, strPlatform)); } } catch (Exception e) { CLogger.LogError(e); } } CLogger.LogDebug("------------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { string strInstallPath = ""; string strClientPath = ""; using (RegistryKey key = Registry.LocalMachine.OpenSubKey(STEAM_REG, RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 { if (key == null) { CLogger.LogInfo("{0} client not found in the registry.", _name.ToUpper()); return; } strInstallPath = GetRegStrVal(key, GAME_INSTALL_PATH); strClientPath = Path.Combine(strInstallPath, STEAM_PATH); } if (!Directory.Exists(strClientPath)) { CLogger.LogInfo("{0} library not found: {1}", _name.ToUpper(), strClientPath); return; } string libFile = Path.Combine(strClientPath, STEAM_LIBFILE); List <string> libs = new() { strClientPath }; int nLibs = 1; try { if (File.Exists(libFile)) { SteamWrapper document = new(libFile); ACF_Struct documentData = document.ACFFileToStruct(); ACF_Struct folders = new(); if (documentData.SubACF.ContainsKey(STEAM_LIBARR)) { folders = documentData.SubACF[STEAM_LIBARR]; } else if (documentData.SubACF.ContainsKey(STEAM_LIBARR.ToLower())) { folders = documentData.SubACF[STEAM_LIBARR.ToLower()]; } for (; nLibs <= STEAM_MAX_LIBS; ++nLibs) { folders.SubItems.TryGetValue(nLibs.ToString(), out string library); if (string.IsNullOrEmpty(library)) { if (folders.SubACF.ContainsKey(nLibs.ToString())) { folders.SubACF[nLibs.ToString()].SubItems.TryGetValue("path", out library); } if (string.IsNullOrEmpty(library)) { nLibs--; break; } } library = Path.Combine(library, STEAM_PATH); if (!library.Equals(strClientPath) && Directory.Exists(library)) { libs.Add(library); } } } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1}", _name.ToUpper(), libFile)); nLibs--; } int i = 0; List <string> allFiles = new(); foreach (string lib in libs) { List <string> libFiles = new(); try { libFiles = Directory.GetFiles(lib, "appmanifest_*.acf", SearchOption.TopDirectoryOnly).ToList(); allFiles.AddRange(libFiles); CLogger.LogInfo("{0} {1} games found in library {2}", libFiles.Count, _name.ToUpper(), lib); } catch (Exception e) { CLogger.LogError(e, string.Format("{0} directory read error: {1}", _name.ToUpper(), lib)); continue; } foreach (string file in libFiles) { try { SteamWrapper document = new(file); ACF_Struct documentData = document.ACFFileToStruct(); ACF_Struct app = documentData.SubACF["AppState"]; string id = app.SubItems["appid"]; if (id.Equals("228980")) // Steamworks Common Redistributables { continue; } string strID = Path.GetFileName(file); string strTitle = app.SubItems["name"]; CLogger.LogDebug($"- {strTitle}"); string strLaunch = START_GAME + "/" + id; string strIconPath = ""; string strUninstall = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); strAlias = GetAlias(strTitle); if (!string.IsNullOrEmpty(strLaunch)) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(Path.Combine(NODE64_REG, STEAM_GAME_PREFIX + id), RegistryKeyPermissionCheck.ReadSubTree), // HKLM64 key2 = Registry.LocalMachine.OpenSubKey(Path.Combine(NODE32_REG, STEAM_GAME_PREFIX + id), RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 { if (key != null) { strIconPath = GetRegStrVal(key, GAME_DISPLAY_ICON).Trim(new char[] { ' ', '"' }); } else if (key2 != null) { strIconPath = GetRegStrVal(key2, GAME_DISPLAY_ICON).Trim(new char[] { ' ', '"' }); } } if (string.IsNullOrEmpty(strIconPath) && expensiveIcons) { bool success = false; // Search for an .exe to use as icon strIconPath = CGameFinder.FindGameBinaryFile(Path.Combine(lib, "common", app.SubItems["installdir"]), strTitle); if (!string.IsNullOrEmpty(strIconPath)) { success = true; strAlias = GetAlias(Path.GetFileNameWithoutExtension(strIconPath)); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } } if (!success && !(bool)(CConfig.GetConfigBool(CConfig.CFG_IMGDOWN))) { // Download missing icons string iconUrl = $"https://cdn.cloudflare.steamstatic.com/steam/apps/{id}/capsule_184x69.jpg"; if (CDock.DownloadCustomImage(strTitle, iconUrl)) { success = true; } } } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } strUninstall = UNINST_GAME + "/" + id; gameDataList.Add(new ImportGameData(strID, strTitle, strLaunch, strIconPath, strUninstall, strAlias, true, strPlatform)); } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } } i++; /* * if (i > nLibs) * CLogger.LogDebug("---------------------"); */ } // Get not-installed games if (!(bool)CConfig.GetConfigBool(CConfig.CFG_INSTONLY)) { // First get Steam user ID ulong userId = (ulong)CConfig.GetConfigULong(CConfig.CFG_STEAMID); if (userId < 1) { try { ulong userIdTmp = 0; string userName = ""; string userNameTmp = ""; string strConfigPath = Path.Combine(strInstallPath, "config"); string appFile = Path.Combine(strConfigPath, STEAM_APPFILE); if (File.Exists(appFile)) { SteamWrapper appDoc = new(appFile); ACF_Struct appDocData = appDoc.ACFFileToStruct(); ACF_Struct appData = appDocData.SubACF["SteamAppData"]; appData.SubItems.TryGetValue("AutoLoginUser", out userName); SteamWrapper usrDoc = new(Path.Combine(strConfigPath, STEAM_USRFILE)); ACF_Struct usrDocData = usrDoc.ACFFileToStruct(); ACF_Struct usrData = usrDocData.SubACF["users"]; foreach (KeyValuePair <string, ACF_Struct> user in usrData.SubACF) { if (!ulong.TryParse(user.Key, out userIdTmp)) { userIdTmp = 0; } foreach (KeyValuePair <string, string> userVal in user.Value.SubItems) { if (userVal.Key.Equals("AccountName")) { userNameTmp = userVal.Value; if (userNameTmp.Equals(userName)) { if (!ulong.TryParse(user.Key, out userId)) { userId = 0; } } } if (userVal.Key.Equals("MostRecent") && userVal.Value.Equals("1") && string.IsNullOrEmpty(userName)) { userId = userIdTmp; userName = userNameTmp; break; } } } if (userId < 1) { userId = userIdTmp; userName = userNameTmp; } } if (userId > 0) { CLogger.LogInfo("Setting default {0} user to {1} #{2}", _name.ToUpper(), userName, userId); CConfig.SetConfigValue(CConfig.CFG_STEAMID, userId); ExportConfig(); } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1} or {2}", _name.ToUpper(), STEAM_APPFILE, STEAM_USRFILE)); } } if (userId > 0) { // Download game list from public user profile try { string url = string.Format("https://steamcommunity.com/profiles/{0}/games/?tab=all", userId); /* #if DEBUG * // Don't re-download if file exists * string tmpfile = $"tmp_{NAME}.html"; * if (!File.Exists(tmpfile)) * { * using (var client = new WebClient()); * client.DownloadFile(url, tmpfile); * } * HtmlDocument doc = new HtmlDocument * { * OptionUseIdAttribute = true * }; * doc.Load(tmpfile); #else */ HtmlWeb web = new() { UseCookies = true }; HtmlDocument doc = web.Load(url); doc.OptionUseIdAttribute = true; //#endif HtmlNode gameList = doc.DocumentNode.SelectSingleNode("//script[@language='javascript']"); if (gameList != null) { CLogger.LogDebug("{0} not-installed games (user #{1}):", _name.ToUpper(), userId); var options = new JsonDocumentOptions { AllowTrailingCommas = true }; string rgGames = gameList.InnerText.Remove(0, gameList.InnerText.IndexOf('[')); rgGames = rgGames.Remove(rgGames.IndexOf(';')); using JsonDocument document = JsonDocument.Parse(@rgGames, options); foreach (JsonElement game in document.RootElement.EnumerateArray()) { ulong id = GetULongProperty(game, "appid"); if (id > 0) { // Check if game is already installed string strID = $"appmanifest_{id}.acf"; bool found = false; foreach (string file in allFiles) { if (file.EndsWith(strID)) { found = true; } } if (!found) { string strTitle = GetStringProperty(game, "name"); string strPlatform = GetPlatformString(ENUM); // Add not-installed games CLogger.LogDebug($"- *{strTitle}"); gameDataList.Add(new ImportGameData(strID, strTitle, "", "", "", "", false, strPlatform)); // Use logo to download not-installed icons if (!(bool)(CConfig.GetConfigBool(CConfig.CFG_IMGDOWN))) { string iconUrl = GetStringProperty(game, "logo"); CDock.DownloadCustomImage(strTitle, iconUrl); } } } } } else { CLogger.LogInfo("Can't get not-installed {0} games. Profile may not be public.\n" + "To change this, go to <https://steamcommunity.com/my/edit/settings>.", _name.ToUpper()); } /* #if DEBUG * File.Delete(tmpfile); #endif */ } catch (Exception e) { CLogger.LogError(e); } CLogger.LogDebug("---------------------"); } } }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { List <RegistryKey> keyList = new(); // Get installed games using (RegistryKey key = Registry.CurrentUser.OpenSubKey(LEG_REG, RegistryKeyPermissionCheck.ReadSubTree)) // HKLM64 { keyList = FindGameFolders(key, ""); CLogger.LogInfo("{0} {1} games found", keyList.Count, _name.ToUpper()); foreach (var data in keyList) { string strID = ""; string strTitle = ""; string strLaunch = ""; string strIconPath = ""; string strUninstall = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); try { strID = GetRegStrVal(data, "InstallerUUID"); if (string.IsNullOrEmpty(strID)) { strID = data.Name; } strTitle = GetRegStrVal(data, "ProductName"); if (string.IsNullOrEmpty(strTitle)) { strTitle = data.Name; } CLogger.LogDebug($"- {strTitle}"); string exeFile = GetRegStrVal(data, "GameExe"); strLaunch = Path.Combine(GetRegStrVal(data, "InstDir").Trim(new char[] { ' ', '"' }), exeFile); if (expensiveIcons) { using RegistryKey key2 = Registry.LocalMachine.OpenSubKey(NODE32_REG, RegistryKeyPermissionCheck.ReadSubTree), // HKLM32 key3 = Registry.LocalMachine.OpenSubKey(NODE64_REG, RegistryKeyPermissionCheck.ReadSubTree); // HKLM64 List <RegistryKey> unList = FindGameKeys(key2, GAME_DISPLAY_NAME, strTitle, new string[] { "Legacy Games Launcher" }); if (unList.Count <= 0) { unList = FindGameKeys(key3, GAME_DISPLAY_NAME, strTitle, new string[] { "Legacy Games Launcher" }); } foreach (RegistryKey unKey in unList) { strUninstall = GetRegStrVal(unKey, GAME_UNINSTALL_STRING); //.Trim(new char[] { ' ', '"' }); strIconPath = GetRegStrVal(unKey, GAME_DISPLAY_ICON); //.Trim(new char[] { ' ', '"' }); break; } } if (string.IsNullOrEmpty(strIconPath)) { strIconPath = strLaunch; } strAlias = GetAlias(Path.GetFileNameWithoutExtension(exeFile)); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } } catch (Exception e) { CLogger.LogError(e); } if (!(string.IsNullOrEmpty(strLaunch))) { gameDataList.Add( new ImportGameData(strID, strTitle, strLaunch, strIconPath, strUninstall, strAlias, true, strPlatform)); } } } if (expensiveIcons && keyList.Count <= 0) { // if no games found in registry, check manually List <string> libPaths = new(); string file = Path.Combine(GetFolderPath(SpecialFolder.ApplicationData), LEG_JSON); if (!File.Exists(file)) { CLogger.LogInfo("{0} installed games not found in AppData", _name.ToUpper()); return; } else { string strDocumentData = File.ReadAllText(file); if (string.IsNullOrEmpty(strDocumentData)) { CLogger.LogWarn(string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } else { try { using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); foreach (JsonElement element in document.RootElement.EnumerateArray()) { element.TryGetProperty("settings", out JsonElement settings); if (!settings.Equals(null)) { settings.TryGetProperty("gameLibraryPath", out JsonElement paths); if (!paths.Equals(null)) { foreach (JsonElement path in paths.EnumerateArray()) { if (!path.Equals(null)) { libPaths.Add(path.ToString()); } } } } } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } } } foreach (string path in libPaths) { List <string> dirs = new(); try { if (!path.Equals(null) && Directory.Exists(path)) { dirs.AddRange(Directory.GetDirectories(path, "*.*", SearchOption.TopDirectoryOnly)); foreach (string dir in dirs) { string strID = Path.GetFileName(dir); string strLaunch = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); CLogger.LogDebug($"- {strID}"); strLaunch = CGameFinder.FindGameBinaryFile(dir, strID); strAlias = GetAlias(Path.GetFileNameWithoutExtension(strLaunch)); if (strAlias.Length > strID.Length) { strAlias = GetAlias(strID); } if (strAlias.Equals(strID, CDock.IGNORE_CASE)) { strAlias = ""; } if (!(string.IsNullOrEmpty(strLaunch))) { gameDataList.Add( new ImportGameData(strID, strID, strLaunch, strLaunch, "", strAlias, true, strPlatform)); } } } } catch (Exception e) { CLogger.LogError(e); } } } CLogger.LogDebug("--------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { List <RegistryKey> keyList; List <string> uplayIds = new(); List <string> uplayIcons = new(); string launcherPath = ""; string strPlatform = GetPlatformString(ENUM); using (RegistryKey launcherKey = Registry.LocalMachine.OpenSubKey(Path.Combine(NODE32_REG, UPLAY_UNREG), RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 { if (launcherKey == null) { CLogger.LogInfo("{0} client not found in the registry.", _name.ToUpper()); return; } launcherPath = GetRegStrVal(launcherKey, GAME_INSTALL_LOCATION); } using (RegistryKey key = Registry.LocalMachine.OpenSubKey(NODE32_REG, RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 { keyList = FindGameFolders(key, UPLAY_PREFIX); CLogger.LogInfo("{0} {1} games found", keyList.Count, _name.ToUpper()); foreach (var data in keyList) { string loc = GetRegStrVal(data, GAME_INSTALL_LOCATION); string strID = ""; string strTitle = ""; string strLaunch = ""; string strIconPath = ""; string strUninstall = ""; string strAlias = ""; try { strID = Path.GetFileName(data.Name); uplayIds.Add(strID); strTitle = GetRegStrVal(data, GAME_DISPLAY_NAME); CLogger.LogDebug($"- {strTitle}"); strLaunch = START_GAME + GetGameID(strID); strIconPath = GetRegStrVal(data, GAME_DISPLAY_ICON).Trim(new char[] { ' ', '"' }); uplayIcons.Add(strIconPath); if (string.IsNullOrEmpty(strIconPath) && expensiveIcons) { strIconPath = CGameFinder.FindGameBinaryFile(loc, strTitle); } strUninstall = GetRegStrVal(data, GAME_UNINSTALL_STRING); //.Trim(new char[] { ' ', '"' }); strAlias = GetAlias(Path.GetFileNameWithoutExtension(loc.Trim(new char[] { ' ', '\'', '"' }).Trim(new char[] { '/', '\\' }))); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } } catch (Exception e) { CLogger.LogError(e); } if (!(string.IsNullOrEmpty(strLaunch))) { gameDataList.Add( new ImportGameData(strID, strTitle, strLaunch, strIconPath, strUninstall, strAlias, true, strPlatform)); } } } // Get not-installed games if (!(bool)CConfig.GetConfigBool(CConfig.CFG_INSTONLY) && !(string.IsNullOrEmpty(launcherPath))) { string uplayCfgFile = Path.Combine(launcherPath, @"cache\configuration\configurations"); try { if (File.Exists(uplayCfgFile)) { char[] trimChars = { ' ', '\'', '"' }; List <string> uplayCfg = new(); int nGames = 0; bool dlc = false; string strID = ""; string strTitle = ""; string strIconPath = ""; CLogger.LogDebug("{0} not-installed games:", _name.ToUpper()); uplayCfg.AddRange(File.ReadAllLines(uplayCfgFile)); foreach (string line in uplayCfg) // Note if the last game is valid, this method won't catch it; but that appears very unlikely { if (line.Trim().StartsWith("root:")) { if (nGames > 0 && !(string.IsNullOrEmpty(strID)) && dlc == false) { bool found = false; foreach (string id in uplayIds) { if (id.Equals(strID)) { found = true; } } if (!found) { // The Uplay ID is not always available, so this is an alternative test // However, if user has e.g., a demo and the full game installed, this might get a false negative foreach (string icon in uplayIcons) { if (Path.GetFileName(icon).Equals(Path.GetFileName(strIconPath))) { found = true; } } } if (!found) { strTitle = strTitle.Replace("''", "'"); CLogger.LogDebug($"- *{strTitle}"); gameDataList.Add( new ImportGameData(strID, strTitle, "", strIconPath, "", "", false, strPlatform)); } } nGames++; dlc = false; strID = ""; strTitle = ""; strIconPath = ""; } if (dlc == true) { continue; } else if (line.Trim().StartsWith("is_dlc: yes")) { dlc = true; continue; } else if (string.IsNullOrEmpty(strTitle) && line.Trim().StartsWith("name: ")) { strTitle = line[(line.IndexOf("name:") + 6)..].Trim(trimChars);
/// <summary> /// Function overload /// Selection handler in the browse state. /// Return selection code and selection index /// </summary> /// <param name="strHeader">Helper header text block which will appear on top of the console</param> /// <param name="nSelectionIndex">Index of the option array - reference</param> /// <param name="bCanExit">Flag indicating if exiting is allowed - unused in this function</param> /// <param name="options">Array of available options</param> /// <returns>Selection code</returns> public int HandleNavigationMenu(string strHeader, out int nSelectionIndex, bool bCanExit, params string[] options) { // Setup int nCurrentSelection = 0; int nLastSelection = 0; ConsoleKey key; Console.CursorVisible = false; // Print the selections Console.Clear(); Console.WriteLine(strHeader); int nStartY = Console.CursorTop + 1; if (m_MenuType == MenuType.cType_Grid) { DrawGridMenu(nCurrentSelection, nStartY, options); } else if (m_MenuType == MenuType.cType_List) { DrawListMenu(nCurrentSelection, nStartY, options); } do { // Track the current selection if (nCurrentSelection != nLastSelection) { UpdateMenu(nLastSelection, nCurrentSelection, nStartY, options[nLastSelection], options[nCurrentSelection]); } key = Console.ReadKey(true).Key; nLastSelection = nCurrentSelection; nSelectionIndex = nCurrentSelection; CLogger.LogDebug("{0} key registered", key); switch (key) { case ConsoleKey.LeftArrow: CLogger.LogDebug("Cursor on new selection: {0}: {1}", nCurrentSelection, options[nCurrentSelection]); HandleSelectionLeft(ref nCurrentSelection); break; case ConsoleKey.RightArrow: CLogger.LogDebug("Cursor on new selection: {0}: {1}", nCurrentSelection, options[nCurrentSelection]); HandleSelectionRight(ref nCurrentSelection, options.Length); break; case ConsoleKey.UpArrow: CLogger.LogDebug("Cursor on new selection: {0}: {1}", nCurrentSelection, options[nCurrentSelection]); HandleSelectionUp(ref nCurrentSelection); break; case ConsoleKey.DownArrow: CLogger.LogDebug("Cursor on new selection: {0}: {1}", nCurrentSelection, options[nCurrentSelection]); HandleSelectionDown(ref nCurrentSelection, options.Length); break; case ConsoleKey.H: // Print help return(-6); case ConsoleKey.Q: // Exit program return(-5); case ConsoleKey.R: // Return to first menu return(-4); case ConsoleKey.F: // Add/remove game from favourites return(-3); case ConsoleKey.S: // Rescan the registry and the 'customGames' folder for new games return(-2); default: break; } } while(key != ConsoleKey.Enter); Console.CursorVisible = true; return(-1); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { List <RegistryKey> keyList = new(); string strPlatform = GetPlatformString(ENUM); //string arcFolder = Path.Combine(GetFolderPath(SpecialFolder.ApplicationData), "Arc"); // AppData\Roaming /* * string launcherPath = ""; * * using (RegistryKey launcherKey = Registry.LocalMachine.OpenSubKey(Path.Combine(ARC_REG, "Arc"), RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 * { * if (launcherKey == null) * { * CLogger.LogInfo("{0} client not found in the registry.", _name.ToUpper()); * return; * } * launcherPath = GetRegStrVal(launcherKey, "client"); * } */ using (RegistryKey key = Registry.LocalMachine.OpenSubKey(Path.Combine(ARC_REG, ARC_GAMES), RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 { foreach (string subKey in key.GetSubKeyNames()) // Add subkeys to search list { try { if (subKey.IndexOf("en") > -1) { keyList.Add(key.OpenSubKey(subKey, RegistryKeyPermissionCheck.ReadSubTree)); } } catch (Exception e) { CLogger.LogError(e); } } CLogger.LogInfo("{0} {1} games found", keyList.Count, _name.ToUpper()); foreach (var data in keyList) { string id = GetRegStrVal(data, ARC_ID); if (string.IsNullOrEmpty(id)) { id = Path.GetFileName(data.Name); int idIndex = id.IndexOf("en"); if (idIndex > -1) { id = id.Substring(0, idIndex); } } string name = Path.GetFileName(GetRegStrVal(data, ARC_PATH).Trim(new char[] { '"', '\\', '/' })); int nameIndex = name.IndexOf("_en"); if (nameIndex > -1) { name = name.Substring(0, nameIndex); } string strID = ""; string strTitle = ""; string strLaunch = ""; string strAlias = ""; bool bInstalled = true; try { strID = "arc_" + id; if (!string.IsNullOrEmpty(name)) { strTitle = name; } else { strTitle = id; } CLogger.LogDebug($"- {strTitle}"); strLaunch = GetRegStrVal(data, ARC_EXEPATH); strAlias = GetAlias(Path.GetFileNameWithoutExtension(strLaunch)); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } int?installed = GetRegDWORDVal(data, ARC_INST); if (installed != null && installed == 0) { bInstalled = false; } } catch (Exception e) { CLogger.LogError(e); } if (!(string.IsNullOrEmpty(strLaunch))) { gameDataList.Add( new ImportGameData(strID, strTitle, strLaunch, strLaunch, "", strAlias, bInstalled, strPlatform)); } } } CLogger.LogDebug("------------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { // Get installed games string db = Path.Combine(GetFolderPath(SpecialFolder.ApplicationData), ITCH_DB); if (!File.Exists(db)) { CLogger.LogInfo("{0} database not found.", _name.ToUpper()); return; } try { using var con = new SQLiteConnection($"Data Source={db}"); con.Open(); // Get both installed and not-installed games using (var cmd = new SQLiteCommand("SELECT id, title, classification, cover_url, still_cover_url FROM games;", con)) using (SQLiteDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { if (!rdr.GetString(2).Equals("assets")) // i.e., just "game" or "tool" { int id = rdr.GetInt32(0); string strID = $"itch_{id}"; string strTitle = rdr.GetString(1); string strAlias = ""; string strLaunch = ""; string strPlatform = GetPlatformString(ENUM); DateTime lastRun = DateTime.MinValue; string iconUrl = rdr.GetString(4); if (string.IsNullOrEmpty(iconUrl)) { iconUrl = rdr.GetString(3); } // SELECT path FROM install_locations; // SELECT install_folder FROM downloads; using (var cmd2 = new SQLiteCommand($"SELECT installed_at, last_touched_at, verdict, install_folder_name FROM caves WHERE game_id = {id};", con)) using (SQLiteDataReader rdr2 = cmd2.ExecuteReader()) { while (rdr2.Read()) { if (!rdr2.IsDBNull(1)) { lastRun = rdr2.GetDateTime(1); //CLogger.LogDebug(" last_touched_at: " + rdr2.GetString(1) + " -> " + lastRun.ToShortDateString()); } //else if (!rdr2.IsDBNull(0)) // lastRun = rdr2.GetDateTime(0); string verdict = rdr2.GetString(2); //strAlias = rdr2.GetString(3); strAlias = GetAlias(strTitle); if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } using JsonDocument document = JsonDocument.Parse(@verdict, jsonTrailingCommas); string basePath = GetStringProperty(document.RootElement, "basePath"); if (document.RootElement.TryGetProperty("candidates", out JsonElement candidates) && !string.IsNullOrEmpty(candidates.ToString())) { foreach (JsonElement jElement in candidates.EnumerateArray()) { strLaunch = string.Format("{0}\\{1}", basePath, GetStringProperty(jElement, "path")); } } // Add installed games if (!string.IsNullOrEmpty(strLaunch)) { CLogger.LogDebug($"- {strTitle}"); gameDataList.Add(new ImportGameData(strID, strTitle, strLaunch, strLaunch, "", strAlias, true, strPlatform, dateLastRun: lastRun)); // Use still_cover_url, or cover_url if it doesn't exist, to download missing icons if (!(bool)(CConfig.GetConfigBool(CConfig.CFG_IMGDOWN)) && !Path.GetExtension(strLaunch).Equals(".exe", CDock.IGNORE_CASE)) { CDock.DownloadCustomImage(strTitle, iconUrl); } } } } // Add not-installed games if (string.IsNullOrEmpty(strLaunch) && !(bool)CConfig.GetConfigBool(CConfig.CFG_INSTONLY)) { CLogger.LogDebug($"- *{strTitle}"); gameDataList.Add(new ImportGameData(strID, strTitle, "", "", "", "", false, strPlatform)); // Use still_cover_url, or cover_url if it doesn't exist, to download not-installed icons if (!(bool)(CConfig.GetConfigBool(CConfig.CFG_IMGDOWN))) { CDock.DownloadCustomImage(strTitle, iconUrl); } } } } } con.Close(); } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} database output!", _name.ToUpper())); } CLogger.LogDebug("-------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { string dataPath = Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), RIOT_FOLDER); try { if (Directory.Exists(dataPath)) { // Should we use YamlDotNet parser? string strClientPath = ""; var clientFile = Path.Combine(dataPath, RIOT_CLIENT_FILE); if (File.Exists(clientFile)) { string strDocumentData = File.ReadAllText(clientFile); if (!string.IsNullOrEmpty(strDocumentData)) { using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); strClientPath = GetStringProperty(document.RootElement, "rc_live"); } } string metaPath = Path.Combine(dataPath, "Metadata"); if (Directory.Exists(metaPath)) { foreach (var dir in Directory.EnumerateDirectories(metaPath)) { string path = ""; string strID = Path.GetFileName(dir); string strTitle = ""; string strLaunch = ""; string strIconPath = ""; string strUninstall = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); foreach (var settingsFile in Directory.EnumerateFiles(dir, "*.yaml")) { foreach (string line in File.ReadLines(settingsFile)) { if (line.StartsWith("product_install_full_path")) { path = line.Substring(line.IndexOf('"')).Trim().Trim('"'); } else if (line.StartsWith("shortcut_name")) { strTitle = Path.GetFileNameWithoutExtension(line.Substring(line.IndexOf('"')).Trim().Trim('"')); } } break; } foreach (var iconFile in Directory.EnumerateFiles(dir, "*.ico")) { strIconPath = iconFile; break; } if (!string.IsNullOrEmpty(strTitle)) { strLaunch = FindGameBinaryFile(path, strTitle); if (!string.IsNullOrEmpty(strLaunch)) { if (string.IsNullOrEmpty(strIconPath)) { strIconPath = strLaunch; } if (!string.IsNullOrEmpty(strClientPath)) { strUninstall = "\"" + strClientPath + "\" --uninstall-product=" + Path.GetFileNameWithoutExtension(strID) + " --uninstall-patchline=live"; } strAlias = GetAlias(strTitle); if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } gameDataList.Add(new ImportGameData(strID, strTitle, strLaunch, strIconPath, strUninstall, strAlias, true, strPlatform)); } } } } } } catch (Exception e) { CLogger.LogError(e); } CLogger.LogDebug("------------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { string strPlatform = GetPlatformString(ENUM); // Stop service (otherwise database is locked) ServiceController sc = new("OVRService"); //bool restartSvc = false; try { if (sc.Status.Equals(ServiceControllerStatus.Running) || sc.Status.Equals(ServiceControllerStatus.StartPending)) { //restartSvc = true; sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped); } } catch (Exception e) { CLogger.LogError(e); } List <string> libPaths = new(); Dictionary <ulong, string> exePaths = new(); string db = Path.Combine(GetFolderPath(SpecialFolder.ApplicationData), OCULUS_DB); using (RegistryKey key = Registry.CurrentUser.OpenSubKey(OCULUS_LIBS, RegistryKeyPermissionCheck.ReadSubTree)) { if (key != null) { foreach (string lib in key.GetSubKeyNames()) { using RegistryKey key2 = Registry.CurrentUser.OpenSubKey(Path.Combine(OCULUS_LIBS, lib), RegistryKeyPermissionCheck.ReadSubTree); libPaths.Add(GetRegStrVal(key2, OCULUS_LIBPATH)); } } } foreach (string lib in libPaths) { List <string> libFiles = new(); try { string manifestPath = Path.Combine(lib, "Manifests"); libFiles = Directory.GetFiles(manifestPath, "*.json.mini", SearchOption.TopDirectoryOnly).ToList(); CLogger.LogInfo("{0} {1} games found in library {2}", libFiles.Count, _name.ToUpper(), lib); } catch (Exception e) { CLogger.LogError(e, string.Format("{0} directory read error: {1}", _name.ToUpper(), lib)); continue; } foreach (string file in libFiles) { try { var options = new JsonDocumentOptions { AllowTrailingCommas = true }; string strDocumentData = File.ReadAllText(file); if (string.IsNullOrEmpty(strDocumentData)) { CLogger.LogWarn(string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } else { using JsonDocument document = JsonDocument.Parse(@strDocumentData, options); string name = GetStringProperty(document.RootElement, "canonicalName"); if (ulong.TryParse(GetStringProperty(document.RootElement, "appId"), out ulong id)) { exePaths.Add(id, Path.Combine(lib, "Software", name, GetStringProperty(document.RootElement, "launchFile"))); } } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } } } try { CultureInfo ci = new("en-GB"); TextInfo ti = ci.TextInfo; string userName = CConfig.GetConfigString(CConfig.CFG_OCULUSID); //ulong userId = 0; using SQLiteConnection con = new($"Data Source={db}"); con.Open(); // Get the user ID to check entitlements for expired trials /* * using (SQLiteCommand cmdU = new("SELECT hashkey, value FROM Objects WHERE typename = 'User'", con)) * { * using SQLiteDataReader rdrU = cmdU.ExecuteReader(); * while (rdrU.Read()) * { * byte[] valU = new byte[rdrU.GetBytes(1, 0, null, 0, int.MaxValue) - 1]; * rdrU.GetBytes(1, 0, valU, 0, valU.Length); * string strValU = System.Text.Encoding.Default.GetString(valU); * * string alias = ParseBlob(strValU, "alias", "app_entitlements"); * if (string.IsNullOrEmpty(userName)) * { * if (ulong.TryParse(rdrU.GetString(0), out userId)) * { * userName = alias; * break; * } * } * else if (userName.Equals(alias, CDock.IGNORE_CASE)) * { * ulong.TryParse(rdrU.GetString(0), out userId); * break; * } * } * } */ using SQLiteCommand cmd = new("SELECT hashkey, value FROM Objects WHERE typename = 'Application'", con); using SQLiteDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { string strID = ""; string strTitle = ""; string strLaunch = ""; string strAlias = ""; string url = ""; /* * string exePath = "", exePath2d = "", exeParams = "", exeParams2d = ""; * string state = "", time = ""; * bool isInstalled = false; */ bool isInstalled = true; if (ulong.TryParse(rdr.GetString(0), out ulong id)) { strID = "oculus_" + id; } //else // strID = "oculus_" + name; if (id == OCULUS_ENV_RIFT) { continue; } byte[] val = new byte[rdr.GetBytes(1, 0, null, 0, int.MaxValue) - 1]; rdr.GetBytes(1, 0, val, 0, val.Length); string strVal = System.Text.Encoding.Default.GetString(val); _ = ulong.TryParse(ParseBlob(strVal, "ApplicationAssetBundle", "can_access_feature_keys", -1, 0), out ulong assets); //ulong.TryParse(ParseBlob(strVal, "PCBinary", "livestreaming_status", -1, 0), out ulong bin); string name = ParseBlob(strVal, "canonical_name", "category"); strTitle = ParseBlob(strVal, "display_name", "display_short_description"); if (!string.IsNullOrEmpty(name) && string.IsNullOrEmpty(strTitle)) { strTitle = ti.ToTitleCase(name.Replace('-', ' ')); } using (SQLiteCommand cmd2 = new($"SELECT value FROM Objects WHERE hashkey = '{assets}'", con)) { using SQLiteDataReader rdr2 = cmd2.ExecuteReader(); while (rdr2.Read()) { byte[] val2 = new byte[rdr2.GetBytes(0, 0, null, 0, int.MaxValue) - 1]; rdr2.GetBytes(0, 0, val2, 0, val2.Length); string strVal2 = System.Text.Encoding.Default.GetString(val2); url = ParseBlob(strVal2, "uri", "version_code", strStart1: "size"); } } // The exe's can be gotten from the .json files, which we have to get anyway to figure out the install path /* * using (SQLiteCommand cmd3 = new($"SELECT value FROM Objects WHERE hashkey = '{bin}'", con)) * { * using SQLiteDataReader rdr3 = cmd3.ExecuteReader(); * while (rdr3.Read()) * { * byte[] val3 = new byte[rdr3.GetBytes(0, 0, null, 0, int.MaxValue) - 1]; * rdr3.GetBytes(0, 0, val3, 0, val3.Length); * string strVal3 = System.Text.Encoding.Default.GetString(val3); * exePath = ParseBlob(strVal3, "launch_file", "launch_file_2d"); * exePath2d = ParseBlob(strVal3, "launch_file_2d", "launch_parameters"); * exeParams = ParseBlob(strVal3, "launch_parameters", "launch_parameters_2d"); * exeParams2d = ParseBlob(strVal3, "launch_parameters_2d", "manifest_signature"); * } * } * * if (userId > 0) * { * // TODO: If this is an expired trial, count it as not-installed * using SQLiteCommand cmd5 = new($"SELECT value FROM Objects WHERE hashkey = '{userId}:{id}'", con); * using SQLiteDataReader rdr5 = cmd5.ExecuteReader(); * while (rdr5.Read()) * { * byte[] val5 = new byte[rdr5.GetBytes(0, 0, null, 0, int.MaxValue) - 1]; * rdr5.GetBytes(0, 0, val5, 0, val5.Length); * string strVal5 = System.Text.Encoding.Default.GetString(val5); * state = ParseBlob(strVal5, "active_state", "expiration_time"); * if (state.Equals("PERMANENT")) * isInstalled = true; * else * { * time = ParseBlob(strVal5, "expiration_time", "grant_reason"); * CLogger.LogDebug($"expiry: {state} {time}"); * //if (!...expired) * isInstalled = true; * } * } * } * else * isInstalled = true; */ if (exePaths.ContainsKey(id)) { CLogger.LogDebug($"- {strTitle}"); strLaunch = exePaths[id]; strAlias = GetAlias(Path.GetFileNameWithoutExtension(exePaths[id])); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } gameDataList.Add(new ImportGameData(strID, strTitle, strLaunch, strLaunch, "", strAlias, isInstalled, strPlatform)); } else { CLogger.LogDebug($"- *{strTitle}"); gameDataList.Add(new ImportGameData(strID, strTitle, "", "", "", "", false, strPlatform)); if (expensiveIcons && !string.IsNullOrEmpty(url)) { // Download missing icons string imgfile = Path.Combine(CDock.currentPath, CDock.IMAGE_FOLDER_NAME, string.Concat(strTitle.Split(Path.GetInvalidFileNameChars()))); bool iconFound = false; foreach (string ext in CDock.supportedImages) { if (File.Exists(imgfile + "." + ext)) { iconFound = true; break; } } if (iconFound) { continue; } string zipfile = $"tmp_{_name}_{id}.zip"; try { #if DEBUG // Don't re-download if file exists if (!File.Exists(zipfile)) { #endif using WebClient client = new(); client.DownloadFile(url, zipfile); #if DEBUG } #endif using ZipArchive archive = ZipFile.OpenRead(zipfile); foreach (ZipArchiveEntry entry in archive.Entries) { foreach (string ext in CDock.supportedImages) { if (entry.Name.Equals("cover_square_image." + ext, CDock.IGNORE_CASE)) { entry.ExtractToFile(imgfile + "." + ext); break; } } } //#if !DEBUG File.Delete(zipfile); //#endif } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} zip file!", _name.ToUpper())); } } } } con.Close(); } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} database output!", _name.ToUpper())); } //if (restartSvc) // sc.Start(); CLogger.LogDebug("--------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { List <string> azIds = new(); string strPlatform = GetPlatformString(ENUM); // Get installed games string db = Path.Combine(GetFolderPath(SpecialFolder.LocalApplicationData), AMAZON_DB); if (!File.Exists(db)) { CLogger.LogInfo("{0} installed game database not found.", _name.ToUpper()); //return; } try { using SQLiteConnection con = new($"Data Source={db}"); con.Open(); using SQLiteCommand cmd = new("SELECT Id, InstallDirectory, ProductTitle FROM DbSet;", con); using SQLiteDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { string dir = rdr.GetString(1); string strID = rdr.GetString(0); azIds.Add(strID); string strTitle = rdr.GetString(2); CLogger.LogDebug($"- {strTitle}"); string strLaunch = START_GAME + strID; string strIconPath = ""; string strUninstall = ""; using (RegistryKey key = Registry.CurrentUser.OpenSubKey(Path.Combine(NODE64_REG, "AmazonGames", strTitle), RegistryKeyPermissionCheck.ReadSubTree)) { if (key != null) { strIconPath = GetRegStrVal(key, "DisplayIcon"); strUninstall = GetRegStrVal(key, "UninstallString"); } } if (string.IsNullOrEmpty(strIconPath)) { if (expensiveIcons) { bool success = false; string fuelPath = Path.Combine(dir, "fuel.json"); if (File.Exists(fuelPath)) { string strDocumentData = File.ReadAllText(fuelPath); if (!string.IsNullOrEmpty(strDocumentData)) { using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); document.RootElement.TryGetProperty("Main", out JsonElement main); if (!main.Equals(null)) { string iconFile = GetStringProperty(main, "Command"); if (!string.IsNullOrEmpty(strIconPath)) { strIconPath = Path.Combine(dir, iconFile); success = true; } } } } if (!success) { strIconPath = CGameFinder.FindGameBinaryFile(dir, strTitle); } } } if (string.IsNullOrEmpty(strUninstall)) { strUninstall = Path.Combine(Directory.GetParent(dir).FullName, UNINST_GAME) + " " + UNINST_GAME_ARGS + " " + strID; } string strAlias = GetAlias(strTitle); if (!string.IsNullOrEmpty(strLaunch)) { if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } gameDataList.Add(new ImportGameData(strID, strTitle, strLaunch, strIconPath, strUninstall, strAlias, true, strPlatform)); } } con.Close(); } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} database output!", _name.ToUpper())); } // Get not-installed games if (!(bool)CConfig.GetConfigBool(CConfig.CFG_INSTONLY)) { db = Path.Combine(GetFolderPath(SpecialFolder.LocalApplicationData), AMAZON_OWN_DB); if (!File.Exists(db)) { CLogger.LogInfo("{0} not-installed game database not found.", _name.ToUpper()); } else { CLogger.LogDebug("{0} not-installed games:", _name.ToUpper()); try { using SQLiteConnection con = new($"Data Source={db}"); con.Open(); using SQLiteCommand cmd = new("SELECT Id, ProductIconUrl, ProductIdStr, ProductTitle FROM DbSet;", con); using SQLiteDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { bool found = false; string strID = rdr.GetString(2); // TODO: Should I use Id or ProductIdStr? foreach (string id in azIds) { if (id.Equals(strID)) { found = true; } } if (!found) { string strTitle = rdr.GetString(3); CLogger.LogDebug($"- *{strTitle}"); gameDataList.Add(new ImportGameData(strID, strTitle, "", "", "", "", false, strPlatform)); // Use ProductIconUrl to download not-installed icons if (!(bool)(CConfig.GetConfigBool(CConfig.CFG_IMGDOWN))) { string iconUrl = rdr.GetString(1); CDock.DownloadCustomImage(strTitle, iconUrl); } } } con.Close(); } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} database output!", _name.ToUpper())); } } } CLogger.LogDebug("-------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { string strPlatform = GetPlatformString(ENUM); string cfgFile = Path.Combine(GetFolderPath(SpecialFolder.ApplicationData), BATTLE_NET_CFG); string dbFile = Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), BATTLE_NET_DB); string dataPath = Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), BATTLE_NET_DATA); string uninstallExe = Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), UNINST_GAME); if (!File.Exists(dbFile)) { CLogger.LogInfo("{0} installed game database not found.", _name.ToUpper()); return; } // grab config file for last run dates string strConfigData = File.ReadAllText(cfgFile); List <string> dataFiles = new(); try { dataFiles = Directory.GetFiles(dataPath, "*.", SearchOption.AllDirectories).ToList(); //CLogger.LogInfo("{0} {1} games found", dataFiles.Count > 3 ? dataFiles.Count - 3 : 0, _name.ToUpper()); } catch (Exception e) { CLogger.LogError(e, string.Format("{0} directory read error: {1}", _name.ToUpper(), dataPath)); } foreach (string dataFile in dataFiles) { string strDocumentData = File.ReadAllText(dataFile); if (!string.IsNullOrEmpty(strDocumentData)) { using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); string all = GetStringProperty(document.RootElement, "all"); if (document.RootElement.TryGetProperty("all", out JsonElement allLocales) && allLocales.TryGetProperty("config", out JsonElement allConfig)) { string code = GetStringProperty(allConfig, "product"); if (code.Equals("agent") || code.Equals("Bna")) // hide Agent and Battle.net { continue; } try { using FileStream file = File.OpenRead(dbFile); BnetDatabase db = Serializer.Deserialize <BnetDatabase>(file); foreach (BnetProductInstall pi in db.productInstalls) { if (pi.productCode.Equals(code, CDock.IGNORE_CASE)) { string installPath = pi.Settings.installPath; if (!string.IsNullOrEmpty(installPath)) { string lang = pi.Settings.selectedTextLanguage; if (string.IsNullOrEmpty(lang)) { lang = "enUS"; //"enGB"; } /* * string timestamp = ""; * foreach (BnetProductConfig pc in db.productConfigs) * { * if (code.Equals(pc.productCode, CDock.IGNORE_CASE)) * { * timestamp = pc.Timestamp; * break; * } * } */ if (allConfig.TryGetProperty("shared_container_default_subfolder", out JsonElement sub)) { installPath = Path.Combine(installPath, sub.GetString()); } if (allConfig.TryGetProperty("supported_locales", out JsonElement locales)) { bool found = false; foreach (JsonElement locale in locales.EnumerateArray()) { if (locale.GetString().Equals("lang", CDock.IGNORE_CASE)) { found = true; } } if (!found) { lang = "enus"; //"engb"; } } string strID = $"battlenet_{code}"; string strTitle = code; if (document.RootElement.TryGetProperty(lang.ToLower(), out JsonElement selectedLocale) && selectedLocale.TryGetProperty("config", out JsonElement localeConfig) && localeConfig.TryGetProperty("install", out JsonElement install)) { foreach (JsonElement item in install.EnumerateArray()) { if (item.TryGetProperty("add_remove_programs_key", out JsonElement uninstall) && uninstall.TryGetProperty("display_name", out JsonElement name)) { strTitle = name.GetString(); } } } CLogger.LogDebug($"- {strTitle}"); if (document.RootElement.TryGetProperty("platform", out JsonElement platform) && platform.TryGetProperty("win", out JsonElement windows)) { if (windows.TryGetProperty("config", out JsonElement config) && config.TryGetProperty("binaries", out JsonElement bins) && bins.TryGetProperty("game", out JsonElement game)) { string strLaunch = ""; JsonElement exePath = new(); if (game.TryGetProperty("relative_path_64", out exePath) || game.TryGetProperty("relative_path", out exePath)) { strLaunch = Path.Combine(installPath, exePath.GetString()); } if (string.IsNullOrEmpty(strLaunch)) { break; } string strUninstall = $"\"{uninstallExe}\" --lang={lang} --uid={code} --displayname=\"{strTitle}\""; string strAlias = ""; long lLastRun = 0; if (!string.IsNullOrEmpty(strConfigData)) { try { using JsonDocument document2 = JsonDocument.Parse(@strConfigData, jsonTrailingCommas); if (document2.RootElement.TryGetProperty("Games", out JsonElement games) && games.TryGetProperty(code, out JsonElement cfgGame)) { string strLastRun = ""; strLastRun = GetStringProperty(cfgGame, "LastPlayed"); //if (string.IsNullOrEmpty(strLastRun)) // strLastRun = GetStringProperty(cfgGame, "LastActioned"); _ = long.TryParse(strLastRun, out lLastRun); //CLogger.LogDebug(" LastPlayed: " + strLastRun + " -> " + DateTimeOffset.FromUnixTimeSeconds(lLastRun).UtcDateTime.ToShortDateString()); } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} configuration file: {1}", _name.ToUpper(), cfgFile)); } } DateTime lastRun = DateTimeOffset.FromUnixTimeSeconds(lLastRun).UtcDateTime; strAlias = GetAlias(strTitle); if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } if (!(string.IsNullOrEmpty(strLaunch))) { gameDataList.Add( new ImportGameData(strID, strTitle, strLaunch, strLaunch, strUninstall, strAlias, true, strPlatform, dateLastRun: lastRun)); } } } } break; } } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} data file: {1}", _name.ToUpper(), dbFile)); } } } } /* * List<RegistryKey> keyList; * * using (RegistryKey key = Registry.LocalMachine.OpenSubKey(NODE32_REG, RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 * { * if (key == null) * { * CLogger.LogInfo("HKLM32 Uninstall not found in the registry.", _name.ToUpper()); * return; * } * * //keyList = FindGameKeys(key, BATTLE_NET, GAME_UNINSTALL_STRING, new string[] { BATTLE_NET_UNREG }); * keyList = FindGameKeys(key, Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), BATTLE_NET_UNINST), GAME_UNINSTALL_STRING, new string[] { BATTLE_NET_UNREG }); * * CLogger.LogInfo("{0} {1} games found", keyList.Count, _name.ToUpper()); * foreach (var data in keyList) * { * string strID = ""; * string strTitle = ""; * string strLaunch = ""; * //string strIconPath = ""; * string strUninstall = ""; * string strAlias = ""; * try * { * strID = Path.GetFileName(data.Name); * strTitle = GetRegStrVal(data, GAME_DISPLAY_NAME); * CLogger.LogDebug($"- {strTitle}"); * strLaunch = GetRegStrVal(data, GAME_DISPLAY_ICON).Trim(new char[] { ' ', '"' }); * strUninstall = GetRegStrVal(data, GAME_UNINSTALL_STRING); //.Trim(new char[] { ' ', '"' }); * strAlias = GetAlias(Path.GetFileNameWithoutExtension(GetRegStrVal(data, GAME_INSTALL_LOCATION).Trim(new char[] { ' ', '\'', '"' }))); * if (strAlias.Length > strTitle.Length) * strAlias = GetAlias(strTitle); * if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) * strAlias = ""; * } * catch (Exception e) * { * CLogger.LogError(e); * } * if (!(string.IsNullOrEmpty(strLaunch))) * gameDataList.Add( * new ImportGameData(strID, strTitle, strLaunch, strLaunch, strUninstall, strAlias, true, strPlatform)); * } * } */ CLogger.LogDebug("--------------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { bool error = false; string file = Path.Combine(GetFolderPath(SpecialFolder.LocalApplicationData), PLARIUM_DB); /* * string launcherPath = ""; * int? lang = 1; * * using (RegistryKey launcherKey = Registry.CurrentUser.OpenSubKey(PLARIUM_REG, RegistryKeyPermissionCheck.ReadSubTree)) // HKCU64 * { * if (launcherKey == null) * { * CLogger.LogInfo("{0} client not found in the registry.", _name.ToUpper()); * return; * } * launcherPath = GetRegStrVal(launcherKey, PLARIUM_FOLDER); * lang = GetRegDWORDVal(launcherKey, "Language"); * } */ if (!File.Exists(file)) { CLogger.LogInfo("{0} database not found.", _name.ToUpper()); return; } try { while (true) { string strDocumentData = File.ReadAllText(file); if (string.IsNullOrEmpty(strDocumentData)) { error = true; break; } using JsonDocument document = JsonDocument.Parse(@strDocumentData, jsonTrailingCommas); document.RootElement.TryGetProperty("InstalledGames", out JsonElement games); if (games.Equals(null)) { error = true; break; } foreach (JsonProperty game in games.EnumerateObject()) { CultureInfo ci = new("en-GB"); TextInfo ti = ci.TextInfo; string strID = ""; string strTitle = ""; string strLaunch = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); foreach (JsonProperty gameVal in game.Value.EnumerateObject()) { if (gameVal.Name.Equals("InsalledGames", CDock.IGNORE_CASE)) { foreach (JsonProperty install in gameVal.Value.EnumerateObject()) { string num = install.Value.GetString(); string id = install.Name; strID = "plarium_" + id; string path = Path.Combine(GetFolderPath(SpecialFolder.LocalApplicationData), PLARIUM_GAMES, id, num); strLaunch = FindGameBinaryFile(path, id); string infoPath = Path.Combine(path, id + "_Data", "app.info"); string jsonPath = Path.Combine(path, "settings.json"); if (File.Exists(infoPath)) { int i = 0; foreach (string line in File.ReadLines(infoPath)) { if (i == 1) { strTitle = line.Trim(); break; } i++; } } if (string.IsNullOrEmpty(strTitle) && File.Exists(jsonPath)) { string strDocumentData2 = File.ReadAllText(jsonPath); if (!string.IsNullOrEmpty(strDocumentData2)) { using JsonDocument document2 = JsonDocument.Parse(@strDocumentData2, jsonTrailingCommas); strTitle = GetStringProperty(document2.RootElement, "productName"); } } if (string.IsNullOrEmpty(strTitle)) { strTitle = ti.ToTitleCase(strID); } CLogger.LogDebug($"- {strTitle}"); strAlias = GetAlias(Path.GetFileNameWithoutExtension(strLaunch)); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } if (!string.IsNullOrEmpty(strLaunch)) { gameDataList.Add(new ImportGameData(strID, strTitle, strLaunch, strLaunch, "", strAlias, true, strPlatform)); } } } } } break; } } catch (Exception e) { CLogger.LogError(e, string.Format("Malformed {0} file: {1}", _name.ToUpper(), file)); } if (error) { CLogger.LogInfo("Malformed {0} file: {1}", _name.ToUpper(), file); return; } CLogger.LogDebug("------------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { List <RegistryKey> keyList; /* * string launcherPath = ""; * * using (RegistryKey launcherKey = Registry.LocalMachine.OpenSubKey(Path.Combine(NODE32_REG, BETHESDA_UNREG), RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 * { * if (launcherKey == null) * { * CLogger.LogInfo("{0} client not found in the registry.", _name.ToUpper()); * return; * } * launcherPath = GetRegStrVal(launcherKey, GAME_INSTALL_LOCATION); * } */ using (RegistryKey key = Registry.LocalMachine.OpenSubKey(NODE32_REG, RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 { keyList = FindGameKeys(key, BETHESDA_UNINST, GAME_UNINSTALL_STRING, new string[] { BETHESDA_CREATION_KIT, BETHESDA_UNREG }); CLogger.LogInfo("{0} {1} games found", keyList.Count, _name.ToUpper()); foreach (var data in keyList) { string loc = GetRegStrVal(data, BETHESDA_PATH); string strID = ""; string strTitle = ""; string strLaunch = ""; string strIconPath = ""; string strUninstall = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); try { strID = Path.GetFileName(data.Name); strTitle = GetRegStrVal(data, GAME_DISPLAY_NAME); CLogger.LogDebug($"- {strTitle}"); strLaunch = START_GAME + "/" + GetRegStrVal(data, BETHESDA_PRODUCT_ID); strIconPath = GetRegStrVal(data, GAME_DISPLAY_ICON).Trim(new char[] { ' ', '"' }); if (string.IsNullOrEmpty(strIconPath)) { strIconPath = Path.Combine(loc.Trim(new char[] { ' ', '"' }), string.Concat(strTitle.Split(Path.GetInvalidFileNameChars())) + ".exe"); } strUninstall = GetRegStrVal(data, GAME_UNINSTALL_STRING); //.Trim(new char[] { ' ', '"' }); strAlias = GetAlias(Path.GetFileNameWithoutExtension(loc.Trim(new char[] { ' ', '\'', '"' }))); if (strAlias.Length > strTitle.Length) { strAlias = GetAlias(strTitle); } if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } } catch (Exception e) { CLogger.LogError(e); } if (!(string.IsNullOrEmpty(strLaunch))) { gameDataList.Add( new ImportGameData(strID, strTitle, strLaunch, strIconPath, strUninstall, strAlias, true, strPlatform)); } } } CLogger.LogDebug("------------------------"); }
public void GetGames(List <ImportGameData> gameDataList, bool expensiveIcons = false) { List <RegistryKey> keyList; using (RegistryKey key = Registry.LocalMachine.OpenSubKey(BIGFISH_GAMES, RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 { if (key == null) { CLogger.LogInfo("{0} client not found in the registry.", _name.ToUpper()); return; } keyList = FindGameFolders(key, ""); CLogger.LogInfo("{0} {1} games found", keyList.Count > 1 ? keyList.Count - 1 : keyList.Count, _name.ToUpper()); foreach (var data in keyList) { string wrap = Path.GetFileName(data.Name); if (wrap.Equals(BIGFISH_CASINO_ID)) // hide Big Fish Casino Activator { continue; } string strID = "bfg_" + wrap; string strTitle = ""; string strLaunch = ""; string strIconPath = ""; string strUninstall = ""; string strAlias = ""; string strPlatform = GetPlatformString(ENUM); try { //found = true; bool isInstalled = false; strTitle = GetRegStrVal(data, "Name"); // If this is an expired trial, count it as not-installed int activated = (int)GetRegDWORDVal(data, "Activated"); int daysLeft = (int)GetRegDWORDVal(data, "DaysLeft"); int timeLeft = (int)GetRegDWORDVal(data, "TimeLeft"); if (activated > 0 || timeLeft > 0 || daysLeft > 0) { isInstalled = true; CLogger.LogDebug($"- {strTitle}"); } else { CLogger.LogDebug($"- *{strTitle}"); } strLaunch = GetRegStrVal(data, BIGFISH_PATH); strAlias = GetAlias(strTitle); if (strAlias.Equals(strTitle, CDock.IGNORE_CASE)) { strAlias = ""; } //strIconPath = GetRegStrVal(data, "Thumbnail"); // 80x80 strIconPath = GetRegStrVal(data, "feature"); // 175x150 //ushort userRating = (ushort)GetRegDWORDVal(data, "Rating"); // Not used? uint numberRuns = (uint)GetRegDWORDVal(data, "PlayCount"); byte[] dateData = GetRegBinaryVal(data, "LastActionTime"); DateTime lastRun = BFRegToDateTime(dateData); //CLogger.LogDebug(" LastActionTime: " + BitConverter.ToString(dateData) + " -> " + lastRun.ToShortDateString()); List <RegistryKey> unKeyList; using (RegistryKey key2 = Registry.LocalMachine.OpenSubKey(NODE32_REG, RegistryKeyPermissionCheck.ReadSubTree)) // HKLM32 { if (key2 != null) { unKeyList = FindGameFolders(key2, BIGFISH_PREFIX); foreach (var data2 in unKeyList) { if (GetRegStrVal(data2, BIGFISH_ID).Equals(wrap)) { if (string.IsNullOrEmpty(strIconPath)) { strIconPath = GetRegStrVal(data2, GAME_DISPLAY_ICON).Trim(new char[] { ' ', '"' }); } strUninstall = GetRegStrVal(data2, GAME_UNINSTALL_STRING).Trim(new char[] { ' ', '"' }); } } } } if (string.IsNullOrEmpty(strIconPath) && expensiveIcons) { bool success = false; string dir = Path.GetDirectoryName(strLaunch); string xmlPath = Path.Combine(dir, "bfgstate.xml"); try { if (File.Exists(xmlPath)) { XmlDocument doc = new(); doc.Load(xmlPath); //XmlNode node = doc.DocumentElement.SelectSingleNode("thumbnail"); // 80x80 XmlNode node = doc.DocumentElement.SelectSingleNode("feature"); // 175x150 if (node != null) { strIconPath = node.InnerText; if (File.Exists(strIconPath)) { success = true; } else { // Use website to download missing icons if (!(bool)(CConfig.GetConfigBool(CConfig.CFG_IMGDOWN))) { if (CDock.DownloadCustomImage(strTitle, GetIconUrl(GetGameID(strID), strTitle))) { success = true; } } } } } } catch (Exception e) { CLogger.LogError(e); } if (!success) { strIconPath = CGameFinder.FindGameBinaryFile(dir, strTitle); } } if (!(string.IsNullOrEmpty(strLaunch))) { gameDataList.Add( new ImportGameData(strID, strTitle, strLaunch, strIconPath, strUninstall, strAlias, isInstalled, strPlatform, dateLastRun: lastRun, numRuns: numberRuns)); } } catch (Exception e) { CLogger.LogError(e); } } } CLogger.LogDebug("------------------------"); }
/// <summary> /// Selection handler in the 'browse' state. /// Return selection code /// </summary> /// <param name="strHeader">Helper header text block which will appear on top of the console</param> /// <param name="bCanExit">Boolean which controls if the menu can be escaped with ESC</param> /// <param name="options">Array of strings representing the possible selections</param> /// <returns>Index of the selected item from the options parameter or -1 (Exit)</returns> protected virtual int HandleNavigationMenu(string strHeader, bool bCanExit, params string[] options) { // Setup int nCurrentSelection = 0; int nLastSelection = 0; ConsoleKey key; Console.CursorVisible = false; // Print the selections Console.Clear(); Console.WriteLine(strHeader); int nStartY = Console.CursorTop + 1; if (m_MenuType == MenuType.cType_Grid) { DrawGridMenu(nCurrentSelection, nStartY, options); } else if (m_MenuType == MenuType.cType_List) { DrawListMenu(nCurrentSelection, nStartY, options); } do { // Track the current selection if (nCurrentSelection != nLastSelection) { UpdateMenu(nLastSelection, nCurrentSelection, nStartY, options[nLastSelection], options[nCurrentSelection]); } key = Console.ReadKey(true).Key; nLastSelection = nCurrentSelection; CLogger.LogDebug("{0} key registered", key); switch (key) { case ConsoleKey.LeftArrow: CLogger.LogDebug("Cursor on new selection: {0}: {1}", nCurrentSelection, options[nCurrentSelection]); HandleSelectionLeft(ref nCurrentSelection); break; case ConsoleKey.RightArrow: CLogger.LogDebug("Cursor on new selection: {0}: {1}", nCurrentSelection, options[nCurrentSelection]); HandleSelectionRight(ref nCurrentSelection, options.Length); break; case ConsoleKey.UpArrow: CLogger.LogDebug("Cursor on new selection: {0}: {1}", nCurrentSelection, options[nCurrentSelection]); HandleSelectionUp(ref nCurrentSelection); break; case ConsoleKey.DownArrow: CLogger.LogDebug("Cursor on new selection: {0}: {1}", nCurrentSelection, options[nCurrentSelection]); HandleSelectionDown(ref nCurrentSelection, options.Length); break; case ConsoleKey.Escape: if (bCanExit) { return(-1); } break; default: break; } } while(key != ConsoleKey.Enter); Console.CursorVisible = true; return(nCurrentSelection); }