Improved app start up
Fixed issues with extraction
This commit is contained in:
parent
8a4e601236
commit
478d5196a6
10 changed files with 84 additions and 91 deletions
|
@ -65,10 +65,10 @@ namespace auto_creamapi.Services
|
|||
var httpCall = client.GetAsync(SteamUri);
|
||||
var response = await httpCall.ConfigureAwait(false);
|
||||
var readAsStringAsync = response.Content.ReadAsStringAsync();
|
||||
var responseBody = await readAsStringAsync;
|
||||
var responseBody = await readAsStringAsync.ConfigureAwait(false);
|
||||
MyLogger.Log.Information("Got content from API successfully. Writing to file...");
|
||||
|
||||
await File.WriteAllTextAsync(CachePath, responseBody, Encoding.UTF8);
|
||||
await File.WriteAllTextAsync(CachePath, responseBody, Encoding.UTF8).ConfigureAwait(false);
|
||||
var cacheString = responseBody;
|
||||
MyLogger.Log.Information("Cache written to file successfully.");
|
||||
return cacheString;
|
||||
|
@ -141,12 +141,12 @@ namespace auto_creamapi.Services
|
|||
|
||||
MyLogger.Log.Information("Get SteamDB App");
|
||||
var httpCall = client.GetAsync(steamDbUri);
|
||||
var response = await httpCall;
|
||||
var response = await httpCall.ConfigureAwait(false);
|
||||
MyLogger.Log.Debug(httpCall.Status.ToString());
|
||||
MyLogger.Log.Debug(response.EnsureSuccessStatusCode().ToString());
|
||||
|
||||
var readAsStringAsync = response.Content.ReadAsStringAsync();
|
||||
var responseBody = await readAsStringAsync;
|
||||
var responseBody = await readAsStringAsync.ConfigureAwait(false);
|
||||
MyLogger.Log.Debug(readAsStringAsync.Status.ToString());
|
||||
|
||||
var parser = new HtmlParser();
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace auto_creamapi.Services
|
|||
bool unlockAll,
|
||||
bool extraProtection,
|
||||
bool forceOffline,
|
||||
ObservableCollection<SteamApp> dlcList);
|
||||
IEnumerable<SteamApp> dlcList);
|
||||
|
||||
public bool ConfigExists();
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace auto_creamapi.Services
|
|||
{
|
||||
private string _configFilePath;
|
||||
|
||||
public CreamConfig Config { get; set; }
|
||||
public CreamConfig Config { get; private set; }
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
|
@ -144,7 +144,7 @@ namespace auto_creamapi.Services
|
|||
bool unlockAll,
|
||||
bool extraProtection,
|
||||
bool forceOffline,
|
||||
ObservableCollection<SteamApp> dlcList)
|
||||
IEnumerable<SteamApp> dlcList)
|
||||
{
|
||||
Config.AppId = appId;
|
||||
Config.Language = language;
|
||||
|
|
|
@ -103,16 +103,13 @@ namespace auto_creamapi.Services
|
|||
|
||||
private static string GetHash(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
using var md5 = MD5.Create();
|
||||
using var stream = File.OpenRead(filename);
|
||||
return BitConverter
|
||||
.ToString(md5.ComputeHash(stream))
|
||||
.Replace("-", string.Empty);
|
||||
}
|
||||
if (!File.Exists(filename)) return "";
|
||||
using var md5 = MD5.Create();
|
||||
using var stream = File.OpenRead(filename);
|
||||
return BitConverter
|
||||
.ToString(md5.ComputeHash(stream))
|
||||
.Replace("-", string.Empty);
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,8 +17,6 @@ namespace auto_creamapi.Services
|
|||
{
|
||||
public interface IDownloadCreamApiService
|
||||
{
|
||||
/*public void Initialize();
|
||||
public Task InitializeAsync();*/
|
||||
public Task<string> Download(string username, string password);
|
||||
public Task Extract(string filename);
|
||||
}
|
||||
|
@ -26,10 +24,7 @@ namespace auto_creamapi.Services
|
|||
public class DownloadCreamApiService : IDownloadCreamApiService
|
||||
{
|
||||
private const string ArchivePassword = "cs.rin.ru";
|
||||
|
||||
//private string _filename;
|
||||
private readonly IMvxMessenger _messenger;
|
||||
//private DownloadWindow _wnd;
|
||||
|
||||
public DownloadCreamApiService(IMvxMessenger messenger)
|
||||
{
|
||||
|
@ -50,23 +45,25 @@ namespace auto_creamapi.Services
|
|||
new KeyValuePair<string, string>("login", "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);
|
||||
MyLogger.Log.Debug($"Login Status Code: {response1.EnsureSuccessStatusCode().StatusCode.ToString()}");
|
||||
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}");
|
||||
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);
|
||||
MyLogger.Log.Debug(
|
||||
$"Download Page Status Code: {response2.EnsureSuccessStatusCode().StatusCode.ToString()}");
|
||||
var content = response2.Content.ReadAsStringAsync();
|
||||
var contentResult = await content;
|
||||
var contentResult = await content.ConfigureAwait(false);
|
||||
|
||||
var expression =
|
||||
new Regex(".*<a href=\"\\.(?<url>\\/download\\/file\\.php\\?id=.*)\">(?<filename>.*)<\\/a>.*");
|
||||
using var reader = new StringReader(contentResult);
|
||||
string line;
|
||||
var archiveFileList = new Dictionary<string, string>();
|
||||
while ((line = await reader.ReadLineAsync()) != null)
|
||||
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
|
||||
{
|
||||
var match = expression.Match(line);
|
||||
// ReSharper disable once InvertIf
|
||||
|
@ -80,7 +77,6 @@ namespace auto_creamapi.Services
|
|||
|
||||
MyLogger.Log.Debug("Choosing first element from list...");
|
||||
var (filename, url) = archiveFileList.FirstOrDefault();
|
||||
//filename = filename;
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
MyLogger.Log.Information($"{filename} already exists, skipping download...");
|
||||
|
@ -92,7 +88,7 @@ namespace auto_creamapi.Services
|
|||
x => _messenger.Publish(new ProgressMessage(this, "Downloading...", filename, x)));
|
||||
await using var fileStream = File.OpenWrite(filename);
|
||||
var task = client.GetAsync(url, fileStream, progress);
|
||||
var response = await task;
|
||||
await task.ConfigureAwait(false);
|
||||
if (task.IsCompletedSuccessfully)
|
||||
_messenger.Publish(new ProgressMessage(this, "Downloading...", filename, 1.0));
|
||||
MyLogger.Log.Information("Download done.");
|
||||
|
@ -107,23 +103,47 @@ namespace auto_creamapi.Services
|
|||
const string steamApi64Dll = "steam_api64.dll";
|
||||
const string steamApiDll = "steam_api.dll";
|
||||
MyLogger.Log.Information($@"Start extraction of ""{filename}""...");
|
||||
var expression1 = new Regex(@"nonlog_build\\steam_api(?:64)?\.dll");
|
||||
_messenger.Publish(new ProgressMessage(this, "Extracting...", filename, 1.0));
|
||||
SevenZipBase.SetLibraryPath(Path.Combine(cwd, "resources/7z.dll"));
|
||||
using (var extractor =
|
||||
new SevenZipExtractor(filename, ArchivePassword, InArchiveFormat.Rar)
|
||||
{PreserveDirectoryStructure = false})
|
||||
try
|
||||
{
|
||||
await extractor.ExtractFilesAsync(cwd,
|
||||
$"{nonlogBuild}\\{steamApi64Dll}",
|
||||
$"{nonlogBuild}\\{steamApiDll}");
|
||||
var nonlogBuildPath = Path.Combine(cwd, nonlogBuild);
|
||||
if (Directory.Exists(nonlogBuildPath))
|
||||
Directory.Delete(nonlogBuildPath, true);
|
||||
_messenger.Publish(new ProgressMessage(this, "Extracting...", filename, 1.0));
|
||||
SevenZipBase.SetLibraryPath(Path.Combine(cwd, "resources/7z.dll"));
|
||||
using (var extractor =
|
||||
new SevenZipExtractor(filename, ArchivePassword, InArchiveFormat.Rar)
|
||||
{PreserveDirectoryStructure = false})
|
||||
{
|
||||
await extractor.ExtractFilesAsync(
|
||||
cwd,
|
||||
$@"{nonlogBuild}\{steamApi64Dll}",
|
||||
$@"{nonlogBuild}\{steamApiDll}"
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (File.Exists(Path.Combine(nonlogBuildPath, steamApi64Dll)))
|
||||
File.Move(
|
||||
Path.Combine(cwd, nonlogBuild, steamApi64Dll),
|
||||
Path.Combine(cwd, steamApi64Dll),
|
||||
true
|
||||
);
|
||||
|
||||
if (File.Exists(Path.Combine(nonlogBuildPath, steamApiDll)))
|
||||
File.Move(
|
||||
Path.Combine(nonlogBuildPath, steamApiDll),
|
||||
Path.Combine(cwd, steamApiDll),
|
||||
true
|
||||
);
|
||||
|
||||
if (Directory.Exists(nonlogBuildPath))
|
||||
Directory.Delete(nonlogBuildPath, true);
|
||||
MyLogger.Log.Information("Extraction done!");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
if (File.Exists(Path.Combine(cwd, nonlogBuild, steamApi64Dll)))
|
||||
File.Move(Path.Combine(cwd, nonlogBuild, steamApi64Dll), Path.Combine(cwd, steamApi64Dll));
|
||||
if (File.Exists(Path.Combine(cwd, nonlogBuild, steamApiDll)))
|
||||
File.Move(Path.Combine(cwd, nonlogBuild, steamApiDll), Path.Combine(cwd, steamApiDll));
|
||||
Directory.Delete(Path.Combine(cwd, nonlogBuild));
|
||||
MyLogger.Log.Information("Extraction done!");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue