Compare commits

..

No commits in common. "e4dfd38dd355faccbbd6ec7d92db8be7555206aa" and "19f460d12d3cd56303604ddf15fca0541cbe13fc" have entirely different histories.

2 changed files with 30 additions and 126 deletions

View File

@ -6,7 +6,6 @@ using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using GoldbergGUI.Core.Models;
using GoldbergGUI.Core.Utils;
using MvvmCross.Logging;
@ -23,9 +22,7 @@ namespace GoldbergGUI.Core.Services
public Task Save(string path, GoldbergConfiguration configuration);
public Task<GoldbergGlobalConfiguration> GetGlobalSettings();
public Task SetGlobalSettings(GoldbergGlobalConfiguration configuration);
public bool GoldbergApplied(string path);
// public Task<bool> Download();
// public Task Extract(string archivePath);
public Task GenerateInterfacesFile(string filePath);
@ -50,9 +47,7 @@ namespace GoldbergGUI.Core.Services
private readonly string _accountNamePath = Path.Combine(GlobalSettingsPath, "settings/account_name.txt");
private readonly string _userSteamIdPath = Path.Combine(GlobalSettingsPath, "settings/user_steam_id.txt");
private readonly string _languagePath = Path.Combine(GlobalSettingsPath, "settings/language.txt");
private readonly string _customBroadcastIpsPath =
Path.Combine(GlobalSettingsPath, "settings/custom_broadcasts.txt");
private readonly string _customBroadcastIpsPath = Path.Combine(GlobalSettingsPath, "settings/custom_broadcasts.txt");
// ReSharper disable StringLiteralTypo
private readonly List<string> _interfaceNames = new List<string>
@ -90,11 +85,7 @@ namespace GoldbergGUI.Core.Services
_log = log;
var download = await Download().ConfigureAwait(false);
if (download)
{
await Extract(_goldbergZipPath).ConfigureAwait(false);
}
if (download) await Extract(_goldbergZipPath).ConfigureAwait(false);
return await GetGlobalSettings().ConfigureAwait(false);
}
@ -113,16 +104,13 @@ namespace GoldbergGUI.Core.Services
!long.TryParse(File.ReadLines(_userSteamIdPath).First().Trim(), out steamId) &&
steamId < 76561197960265729 && steamId > 76561202255233023)
{
_log.Error("Invalid User Steam ID! Using default Steam ID...");
steamId = DefaultSteamId;
_log.Error("Invalid User Steam ID!");
}
if (File.Exists(_languagePath)) language = File.ReadLines(_languagePath).First().Trim();
if (File.Exists(_customBroadcastIpsPath))
customBroadcastIps.AddRange(
File.ReadLines(_customBroadcastIpsPath).Select(line => line.Trim()));
}).ConfigureAwait(false);
_log.Info("Got global settings.");
return new GoldbergGlobalConfiguration
{
AccountName = accountName,
@ -154,7 +142,6 @@ namespace GoldbergGUI.Core.Services
await File.Create(_accountNamePath).DisposeAsync().ConfigureAwait(false);
await File.WriteAllTextAsync(_accountNamePath, DefaultAccountName).ConfigureAwait(false);
}
// User SteamID
if (userSteamId >= 76561197960265729 && userSteamId <= 76561202255233023)
{
@ -170,7 +157,6 @@ namespace GoldbergGUI.Core.Services
await File.Create(_userSteamIdPath).DisposeAsync().ConfigureAwait(false);
await File.WriteAllTextAsync(_userSteamIdPath, DefaultSteamId.ToString()).ConfigureAwait(false);
}
// Language
if (!string.IsNullOrEmpty(language))
{
@ -186,7 +172,6 @@ namespace GoldbergGUI.Core.Services
await File.Create(_languagePath).DisposeAsync().ConfigureAwait(false);
await File.WriteAllTextAsync(_languagePath, DefaultLanguage).ConfigureAwait(false);
}
// Custom Broadcast IPs
if (customBroadcastIps != null && customBroadcastIps.Count > 0)
{
@ -202,7 +187,6 @@ namespace GoldbergGUI.Core.Services
_log.Info("Empty list of custom broadcast IPs! Skipping...");
await Task.Run(() => File.Delete(_customBroadcastIpsPath)).ConfigureAwait(false);
}
_log.Info("Setting global configuration finished.");
}
// If first time, call GenerateInterfaces
@ -286,8 +270,7 @@ namespace GoldbergGUI.Core.Services
}
// create steam_appid.txt
await File.WriteAllTextAsync(Path.Combine(path, "steam_appid.txt"), c.AppId.ToString())
.ConfigureAwait(false);
await File.WriteAllTextAsync(Path.Combine(path, "steam_appid.txt"), c.AppId.ToString()).ConfigureAwait(false);
// DLC
if (c.DlcList.Count > 0)
@ -378,8 +361,6 @@ namespace GoldbergGUI.Core.Services
var jobIdPath = Path.Combine(_goldbergPath, "job_id");
var match = regex.Match(body);
if (File.Exists(jobIdPath))
{
try
{
_log.Info("Check if update is needed...");
var jobIdLocal = Convert.ToInt32(File.ReadLines(jobIdPath).First().Trim());
@ -391,105 +372,36 @@ namespace GoldbergGUI.Core.Services
return false;
}
}
catch (Exception)
{
_log.Error("An error occured, local Goldberg setup might be broken!");
}
}
_log.Info("Starting download...");
await StartDownload(match.Value).ConfigureAwait(false);
return true;
}
private async Task StartDownload(string downloadUrl)
{
try
{
var client = new HttpClient();
_log.Debug(downloadUrl);
await using var fileStream = File.OpenWrite(_goldbergZipPath);
//client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead)
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Head, downloadUrl);
var headResponse = await client.SendAsync(httpRequestMessage).ConfigureAwait(false);
var contentLength = headResponse.Content.Headers.ContentLength;
await client.GetFileAsync(downloadUrl, fileStream).ContinueWith(async t =>
{
await fileStream.DisposeAsync().ConfigureAwait(false);
var fileLength = new FileInfo(_goldbergZipPath).Length;
// Environment.Exit(128);
if (contentLength == fileLength)
var task = client.GetFileAsync(downloadUrl, fileStream).ConfigureAwait(false);
await task;
if (task.GetAwaiter().IsCompleted)
{
_log.Info("Download finished!");
}
else
{
throw new Exception("File size does not match!");
}
}).ConfigureAwait(false);
}
catch (Exception e)
{
ShowErrorMessage();
_log.Error(e.ToString);
Environment.Exit(1);
}
}
// Empty subfolder ./goldberg/
// Extract all from archive to subfolder ./goldberg/
private async Task Extract(string archivePath)
{
var errorOccured = false;
_log.Debug("Start extraction...");
Directory.Delete(_goldbergPath, true);
Directory.CreateDirectory(_goldbergPath);
using (var archive = await Task.Run(() => ZipFile.OpenRead(archivePath)).ConfigureAwait(false))
{
foreach (var entry in archive.Entries)
{
await Task.Run(() =>
{
try
{
var fullPath = Path.Combine(_goldbergPath, entry.FullName);
if (string.IsNullOrEmpty(entry.Name))
{
Directory.CreateDirectory(fullPath);
}
else
{
entry.ExtractToFile(fullPath, true);
}
}
catch (Exception e)
{
errorOccured = true;
_log.Error($"Error while trying to extract {entry.FullName}");
_log.Error(e.ToString);
}
}).ConfigureAwait(false);
}
}
if (errorOccured)
{
ShowErrorMessage();
_log.Warn("Error occured while extraction! Please setup Goldberg manually");
}
_log.Info("Extraction was successful!");
}
private void ShowErrorMessage()
{
if (Directory.Exists(_goldbergPath))
{
Directory.Delete(_goldbergPath, true);
}
Directory.CreateDirectory(_goldbergPath);
MessageBox.Show("Could not setup Goldberg Emulator!\n" +
"Please download it manually and extract its content into the \"goldberg\" subfolder!");
ZipFile.ExtractToDirectory(archivePath, _goldbergPath);
}).ConfigureAwait(false);
_log.Debug("Extraction done!");
}
// https://gitlab.com/Mr_Goldberg/goldberg_emulator/-/blob/master/generate_interfaces_file.cpp

View File

@ -193,10 +193,10 @@ namespace GoldbergGUI.Core.Services
public async Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb)
{
_log.Info("Get DLC");
var dlcList = new List<SteamApp>();
if (steamApp != null)
{
_log.Info($"Get DLC for App {steamApp}");
var task = AppDetails.GetAsync(steamApp.AppId);
var steamAppDetails = await task.ConfigureAwait(true);
if (steamAppDetails.Type == AppType.Game.Value)
@ -216,17 +216,15 @@ namespace GoldbergGUI.Core.Services
// Scrape and parse HTML page
// Add missing to DLC list
// Return current list if we don't intend to use SteamDB
if (!useSteamDb) return dlcList;
try
// ReSharper disable once InvertIf
if (useSteamDb)
{
var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/");
var client = new HttpClient();
client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
_log.Info($"Get SteamDB App {steamApp}");
_log.Info("Get SteamDB App");
var httpCall = client.GetAsync(steamDbUri);
var response = await httpCall.ConfigureAwait(false);
_log.Debug(httpCall.Status.ToString());
@ -242,7 +240,6 @@ namespace GoldbergGUI.Core.Services
var query1 = doc.QuerySelector("#dlc");
if (query1 != null)
{
_log.Info("Got list of DLC from SteamDB.");
var query2 = query1.QuerySelectorAll(".app");
foreach (var element in query2)
{
@ -271,11 +268,6 @@ namespace GoldbergGUI.Core.Services
_log.Error("Could not get DLC from SteamDB!");
}
}
catch (Exception e)
{
_log.Error("Could not get DLC from SteamDB! Skipping...");
_log.Error(e.ToString);
}
}
else
{