public static async void AddNewLibraryAsync(string libraryPath, bool isMainLibrary = false) { try { if (!libraryPath.EndsWith(Path.DirectorySeparatorChar.ToString())) { libraryPath += Path.DirectorySeparatorChar; } var newLibrary = new Definitions.OriginLibrary(libraryPath, isMainLibrary); Definitions.List.LibraryProgress.Report(newLibrary); await Task.Run(newLibrary.UpdateAppList).ConfigureAwait(true); } catch (Exception ex) { Logger.Fatal(ex); } }
public static async Task ParseAppDetailsAsync(Stream fileStream, string installerFilePath, Definitions.OriginLibrary library, bool isCompressed = false) { try { if (!isCompressed && new FileInfo(installerFilePath).Directory.Parent.Parent.Name != new DirectoryInfo(library.FullPath).Name) { return; } var installerLog = Path.Combine(Directory.GetParent(installerFilePath).FullName, "InstallLog.txt"); var installedLocale = "en_US"; if (!isCompressed && File.Exists(installerLog)) { foreach (var line in File.ReadAllLines(installerLog)) { if (!line.Contains("Install Locale:")) { continue; } installedLocale = line.Split(new string[] { "Install Locale:" }, StringSplitOptions.None)[1]; break; } installedLocale = installedLocale.Replace(" ", ""); } var xml = XDocument.Load(fileStream); var manifestVersion = new Version((xml.Root.Name.LocalName == "game") ? xml.Root.Attribute("manifestVersion").Value : ((xml.Root.Name.LocalName == "DiPManifest") ? xml.Root.Attribute("version").Value : "1.0")); Definitions.OriginAppInfo originAppInfo = null; if (manifestVersion == new Version("4.0")) { originAppInfo = new Definitions.OriginAppInfo(library, xml.Root.Element("gameTitles")?.Elements("gameTitle") ?.First(x => x.Attribute("locale").Value == "en_US")?.Value, Convert.ToInt32(xml.Root.Element("contentIDs")?.Elements() .FirstOrDefault(x => int.TryParse(x.Value, out int appId))?.Value), (isCompressed) ? new FileInfo(installerFilePath).Directory : new FileInfo(installerFilePath).Directory.Parent, new Version(xml.Root.Element("buildMetaData")?.Element("gameVersion") ?.Attribute("version")?.Value), xml.Root.Element("installMetaData")?.Element("locales")?.Value.Split(','), installedLocale, isCompressed, xml.Root.Element("touchup")?.Element("filePath")?.Value, xml.Root.Element("touchup")?.Element("parameters")?.Value, xml.Root.Element("touchup")?.Element("updateParameters")?.Value, xml.Root.Element("touchup")?.Element("repairParameters")?.Value); } else if (manifestVersion >= new Version("1.1") && manifestVersion <= new Version("3.0")) { var locales = new List <string>(); foreach (var locale in xml.Root.Element("metadata")?.Elements("localeInfo") ?.Attributes()?.Where(x => x.Name == "locale")) { locales.Add(locale.Value); } originAppInfo = new Definitions.OriginAppInfo(library, xml.Root.Element("metadata")?.Elements("localeInfo") ?.First(x => x.Attribute("locale").Value == "en_US")?.Element("title").Value, Convert.ToInt32(xml.Root.Element("contentIDs")?.Element("contentID")?.Value .Replace("EAX", "")), (isCompressed) ? new FileInfo(installerFilePath).Directory : new FileInfo(installerFilePath).Directory.Parent, new Version(xml.Root.Attribute("gameVersion").Value), locales.ToArray(), installedLocale, isCompressed, xml.Root.Element("executable")?.Element("filePath")?.Value, xml.Root.Element("executable")?.Element("parameters")?.Value); } else { MessageBox.Show(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.OriginUnknownManifestFile)), new { ManifestVersion = manifestVersion, OriginApp = installerFilePath })); return; } if (Definitions.Global.Origin.AppIds.Count(x => x.Key == originAppInfo.InstallationDirectory.Name) > 0) { var appId = Definitions.Global.Origin.AppIds.First(x => x.Key == originAppInfo.InstallationDirectory.Name); var appLocalData = library.GetGameLocalData(appId.Value); if (appLocalData != null) { await Framework.CachedImage.FileCache.HitAsync(string.Concat(appLocalData["customAttributes"]["imageServer"], appLocalData["localizableAttributes"]["packArtLarge"]) , $"{originAppInfo.AppId}_o") .ConfigureAwait(false); } } originAppInfo.GameHeaderImage = $"{Definitions.Directories.SLM.Cache}\\{originAppInfo.AppId}_o.jpg"; library.Apps.Add(originAppInfo); } catch (Exception ex) { Debug.WriteLine(ex); Logger.Error(ex); } }