Added new class GoldbergConfiguration.
Global settings can now be saved and reset. Language can now be edited (globally). If Cache is broken, try to forcibly update it from the API.
This commit is contained in:
parent
2b9ee795fb
commit
1540e6cb7a
13
GoldbergGUI.Core/Models/GoldbergModel.cs
Normal file
13
GoldbergGUI.Core/Models/GoldbergModel.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace GoldbergGUI.Core.Models
|
||||||
|
{
|
||||||
|
public class GoldbergConfiguration
|
||||||
|
{
|
||||||
|
public int AppId { get; set; }
|
||||||
|
public List<SteamApp> DlcList { get; set; }
|
||||||
|
public bool Offline { get; set; }
|
||||||
|
public bool DisableNetworking { get; set; }
|
||||||
|
public bool DisableOverlay { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -17,29 +17,35 @@ namespace GoldbergGUI.Core.Services
|
|||||||
// does file copy stuff
|
// does file copy stuff
|
||||||
public interface IGoldbergService
|
public interface IGoldbergService
|
||||||
{
|
{
|
||||||
public Task<(string accountName, long userSteamId)> Initialize(IMvxLog log);
|
public Task<(string accountName, long userSteamId, string language)> Initialize(IMvxLog log);
|
||||||
public Task<(int appId, List<SteamApp> dlcList, bool offline, bool disableNetworking, bool disableOverlay)>
|
public Task<GoldbergConfiguration> Read(string path);
|
||||||
Read(string path);
|
public Task Save(string path, GoldbergConfiguration configuration);
|
||||||
public Task Save(string path, int appId, List<SteamApp> dlcList,
|
public Task<(string accountName, long steamId, string language)> GetGlobalSettings();
|
||||||
bool offline, bool disableNetworking, bool disableOverlay);
|
public Task SetGlobalSettings(string accountName, long userSteamId, string language);
|
||||||
public bool GoldbergApplied(string path);
|
public bool GoldbergApplied(string path);
|
||||||
public Task<bool> Download();
|
public Task<bool> Download();
|
||||||
public Task Extract(string archivePath);
|
public Task Extract(string archivePath);
|
||||||
public Task GenerateInterfacesFile(string filePath);
|
public Task GenerateInterfacesFile(string filePath);
|
||||||
|
public List<string> Languages();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once UnusedType.Global
|
// ReSharper disable once UnusedType.Global
|
||||||
public class GoldbergService : IGoldbergService
|
public class GoldbergService : IGoldbergService
|
||||||
{
|
{
|
||||||
private IMvxLog _log;
|
private IMvxLog _log;
|
||||||
private const string GoldbergUrl = "https://mr_goldberg.gitlab.io/goldberg_emulator/";
|
private const string GoldbergUrl = "https://mr_goldberg.gitlab.io/goldberg_emulator/";
|
||||||
|
private const string DefaultLanguage = "english";
|
||||||
private readonly string _goldbergZipPath = Path.Combine(Directory.GetCurrentDirectory(), "goldberg.zip");
|
private readonly string _goldbergZipPath = Path.Combine(Directory.GetCurrentDirectory(), "goldberg.zip");
|
||||||
private readonly string _goldbergPath = Path.Combine(Directory.GetCurrentDirectory(), "goldberg");
|
private readonly string _goldbergPath = Path.Combine(Directory.GetCurrentDirectory(), "goldberg");
|
||||||
|
|
||||||
private static readonly string GlobalSettingsPath =
|
private static readonly string GlobalSettingsPath =
|
||||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
"Goldberg SteamEmu Saves");
|
"Goldberg SteamEmu Saves");
|
||||||
|
|
||||||
private readonly string _accountNamePath = Path.Combine(GlobalSettingsPath, "settings/account_name.txt");
|
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 _userSteamIdPath = Path.Combine(GlobalSettingsPath, "settings/user_steam_id.txt");
|
||||||
|
private readonly string _languagePath = Path.Combine(GlobalSettingsPath, "settings/language.txt");
|
||||||
|
|
||||||
private readonly List<string> _interfaceNames = new List<string>
|
private readonly List<string> _interfaceNames = new List<string>
|
||||||
{
|
{
|
||||||
"SteamClient",
|
"SteamClient",
|
||||||
@ -68,33 +74,53 @@ namespace GoldbergGUI.Core.Services
|
|||||||
"STEAMVIDEO_INTERFACE_V"
|
"STEAMVIDEO_INTERFACE_V"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Call Download
|
// Call Download
|
||||||
// Get global settings
|
// Get global settings
|
||||||
public async Task<(string accountName, long userSteamId)> Initialize(IMvxLog log)
|
public async Task<(string accountName, long userSteamId, string language)> Initialize(IMvxLog log)
|
||||||
{
|
{
|
||||||
_log = log;
|
_log = log;
|
||||||
|
|
||||||
var download = await Download().ConfigureAwait(false);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<(string accountName, long steamId, string language)> GetGlobalSettings()
|
||||||
|
{
|
||||||
var accountName = "Account name...";
|
var accountName = "Account name...";
|
||||||
long steamId = -1;
|
long steamId = -1;
|
||||||
|
var language = DefaultLanguage;
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
if (File.Exists(_accountNamePath)) accountName = File.ReadLines(_accountNamePath).First().Trim();
|
if (File.Exists(_accountNamePath)) accountName = File.ReadLines(_accountNamePath).First().Trim();
|
||||||
if (File.Exists(_userSteamIdPath) &&
|
if (File.Exists(_userSteamIdPath) &&
|
||||||
!long.TryParse(File.ReadLines(_userSteamIdPath).First().Trim(), out steamId))
|
!long.TryParse(File.ReadLines(_userSteamIdPath).First().Trim(), out steamId) &&
|
||||||
|
steamId < 76561197960265729 && steamId > 76561202255233023)
|
||||||
_log.Error("Invalid User Steam ID!");
|
_log.Error("Invalid User Steam ID!");
|
||||||
|
if (File.Exists(_languagePath)) language = File.ReadLines(_languagePath).First().Trim();
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
return (accountName, steamId, language);
|
||||||
|
}
|
||||||
|
|
||||||
return (accountName, steamId);
|
public async Task SetGlobalSettings(string accountName, long userSteamId, string language)
|
||||||
|
{
|
||||||
|
if (accountName != null && accountName != "Account name...")
|
||||||
|
await File.WriteAllTextAsync(_accountNamePath, accountName).ConfigureAwait(false);
|
||||||
|
else
|
||||||
|
await File.WriteAllTextAsync(_accountNamePath, "Goldberg").ConfigureAwait(false);
|
||||||
|
if (userSteamId >= 76561197960265729 && userSteamId <= 76561202255233023)
|
||||||
|
await File.WriteAllTextAsync(_userSteamIdPath, userSteamId.ToString()).ConfigureAwait(false);
|
||||||
|
else
|
||||||
|
await Task.Run(() => File.Delete(_userSteamIdPath)).ConfigureAwait(false);
|
||||||
|
if (language != null)
|
||||||
|
await File.WriteAllTextAsync(_languagePath, language).ConfigureAwait(false);
|
||||||
|
else
|
||||||
|
await File.WriteAllTextAsync(_languagePath, DefaultLanguage).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If first time, call GenerateInterfaces
|
// If first time, call GenerateInterfaces
|
||||||
// else try to read config
|
// else try to read config
|
||||||
public async Task<(int appId, List<SteamApp> dlcList, bool offline, bool disableNetworking, bool disableOverlay)>
|
public async Task<GoldbergConfiguration> Read(string path)
|
||||||
Read(string path)
|
|
||||||
{
|
{
|
||||||
var appId = -1;
|
var appId = -1;
|
||||||
var dlcList = new List<SteamApp>();
|
var dlcList = new List<SteamApp>();
|
||||||
@ -104,6 +130,7 @@ namespace GoldbergGUI.Core.Services
|
|||||||
await Task.Run(() => int.TryParse(File.ReadLines(steamAppidTxt).First().Trim(), out appId))
|
await Task.Run(() => int.TryParse(File.ReadLines(steamAppidTxt).First().Trim(), out appId))
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var dlcTxt = Path.Combine(path, "steam_settings", "DLC.txt");
|
var dlcTxt = Path.Combine(path, "steam_settings", "DLC.txt");
|
||||||
if (File.Exists(dlcTxt))
|
if (File.Exists(dlcTxt))
|
||||||
{
|
{
|
||||||
@ -113,23 +140,29 @@ namespace GoldbergGUI.Core.Services
|
|||||||
{
|
{
|
||||||
var match = expression.Match(line);
|
var match = expression.Match(line);
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
dlcList.Add(new SteamApp {AppId = Convert.ToInt32(match.Groups["id"].Value),
|
dlcList.Add(new SteamApp
|
||||||
Name = match.Groups["name"].Value});
|
{
|
||||||
|
AppId = Convert.ToInt32(match.Groups["id"].Value),
|
||||||
|
Name = match.Groups["name"].Value
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (appId, dlcList,
|
|
||||||
File.Exists(Path.Combine(path, "steam_settings", "offline.txt")),
|
return new GoldbergConfiguration
|
||||||
File.Exists(Path.Combine(path, "steam_settings", "disable_networking.txt")),
|
{
|
||||||
File.Exists(Path.Combine(path, "steam_settings", "disable_overlay.txt"))
|
AppId = appId,
|
||||||
);
|
DlcList = dlcList,
|
||||||
|
Offline = File.Exists(Path.Combine(path, "steam_settings", "offline.txt")),
|
||||||
|
DisableNetworking = File.Exists(Path.Combine(path, "steam_settings", "disable_networking.txt")),
|
||||||
|
DisableOverlay = File.Exists(Path.Combine(path, "steam_settings", "disable_overlay.txt"))
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// If first time, rename original SteamAPI DLL to steam_api(64)_o.dll
|
// If first time, rename original SteamAPI DLL to steam_api(64)_o.dll
|
||||||
// If not, rename current SteamAPI DLL to steam_api(64).dll.backup
|
// If not, rename current SteamAPI DLL to steam_api(64).dll.backup
|
||||||
// Copy Goldberg DLL to path
|
// Copy Goldberg DLL to path
|
||||||
// Save configuration files
|
// Save configuration files
|
||||||
public async Task Save(string path, int appId, List<SteamApp> dlcList,
|
public async Task Save(string path, GoldbergConfiguration c)
|
||||||
bool offline, bool disableNetworking, bool disableOverlay)
|
|
||||||
{
|
{
|
||||||
// DLL setup
|
// DLL setup
|
||||||
const string x86Name = "steam_api";
|
const string x86Name = "steam_api";
|
||||||
@ -149,15 +182,15 @@ namespace GoldbergGUI.Core.Services
|
|||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.Combine(path, "steam_settings"));
|
Directory.CreateDirectory(Path.Combine(path, "steam_settings"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// create steam_appid.txt
|
// create steam_appid.txt
|
||||||
await File.WriteAllTextAsync(Path.Combine(path, "steam_appid.txt"), appId.ToString()).ConfigureAwait(false);
|
await File.WriteAllTextAsync(Path.Combine(path, "steam_appid.txt"), c.AppId.ToString()).ConfigureAwait(false);
|
||||||
|
|
||||||
// DLC
|
// DLC
|
||||||
if (dlcList.Count > 0)
|
if (c.DlcList.Count > 0)
|
||||||
{
|
{
|
||||||
var dlcString = "";
|
var dlcString = "";
|
||||||
dlcList.ForEach(x => dlcString += $"{x}\n");
|
c.DlcList.ForEach(x => dlcString += $"{x}\n");
|
||||||
await File.WriteAllTextAsync(Path.Combine(path, "steam_settings", "DLC.txt"), dlcString)
|
await File.WriteAllTextAsync(Path.Combine(path, "steam_settings", "DLC.txt"), dlcString)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@ -166,37 +199,39 @@ namespace GoldbergGUI.Core.Services
|
|||||||
if (File.Exists(Path.Combine(path, "steam_settings", "DLC.txt")))
|
if (File.Exists(Path.Combine(path, "steam_settings", "DLC.txt")))
|
||||||
File.Delete(Path.Combine(path, "steam_settings", "DLC.txt"));
|
File.Delete(Path.Combine(path, "steam_settings", "DLC.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Offline
|
// Offline
|
||||||
if (offline)
|
if (c.Offline)
|
||||||
{
|
{
|
||||||
await File.Create(Path.Combine(path, "steam_settings", "offline.txt")).DisposeAsync().ConfigureAwait(false);
|
await File.Create(Path.Combine(path, "steam_settings", "offline.txt")).DisposeAsync()
|
||||||
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.Delete(Path.Combine(path, "steam_settings", "offline.txt"));
|
File.Delete(Path.Combine(path, "steam_settings", "offline.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable Networking
|
// Disable Networking
|
||||||
if (disableNetworking)
|
if (c.DisableNetworking)
|
||||||
{
|
{
|
||||||
await File.Create(Path.Combine(path, "steam_settings", "disable_networking.txt")).DisposeAsync().ConfigureAwait(false);
|
await File.Create(Path.Combine(path, "steam_settings", "disable_networking.txt")).DisposeAsync()
|
||||||
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.Delete(Path.Combine(path, "steam_settings", "disable_networking.txt"));
|
File.Delete(Path.Combine(path, "steam_settings", "disable_networking.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable Overlay
|
// Disable Overlay
|
||||||
if (disableOverlay)
|
if (c.DisableOverlay)
|
||||||
{
|
{
|
||||||
await File.Create(Path.Combine(path, "steam_settings", "disable_overlay.txt")).DisposeAsync().ConfigureAwait(false);
|
await File.Create(Path.Combine(path, "steam_settings", "disable_overlay.txt")).DisposeAsync()
|
||||||
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.Delete(Path.Combine(path, "steam_settings", "disable_overlay.txt"));
|
File.Delete(Path.Combine(path, "steam_settings", "disable_overlay.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyDllFiles(string path, string name)
|
private void CopyDllFiles(string path, string name)
|
||||||
@ -205,7 +240,7 @@ namespace GoldbergGUI.Core.Services
|
|||||||
var originalDll = Path.Combine(path, $"{name}_o.dll");
|
var originalDll = Path.Combine(path, $"{name}_o.dll");
|
||||||
var guiBackup = Path.Combine(path, $"{name}.dll.GOLDBERGGUIBACKUP");
|
var guiBackup = Path.Combine(path, $"{name}.dll.GOLDBERGGUIBACKUP");
|
||||||
var goldbergDll = Path.Combine(_goldbergPath, $"{name}.dll");
|
var goldbergDll = Path.Combine(_goldbergPath, $"{name}.dll");
|
||||||
|
|
||||||
if (!File.Exists(originalDll))
|
if (!File.Exists(originalDll))
|
||||||
File.Move(steamApiDll, originalDll);
|
File.Move(steamApiDll, originalDll);
|
||||||
else
|
else
|
||||||
@ -213,6 +248,7 @@ namespace GoldbergGUI.Core.Services
|
|||||||
File.Move(steamApiDll, guiBackup, true);
|
File.Move(steamApiDll, guiBackup, true);
|
||||||
File.SetAttributes(guiBackup, FileAttributes.Hidden);
|
File.SetAttributes(guiBackup, FileAttributes.Hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
File.Copy(goldbergDll, steamApiDll);
|
File.Copy(goldbergDll, steamApiDll);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +258,7 @@ namespace GoldbergGUI.Core.Services
|
|||||||
var steamAppIdTxtExists = File.Exists(Path.Combine(path, "steam_appid.txt"));
|
var steamAppIdTxtExists = File.Exists(Path.Combine(path, "steam_appid.txt"));
|
||||||
return steamSettingsDirExists && steamAppIdTxtExists;
|
return steamSettingsDirExists && steamAppIdTxtExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get webpage
|
// Get webpage
|
||||||
// Get job id, compare with local if exists, save it if false or missing
|
// Get job id, compare with local if exists, save it if false or missing
|
||||||
// Get latest archive if mismatch, call Extract
|
// Get latest archive if mismatch, call Extract
|
||||||
@ -313,6 +349,7 @@ namespace GoldbergGUI.Core.Services
|
|||||||
FindInterfaces(ref result, dllContent, new Regex("STEAMCONTROLLER_INTERFACE_VERSION"));
|
FindInterfaces(ref result, dllContent, new Regex("STEAMCONTROLLER_INTERFACE_VERSION"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var dirPath = Path.GetDirectoryName(filePath);
|
var dirPath = Path.GetDirectoryName(filePath);
|
||||||
if (dirPath == null) return;
|
if (dirPath == null) return;
|
||||||
await using var destination = File.CreateText(dirPath + "/steam_interfaces.txt");
|
await using var destination = File.CreateText(dirPath + "/steam_interfaces.txt");
|
||||||
@ -322,6 +359,37 @@ namespace GoldbergGUI.Core.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<string> Languages() => new List<string>
|
||||||
|
{
|
||||||
|
DefaultLanguage,
|
||||||
|
"arabic",
|
||||||
|
"bulgarian",
|
||||||
|
"schinese",
|
||||||
|
"tchinese",
|
||||||
|
"czech",
|
||||||
|
"danish",
|
||||||
|
"dutch",
|
||||||
|
"finnish",
|
||||||
|
"french",
|
||||||
|
"german",
|
||||||
|
"greek",
|
||||||
|
"hungarian",
|
||||||
|
"italian",
|
||||||
|
"japanese",
|
||||||
|
"koreana",
|
||||||
|
"norwegian",
|
||||||
|
"polish",
|
||||||
|
"portuguese",
|
||||||
|
"brazilian",
|
||||||
|
"romanian",
|
||||||
|
"russian",
|
||||||
|
"spanish",
|
||||||
|
"swedish",
|
||||||
|
"thai",
|
||||||
|
"turkish",
|
||||||
|
"ukrainian"
|
||||||
|
};
|
||||||
|
|
||||||
private static bool FindInterfaces(ref HashSet<string> result, string dllContent, Regex regex)
|
private static bool FindInterfaces(ref HashSet<string> result, string dllContent, Regex regex)
|
||||||
{
|
{
|
||||||
var success = false;
|
var success = false;
|
||||||
@ -332,6 +400,7 @@ namespace GoldbergGUI.Core.Services
|
|||||||
//result += $@"{match.Value}\n";
|
//result += $@"{match.Value}\n";
|
||||||
result.Add(match.Value);
|
result.Add(match.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,12 @@ namespace GoldbergGUI.Core.Services
|
|||||||
// ReSharper disable once UnusedType.Global
|
// ReSharper disable once UnusedType.Global
|
||||||
public class SteamService : ISteamService
|
public class SteamService : ISteamService
|
||||||
{
|
{
|
||||||
private const string CachePath = "steamapps.json";
|
private const string CachePath1 = "steamapps.json";
|
||||||
private const string SteamUri = "https://api.steampowered.com/ISteamApps/GetAppList/v2/";
|
//private const string CachePath1 = "steamapps_games.json";
|
||||||
|
//private const string CachePath2 = "steamapps_dlc.json";
|
||||||
|
private const string SteamUri1 = "https://api.steampowered.com/ISteamApps/GetAppList/v2/";
|
||||||
|
//private const string SteamUri1 = "https://api.steampowered.com/IStoreService/GetAppList/v1/?include_games=1&key=";
|
||||||
|
//private const string SteamUri2 = "https://api.steampowered.com/IStoreService/GetAppList/v1/?include_games=0&include_dlc=1&key=";
|
||||||
|
|
||||||
private const string UserAgent =
|
private const string UserAgent =
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " +
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " +
|
||||||
@ -42,33 +46,50 @@ namespace GoldbergGUI.Core.Services
|
|||||||
|
|
||||||
public async Task Initialize(IMvxLog log)
|
public async Task Initialize(IMvxLog log)
|
||||||
{
|
{
|
||||||
|
var secrets = new Secrets();
|
||||||
_log = log;
|
_log = log;
|
||||||
_log.Info("Updating cache...");
|
_log.Info("Updating cache...");
|
||||||
var updateNeeded = DateTime.Now.Subtract(File.GetLastWriteTimeUtc(CachePath)).TotalDays >= 1;
|
var updateNeeded = DateTime.Now.Subtract(File.GetLastWriteTimeUtc(CachePath1)).TotalDays >= 1;
|
||||||
|
var cacheString = await GetCache(updateNeeded, SteamUri1, CachePath1).ConfigureAwait(false);
|
||||||
|
SteamApps steamApps;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
steamApps = JsonSerializer.Deserialize<SteamApps>(cacheString);
|
||||||
|
}
|
||||||
|
catch (JsonException)
|
||||||
|
{
|
||||||
|
cacheString = await GetCache(true, SteamUri1, CachePath1).ConfigureAwait(false);
|
||||||
|
steamApps = JsonSerializer.Deserialize<SteamApps>(cacheString);
|
||||||
|
}
|
||||||
|
_cache = new HashSet<SteamApp>(steamApps.AppList.Apps);
|
||||||
|
_log.Info("Loaded cache into memory!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<string> GetCache(bool updateNeeded, string steamUri, string cachePath)
|
||||||
|
{
|
||||||
|
var secrets = new Secrets();
|
||||||
string cacheString;
|
string cacheString;
|
||||||
if (updateNeeded)
|
if (updateNeeded)
|
||||||
{
|
{
|
||||||
_log.Info("Getting content from API...");
|
_log.Info("Getting content from API...");
|
||||||
var client = new HttpClient();
|
var client = new HttpClient();
|
||||||
var httpCall = client.GetAsync(SteamUri);
|
var httpCall = client.GetAsync(steamUri + secrets.SteamWebApiKey());
|
||||||
var response = await httpCall.ConfigureAwait(false);
|
var response = await httpCall.ConfigureAwait(false);
|
||||||
var readAsStringAsync = response.Content.ReadAsStringAsync();
|
var readAsStringAsync = response.Content.ReadAsStringAsync();
|
||||||
var responseBody = await readAsStringAsync.ConfigureAwait(false);
|
var responseBody = await readAsStringAsync.ConfigureAwait(false);
|
||||||
_log.Info("Got content from API successfully. Writing to file...");
|
_log.Info("Got content from API successfully. Writing to file...");
|
||||||
|
|
||||||
await File.WriteAllTextAsync(CachePath, responseBody, Encoding.UTF8).ConfigureAwait(false);
|
await File.WriteAllTextAsync(cachePath, responseBody, Encoding.UTF8).ConfigureAwait(false);
|
||||||
cacheString = responseBody;
|
cacheString = responseBody;
|
||||||
_log.Info("Cache written to file successfully.");
|
_log.Info("Cache written to file successfully.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_log.Info("Cache already up to date!");
|
_log.Info("Cache already up to date!");
|
||||||
cacheString = await File.ReadAllTextAsync(CachePath).ConfigureAwait(false);
|
cacheString = await File.ReadAllTextAsync(cachePath).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var steamApps = JsonSerializer.Deserialize<SteamApps>(cacheString);
|
return cacheString;
|
||||||
_cache = new HashSet<SteamApp>(steamApps.AppList.Apps);
|
|
||||||
_log.Info("Loaded cache into memory!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<SteamApp> GetListOfAppsByName(string name)
|
public IEnumerable<SteamApp> GetListOfAppsByName(string name)
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Linq;
|
||||||
using GoldbergGUI.Core.Models;
|
using System.Threading.Tasks;
|
||||||
using GoldbergGUI.Core.Services;
|
using GoldbergGUI.Core.Models;
|
||||||
using Microsoft.Win32;
|
using GoldbergGUI.Core.Services;
|
||||||
using MvvmCross.Commands;
|
using Microsoft.Win32;
|
||||||
using MvvmCross.Logging;
|
using MvvmCross.Commands;
|
||||||
using MvvmCross.Navigation;
|
using MvvmCross.Logging;
|
||||||
using MvvmCross.ViewModels;
|
using MvvmCross.Navigation;
|
||||||
|
using MvvmCross.ViewModels;
|
||||||
|
|
||||||
namespace GoldbergGUI.Core.ViewModels
|
namespace GoldbergGUI.Core.ViewModels
|
||||||
{
|
{
|
||||||
// ReSharper disable once ClassNeverInstantiated.Global
|
// ReSharper disable once ClassNeverInstantiated.Global
|
||||||
public class MainViewModel : MvxViewModel
|
public class MainViewModel : MvxViewModel
|
||||||
@ -35,8 +36,10 @@
|
|||||||
private readonly IMvxLog _log;
|
private readonly IMvxLog _log;
|
||||||
private bool _mainWindowEnabled;
|
private bool _mainWindowEnabled;
|
||||||
private bool _goldbergApplied;
|
private bool _goldbergApplied;
|
||||||
|
private ObservableCollection<string> _steamLanguages;
|
||||||
|
private string _selectedLanguage;
|
||||||
|
|
||||||
public MainViewModel(ISteamService steam, IGoldbergService goldberg, IMvxLogProvider logProvider,
|
public MainViewModel(ISteamService steam, IGoldbergService goldberg, IMvxLogProvider logProvider,
|
||||||
IMvxNavigationService navigationService)
|
IMvxNavigationService navigationService)
|
||||||
{
|
{
|
||||||
_steam = steam;
|
_steam = steam;
|
||||||
@ -50,24 +53,37 @@
|
|||||||
base.Prepare();
|
base.Prepare();
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
//var errorDuringInit = false;
|
||||||
MainWindowEnabled = false;
|
MainWindowEnabled = false;
|
||||||
ResetForm();
|
try
|
||||||
await _steam.Initialize(_log).ConfigureAwait(false);
|
{
|
||||||
var (accountName, userSteamId) = await _goldberg.Initialize(_log).ConfigureAwait(false);
|
SteamLanguages = new ObservableCollection<string>(_goldberg.Languages());
|
||||||
AccountName = accountName;
|
ResetForm();
|
||||||
SteamId = userSteamId;
|
await _steam.Initialize(_log).ConfigureAwait(false);
|
||||||
|
var (accountName, userSteamId, language) =
|
||||||
|
await _goldberg.Initialize(_log).ConfigureAwait(false);
|
||||||
|
AccountName = accountName;
|
||||||
|
SteamId = userSteamId;
|
||||||
|
SelectedLanguage = language;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
throw;
|
||||||
|
//errorDuringInit = true;
|
||||||
|
}
|
||||||
|
|
||||||
MainWindowEnabled = true;
|
MainWindowEnabled = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Initialize()
|
public override async Task Initialize()
|
||||||
{
|
{
|
||||||
_log.Info("Init");
|
|
||||||
await base.Initialize().ConfigureAwait(false);
|
await base.Initialize().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PROPERTIES //
|
// PROPERTIES //
|
||||||
|
|
||||||
public string DllPath
|
public string DllPath
|
||||||
{
|
{
|
||||||
get => _dllPath;
|
get => _dllPath;
|
||||||
@ -192,7 +208,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool DllSelected => !DllPath.Contains("Path to game's steam_api(64).dll");
|
public bool DllSelected => !DllPath.Contains("Path to game's steam_api(64).dll");
|
||||||
|
|
||||||
|
public ObservableCollection<string> SteamLanguages
|
||||||
|
{
|
||||||
|
get => _steamLanguages;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_steamLanguages = value;
|
||||||
|
RaisePropertyChanged(() => SteamLanguages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string SelectedLanguage
|
||||||
|
{
|
||||||
|
get => _selectedLanguage;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_selectedLanguage = value;
|
||||||
|
RaisePropertyChanged(() => SelectedLanguage);
|
||||||
|
//MyLogger.Log.Debug($"Lang: {value}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// COMMANDS //
|
// COMMANDS //
|
||||||
|
|
||||||
public IMvxCommand OpenFileCommand => new MvxAsyncCommand(OpenFile);
|
public IMvxCommand OpenFileCommand => new MvxAsyncCommand(OpenFile);
|
||||||
@ -211,8 +248,8 @@
|
|||||||
_log.Warn("File selection canceled.");
|
_log.Warn("File selection canceled.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DllPath = dialog.FileName;
|
DllPath = dialog.FileName;
|
||||||
//_goldberg.GenerateInterfacesFile(filePath);
|
|
||||||
await ReadConfig().ConfigureAwait(false);
|
await ReadConfig().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +262,7 @@
|
|||||||
_log.Error("No game name entered!");
|
_log.Error("No game name entered!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindowEnabled = false;
|
MainWindowEnabled = false;
|
||||||
var appByName = _steam.GetAppByName(_gameName);
|
var appByName = _steam.GetAppByName(_gameName);
|
||||||
if (appByName != null)
|
if (appByName != null)
|
||||||
@ -253,6 +291,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindowEnabled = true;
|
MainWindowEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,6 +304,7 @@
|
|||||||
_log.Error("Invalid Steam App!");
|
_log.Error("Invalid Steam App!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var steamApp = await Task.Run(() => _steam.GetAppById(AppId)).ConfigureAwait(false);
|
var steamApp = await Task.Run(() => _steam.GetAppById(AppId)).ConfigureAwait(false);
|
||||||
if (steamApp != null) GameName = steamApp.Name;
|
if (steamApp != null) GameName = steamApp.Name;
|
||||||
}
|
}
|
||||||
@ -278,8 +318,10 @@
|
|||||||
_log.Error("Invalid Steam App!");
|
_log.Error("Invalid Steam App!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindowEnabled = false;
|
MainWindowEnabled = false;
|
||||||
var listOfDlc = await _steam.GetListOfDlc(new SteamApp {AppId = AppId, Name = GameName}, true).ConfigureAwait(false);
|
var listOfDlc = await _steam.GetListOfDlc(new SteamApp {AppId = AppId, Name = GameName}, true)
|
||||||
|
.ConfigureAwait(false);
|
||||||
DLCs = new MvxObservableCollection<SteamApp>(listOfDlc);
|
DLCs = new MvxObservableCollection<SteamApp>(listOfDlc);
|
||||||
MainWindowEnabled = true;
|
MainWindowEnabled = true;
|
||||||
}
|
}
|
||||||
@ -288,20 +330,25 @@
|
|||||||
|
|
||||||
private async Task SaveConfig()
|
private async Task SaveConfig()
|
||||||
{
|
{
|
||||||
|
await _goldberg.SetGlobalSettings(AccountName, SteamId, SelectedLanguage).ConfigureAwait(false);
|
||||||
if (!DllSelected)
|
if (!DllSelected)
|
||||||
{
|
{
|
||||||
_log.Error("No DLL selected!");
|
_log.Error("No DLL selected!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_log.Info("Saving...");
|
_log.Info("Saving...");
|
||||||
if (!GetDllPathDir(out var dirPath)) return;
|
if (!GetDllPathDir(out var dirPath)) return;
|
||||||
MainWindowEnabled = false;
|
MainWindowEnabled = false;
|
||||||
await _goldberg.Save(dirPath,
|
await _goldberg.Save(dirPath, new GoldbergConfiguration
|
||||||
AppId,
|
{
|
||||||
DLCs.ToList(),
|
AppId = AppId,
|
||||||
Offline,
|
DlcList = DLCs.ToList(),
|
||||||
DisableNetworking,
|
Offline = Offline,
|
||||||
DisableOverlay).ConfigureAwait(false);
|
DisableNetworking = DisableNetworking,
|
||||||
|
DisableOverlay = DisableOverlay
|
||||||
|
}
|
||||||
|
).ConfigureAwait(false);
|
||||||
GoldbergApplied = _goldberg.GoldbergApplied(dirPath);
|
GoldbergApplied = _goldberg.GoldbergApplied(dirPath);
|
||||||
MainWindowEnabled = true;
|
MainWindowEnabled = true;
|
||||||
}
|
}
|
||||||
@ -310,17 +357,19 @@
|
|||||||
|
|
||||||
private async Task ResetConfig()
|
private async Task ResetConfig()
|
||||||
{
|
{
|
||||||
|
(AccountName, SteamId, SelectedLanguage) = await _goldberg.GetGlobalSettings().ConfigureAwait(false);
|
||||||
if (!DllSelected)
|
if (!DllSelected)
|
||||||
{
|
{
|
||||||
_log.Error("No DLL selected!");
|
_log.Error("No DLL selected!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_log.Info("Reset form...");
|
_log.Info("Reset form...");
|
||||||
MainWindowEnabled = false;
|
MainWindowEnabled = false;
|
||||||
await ReadConfig().ConfigureAwait(false);
|
await ReadConfig().ConfigureAwait(false);
|
||||||
MainWindowEnabled = true;
|
MainWindowEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMvxCommand GenerateSteamInterfacesCommand => new MvxAsyncCommand(GenerateSteamInterfaces);
|
public IMvxCommand GenerateSteamInterfacesCommand => new MvxAsyncCommand(GenerateSteamInterfaces);
|
||||||
|
|
||||||
private async Task GenerateSteamInterfaces()
|
private async Task GenerateSteamInterfaces()
|
||||||
@ -330,20 +379,22 @@
|
|||||||
_log.Error("No DLL selected!");
|
_log.Error("No DLL selected!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_log.Info("Generate steam_interfaces.txt...");
|
_log.Info("Generate steam_interfaces.txt...");
|
||||||
MainWindowEnabled = false;
|
MainWindowEnabled = false;
|
||||||
GetDllPathDir(out var dirPath);
|
GetDllPathDir(out var dirPath);
|
||||||
if (File.Exists(Path.Combine(dirPath, "steam_api_o.dll")))
|
if (File.Exists(Path.Combine(dirPath, "steam_api_o.dll")))
|
||||||
await _goldberg.GenerateInterfacesFile(Path.Combine(dirPath, "steam_api_o.dll")).ConfigureAwait(false);
|
await _goldberg.GenerateInterfacesFile(Path.Combine(dirPath, "steam_api_o.dll")).ConfigureAwait(false);
|
||||||
else if (File.Exists(Path.Combine(dirPath, "steam_api64_o.dll")))
|
else if (File.Exists(Path.Combine(dirPath, "steam_api64_o.dll")))
|
||||||
await _goldberg.GenerateInterfacesFile(Path.Combine(dirPath, "steam_api64_o.dll")).ConfigureAwait(false);
|
await _goldberg.GenerateInterfacesFile(Path.Combine(dirPath, "steam_api64_o.dll"))
|
||||||
|
.ConfigureAwait(false);
|
||||||
else await _goldberg.GenerateInterfacesFile(DllPath).ConfigureAwait(false);
|
else await _goldberg.GenerateInterfacesFile(DllPath).ConfigureAwait(false);
|
||||||
await RaisePropertyChanged(() => SteamInterfacesTxtExists).ConfigureAwait(false);
|
await RaisePropertyChanged(() => SteamInterfacesTxtExists).ConfigureAwait(false);
|
||||||
MainWindowEnabled = true;
|
MainWindowEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// OTHER METHODS //
|
// OTHER METHODS //
|
||||||
|
|
||||||
private void ResetForm()
|
private void ResetForm()
|
||||||
{
|
{
|
||||||
DllPath = "Path to game's steam_api(64).dll...";
|
DllPath = "Path to game's steam_api(64).dll...";
|
||||||
@ -361,15 +412,22 @@
|
|||||||
{
|
{
|
||||||
if (!GetDllPathDir(out var dirPath)) return;
|
if (!GetDllPathDir(out var dirPath)) return;
|
||||||
MainWindowEnabled = false;
|
MainWindowEnabled = false;
|
||||||
List<SteamApp> dlcList;
|
var config = await _goldberg.Read(dirPath).ConfigureAwait(false);
|
||||||
(AppId, dlcList, Offline, DisableNetworking, DisableOverlay) =
|
SetFormFromConfig(config);
|
||||||
await _goldberg.Read(dirPath).ConfigureAwait(false);
|
|
||||||
DLCs = new ObservableCollection<SteamApp>(dlcList);
|
|
||||||
GoldbergApplied = _goldberg.GoldbergApplied(dirPath);
|
GoldbergApplied = _goldberg.GoldbergApplied(dirPath);
|
||||||
await RaisePropertyChanged(() => SteamInterfacesTxtExists).ConfigureAwait(false);
|
await RaisePropertyChanged(() => SteamInterfacesTxtExists).ConfigureAwait(false);
|
||||||
MainWindowEnabled = true;
|
MainWindowEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetFormFromConfig(GoldbergConfiguration config)
|
||||||
|
{
|
||||||
|
AppId = config.AppId;
|
||||||
|
DLCs = new ObservableCollection<SteamApp>(config.DlcList);
|
||||||
|
Offline = config.Offline;
|
||||||
|
DisableNetworking = config.DisableNetworking;
|
||||||
|
DisableOverlay = config.DisableOverlay;
|
||||||
|
}
|
||||||
|
|
||||||
private bool GetDllPathDir(out string dirPath)
|
private bool GetDllPathDir(out string dirPath)
|
||||||
{
|
{
|
||||||
if (!DllSelected)
|
if (!DllSelected)
|
||||||
@ -381,7 +439,7 @@
|
|||||||
|
|
||||||
dirPath = Path.GetDirectoryName(DllPath);
|
dirPath = Path.GetDirectoryName(DllPath);
|
||||||
if (dirPath != null) return true;
|
if (dirPath != null) return true;
|
||||||
|
|
||||||
_log.Error($"Invalid directory for {DllPath}.");
|
_log.Error($"Invalid directory for {DllPath}.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -80,12 +80,16 @@
|
|||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition/>
|
<RowDefinition/>
|
||||||
<RowDefinition/>
|
<RowDefinition/>
|
||||||
|
<RowDefinition/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Label Content="Account name" HorizontalAlignment="Left" Margin="0,0,10,0" />
|
<Label Content="Account name" HorizontalAlignment="Left" Margin="0,0,10,0" />
|
||||||
<TextBox Text="{Binding AccountName, Mode=TwoWay}" Height="20" Grid.Row="0" Grid.Column="1"/>
|
<TextBox Text="{Binding AccountName, Mode=TwoWay}" Height="20" Grid.Row="0" Grid.Column="1"/>
|
||||||
<Label Content="Steam64ID" HorizontalAlignment="Left" Grid.Row="1"
|
<Label Content="Steam64ID" HorizontalAlignment="Left" Grid.Row="1"
|
||||||
Grid.Column="0" Margin="0,0,10,0" />
|
Grid.Column="0" Margin="0,0,10,0" />
|
||||||
<TextBox Text="{Binding SteamId, Mode=TwoWay}" Grid.Column="1" Height="20" Grid.Row="1"/>
|
<TextBox Text="{Binding SteamId, Mode=TwoWay}" Grid.Column="1" Height="20" Grid.Row="1"/>
|
||||||
|
<Label Content="Language" HorizontalAlignment="Left" Grid.Row="2"
|
||||||
|
Grid.Column="0" Margin="0,0,10,0" />
|
||||||
|
<ComboBox Grid.Row="2" Grid.Column="1" ItemsSource="{Binding SteamLanguages}" SelectedItem="{Binding SelectedLanguage}"></ComboBox>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
Loading…
Reference in New Issue
Block a user