SearchResultView and DownloadView implemented;

Ignore whitespaces and special chars when looking for games;
This commit is contained in:
Jeddunk 2020-12-28 15:27:37 +01:00
parent aada82693d
commit 73baa27245
26 changed files with 783 additions and 642 deletions

View file

@ -11,8 +11,7 @@ namespace auto_creamapi.Services
public interface ICreamDllService
{
public string TargetPath { get; set; }
public void Initialize();
//public Task InitializeAsync();
public Task Initialize();
public void Save();
public void CheckIfDllExistsAtTarget();
public bool CreamApiApplied();
@ -20,28 +19,18 @@ namespace auto_creamapi.Services
public class CreamDllService : ICreamDllService
{
private readonly IDownloadCreamApiService _downloadService;
public string TargetPath { get; set; }
private readonly Dictionary<string, CreamDll> _creamDlls = new Dictionary<string, CreamDll>();
private static readonly string HashPath = Path.Combine(Directory.GetCurrentDirectory(), "cream_api.md5");
private const string X86Arch = "x86";
private const string X64Arch = "x64";
private static readonly string HashPath = Path.Combine(Directory.GetCurrentDirectory(), "cream_api.md5");
private bool _x86Exists;
private readonly Dictionary<string, CreamDll> _creamDlls = new Dictionary<string, CreamDll>();
private bool _x64Exists;
public CreamDllService(IDownloadCreamApiService downloadService)
{
_downloadService = downloadService;
}
private bool _x86Exists;
public Task InitializeAsync()
{
return Task.Run(Initialize);
}
public string TargetPath { get; set; }
public void Initialize()
public async Task Initialize()
{
MyLogger.Log.Debug("CreamDllService: Initialize begin");
@ -51,11 +40,12 @@ namespace auto_creamapi.Services
if (!File.Exists(HashPath))
{
MyLogger.Log.Information("Writing md5sum file...");
File.WriteAllLines(HashPath, new[]
{
$"{_creamDlls[X86Arch].Hash} {_creamDlls[X86Arch].Filename}",
$"{_creamDlls[X64Arch].Hash} {_creamDlls[X64Arch].Filename}"
});
await File.WriteAllLinesAsync(HashPath,
new[]
{
$"{_creamDlls[X86Arch].Hash} {_creamDlls[X86Arch].Filename}",
$"{_creamDlls[X64Arch].Hash} {_creamDlls[X64Arch].Filename}"
});
}
MyLogger.Log.Debug("CreamDllService: Initialize end");
@ -67,6 +57,23 @@ namespace auto_creamapi.Services
if (_x64Exists) CopyDll(X64Arch);
}
public void CheckIfDllExistsAtTarget()
{
var x86file = Path.Combine(TargetPath, "steam_api.dll");
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}");
}
public bool CreamApiApplied()
{
var a = CreamApiApplied("x86");
var b = CreamApiApplied("x64");
return a | b;
}
private void CopyDll(string arch)
{
var sourceSteamApiDll = _creamDlls[arch].Filename;
@ -84,30 +91,13 @@ namespace auto_creamapi.Services
File.Copy(sourceSteamApiDll, targetSteamApiDll, true);
}
public void CheckIfDllExistsAtTarget()
{
var x86file = Path.Combine(TargetPath, "steam_api.dll");
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}");
}
public bool CreamApiApplied(string arch)
{
bool a = File.Exists(Path.Combine(TargetPath, _creamDlls[arch].OrigFilename));
bool b = GetHash(Path.Combine(TargetPath, _creamDlls[arch].Filename)).Equals(_creamDlls[arch].Hash);
var a = File.Exists(Path.Combine(TargetPath, _creamDlls[arch].OrigFilename));
var b = GetHash(Path.Combine(TargetPath, _creamDlls[arch].Filename)).Equals(_creamDlls[arch].Hash);
return a & b;
}
public bool CreamApiApplied()
{
bool a = CreamApiApplied("x86");
bool b = CreamApiApplied("x64");
return a | b;
}
private string GetHash(string filename)
{
if (File.Exists(filename))
@ -118,10 +108,8 @@ namespace auto_creamapi.Services
.ToString(md5.ComputeHash(stream))
.Replace("-", string.Empty);
}
else
{
return "";
}
return "";
}
}
}