private async void DownloadMinecraftVersionsButton_Click(object sender, RoutedEventArgs e) { LockView(); await MinecraftService.InitializeAsync(); UnlockView(); }
public static async Task <string> DetectVersion(StorageFile resourcePackFile, bool onlyReleases = true) { if (resourcePackFile == null) { throw new ArgumentNullException(nameof(resourcePackFile)); } Logger.WriteLine($"Detecting resource pack version of file {resourcePackFile.Name}."); var relations = await ResourceRelationService.GetOrCreateAsync(); if (relations?.Count == 0) { throw new InvalidOperationException("Retrieved relation set is empty."); } if (!MinecraftService.IsInitialized) { await MinecraftService.InitializeAsync(); } var versionCount = onlyReleases ? MinecraftAPI.Releases.ToDictionary(x => x.Id, x => 0) : MinecraftAPI.Versions.ToDictionary(x => x.Id, x => 0); using (var stream = await resourcePackFile.OpenStreamForReadAsync()) using (var archive = new ZipArchive(stream, ZipArchiveMode.Read)) { foreach (var entry in archive.Entries.ToList()) { var entryPath = entry.FullName.Replace("/", "\\"); foreach (var relation in relations) { foreach (var versionPathPair in relation) { if (versionPathPair.Value.Equals(entryPath) && versionCount.ContainsKey(versionPathPair.Key)) { versionCount[versionPathPair.Key]++; } } } } } var maxCount = versionCount.Max(vp => vp.Value); var mostNominatedVersions = versionCount.Where(r => r.Value == maxCount).Select(vp => vp.Key); string maxVersion = null; foreach (var nominatedVersion in mostNominatedVersions) { if (maxVersion == null) { maxVersion = nominatedVersion; } else { maxVersion = MinecraftAPI.MaxVersion(maxVersion, nominatedVersion); } } return(maxVersion); }
private async Task InitializeApplication() { NavigationService.Lock(); // Sign in to database await AuthService.SignInAsync(); // Ask user for permission await ResourcePackService.EnsureAccessToMinecraftDirectoryAsync(); await MinecraftService.InitializeAsync(); AppSettings.PrintSettings(); NavigationService.Unlock(); }