Compare commits

...

2 Commits

7 changed files with 61 additions and 45 deletions

View File

@ -84,18 +84,18 @@ namespace auto_creamapi.Services
public SteamApp GetAppByName(string name) public SteamApp GetAppByName(string name)
{ {
MyLogger.Log.Information($"Trying to get app {name}"); MyLogger.Log.Information("Trying to get app {Name}", name);
var comparableName = Regex.Replace(name, Misc.SpecialCharsRegex, "").ToLower(); var comparableName = Regex.Replace(name, Misc.SpecialCharsRegex, "").ToLower();
var app = _cache.FirstOrDefault(x => x.CompareName(comparableName)); var app = _cache.FirstOrDefault(x => x.CompareName(comparableName));
if (app != null) MyLogger.Log.Information($"Successfully got app {app}"); if (app != null) MyLogger.Log.Information("Successfully got app {App}", app);
return app; return app;
} }
public SteamApp GetAppById(int appid) public SteamApp GetAppById(int appid)
{ {
MyLogger.Log.Information($"Trying to get app with ID {appid}"); MyLogger.Log.Information("Trying to get app with ID {AppId}", appid);
var app = _cache.FirstOrDefault(x => x.AppId.Equals(appid)); var app = _cache.FirstOrDefault(x => x.AppId.Equals(appid));
if (app != null) MyLogger.Log.Information($"Successfully got app {app}"); if (app != null) MyLogger.Log.Information("Successfully got app {App}", app);
return app; return app;
} }
@ -108,7 +108,7 @@ namespace auto_creamapi.Services
var steamAppDetails = await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false); var steamAppDetails = await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false);
if (steamAppDetails != null) if (steamAppDetails != null)
{ {
MyLogger.Log.Debug($"Type for Steam App {steamApp.Name}: \"{steamAppDetails.Type}\""); MyLogger.Log.Debug("Type for Steam App {Name}: \"{Type}\"", steamApp.Name, steamAppDetails.Type);
if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo") if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo")
{ {
steamAppDetails.DLC.ForEach(x => steamAppDetails.DLC.ForEach(x =>
@ -121,7 +121,7 @@ namespace auto_creamapi.Services
: new SteamApp { AppId = x, Name = $"Unknown DLC {x}" }); : new SteamApp { AppId = x, Name = $"Unknown DLC {x}" });
}); });
dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}")); dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name));
MyLogger.Log.Information("Got DLC successfully..."); MyLogger.Log.Information("Got DLC successfully...");
if (!useSteamDb) return dlcList; if (!useSteamDb) return dlcList;
@ -138,12 +138,12 @@ namespace auto_creamapi.Services
MyLogger.Log.Information("Get SteamDB App"); MyLogger.Log.Information("Get SteamDB App");
var httpCall = client.GetAsync(steamDbUri); var httpCall = client.GetAsync(steamDbUri);
var response = await httpCall.ConfigureAwait(false); var response = await httpCall.ConfigureAwait(false);
MyLogger.Log.Debug(httpCall.Status.ToString()); MyLogger.Log.Debug("{Status}", httpCall.Status.ToString());
MyLogger.Log.Debug(response.EnsureSuccessStatusCode().ToString()); MyLogger.Log.Debug("{Boolean}", response.EnsureSuccessStatusCode().ToString());
var readAsStringAsync = response.Content.ReadAsStringAsync(); var readAsStringAsync = response.Content.ReadAsStringAsync();
var responseBody = await readAsStringAsync.ConfigureAwait(false); var responseBody = await readAsStringAsync.ConfigureAwait(false);
MyLogger.Log.Debug(readAsStringAsync.Status.ToString()); MyLogger.Log.Debug("{Status}", readAsStringAsync.Status.ToString());
var parser = new HtmlParser(); var parser = new HtmlParser();
var doc = parser.ParseDocument(responseBody); var doc = parser.ParseDocument(responseBody);
@ -163,7 +163,7 @@ namespace auto_creamapi.Services
if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App")) if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App"))
{ {
MyLogger.Log.Information($"Skipping SteamDB Unknown App {dlcId}"); MyLogger.Log.Information("Skipping SteamDB Unknown App {DlcId}", dlcId);
} }
else else
{ {
@ -179,7 +179,7 @@ namespace auto_creamapi.Services
} }
} }
} }
dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}")); dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name));
MyLogger.Log.Information("Got DLC from SteamDB successfully..."); MyLogger.Log.Information("Got DLC from SteamDB successfully...");
} }
else else

View File

@ -65,7 +65,7 @@ namespace auto_creamapi.Services
_configFilePath = configFilePath; _configFilePath = configFilePath;
if (File.Exists(configFilePath)) if (File.Exists(configFilePath))
{ {
MyLogger.Log.Information($"Config file found @ {configFilePath}, parsing..."); MyLogger.Log.Information("Config file found @ {ConfigFilePath}, parsing...", configFilePath);
var parser = new FileIniDataParser(); var parser = new FileIniDataParser();
var data = parser.ReadFile(_configFilePath, Encoding.UTF8); var data = parser.ReadFile(_configFilePath, Encoding.UTF8);
@ -83,7 +83,7 @@ namespace auto_creamapi.Services
} }
else else
{ {
MyLogger.Log.Information($"Config file does not exist @ {configFilePath}, skipping..."); MyLogger.Log.Information("Config file does not exist @ {ConfigFilePath}, skipping...", configFilePath);
ResetConfigData(); ResetConfigData();
} }
} }

View File

@ -66,8 +66,8 @@ namespace auto_creamapi.Services
var x64File = Path.Combine(TargetPath, "steam_api64.dll"); var x64File = Path.Combine(TargetPath, "steam_api64.dll");
_x86Exists = File.Exists(x86File); _x86Exists = File.Exists(x86File);
_x64Exists = File.Exists(x64File); _x64Exists = File.Exists(x64File);
if (_x86Exists) MyLogger.Log.Information($"x86 SteamAPI DLL found: {x86File}"); if (_x86Exists) MyLogger.Log.Information("x86 SteamAPI DLL found: {X}", x86File);
if (_x64Exists) MyLogger.Log.Information($"x64 SteamAPI DLL found: {x64File}"); if (_x64Exists) MyLogger.Log.Information("x64 SteamAPI DLL found: {X}", x64File);
} }
public bool CreamApiApplied() public bool CreamApiApplied()
@ -83,7 +83,7 @@ namespace auto_creamapi.Services
var targetSteamApiDll = Path.Combine(TargetPath, _creamDlls[arch].Filename); var targetSteamApiDll = Path.Combine(TargetPath, _creamDlls[arch].Filename);
var targetSteamApiOrigDll = Path.Combine(TargetPath, _creamDlls[arch].OrigFilename); var targetSteamApiOrigDll = Path.Combine(TargetPath, _creamDlls[arch].OrigFilename);
var targetSteamApiDllBackup = Path.Combine(TargetPath, $"{_creamDlls[arch].Filename}.backup"); var targetSteamApiDllBackup = Path.Combine(TargetPath, $"{_creamDlls[arch].Filename}.backup");
MyLogger.Log.Information($"Setting up CreamAPI DLL @ {TargetPath} (arch :{arch})"); MyLogger.Log.Information("Setting up CreamAPI DLL @ {TargetPath} (arch :{Arch})", TargetPath, arch);
// Create backup of steam_api.dll // Create backup of steam_api.dll
File.Copy(targetSteamApiDll, targetSteamApiDllBackup, true); File.Copy(targetSteamApiDll, targetSteamApiDllBackup, true);
// Check if steam_api_o.dll already exists // Check if steam_api_o.dll already exists

View File

@ -4,7 +4,6 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using auto_creamapi.Messenger; using auto_creamapi.Messenger;
@ -37,6 +36,8 @@ namespace auto_creamapi.Services
var container = new CookieContainer(); var container = new CookieContainer();
var handler = new HttpClientHandler {CookieContainer = container}; var handler = new HttpClientHandler {CookieContainer = container};
var client = new HttpClient(handler); var client = new HttpClient(handler);
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) " +
"Gecko/20100101 Firefox/86.0");
var formContent = new FormUrlEncodedContent(new[] var formContent = new FormUrlEncodedContent(new[]
{ {
new KeyValuePair<string, string>("username", username), new KeyValuePair<string, string>("username", username),
@ -47,14 +48,15 @@ namespace auto_creamapi.Services
MyLogger.Log.Debug("Download: post login"); MyLogger.Log.Debug("Download: post login");
var response1 = await client.PostAsync("https://cs.rin.ru/forum/ucp.php?mode=login", formContent) var response1 = await client.PostAsync("https://cs.rin.ru/forum/ucp.php?mode=login", formContent)
.ConfigureAwait(false); .ConfigureAwait(false);
MyLogger.Log.Debug($"Login Status Code: {response1.EnsureSuccessStatusCode().StatusCode.ToString()}"); MyLogger.Log.Debug("Login Status Code: {StatusCode}",
response1.EnsureSuccessStatusCode().StatusCode);
var cookie = container.GetCookies(new Uri("https://cs.rin.ru/forum/ucp.php?mode=login")) var cookie = container.GetCookies(new Uri("https://cs.rin.ru/forum/ucp.php?mode=login"))
.FirstOrDefault(c => c.Name.Contains("_sid")); .FirstOrDefault(c => c.Name.Contains("_sid"));
MyLogger.Log.Debug($"Login Cookie: {cookie}"); MyLogger.Log.Debug("Login Cookie: {Cookie}", cookie);
var response2 = await client.GetAsync("https://cs.rin.ru/forum/viewtopic.php?t=70576") var response2 = await client.GetAsync("https://cs.rin.ru/forum/viewtopic.php?t=70576")
.ConfigureAwait(false); .ConfigureAwait(false);
MyLogger.Log.Debug( MyLogger.Log.Debug("Download Page Status Code: {StatusCode}",
$"Download Page Status Code: {response2.EnsureSuccessStatusCode().StatusCode.ToString()}"); response2.EnsureSuccessStatusCode().StatusCode);
var content = response2.Content.ReadAsStringAsync(); var content = response2.Content.ReadAsStringAsync();
var contentResult = await content.ConfigureAwait(false); var contentResult = await content.ConfigureAwait(false);
@ -71,7 +73,7 @@ namespace auto_creamapi.Services
{ {
archiveFileList.Add(match.Groups["filename"].Value, archiveFileList.Add(match.Groups["filename"].Value,
$"https://cs.rin.ru/forum{match.Groups["url"].Value}"); $"https://cs.rin.ru/forum{match.Groups["url"].Value}");
MyLogger.Log.Debug(archiveFileList.LastOrDefault().Key); MyLogger.Log.Debug("{X}", archiveFileList.LastOrDefault().Key);
} }
} }
@ -79,7 +81,7 @@ namespace auto_creamapi.Services
var (filename, url) = archiveFileList.FirstOrDefault(); var (filename, url) = archiveFileList.FirstOrDefault();
if (File.Exists(filename)) if (File.Exists(filename))
{ {
MyLogger.Log.Information($"{filename} already exists, skipping download..."); MyLogger.Log.Information("{Filename} already exists, skipping download...", filename);
return filename; return filename;
} }
@ -102,7 +104,7 @@ namespace auto_creamapi.Services
const string nonlogBuild = "nonlog_build"; const string nonlogBuild = "nonlog_build";
const string steamApi64Dll = "steam_api64.dll"; const string steamApi64Dll = "steam_api64.dll";
const string steamApiDll = "steam_api.dll"; const string steamApiDll = "steam_api.dll";
MyLogger.Log.Information($@"Start extraction of ""{filename}""..."); MyLogger.Log.Information(@"Start extraction of ""{Filename}""...", filename);
var nonlogBuildPath = Path.Combine(cwd, nonlogBuild); var nonlogBuildPath = Path.Combine(cwd, nonlogBuild);
if (Directory.Exists(nonlogBuildPath)) if (Directory.Exists(nonlogBuildPath))
Directory.Delete(nonlogBuildPath, true); Directory.Delete(nonlogBuildPath, true);

View File

@ -1,4 +1,7 @@
using System;
using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using auto_creamapi.Messenger; using auto_creamapi.Messenger;
using auto_creamapi.Services; using auto_creamapi.Services;
using auto_creamapi.Utils; using auto_creamapi.Utils;
@ -26,7 +29,7 @@ namespace auto_creamapi.ViewModels
_navigationService = navigationService; _navigationService = navigationService;
_download = download; _download = download;
_token = messenger.Subscribe<ProgressMessage>(OnProgressMessage); _token = messenger.Subscribe<ProgressMessage>(OnProgressMessage);
MyLogger.Log.Debug(messenger.CountSubscriptionsFor<ProgressMessage>().ToString()); MyLogger.Log.Debug("{Count}", messenger.CountSubscriptionsFor<ProgressMessage>());
} }
public string InfoLabel public string InfoLabel
@ -62,20 +65,36 @@ namespace auto_creamapi.ViewModels
public string ProgressPercent => _progress.ToString("P2"); public string ProgressPercent => _progress.ToString("P2");
public override async Task Initialize() public override void Prepare()
{ {
await base.Initialize().ConfigureAwait(false);
InfoLabel = "Please wait..."; InfoLabel = "Please wait...";
FilenameLabel = ""; FilenameLabel = "";
Progress = 0.0; Progress = 0.0;
var download = _download.Download(Secrets.ForumUsername, Secrets.ForumPassword); }
var filename = await download.ConfigureAwait(false);
/*var extract = _download.Extract(filename); public override async Task Initialize()
await extract;*/ {
var extract = _download.Extract(filename); try
await extract.ConfigureAwait(false); {
_token.Dispose(); await base.Initialize().ConfigureAwait(false);
await _navigationService.Close(this).ConfigureAwait(false); var download = _download.Download(Secrets.ForumUsername, Secrets.ForumPassword);
var filename = await download.ConfigureAwait(false);
/*var extract = _download.Extract(filename);
await extract;*/
var extract = _download.Extract(filename);
await extract.ConfigureAwait(false);
_token.Dispose();
await _navigationService.Close(this).ConfigureAwait(false);
}
catch (Exception e)
{
MessageBox.Show("Could not download CreamAPI!\nPlease add CreamAPI DLLs manually!\nShutting down...",
"Error", MessageBoxButton.OK, MessageBoxImage.Error);
_token.Dispose();
await _navigationService.Close(this).ConfigureAwait(false);
Console.WriteLine(e);
throw;
}
} }
private void OnProgressMessage(ProgressMessage obj) private void OnProgressMessage(ProgressMessage obj)

View File

@ -69,11 +69,6 @@ namespace auto_creamapi.ViewModels
Status = "Ready."; Status = "Ready.";
} }
public override Task Initialize()
{
return base.Initialize();
}
// // COMMANDS // // // // COMMANDS // //
public IMvxCommand OpenFileCommand => new MvxAsyncCommand(OpenFile); public IMvxCommand OpenFileCommand => new MvxAsyncCommand(OpenFile);
@ -275,7 +270,7 @@ namespace auto_creamapi.ViewModels
var s = index > -1 ? strings[index] : null; var s = index > -1 ? strings[index] : null;
if (s != null) GameName = s; if (s != null) GameName = s;
await Search().ConfigureAwait(false); await Search().ConfigureAwait(false);
await GetListOfDlc().ConfigureAwait(false); // await GetListOfDlc().ConfigureAwait(false);
} }
Status = "Ready."; Status = "Ready.";
@ -311,7 +306,7 @@ namespace auto_creamapi.ViewModels
} }
} }
await GetListOfDlc().ConfigureAwait(false); // await GetListOfDlc().ConfigureAwait(false);
} }
else else
{ {
@ -346,7 +341,7 @@ namespace auto_creamapi.ViewModels
else else
{ {
Status = $"Could not get DLC for AppID {AppId}"; Status = $"Could not get DLC for AppID {AppId}";
MyLogger.Log.Error($"GetListOfDlc: Invalid AppID {AppId}"); MyLogger.Log.Error("GetListOfDlc: Invalid AppID {AppId}", AppId);
} }
} }
@ -397,7 +392,7 @@ namespace auto_creamapi.ViewModels
} }
else else
{ {
MyLogger.Log.Error($"OpenURL: Invalid AppID {AppId}"); MyLogger.Log.Error("OpenURL: Invalid AppID {AppId}", AppId);
Status = $"Could not open URL: Invalid AppID {AppId}"; Status = $"Could not open URL: Invalid AppID {AppId}";
} }
} }

View File

@ -66,7 +66,7 @@ namespace auto_creamapi.ViewModels
{ {
if (Selected != null) if (Selected != null)
{ {
MyLogger.Log.Information($"Successfully got app {Selected}"); MyLogger.Log.Information("Successfully got app {Selected}", Selected);
await _navigationService.Close(this, Selected).ConfigureAwait(false); await _navigationService.Close(this, Selected).ConfigureAwait(false);
} }
} }