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)
{
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 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;
}
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));
if (app != null) MyLogger.Log.Information($"Successfully got app {app}");
if (app != null) MyLogger.Log.Information("Successfully got app {App}", app);
return app;
}
@ -108,7 +108,7 @@ namespace auto_creamapi.Services
var steamAppDetails = await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false);
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")
{
steamAppDetails.DLC.ForEach(x =>
@ -121,7 +121,7 @@ namespace auto_creamapi.Services
: 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...");
if (!useSteamDb) return dlcList;
@ -138,12 +138,12 @@ namespace auto_creamapi.Services
MyLogger.Log.Information("Get SteamDB App");
var httpCall = client.GetAsync(steamDbUri);
var response = await httpCall.ConfigureAwait(false);
MyLogger.Log.Debug(httpCall.Status.ToString());
MyLogger.Log.Debug(response.EnsureSuccessStatusCode().ToString());
MyLogger.Log.Debug("{Status}", httpCall.Status.ToString());
MyLogger.Log.Debug("{Boolean}", response.EnsureSuccessStatusCode().ToString());
var readAsStringAsync = response.Content.ReadAsStringAsync();
var responseBody = await readAsStringAsync.ConfigureAwait(false);
MyLogger.Log.Debug(readAsStringAsync.Status.ToString());
MyLogger.Log.Debug("{Status}", readAsStringAsync.Status.ToString());
var parser = new HtmlParser();
var doc = parser.ParseDocument(responseBody);
@ -163,7 +163,7 @@ namespace auto_creamapi.Services
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
{
@ -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...");
}
else

View File

@ -65,7 +65,7 @@ namespace auto_creamapi.Services
_configFilePath = 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 data = parser.ReadFile(_configFilePath, Encoding.UTF8);
@ -83,7 +83,7 @@ namespace auto_creamapi.Services
}
else
{
MyLogger.Log.Information($"Config file does not exist @ {configFilePath}, skipping...");
MyLogger.Log.Information("Config file does not exist @ {ConfigFilePath}, skipping...", configFilePath);
ResetConfigData();
}
}

View File

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

View File

@ -4,7 +4,6 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using auto_creamapi.Messenger;
@ -37,6 +36,8 @@ namespace auto_creamapi.Services
var container = new CookieContainer();
var handler = new HttpClientHandler {CookieContainer = container};
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[]
{
new KeyValuePair<string, string>("username", username),
@ -47,14 +48,15 @@ namespace auto_creamapi.Services
MyLogger.Log.Debug("Download: post login");
var response1 = await client.PostAsync("https://cs.rin.ru/forum/ucp.php?mode=login", formContent)
.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"))
.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")
.ConfigureAwait(false);
MyLogger.Log.Debug(
$"Download Page Status Code: {response2.EnsureSuccessStatusCode().StatusCode.ToString()}");
MyLogger.Log.Debug("Download Page Status Code: {StatusCode}",
response2.EnsureSuccessStatusCode().StatusCode);
var content = response2.Content.ReadAsStringAsync();
var contentResult = await content.ConfigureAwait(false);
@ -71,7 +73,7 @@ namespace auto_creamapi.Services
{
archiveFileList.Add(match.Groups["filename"].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();
if (File.Exists(filename))
{
MyLogger.Log.Information($"{filename} already exists, skipping download...");
MyLogger.Log.Information("{Filename} already exists, skipping download...", filename);
return filename;
}
@ -102,7 +104,7 @@ namespace auto_creamapi.Services
const string nonlogBuild = "nonlog_build";
const string steamApi64Dll = "steam_api64.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);
if (Directory.Exists(nonlogBuildPath))
Directory.Delete(nonlogBuildPath, true);

View File

@ -1,4 +1,7 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows;
using auto_creamapi.Messenger;
using auto_creamapi.Services;
using auto_creamapi.Utils;
@ -26,7 +29,7 @@ namespace auto_creamapi.ViewModels
_navigationService = navigationService;
_download = download;
_token = messenger.Subscribe<ProgressMessage>(OnProgressMessage);
MyLogger.Log.Debug(messenger.CountSubscriptionsFor<ProgressMessage>().ToString());
MyLogger.Log.Debug("{Count}", messenger.CountSubscriptionsFor<ProgressMessage>());
}
public string InfoLabel
@ -62,20 +65,36 @@ namespace auto_creamapi.ViewModels
public string ProgressPercent => _progress.ToString("P2");
public override async Task Initialize()
public override void Prepare()
{
await base.Initialize().ConfigureAwait(false);
InfoLabel = "Please wait...";
FilenameLabel = "";
Progress = 0.0;
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);
}
public override async Task Initialize()
{
try
{
await base.Initialize().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)

View File

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

View File

@ -66,7 +66,7 @@ namespace auto_creamapi.ViewModels
{
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);
}
}