public static async void ReadDetailsFromZip(string ZipPath, Definitions.Library targetLibrary) { try { // Open archive for read using (ZipArchive Archive = ZipFile.OpenRead(ZipPath)) { if (Archive.Entries.Count > 0) { // For each file in opened archive foreach (ZipArchiveEntry AcfEntry in Archive.Entries.Where(x => x.Name.Contains("appmanifest_"))) { // If it contains // Define a KeyValue reader Framework.KeyValue KeyValReader = new Framework.KeyValue(); // Open .acf file from archive as text KeyValReader.ReadAsText(AcfEntry.Open()); // If acf file has no children, skip this archive if (KeyValReader.Children.Count == 0) { continue; } AddSteamApp(Convert.ToInt32(KeyValReader["appID"].Value), !string.IsNullOrEmpty(KeyValReader["name"].Value) ? KeyValReader["name"].Value : KeyValReader["UserConfig"]["name"].Value, KeyValReader["installdir"].Value, targetLibrary, Convert.ToInt64(KeyValReader["SizeOnDisk"].Value), Convert.ToInt64(KeyValReader["LastUpdated"].Value), true); } } } } catch (IOException IEx) { await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate { if (await Main.FormAccessor.ShowMessageAsync(SLM.Translate(nameof(Properties.Resources.ReadZip_IOException)), Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.ReadZip_IOExceptionMessage)), new { ZipPath }), MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { NegativeButtonText = SLM.Translate(Properties.Resources.ReadZip_DontDelete) }) == MessageDialogResult.Affirmative) { File.Delete(ZipPath); } }); System.Diagnostics.Debug.WriteLine(IEx); logger.Fatal(IEx); } catch (InvalidDataException IEx) { await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate { if (await Main.FormAccessor.ShowMessageAsync(SLM.Translate(nameof(Properties.Resources.ReadZip_InvalidDataException)), Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.ReadZip_InvalidDataExceptionMessage)), new { ZipPath }), MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { NegativeButtonText = SLM.Translate(Properties.Resources.ReadZip_DontDelete) }) == MessageDialogResult.Affirmative) { File.Delete(ZipPath); } }); System.Diagnostics.Debug.WriteLine(IEx); logger.Fatal(IEx); } catch (Exception ex) { logger.Fatal(ex); } }
public static async void ReadDetailsFromZip(string ZipPath, Definitions.Library targetLibrary) { try { // Open archive for read using (ZipArchive Archive = ZipFile.OpenRead(ZipPath)) { if (Archive.Entries.Count > 0) { // For each file in opened archive foreach (ZipArchiveEntry AcfEntry in Archive.Entries.Where(x => x.Name.Contains("appmanifest_"))) { // If it contains // Define a KeyValue reader Framework.KeyValue KeyValReader = new Framework.KeyValue(); // Open .acf file from archive as text KeyValReader.ReadAsText(AcfEntry.Open()); // If acf file has no children, skip this archive if (KeyValReader.Children.Count == 0) { continue; } AddSteamApp(Convert.ToInt32(KeyValReader["appID"].Value), !string.IsNullOrEmpty(KeyValReader["name"].Value) ? KeyValReader["name"].Value : KeyValReader["UserConfig"]["name"].Value, KeyValReader["installdir"].Value, targetLibrary, Convert.ToInt64(KeyValReader["SizeOnDisk"].Value), Convert.ToInt64(KeyValReader["LastUpdated"].Value), true); } } } } catch (IOException IEx) { await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate { if (await Main.FormAccessor.ShowMessageAsync("An error happened while parsing zip file", $"An error happened while parsing zip file:\n\n{ZipPath}\n\nIt is still suggested to check the archive file manually to see if it is really corrupted or not!\n\nWould you like to remove the given archive file?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { NegativeButtonText = "Do NOT Remove the archive file" }) == MessageDialogResult.Affirmative) { new FileInfo(ZipPath).Delete(); } }); System.Diagnostics.Debug.WriteLine(IEx); logger.Fatal(IEx); } catch (InvalidDataException IEx) { await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate { if (await Main.FormAccessor.ShowMessageAsync("An error happened while parsing zip file", $"An error happened while parsing zip file:\n\n{ZipPath}\n\nIt is still suggested to check the archive file manually to see if it is really corrupted or not!\n\nWould you like to remove the given archive file?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { NegativeButtonText = "Do NOT Remove the archive file" }) == MessageDialogResult.Affirmative) { new FileInfo(ZipPath).Delete(); } }); System.Diagnostics.Debug.WriteLine(IEx); logger.Fatal(IEx); } catch (Exception ex) { Definitions.SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex)); logger.Fatal(ex); } }