Improved app start up
Fixed issues with extraction
This commit is contained in:
parent
8a4e601236
commit
478d5196a6
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@ -19,6 +20,7 @@ namespace auto_creamapi.Converters
|
||||
protected override string Convert(ObservableCollection<SteamApp> value, Type targetType, object parameter,
|
||||
CultureInfo culture)
|
||||
{
|
||||
if (value == null) return "";
|
||||
MyLogger.Log.Debug("ListOfDLcToStringConverter: Convert");
|
||||
var dlcListToString = DlcListToString(value);
|
||||
return dlcListToString.GetType() == targetType ? dlcListToString : "";
|
||||
@ -52,7 +54,7 @@ namespace auto_creamapi.Converters
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string DlcListToString(ObservableCollection<SteamApp> value)
|
||||
private static string DlcListToString(IEnumerable<SteamApp> value)
|
||||
{
|
||||
var result = "";
|
||||
//value.ForEach(x => result += $"{x}\n");
|
||||
|
@ -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))
|
||||
{
|
||||
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");
|
||||
try
|
||||
{
|
||||
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}");
|
||||
await extractor.ExtractFilesAsync(
|
||||
cwd,
|
||||
$@"{nonlogBuild}\{steamApi64Dll}",
|
||||
$@"{nonlogBuild}\{steamApiDll}"
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
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));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ using MvvmCross.ViewModels;
|
||||
|
||||
namespace auto_creamapi.ViewModels
|
||||
{
|
||||
|
||||
public class DownloadViewModel : MvxNavigationViewModel
|
||||
{
|
||||
private readonly IDownloadCreamApiService _download;
|
||||
@ -63,18 +64,18 @@ namespace auto_creamapi.ViewModels
|
||||
|
||||
public override async Task Initialize()
|
||||
{
|
||||
await base.Initialize();
|
||||
await base.Initialize().ConfigureAwait(false);
|
||||
InfoLabel = "Please wait...";
|
||||
FilenameLabel = "";
|
||||
Progress = 0.0;
|
||||
var download = _download.Download(Secrets.ForumUsername, Secrets.ForumPassword);
|
||||
var filename = await download;
|
||||
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);
|
||||
await _navigationService.Close(this).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private void OnProgressMessage(ProgressMessage obj)
|
||||
|
@ -52,14 +52,16 @@ namespace auto_creamapi.ViewModels
|
||||
//_download = download;
|
||||
}
|
||||
|
||||
public override async Task Initialize()
|
||||
public override async void Prepare()
|
||||
{
|
||||
base.Prepare();
|
||||
_config.Initialize();
|
||||
var tasks = new List<Task> {base.Initialize(), _cache.Initialize()};
|
||||
var tasks = new List<Task> {_cache.Initialize()};
|
||||
if (!File.Exists("steam_api.dll") | !File.Exists("steam_api64.dll"))
|
||||
tasks.Add(_navigationService.Navigate<DownloadViewModel>());
|
||||
//tasks.Add(_navigationService.Navigate<DownloadViewModel>());
|
||||
tasks.Add(_dll.Initialize());
|
||||
await Task.WhenAll(tasks);
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
Languages = new ObservableCollection<string>(Misc.DefaultLanguages);
|
||||
ResetForm();
|
||||
UseSteamDb = true;
|
||||
@ -67,11 +69,16 @@ namespace auto_creamapi.ViewModels
|
||||
Status = "Ready.";
|
||||
}
|
||||
|
||||
public override Task Initialize()
|
||||
{
|
||||
return base.Initialize();
|
||||
}
|
||||
|
||||
// // COMMANDS // //
|
||||
|
||||
public IMvxCommand OpenFileCommand => new MvxAsyncCommand(OpenFile);
|
||||
|
||||
public IMvxCommand SearchCommand => new MvxAsyncCommand(async () => await Search()); //Command(Search);
|
||||
public IMvxCommand SearchCommand => new MvxAsyncCommand(async () => await Search().ConfigureAwait(false)); //Command(Search);
|
||||
|
||||
public IMvxCommand GetListOfDlcCommand => new MvxAsyncCommand(GetListOfDlc);
|
||||
|
||||
@ -110,7 +117,6 @@ namespace auto_creamapi.ViewModels
|
||||
{
|
||||
_gameName = value;
|
||||
RaisePropertyChanged(() => GameName);
|
||||
//MyLogger.Log.Debug($"GameName: {value}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,7 +138,6 @@ namespace auto_creamapi.ViewModels
|
||||
{
|
||||
_lang = value;
|
||||
RaisePropertyChanged(() => Lang);
|
||||
//MyLogger.Log.Debug($"Lang: {value}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -269,8 +274,8 @@ namespace auto_creamapi.ViewModels
|
||||
: -1;
|
||||
var s = index > -1 ? strings[index] : null;
|
||||
if (s != null) GameName = s;
|
||||
await Search();
|
||||
await GetListOfDlc();
|
||||
await Search().ConfigureAwait(false);
|
||||
await GetListOfDlc().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Status = "Ready.";
|
||||
@ -297,7 +302,7 @@ namespace auto_creamapi.ViewModels
|
||||
MainWindowEnabled = false;
|
||||
var navigate = _navigationService.Navigate<SearchResultViewModel, IEnumerable<SteamApp>, SteamApp>(
|
||||
_cache.GetListOfAppsByName(GameName));
|
||||
await navigate;
|
||||
await navigate.ConfigureAwait(false);
|
||||
var navigateResult = navigate.Result;
|
||||
if (navigateResult != null)
|
||||
{
|
||||
@ -306,7 +311,7 @@ namespace auto_creamapi.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
await GetListOfDlc();
|
||||
await GetListOfDlc().ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -324,7 +329,7 @@ namespace auto_creamapi.ViewModels
|
||||
var app = new SteamApp {AppId = AppId, Name = GameName};
|
||||
var task = _cache.GetListOfDlc(app, UseSteamDb, IgnoreUnknown);
|
||||
MainWindowEnabled = false;
|
||||
var listOfDlc = await task;
|
||||
var listOfDlc = await task.ConfigureAwait(false);
|
||||
if (task.IsCompletedSuccessfully)
|
||||
{
|
||||
listOfDlc.Sort((app1, app2) => app1.AppId.CompareTo(app2.AppId));
|
||||
|
@ -67,7 +67,7 @@ namespace auto_creamapi.ViewModels
|
||||
if (Selected != null)
|
||||
{
|
||||
MyLogger.Log.Information($"Successfully got app {Selected}");
|
||||
await _navigationService.Close(this, Selected);
|
||||
await _navigationService.Close(this, Selected).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@
|
||||
VerticalAlignment="Bottom" Width="108" Command="{Binding GetListOfDlcCommand}" Grid.Row="4" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Header="Status" Grid.Row="1" VerticalAlignment="Bottom" IsEnabled="False">
|
||||
<GroupBox Header="Status" Grid.Row="1" VerticalAlignment="Bottom" IsEnabled="False" Margin="0,10,0,0">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
|
@ -11,38 +11,6 @@ namespace auto_creamapi.Views
|
||||
public SearchResultView()
|
||||
{
|
||||
InitializeComponent();
|
||||
//DgApps.ItemsSource = list;
|
||||
}
|
||||
|
||||
/*private void OK_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
GetSelectedApp();
|
||||
}
|
||||
|
||||
private void DgApps_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
GetSelectedApp();
|
||||
}
|
||||
|
||||
private void Cancel_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void GetSelectedApp()
|
||||
{
|
||||
if (Application.Current.MainWindow is MainWindow currentMainWindow)
|
||||
{
|
||||
var app = (SteamApp) DgApps.SelectedItem;
|
||||
if (app != null)
|
||||
{
|
||||
MyLogger.Log.Information($"Successfully got app {app}");
|
||||
//currentMainWindow.Game.Text = app.Name;
|
||||
//currentMainWindow.AppId.Text = app.AppId.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
Close();
|
||||
}*/
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user