public static async Task <bool> IsGameUpToDate() { try { if (ManagementData == null) { await PullManagementData(); } if (ManagementData == null) { return(true); } var versionUrl = new Uri(new Uri(ManagementData["PatchURL"]), "version.ver"); string localVersion = await Task.Run(() => File.Exists(VersionPath)?File.ReadAllText(VersionPath) : string.Empty); using (var client = new AquaHttpClient()) { client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); string remoteVersion = await client.DownloadStringTaskAsync(versionUrl); await Task.Run(() => File.WriteAllText(Path.Combine(GameConfigFolder, "_version.ver"), remoteVersion)); return(localVersion == remoteVersion); } } catch { return(true); } }
public static async Task PullManagementData() { using (var client = new AquaHttpClient()) { client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); ManagementData = (await client.DownloadStringTaskAsync(ManagementUrl)) .LineSplit() .Where(x => !string.IsNullOrWhiteSpace(x)) .ToDictionary(x => x.Split('=')[0], y => y.Split('=')[1]); } }
public async Task <bool> SetupProxy(string url) { using (var client = new AquaHttpClient()) { var json = await client.DownloadStringTaskAsync(new Uri(url)); dynamic jsonData = JsonConvert.DeserializeObject(json); if (jsonData.version != 1) { await this.ShowMessageAsync(string.Empty, Text.BadProxyVersion); return(false); } var hostAddress = (await Dns.GetHostAddressesAsync((string)jsonData.host))?.FirstOrDefault()?.ToString(); var file = StripProxyEntries(File.ReadAllLines(HostsPath)).ToArray(); var lines = file.Concat(new[] { "# Dogstar Proxy Start", $"{hostAddress} gs001.pso2gs.net # {jsonData.name} Ship 01", $"{hostAddress} gs016.pso2gs.net # {jsonData.name} Ship 02", $"{hostAddress} gs031.pso2gs.net # {jsonData.name} Ship 03", $"{hostAddress} gs046.pso2gs.net # {jsonData.name} Ship 04", $"{hostAddress} gs061.pso2gs.net # {jsonData.name} Ship 05", $"{hostAddress} gs076.pso2gs.net # {jsonData.name} Ship 06", $"{hostAddress} gs091.pso2gs.net # {jsonData.name} Ship 07", $"{hostAddress} gs106.pso2gs.net # {jsonData.name} Ship 08", $"{hostAddress} gs121.pso2gs.net # {jsonData.name} Ship 09", $"{hostAddress} gs136.pso2gs.net # {jsonData.name} Ship 10", "# Dogstar Proxy End" }); File.WriteAllLines(HostsPath, lines); client.DownloadFileAsync(new Uri((string)jsonData.publickeyurl), Path.Combine(Settings.Default.GameFolder, "publickey.blob")); var gameHost = (await Dns.GetHostAddressesAsync("gs001.pso2gs.net"))?.FirstOrDefault()?.ToString(); if (gameHost != hostAddress) { await this.ShowMessageAsync(Text.Failed, Text.ProxyRevert); File.WriteAllLines(HostsPath, file); return(false); } return(true); } }
private async void metroWindow_Loaded(object sender, RoutedEventArgs e) { _lastTop = Top; _lastLeft = Left; if (!Settings.Default.IsGameInstalled) { var gamefolder = GetTweakerGameFolder(); if (string.IsNullOrWhiteSpace(gamefolder)) { await SetupGameInfo(); } else { var result = await this.ShowMessageAsync(Text.GameDetected, $"\"{gamefolder}\"", AffirmNeg, YesNo); if (result == MessageDialogResult.Affirmative) { Settings.Default.GameFolder = gamefolder; Settings.Default.IsGameInstalled = true; } else { await SetupGameInfo(); } } } if (Settings.Default.IsGameInstalled) { if (!Directory.Exists(Settings.Default.GameFolder)) { var result = await this.ShowMessageAsync(Text.MissingFolder, Text.MovedOrDeleted, AffirmNeg, MovedDeleted); if (result == MessageDialogResult.Affirmative) { await SelectGameFolder(); } else { Settings.Default.IsGameInstalled = false; Settings.Default.GameFolder = string.Empty; await SetupGameInfo(); } } } if (Settings.Default.IsGameInstalled) { await Task.Run(() => CreateDirectoryIfNoneExists(GameConfigFolder)); var editionPath = Path.Combine(Settings.Default.GameFolder, "edition.txt"); var plugins = JsonConvert.DeserializeObject <PluginInfo[]>(Settings.Default.PluginSettings); var pluginInfoPullArray = plugins.Select(x => { using (var client = new AquaHttpClient()) { return(client.DownloadStringTaskAsync(x.Url)); } }).ToArray(); if (File.Exists(editionPath)) { var edition = await Task.Run(() => File.ReadAllText(editionPath)); if (edition != "jp") { await this.ShowMessageAsync(Text.Warning, Text.NonJPPSO2); } } if (!await IsGameUpToDate()) { var result = await this.ShowMessageAsync(Text.GameUpdate, Text.GameUpdateAvailable, AffirmNeg, YesNo); if (result == MessageDialogResult.Affirmative) { await CheckGameFiles(UpdateMethod.Update); } } var updatedPluginInfos = (await Task.WhenAll(pluginInfoPullArray)).Select(JsonConvert.DeserializeObject <PluginInfo>).ToArray(); var pluginsUpdateingTasks = new List <Task>(); PluginManager.DownloadManager = _generalDownloadManager; for (int index = 0; index < updatedPluginInfos.Length; index++) { if (updatedPluginInfos[index].CurrentVersion > plugins[index].CurrentVersion) { if (await this.ShowMessageAsync(Text.UpdateAvailable, string.Format(Text.DownloadLatest, plugins[index].Name), AffirmNeg, YesNo) == MessageDialogResult.Affirmative) { updatedPluginInfos[index].Url = plugins[index].Url; var plugin = plugins[index] = updatedPluginInfos[index]; pluginsUpdateingTasks.Add(plugin.IsEnabled ? PluginManager.Install(plugin) : PluginManager.Install(plugin).ContinueWith(x => PluginManager.Disable(plugin))); } } } if (pluginsUpdateingTasks.Count > 0) { _gameTabController.ChangeTab(GeneralDownloadTab); await Task.WhenAll(pluginsUpdateingTasks); _gameTabController.PreviousTab(); } PluginManager.PluginSettings.AddRange(plugins); if (await IsNewPrecedeAvailable() && await this.ShowMessageAsync(Text.PrecedeAvailable, Text.DownloadLatestPreced, AffirmNeg, YesNo) == MessageDialogResult.Affirmative) { var precedeWindow = new PrecedeWindow { Owner = this, Top = Top + Height, Left = Left }; _isPrecedeDownloading = true; precedeWindow.Show(); precedeWindow.Closed += delegate { _isPrecedeDownloading = false; }; } } EnableGameButtions(Settings.Default.IsGameInstalled); Settings.Default.Save(); }