public GameTask GetGamePlayTask(GameLocalDataResponse manifest) { var platform = manifest.publishing.softwareList.software.FirstOrDefault(a => a.softwarePlatform == "PCWIN"); var playTask = new GameTask() { IsBuiltIn = true, IsPrimary = true }; if (string.IsNullOrEmpty(platform.fulfillmentAttributes.executePathOverride)) { return(null); } if (platform.fulfillmentAttributes.executePathOverride.Contains(@"://")) { playTask.Type = GameTaskType.URL; playTask.Path = platform.fulfillmentAttributes.executePathOverride; } else { var executePath = GetPathFromPlatformPath(platform.fulfillmentAttributes.executePathOverride); playTask.WorkingDir = Path.GetDirectoryName(GetPathFromPlatformPath(platform.fulfillmentAttributes.installCheckOverride)); playTask.Path = executePath; } return(playTask); }
public OriginGameStateMonitor(string id, IOriginLibrary originLibrary) { this.id = id; library = originLibrary; manifest = library.GetLocalManifest(id, null, true); platform = manifest.publishing.softwareList.software.FirstOrDefault(a => a.softwarePlatform == "PCWIN"); }
public GameLocalDataResponse GetLocalManifest(string id, string packageName = null, bool useDataCache = false) { var package = packageName; if (string.IsNullOrEmpty(package)) { package = id.Replace(":", ""); } var cacheFile = Path.Combine(OriginPaths.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(OriginPaths.CachePath); try { var data = WebApiClient.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(WebApiClient.GetGameLocalData(id)); } }
public GameTask GetGamePlayTask(GameLocalDataResponse manifest) { var platform = manifest.publishing.softwareList.software.FirstOrDefault(a => a.softwarePlatform == "PCWIN"); var playTask = new GameTask() { IsBuiltIn = true, IsPrimary = true }; if (string.IsNullOrEmpty(platform.fulfillmentAttributes.executePathOverride)) { return(null); } if (platform.fulfillmentAttributes.executePathOverride.Contains(@"://")) { playTask.Type = GameTaskType.URL; playTask.Path = platform.fulfillmentAttributes.executePathOverride; } else { var executePath = GetPathFromPlatformPath(platform.fulfillmentAttributes.executePathOverride); if (executePath.EndsWith("installerdata.xml", StringComparison.InvariantCultureIgnoreCase)) { 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); playTask.WorkingDir = Path.GetDirectoryName(executePath); playTask.Path = executePath; } } else { playTask.WorkingDir = Path.GetDirectoryName(GetPathFromPlatformPath(platform.fulfillmentAttributes.installCheckOverride)); playTask.Path = executePath; } } return(playTask); }
public List <Game> GetInstalledGames(bool useDataCache = false) { var contentPath = Path.Combine(OriginPaths.DataPath, "LocalContent"); var games = new List <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() { Provider = Provider.Origin, Source = Enums.GetEnumDescription(Provider.Origin), ProviderId = gameId }; GameLocalDataResponse localData = null; try { localData = GetLocalManifest(gameId, package, useDataCache); } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { 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.InstallDirectory = Path.GetDirectoryName(installPath); newGame.PlayTask = GetGamePlayTask(localData); if (newGame.PlayTask?.Type == GameTaskType.File) { newGame.PlayTask.WorkingDir = newGame.PlayTask.WorkingDir.Replace(newGame.InstallDirectory, "{InstallDir}"); newGame.PlayTask.Path = newGame.PlayTask.Path.Replace(newGame.InstallDirectory, "{InstallDir}"); } games.Add(newGame); } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, $"Failed to import installed Origin game {package}."); } } } return(games); }
public List <IGame> GetInstalledGames(bool useDataCache = false) { var contentPath = Path.Combine(OriginPaths.DataPath, "LocalContent"); var games = new List <IGame>(); if (Directory.Exists(contentPath)) { var packages = Directory.GetFiles(contentPath, "*.mfst", SearchOption.AllDirectories); foreach (var package in packages) { 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() { Provider = Provider.Origin, ProviderId = gameId }; GameLocalDataResponse localData = GetLocalManifest(gameId, package, useDataCache); if (localData.offerType != "Base Game" && localData.offerType != "DEMO") { continue; } newGame.Name = 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.InstallDirectory = Path.GetDirectoryName(installPath); newGame.PlayTask = GetGamePlayTask(localData); games.Add(newGame); } } return(games); }