public string GetInstallDirectory(GameLocalDataResponse localData) { var platform = localData.publishing.softwareList.software.FirstOrDefault(a => a.softwarePlatform == "PCWIN"); if (platform == null) { return(null); } var installPath = GetPathFromPlatformPath(platform.fulfillmentAttributes.installCheckOverride); if (installPath == null || installPath.CompletePath.IsNullOrEmpty() || !File.Exists(installPath.CompletePath)) { return(null); } var action = GetGamePlayTask(localData); if (action?.Type == GameActionType.File) { return(action.WorkingDir); } else { return(Path.GetDirectoryName(installPath.CompletePath)); } }
internal GameLocalDataResponse GetLocalManifest(string id, string packageName = null, bool useDataCache = false) { var package = packageName; var cachePath = Origin.GetCachePath(playniteApi.GetPluginUserDataPath(this)); if (string.IsNullOrEmpty(package)) { package = id.Replace(":", ""); } var cacheFile = Path.Combine(cachePath, Path.GetFileNameWithoutExtension(package) + ".json"); if (useDataCache == true && File.Exists(cacheFile)) { return(JsonConvert.DeserializeObject <GameLocalDataResponse>(File.ReadAllText(cacheFile, Encoding.UTF8))); } else if (useDataCache == true && !File.Exists(cacheFile)) { logger.Debug($"Downloading game manifest {id}"); FileSystem.CreateDirectory(cachePath); try { var data = OriginApiClient.GetGameLocalData(id); File.WriteAllText(cacheFile, JsonConvert.SerializeObject(data), Encoding.UTF8); return(data); } catch (WebException exc) when((exc.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { logger.Info($"Origin manifest {id} not found on EA server, generating fake manifest."); var data = new GameLocalDataResponse() { offerId = id, offerType = "Doesn't exists" }; File.WriteAllText(cacheFile, JsonConvert.SerializeObject(data), Encoding.UTF8); return(data); } } else { return(OriginApiClient.GetGameLocalData(id)); } }
public GameAction GetGamePlayTask(GameLocalDataResponse manifest) { var platform = manifest.publishing.softwareList.software.FirstOrDefault(a => a.softwarePlatform == "PCWIN"); var playAction = new GameAction() { IsHandledByPlugin = true }; if (string.IsNullOrEmpty(platform.fulfillmentAttributes.executePathOverride)) { return(null); } if (platform.fulfillmentAttributes.executePathOverride.Contains(@"://")) { playAction.Type = GameActionType.URL; playAction.Path = platform.fulfillmentAttributes.executePathOverride; } else { var executePath = GetPathFromPlatformPath(platform.fulfillmentAttributes.executePathOverride); if (executePath.EndsWith("installerdata.xml", StringComparison.OrdinalIgnoreCase)) { var doc = XDocument.Load(executePath); var root = XElement.Parse(doc.ToString()); var elem = root.Element("runtime")?.Element("launcher")?.Element("filePath"); var path = elem?.Value; if (path != null) { executePath = GetPathFromPlatformPath(path); playAction.WorkingDir = Path.GetDirectoryName(executePath); playAction.Path = executePath; } } else { playAction.WorkingDir = Path.GetDirectoryName(GetPathFromPlatformPath(platform.fulfillmentAttributes.installCheckOverride)); playAction.Path = executePath; } } return(playAction); }
public GameAction GetGamePlayTask(GameLocalDataResponse manifest) { var platform = manifest.publishing.softwareList.software.FirstOrDefault(a => a.softwarePlatform == "PCWIN"); var playAction = new GameAction() { IsHandledByPlugin = true }; if (string.IsNullOrEmpty(platform.fulfillmentAttributes.executePathOverride)) { return(null); } if (platform.fulfillmentAttributes.executePathOverride.Contains(@"://")) { playAction.Type = GameActionType.URL; playAction.Path = platform.fulfillmentAttributes.executePathOverride; } else { var executePath = GetPathFromPlatformPath(platform.fulfillmentAttributes.executePathOverride); if (executePath != null) { if (executePath.CompletePath.EndsWith("installerdata.xml", StringComparison.OrdinalIgnoreCase)) { return(GetGamePlayTask(executePath.CompletePath)); } else { playAction.WorkingDir = executePath.Root; playAction.Path = executePath.CompletePath; } } } return(playAction); }
public Dictionary <string, Game> GetInstalledGames(bool useDataCache = false) { var contentPath = Path.Combine(Origin.DataPath, "LocalContent"); var games = new Dictionary <string, Game>(); if (Directory.Exists(contentPath)) { var packages = Directory.GetFiles(contentPath, "*.mfst", SearchOption.AllDirectories); foreach (var package in packages) { try { var gameId = Path.GetFileNameWithoutExtension(package); if (!gameId.StartsWith("Origin")) { // Get game id by fixing file via adding : before integer part of the name // for example OFB-EAST52017 converts to OFB-EAST:52017 var match = Regex.Match(gameId, @"^(.*?)(\d+)$"); if (!match.Success) { logger.Warn("Failed to get game id from file " + package); continue; } gameId = match.Groups[1].Value + ":" + match.Groups[2].Value; } var newGame = new Game() { PluginId = Id, Source = "Origin", GameId = gameId, IsInstalled = true }; GameLocalDataResponse localData = null; try { localData = GetLocalManifest(gameId, package, useDataCache); } catch (Exception e) when(!Environment.IsDebugBuild) { logger.Error(e, $"Failed to get Origin manifest for a {gameId}, {package}"); continue; } if (localData.offerType != "Base Game" && localData.offerType != "DEMO") { continue; } newGame.Name = StringExtensions.NormalizeGameName(localData.localizableAttributes.displayName); var platform = localData.publishing.softwareList.software.FirstOrDefault(a => a.softwarePlatform == "PCWIN"); if (platform == null) { logger.Warn(gameId + " game doesn't have windows platform, skipping install import."); continue; } var installPath = GetPathFromPlatformPath(platform.fulfillmentAttributes.installCheckOverride); if (string.IsNullOrEmpty(installPath) || !File.Exists(installPath)) { continue; } newGame.PlayAction = GetGamePlayTask(localData); if (newGame.PlayAction?.Type == GameActionType.File) { newGame.InstallDirectory = newGame.PlayAction.WorkingDir; newGame.PlayAction.WorkingDir = newGame.PlayAction.WorkingDir.Replace(newGame.InstallDirectory, "{InstallDir}"); newGame.PlayAction.Path = newGame.PlayAction.Path.Replace(newGame.InstallDirectory, "").Trim(new char[] { '\\', '/' }); } else { newGame.InstallDirectory = Path.GetDirectoryName(installPath); } games.Add(newGame.GameId, newGame); } catch (Exception e) when(!Environment.IsDebugBuild) { logger.Error(e, $"Failed to import installed Origin game {package}."); } } } return(games); }
public Dictionary <string, GameInfo> GetInstalledGames() { var contentPath = Path.Combine(Origin.DataPath, "LocalContent"); var games = new Dictionary <string, GameInfo>(); if (Directory.Exists(contentPath)) { var packages = Directory.GetFiles(contentPath, "*.mfst", SearchOption.AllDirectories); foreach (var package in packages) { try { var gameId = Path.GetFileNameWithoutExtension(package); if (!gameId.StartsWith("Origin")) { // Get game id by fixing file via adding : before integer part of the name // for example OFB-EAST52017 converts to OFB-EAST:52017 var match = Regex.Match(gameId, @"^(.*?)(\d+)$"); if (!match.Success) { logger.Warn("Failed to get game id from file " + package); continue; } gameId = match.Groups[1].Value + ":" + match.Groups[2].Value; } var newGame = new GameInfo() { Source = "Origin", GameId = gameId, IsInstalled = true, Platform = "PC" }; GameLocalDataResponse localData = null; try { localData = GetLocalManifest(gameId); } catch (Exception e) when(!Environment.IsDebugBuild) { logger.Error(e, $"Failed to get Origin manifest for a {gameId}, {package}"); continue; } if (localData == null) { continue; } if (localData.offerType != "Base Game" && localData.offerType != "DEMO") { continue; } newGame.Name = StringExtensions.NormalizeGameName(localData.localizableAttributes.displayName); var installDir = GetInstallDirectory(localData); if (installDir.IsNullOrEmpty()) { continue; } newGame.InstallDirectory = installDir; newGame.PlayAction = new GameAction { IsHandledByPlugin = true, Type = GameActionType.URL, Path = Origin.GetLaunchString(gameId) }; games.Add(newGame.GameId, newGame); } catch (Exception e) when(!Environment.IsDebugBuild) { logger.Error(e, $"Failed to import installed Origin game {package}."); } } } return(games); }
public Dictionary <string, GameInfo> GetInstalledGames() { var contentPath = Path.Combine(Origin.DataPath, "LocalContent"); var games = new Dictionary <string, GameInfo>(); if (Directory.Exists(contentPath)) { var packages = Directory.GetFiles(contentPath, "*.mfst", SearchOption.AllDirectories); foreach (var package in packages) { try { var gameId = Path.GetFileNameWithoutExtension(package); if (!gameId.StartsWith("Origin")) { // Get game id by fixing file via adding : before integer part of the name // for example OFB-EAST52017 converts to OFB-EAST:52017 var match = Regex.Match(gameId, @"^(.*?)(\d+)$"); if (!match.Success) { logger.Warn("Failed to get game id from file " + package); continue; } gameId = match.Groups[1].Value + ":" + match.Groups[2].Value; } var newGame = new GameInfo() { Source = "Origin", GameId = gameId, IsInstalled = true }; GameLocalDataResponse localData = null; try { localData = GetLocalManifest(gameId); } catch (Exception e) when(!Environment.IsDebugBuild) { logger.Error(e, $"Failed to get Origin manifest for a {gameId}, {package}"); continue; } if (localData == null) { continue; } if (localData.offerType != "Base Game" && localData.offerType != "DEMO") { continue; } newGame.Name = StringExtensions.NormalizeGameName(localData.localizableAttributes.displayName); var platform = localData.publishing.softwareList.software.FirstOrDefault(a => a.softwarePlatform == "PCWIN"); if (platform == null) { logger.Warn(gameId + " game doesn't have windows platform, skipping install import."); continue; } var installPath = GetPathFromPlatformPath(platform.fulfillmentAttributes.installCheckOverride); if (installPath == null || installPath.CompletePath.IsNullOrEmpty() || !File.Exists(installPath.CompletePath)) { continue; } var installDirReplacement = ExpandableVariables.InstallationDirectory + Path.DirectorySeparatorChar; newGame.PlayAction = GetGamePlayTask(localData); if (newGame.PlayAction?.Type == GameActionType.File) { newGame.InstallDirectory = newGame.PlayAction.WorkingDir; newGame.PlayAction.Path = newGame.PlayAction.Path.Replace(newGame.InstallDirectory, installDirReplacement); } else { newGame.InstallDirectory = Path.GetDirectoryName(installPath.CompletePath); } // For games like Sims 4 if (newGame.PlayAction?.Path.EndsWith("exe", StringComparison.OrdinalIgnoreCase) == false) { var task = GetGamePlayTask(newGame.InstallDirectory); newGame.InstallDirectory = task.WorkingDir; newGame.PlayAction.Path = task.Path.Replace(newGame.InstallDirectory, installDirReplacement); } // If game uses EasyAntiCheat then use executable referenced by it if (Origin.GetGameUsesEasyAntiCheat(newGame.InstallDirectory)) { var eac = EasyAntiCheat.GetLauncherSettings(newGame.InstallDirectory); if (newGame.PlayAction == null) { newGame.PlayAction = new GameAction { Type = GameActionType.File, IsHandledByPlugin = true }; } newGame.PlayAction.Path = eac.Executable.Replace(newGame.InstallDirectory, installDirReplacement); if (!string.IsNullOrEmpty(eac.Parameters) && eac.UseCmdlineParameters == "1") { newGame.PlayAction.Arguments = eac.Parameters; } if (!string.IsNullOrEmpty(eac.WorkingDirectory)) { newGame.PlayAction.WorkingDir = Path.Combine(ExpandableVariables.InstallationDirectory, eac.WorkingDirectory); } } if (newGame.PlayAction != null) { if (!newGame.PlayAction.Path.Contains(ExpandableVariables.InstallationDirectory)) { newGame.PlayAction.Path = installDirReplacement + newGame.PlayAction.Path; } newGame.PlayAction.WorkingDir = null; games.Add(newGame.GameId, newGame); } else { logger.Warn("Found installed Origin game that's not launchable, skipping import."); logger.Warn(newGame.ToString()); } } catch (Exception e) when(!Environment.IsDebugBuild) { logger.Error(e, $"Failed to import installed Origin game {package}."); } } } return(games); }
public Dictionary <string, GameInfo> GetInstalledGames() { var games = new Dictionary <string, GameInfo>(); foreach (var package in GetInstallPackages()) { try { var newGame = new GameInfo() { Source = "Origin", GameId = package.ConvertedId, IsInstalled = true, Platform = "PC" }; GameLocalDataResponse localData = null; try { localData = GetLocalManifest(package.ConvertedId); } catch (Exception e) when(!Environment.IsDebugBuild) { logger.Error(e, $"Failed to get Origin manifest for a {package.ConvertedId}, {package}"); continue; } if (localData == null) { continue; } if (localData.offerType != "Base Game" && localData.offerType != "DEMO") { continue; } newGame.Name = StringExtensions.NormalizeGameName(localData.localizableAttributes.displayName); var installDir = GetInstallDirectory(localData); if (installDir.IsNullOrEmpty()) { continue; } newGame.InstallDirectory = installDir; newGame.PlayAction = new GameAction { IsHandledByPlugin = true, Type = GameActionType.URL, Path = Origin.GetLaunchString(package.ConvertedId + package.Source) }; games.Add(newGame.GameId, newGame); } catch (Exception e) when(!Environment.IsDebugBuild) { logger.Error(e, $"Failed to import installed Origin game {package}."); } } return(games); }