diff --git a/auto-creamapi/App.xaml.cs b/auto-creamapi/App.xaml.cs
index e6b5949..95e07c3 100644
--- a/auto-creamapi/App.xaml.cs
+++ b/auto-creamapi/App.xaml.cs
@@ -1,11 +1,10 @@
using MvvmCross.Core;
using MvvmCross.Platforms.Wpf.Core;
-using MvvmCross.Platforms.Wpf.Views;
namespace auto_creamapi
{
///
- /// Interaction logic for App.xaml
+ /// Interaction logic for App.xaml
///
public partial class App
{
@@ -14,4 +13,4 @@ namespace auto_creamapi
this.RegisterSetupType>();
}
}
-}
+}
\ No newline at end of file
diff --git a/auto-creamapi/Converters/ListOfDLcToStringConverter.cs b/auto-creamapi/Converters/ListOfDLcToStringConverter.cs
index ca3bd46..aabfdd6 100644
--- a/auto-creamapi/Converters/ListOfDLcToStringConverter.cs
+++ b/auto-creamapi/Converters/ListOfDLcToStringConverter.cs
@@ -1,30 +1,40 @@
using System;
-using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Text.RegularExpressions;
using auto_creamapi.Models;
+using auto_creamapi.Utils;
using MvvmCross.Converters;
+using MvvmCross.Platforms.Wpf.Converters;
namespace auto_creamapi.Converters
{
- public class ListOfDLcToStringConverter : MvxValueConverter, string>
+ public class ListOfDLcToStringNativeConverter : MvxNativeValueConverter
{
- protected override string Convert(List value, Type targetType, object parameter, CultureInfo culture)
+ }
+
+ public class ListOfDLcToStringConverter : MvxValueConverter, string>
+ {
+ protected override string Convert(ObservableCollection value, Type targetType, object parameter,
+ CultureInfo culture)
{
+ MyLogger.Log.Debug("ListOfDLcToStringConverter: Convert");
var dlcListToString = DlcListToString(value);
return dlcListToString.GetType() == targetType ? dlcListToString : "";
}
- protected override List ConvertBack(string value, Type targetType, object parameter, CultureInfo culture)
+ protected override ObservableCollection ConvertBack(string value, Type targetType, object parameter,
+ CultureInfo culture)
{
+ MyLogger.Log.Debug("ListOfDLcToStringConverter: ConvertBack");
var stringToDlcList = StringToDlcList(value);
- return stringToDlcList.GetType() == targetType ? stringToDlcList : new List();
+ return stringToDlcList.GetType() == targetType ? stringToDlcList : new ObservableCollection();
}
- private static List StringToDlcList(string value)
+ private static ObservableCollection StringToDlcList(string value)
{
- var result = new List();
+ var result = new ObservableCollection();
var expression = new Regex(@"(?.*) *= *(?.*)");
using var reader = new StringReader(value);
string line;
@@ -32,22 +42,21 @@ namespace auto_creamapi.Converters
{
var match = expression.Match(line);
if (match.Success)
- {
result.Add(new SteamApp
{
AppId = int.Parse(match.Groups["id"].Value),
Name = match.Groups["name"].Value
});
- }
}
return result;
}
- private static string DlcListToString(List value)
+ private static string DlcListToString(ObservableCollection value)
{
var result = "";
- value.ForEach(x => result += $"{x}\n");
+ //value.ForEach(x => result += $"{x}\n");
+ foreach (var steamApp in value) result += $"{steamApp}\n";
return result;
}
}
diff --git a/auto-creamapi/Core/App.cs b/auto-creamapi/Core/App.cs
index 4f11a3b..f64d409 100644
--- a/auto-creamapi/Core/App.cs
+++ b/auto-creamapi/Core/App.cs
@@ -1,6 +1,4 @@
-using auto_creamapi.Services;
using auto_creamapi.ViewModels;
-using MvvmCross;
using MvvmCross.IoC;
using MvvmCross.ViewModels;
diff --git a/auto-creamapi/DownloadWindow.xaml b/auto-creamapi/DownloadWindow.xaml
deleted file mode 100644
index dcf379a..0000000
--- a/auto-creamapi/DownloadWindow.xaml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/auto-creamapi/DownloadWindow.xaml.cs b/auto-creamapi/DownloadWindow.xaml.cs
deleted file mode 100644
index dc0c492..0000000
--- a/auto-creamapi/DownloadWindow.xaml.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Shapes;
-using auto_creamapi.Utils;
-
-namespace auto_creamapi
-{
- ///
- /// Interaction logic for DownloadWindow.xaml
- ///
- public partial class DownloadWindow
- {
- public DownloadWindow()
- {
- WindowStartupLocation = WindowStartupLocation.CenterScreen;
- InitializeComponent();
- }
-
- private void ProgressBar_OnValueChanged(object sender, RoutedPropertyChangedEventArgs e)
- {
- //MyLogger.Log.Information(ProgressBar.Value.ToString("N"));
- }
- }
-}
diff --git a/auto-creamapi/MainWindow.xaml.cs b/auto-creamapi/MainWindow.xaml.cs
index 17f2bfe..2e09a9c 100644
--- a/auto-creamapi/MainWindow.xaml.cs
+++ b/auto-creamapi/MainWindow.xaml.cs
@@ -1,6 +1,4 @@
-using System.Windows;
using MvvmCross.Platforms.Wpf.Presenters.Attributes;
-using MvvmCross.Platforms.Wpf.Views;
namespace auto_creamapi
{
diff --git a/auto-creamapi/Messenger/ProgressMessage.cs b/auto-creamapi/Messenger/ProgressMessage.cs
new file mode 100644
index 0000000..a83606b
--- /dev/null
+++ b/auto-creamapi/Messenger/ProgressMessage.cs
@@ -0,0 +1,40 @@
+using HttpProgress;
+using MvvmCross.Plugin.Messenger;
+
+namespace auto_creamapi.Messenger
+{
+ public class ProgressMessage : MvxMessage
+ {
+ private readonly ICopyProgress _progress;
+ private double _percentProgress;
+
+ public ProgressMessage(object sender, string info, string filename, ICopyProgress progress) : base(sender)
+ {
+ Info = info;
+ Filename = filename;
+ _progress = progress;
+ }
+
+ public ProgressMessage(object sender, string info, string filename, double progress) : base(sender)
+ {
+ _progress = null;
+ Info = info;
+ Filename = filename;
+ PercentComplete = progress;
+ }
+
+ public string Info { get; }
+ public string Filename { get; }
+
+ public double PercentComplete
+ {
+ get => _progress?.PercentComplete ?? _percentProgress;
+ private set => _percentProgress = value;
+ }
+
+ // public long BytesTransferred => _progress.BytesTransferred;
+ // public long ExpectedBytes => _progress.ExpectedBytes;
+ // public long BytesPerSecond => _progress.BytesPerSecond;
+ // public TimeSpan TransferTime => _progress.TransferTime;
+ }
+}
\ No newline at end of file
diff --git a/auto-creamapi/Models/CreamConfigModel.cs b/auto-creamapi/Models/CreamConfigModel.cs
index 3e247e2..5c771e5 100644
--- a/auto-creamapi/Models/CreamConfigModel.cs
+++ b/auto-creamapi/Models/CreamConfigModel.cs
@@ -1,30 +1,23 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using System.Text.RegularExpressions;
-using auto_creamapi.Utils;
-using IniParser;
-using IniParser.Model;
+using System.Collections.Generic;
namespace auto_creamapi.Models
{
public class CreamConfig
{
+ public CreamConfig()
+ {
+ DlcList = new List();
+ }
+
public int AppId { get; set; }
public string Language { get; set; }
public bool UnlockAll { get; set; }
public bool ExtraProtection { get; set; }
public bool ForceOffline { get; set; }
public List DlcList { get; set; }
-
- public CreamConfig()
- {
- DlcList = new List();
- }
}
+
public sealed class CreamConfigModel
{
-
}
-}
+}
\ No newline at end of file
diff --git a/auto-creamapi/Models/CreamDllModel.cs b/auto-creamapi/Models/CreamDllModel.cs
index 2a6745e..6415459 100644
--- a/auto-creamapi/Models/CreamDllModel.cs
+++ b/auto-creamapi/Models/CreamDllModel.cs
@@ -1,18 +1,14 @@
using System;
-using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
-using System.Threading.Tasks;
-using auto_creamapi.Services;
-using auto_creamapi.Utils;
namespace auto_creamapi.Models
{
internal class CreamDll
{
public readonly string Filename;
- public readonly string OrigFilename;
public readonly string Hash;
+ public readonly string OrigFilename;
public CreamDll(string filename, string origFilename)
{
@@ -30,8 +26,8 @@ namespace auto_creamapi.Models
}
}
}
+
public class CreamDllModel
{
-
}
}
\ No newline at end of file
diff --git a/auto-creamapi/Models/SteamAppModel.cs b/auto-creamapi/Models/SteamAppModel.cs
index 9fff2a6..5c85687 100644
--- a/auto-creamapi/Models/SteamAppModel.cs
+++ b/auto-creamapi/Models/SteamAppModel.cs
@@ -1,16 +1,13 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
-using MvvmCross.ViewModels;
namespace auto_creamapi.Models
{
public class SteamApp
{
- [JsonPropertyName("appid")]
- public int AppId { get; set; }
-
- [JsonPropertyName("name")]
- public string Name { get; set; }
+ [JsonPropertyName("appid")] public int AppId { get; set; }
+
+ [JsonPropertyName("name")] public string Name { get; set; }
public override string ToString()
{
@@ -26,13 +23,11 @@ namespace auto_creamapi.Models
public class AppList
{
- [JsonPropertyName("apps")]
- public List Apps { get; set; }
+ [JsonPropertyName("apps")] public List Apps { get; set; }
}
public class SteamApps
{
- [JsonPropertyName("applist")]
- public AppList AppList { get; set; }
+ [JsonPropertyName("applist")] public AppList AppList { get; set; }
}
}
\ No newline at end of file
diff --git a/auto-creamapi/SearchResultWindow.xaml b/auto-creamapi/SearchResultWindow.xaml
deleted file mode 100644
index 23617ef..0000000
--- a/auto-creamapi/SearchResultWindow.xaml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs
index 0596e03..3d18e68 100644
--- a/auto-creamapi/Services/CacheService.cs
+++ b/auto-creamapi/Services/CacheService.cs
@@ -4,6 +4,7 @@ using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AngleSharp.Dom;
using AngleSharp.Html.Parser;
@@ -17,7 +18,10 @@ namespace auto_creamapi.Services
public interface ICacheService
{
public List Languages { get; }
- public void UpdateCache();
+
+ public Task Initialize();
+
+ //public Task UpdateCache();
public IEnumerable GetListOfAppsByName(string name);
public SteamApp GetAppByName(string name);
public SteamApp GetAppById(int appid);
@@ -28,43 +32,14 @@ namespace auto_creamapi.Services
{
private const string CachePath = "steamapps.json";
private const string SteamUri = "https://api.steampowered.com/ISteamApps/GetAppList/v2/";
+
private const string UserAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " +
"Chrome/87.0.4280.88 Safari/537.36";
+ private const string SpecialCharsRegex = "[^0-9a-zA-Z]+";
+
private List _cache = new List();
- private readonly List _languages = new List(new[]
- {
- "arabic",
- "bulgarian",
- "schinese",
- "tchinese",
- "czech",
- "danish",
- "dutch",
- "english",
- "finnish",
- "french",
- "german",
- "greek",
- "hungarian",
- "italian",
- "japanese",
- "koreana",
- "norwegian",
- "polish",
- "portuguese",
- "brazilian",
- "romanian",
- "russian",
- "spanish",
- "latam",
- "swedish",
- "thai",
- "turkish",
- "ukrainian",
- "vietnamese"
- });
/*private static readonly Lazy Lazy =
new Lazy(() => new CacheService());
@@ -73,13 +48,18 @@ namespace auto_creamapi.Services
public CacheService()
{
- Languages = _languages;
- UpdateCache();
+ Languages = Misc.DefaultLanguages;
}
+ /*public async void Initialize()
+ {
+ //Languages = _defaultLanguages;
+ await UpdateCache();
+ }*/
+
public List Languages { get; }
- public void UpdateCache()
+ public async Task Initialize()
{
MyLogger.Log.Information("Updating cache...");
var updateNeeded = DateTime.Now.Subtract(File.GetLastWriteTimeUtc(CachePath)).TotalDays >= 1;
@@ -89,20 +69,19 @@ namespace auto_creamapi.Services
MyLogger.Log.Information("Getting content from API...");
var client = new HttpClient();
var httpCall = client.GetAsync(SteamUri);
- var response = httpCall.Result;
+ var response = await httpCall;
var readAsStringAsync = response.Content.ReadAsStringAsync();
- var responseBody = readAsStringAsync.Result;
+ var responseBody = await readAsStringAsync;
MyLogger.Log.Information("Got content from API successfully. Writing to file...");
- //var writeAllTextAsync = File.WriteAllTextAsync(CachePath, responseBody, Encoding.UTF8);
- //writeAllTextAsync.RunSynchronously();
- File.WriteAllText(CachePath, responseBody, Encoding.UTF8);
+ await File.WriteAllTextAsync(CachePath, responseBody, Encoding.UTF8);
cacheString = responseBody;
MyLogger.Log.Information("Cache written to file successfully.");
}
else
{
MyLogger.Log.Information("Cache already up to date!");
+ // ReSharper disable once MethodHasAsyncOverload
cacheString = File.ReadAllText(CachePath);
}
@@ -122,7 +101,9 @@ namespace auto_creamapi.Services
public SteamApp GetAppByName(string name)
{
MyLogger.Log.Information($"Trying to get app {name}");
- var app = _cache.Find(x => x.Name.ToLower().Equals(name.ToLower()));
+ var app = _cache.Find(x =>
+ Regex.Replace(x.Name, SpecialCharsRegex, "").ToLower()
+ .Equals(Regex.Replace(name, SpecialCharsRegex, "").ToLower()));
if (app != null) MyLogger.Log.Information($"Successfully got app {app}");
return app;
}
@@ -194,10 +175,7 @@ namespace auto_creamapi.Services
var dlcId = element.GetAttribute("data-appid");
var dlcName = $"Unknown DLC {dlcId}";
var query3 = element.QuerySelectorAll("td");
- if (query3 != null)
- {
- dlcName = query3[1].Text().Replace("\n", "").Trim();
- }
+ if (query3 != null) dlcName = query3[1].Text().Replace("\n", "").Trim();
var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName};
var i = dlcList.FindIndex(x => x.CompareId(dlcApp));
@@ -222,7 +200,7 @@ namespace auto_creamapi.Services
}
else
{
- MyLogger.Log.Error($"Could not get DLC: Invalid Steam App");
+ MyLogger.Log.Error("Could not get DLC: Invalid Steam App");
}
return dlcList;
diff --git a/auto-creamapi/Services/CreamConfigService.cs b/auto-creamapi/Services/CreamConfigService.cs
index 9889655..712e193 100644
--- a/auto-creamapi/Services/CreamConfigService.cs
+++ b/auto-creamapi/Services/CreamConfigService.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
@@ -14,6 +15,7 @@ namespace auto_creamapi.Services
public interface ICreamConfigService
{
public CreamConfig Config { get; }
+ public void Initialize();
public void ReadFile(string configFilePath);
public void SaveFile();
@@ -31,21 +33,31 @@ namespace auto_creamapi.Services
bool forceOffline,
List dlcList);
+ public void SetConfigData(int appId,
+ string language,
+ bool unlockAll,
+ bool extraProtection,
+ bool forceOffline,
+ ObservableCollection dlcList);
+
public bool ConfigExists();
-
-
}
public class CreamConfigService : ICreamConfigService
{
- public CreamConfig Config { get; }
-
private string _configFilePath;
- public CreamConfigService()
+ public CreamConfig Config { get; set; }
+
+ public void Initialize()
{
+ //await Task.Run(() =>
+ //{
+ //MyLogger.Log.Debug("CreamConfigService: init start");
Config = new CreamConfig();
ResetConfigData();
+ //MyLogger.Log.Debug("CreamConfigService: init end");
+ //});
}
public void ReadFile(string configFilePath)
@@ -66,10 +78,8 @@ namespace auto_creamapi.Services
var dlcCollection = data["dlc"];
foreach (var item in dlcCollection)
- {
//Config.DlcList.Add(int.Parse(item.KeyName), item.Value);
- Config.DlcList.Add(new SteamApp{AppId = int.Parse(item.KeyName), Name = item.Value});
- }
+ Config.DlcList.Add(new SteamApp {AppId = int.Parse(item.KeyName), Name = item.Value});
}
else
{
@@ -99,16 +109,6 @@ namespace auto_creamapi.Services
parser.WriteFile(_configFilePath, data, Encoding.UTF8);
}
- private void ResetConfigData()
- {
- Config.AppId = -1;
- Config.Language = "";
- Config.UnlockAll = false;
- Config.ExtraProtection = false;
- Config.ForceOffline = false;
- Config.DlcList.Clear();
- }
-
public void SetConfigData(int appId,
string language,
bool unlockAll,
@@ -123,7 +123,7 @@ namespace auto_creamapi.Services
Config.ForceOffline = forceOffline;
SetDlcFromString(dlcList);
}
-
+
public void SetConfigData(int appId,
string language,
bool unlockAll,
@@ -138,7 +138,37 @@ namespace auto_creamapi.Services
Config.ForceOffline = forceOffline;
Config.DlcList = dlcList;
}
-
+
+ public void SetConfigData(int appId,
+ string language,
+ bool unlockAll,
+ bool extraProtection,
+ bool forceOffline,
+ ObservableCollection dlcList)
+ {
+ Config.AppId = appId;
+ Config.Language = language;
+ Config.UnlockAll = unlockAll;
+ Config.ExtraProtection = extraProtection;
+ Config.ForceOffline = forceOffline;
+ Config.DlcList = new List(dlcList);
+ }
+
+ public bool ConfigExists()
+ {
+ return File.Exists(_configFilePath);
+ }
+
+ private void ResetConfigData()
+ {
+ Config.AppId = -1;
+ Config.Language = "";
+ Config.UnlockAll = false;
+ Config.ExtraProtection = false;
+ Config.ForceOffline = false;
+ Config.DlcList.Clear();
+ }
+
private void SetDlcFromString(string dlcList)
{
Config.DlcList.Clear();
@@ -149,10 +179,8 @@ namespace auto_creamapi.Services
{
var match = expression.Match(line);
if (match.Success)
- {
Config.DlcList.Add(
- new SteamApp{AppId = int.Parse(match.Groups["id"].Value), Name = match.Groups["name"].Value});
- }
+ new SteamApp {AppId = int.Parse(match.Groups["id"].Value), Name = match.Groups["name"].Value});
}
}
/*private void SetDlcFromAppList(List dlcList)
@@ -171,22 +199,15 @@ namespace auto_creamapi.Services
$"ForceOffline: {Config.ForceOffline}, " +
$"DLC ({Config.DlcList.Count}):\n[\n";
if (Config.DlcList.Count > 0)
- {
str = Config.DlcList.Aggregate(str, (current, x) => current + $" {x.AppId}={x.Name},\n");
- /*foreach (var (key, value) in Config.DlcList)
+ /*foreach (var (key, value) in Config.DlcList)
{
str += $" {key}={value},\n";
}*/
- }
str += "]";
return str;
}
-
- public bool ConfigExists()
- {
- return File.Exists(_configFilePath);
- }
}
}
\ No newline at end of file
diff --git a/auto-creamapi/Services/CreamDllService.cs b/auto-creamapi/Services/CreamDllService.cs
index 554654e..de0470c 100644
--- a/auto-creamapi/Services/CreamDllService.cs
+++ b/auto-creamapi/Services/CreamDllService.cs
@@ -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 _creamDlls = new Dictionary();
- 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 _creamDlls = new Dictionary();
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 "";
}
}
}
\ No newline at end of file
diff --git a/auto-creamapi/Services/DownloadCreamApiService.cs b/auto-creamapi/Services/DownloadCreamApiService.cs
index 5d2678a..34126f1 100644
--- a/auto-creamapi/Services/DownloadCreamApiService.cs
+++ b/auto-creamapi/Services/DownloadCreamApiService.cs
@@ -6,9 +6,10 @@ using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
-using System.Windows.Threading;
+using auto_creamapi.Messenger;
using auto_creamapi.Utils;
using HttpProgress;
+using MvvmCross.Plugin.Messenger;
using SharpCompress.Archives;
using SharpCompress.Common;
using SharpCompress.Readers;
@@ -17,73 +18,26 @@ namespace auto_creamapi.Services
{
public interface IDownloadCreamApiService
{
- public void Initialize();
- // public Task InitializeAsync();
- public Task DownloadAndExtract(string username, string password);
+ /*public void Initialize();
+ public Task InitializeAsync();*/
+ public Task Download(string username, string password);
+ public void Extract(string filename);
}
+
public class DownloadCreamApiService : IDownloadCreamApiService
{
private const string ArchivePassword = "cs.rin.ru";
- private static string _filename;
- //private static DownloadWindow _wnd;
- public DownloadCreamApiService()
+ //private string _filename;
+ private readonly IMvxMessenger _messenger;
+ //private DownloadWindow _wnd;
+
+ public DownloadCreamApiService(IMvxMessenger messenger)
{
-
+ _messenger = messenger;
}
- public void Initialize()
- {
- MyLogger.Log.Debug("DownloadCreamApiService: Initialize begin");
- if (File.Exists("steam_api.dll") && File.Exists("steam_api64.dll"))
- {
- MyLogger.Log.Information("Skipping download...");
- }
- else
- {
- MyLogger.Log.Information("Missing files, trying to download...");
- DownloadAndExtract(Secrets.ForumUsername, Secrets.ForumPassword).Start();
- }
- //await creamDllService.InitializeAsync();
- MyLogger.Log.Debug("DownloadCreamApiService: Initialize end");
- }
-
- public async Task InitializeAsync()
- {
- MyLogger.Log.Debug("DownloadCreamApiService: Initialize begin");
- if (File.Exists("steam_api.dll") && File.Exists("steam_api64.dll"))
- {
- MyLogger.Log.Information("Skipping download...");
- }
- else
- {
- MyLogger.Log.Information("Missing files, trying to download...");
- var downloadAndExtract = DownloadAndExtract(Secrets.ForumUsername, Secrets.ForumPassword);
- await downloadAndExtract;
- downloadAndExtract.Wait();
- }
- //await creamDllService.InitializeAsync();
- MyLogger.Log.Debug("DownloadCreamApiService: Initialize end");
- }
-
- public async Task DownloadAndExtract(string username, string password)
- {
- MyLogger.Log.Debug("DownloadAndExtract");
- //_wnd = new DownloadWindow();
- //_wnd.Show();
- var download = Download(username, password);
- await download;
- download.Wait();
- /*var extract = Extract();
- await extract;
- extract.Wait();*/
- var extract = Task.Run(Extract);
- await extract;
- extract.Wait();
- //_wnd.Close();
- }
-
- private static async Task Download(string username, string password)
+ public async Task Download(string username, string password)
{
MyLogger.Log.Debug("Download");
var container = new CookieContainer();
@@ -125,69 +79,36 @@ namespace auto_creamapi.Services
}
}
- /*foreach (var (filename, url) in archiveFileList)
- {
- MyLogger.Log.Information($"Downloading file: {filename}");
- var fileResponse = await client.GetAsync(url);
- var download = fileResponse.Content.ReadAsByteArrayAsync();
- await File.WriteAllBytesAsync(filename, await download);
- }*/
MyLogger.Log.Debug("Choosing first element from list...");
var (filename, url) = archiveFileList.FirstOrDefault();
- _filename = filename;
- if (File.Exists(_filename))
+ //filename = filename;
+ if (File.Exists(filename))
{
- MyLogger.Log.Information($"{_filename} already exists, skipping download...");
- return;
+ MyLogger.Log.Information($"{filename} already exists, skipping download...");
+ return filename;
}
MyLogger.Log.Information("Start download...");
- /*await _wnd.FilenameLabel.Dispatcher.InvokeAsync(
- () => _wnd.FilenameLabel.Content = _filename, DispatcherPriority.Background);
- await _wnd.InfoLabel.Dispatcher.InvokeAsync(
- () => _wnd.InfoLabel.Content = "Downloading...", DispatcherPriority.Background);*/
- /*var fileResponse = await client.GetAsync(url);
- var download = fileResponse.Content.ReadAsByteArrayAsync();
- await File.WriteAllBytesAsync(filename, await download);
- MyLogger.Log.Information($"Download success? {download.IsCompletedSuccessfully}");*/
var progress = new Progress(
- x =>
- {
- /*_wnd.PercentLabel.Dispatcher.Invoke(
- () => _wnd.PercentLabel.Content = x.PercentComplete.ToString("P"),
- DispatcherPriority.Background);
- _wnd.ProgressBar.Dispatcher.Invoke(
- () => _wnd.ProgressBar.Value = x.PercentComplete, DispatcherPriority.Background);*/
- });
- await using var fileStream = File.OpenWrite(_filename);
+ 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;
if (task.IsCompletedSuccessfully)
- {
- /*_wnd.PercentLabel.Dispatcher.Invoke(
- () => _wnd.PercentLabel.Content = "100,00%", DispatcherPriority.Background);
- _wnd.ProgressBar.Dispatcher.Invoke(
- () => _wnd.ProgressBar.Value = 1, DispatcherPriority.Background);*/
- }
+ _messenger.Publish(new ProgressMessage(this, "Downloading...", filename, 1.0));
+ MyLogger.Log.Information("Download done.");
+ return filename;
}
- private static void Extract()
+ public void Extract(string filename)
{
MyLogger.Log.Debug("Extract");
- MyLogger.Log.Information("Start extraction...");
+ MyLogger.Log.Information($@"Start extraction of ""{filename}""...");
var options = new ReaderOptions {Password = ArchivePassword};
- var archive = ArchiveFactory.Open(_filename, options);
+ var archive = ArchiveFactory.Open(filename, options);
var expression1 = new Regex(@"nonlog_build\\steam_api(?:64)?\.dll");
- /*await _wnd.ProgressBar.Dispatcher.InvokeAsync(
- () => _wnd.ProgressBar.IsIndeterminate = true, DispatcherPriority.ContextIdle);
- await _wnd.FilenameLabel.Dispatcher.InvokeAsync(
- () => _wnd.FilenameLabel.Content = _filename, DispatcherPriority.ContextIdle);
- await _wnd.InfoLabel.Dispatcher.InvokeAsync(
- () => _wnd.InfoLabel.Content = "Extracting...", DispatcherPriority.ContextIdle);
- await _wnd.PercentLabel.Dispatcher.InvokeAsync(
- () => _wnd.PercentLabel.Content = "100%", DispatcherPriority.ContextIdle);*/
+ _messenger.Publish(new ProgressMessage(this, "Extracting...", filename, 1.0));
foreach (var entry in archive.Entries)
- {
// ReSharper disable once InvertIf
if (!entry.IsDirectory && expression1.IsMatch(entry.Key))
{
@@ -198,7 +119,6 @@ namespace auto_creamapi.Services
Overwrite = true
});
}
- }
MyLogger.Log.Information("Extraction done!");
}
diff --git a/auto-creamapi/Utils/Misc.cs b/auto-creamapi/Utils/Misc.cs
new file mode 100644
index 0000000..6a04bbd
--- /dev/null
+++ b/auto-creamapi/Utils/Misc.cs
@@ -0,0 +1,40 @@
+using System.Collections.Generic;
+
+namespace auto_creamapi.Utils
+{
+ public class Misc
+ {
+ public static readonly List DefaultLanguages = new List(new[]
+ {
+ "arabic",
+ "bulgarian",
+ "schinese",
+ "tchinese",
+ "czech",
+ "danish",
+ "dutch",
+ "english",
+ "finnish",
+ "french",
+ "german",
+ "greek",
+ "hungarian",
+ "italian",
+ "japanese",
+ "koreana",
+ "norwegian",
+ "polish",
+ "portuguese",
+ "brazilian",
+ "romanian",
+ "russian",
+ "spanish",
+ "latam",
+ "swedish",
+ "thai",
+ "turkish",
+ "ukrainian",
+ "vietnamese"
+ });
+ }
+}
\ No newline at end of file
diff --git a/auto-creamapi/Utils/Secrets.EXAMPLE.cs b/auto-creamapi/Utils/Secrets.EXAMPLE.cs
index 06fcee6..f885562 100644
--- a/auto-creamapi/Utils/Secrets.EXAMPLE.cs
+++ b/auto-creamapi/Utils/Secrets.EXAMPLE.cs
@@ -1,10 +1,10 @@
namespace auto_creamapi.Utils
{
///
- /// To use this:
- /// Rename file Secrets.EXAMPLE.cs to Secrets.cs
- /// Rename class Secrets_REMOVETHIS to Secrets
- /// Enter the relevant info below
+ /// To use this:
+ /// Rename file Secrets.EXAMPLE.cs to Secrets.cs
+ /// Rename class Secrets_REMOVETHIS to Secrets
+ /// Enter the relevant info below
///
public class Secrets_REMOVETHIS
{
diff --git a/auto-creamapi/ViewModels/DownloadViewModel.cs b/auto-creamapi/ViewModels/DownloadViewModel.cs
new file mode 100644
index 0000000..63475f3
--- /dev/null
+++ b/auto-creamapi/ViewModels/DownloadViewModel.cs
@@ -0,0 +1,87 @@
+using System.Threading.Tasks;
+using auto_creamapi.Messenger;
+using auto_creamapi.Services;
+using auto_creamapi.Utils;
+using MvvmCross.Logging;
+using MvvmCross.Navigation;
+using MvvmCross.Plugin.Messenger;
+using MvvmCross.ViewModels;
+
+namespace auto_creamapi.ViewModels
+{
+ public class DownloadViewModel : MvxNavigationViewModel
+ {
+ private readonly IDownloadCreamApiService _download;
+ private readonly IMvxNavigationService _navigationService;
+ private readonly MvxSubscriptionToken _token;
+ private string _filename;
+
+ private string _info;
+ private double _progress;
+
+ public DownloadViewModel(IMvxLogProvider logProvider, IMvxNavigationService navigationService,
+ IDownloadCreamApiService download, IMvxMessenger messenger) : base(logProvider, navigationService)
+ {
+ _navigationService = navigationService;
+ _download = download;
+ _token = messenger.Subscribe(OnProgressMessage);
+ MyLogger.Log.Debug(messenger.CountSubscriptionsFor().ToString());
+ }
+
+ public string InfoLabel
+ {
+ get => _info;
+ set
+ {
+ _info = value;
+ RaisePropertyChanged(() => InfoLabel);
+ }
+ }
+
+ public string FilenameLabel
+ {
+ get => _filename;
+ set
+ {
+ _filename = value;
+ RaisePropertyChanged(() => FilenameLabel);
+ }
+ }
+
+ public double Progress
+ {
+ get => _progress;
+ set
+ {
+ _progress = value;
+ RaisePropertyChanged(() => Progress);
+ RaisePropertyChanged(() => ProgressPercent);
+ }
+ }
+
+ public string ProgressPercent => _progress.ToString("P2");
+
+ public override async Task Initialize()
+ {
+ await base.Initialize();
+ InfoLabel = "Please wait...";
+ FilenameLabel = "";
+ Progress = 0.0;
+ var download = _download.Download(Secrets.ForumUsername, Secrets.ForumPassword);
+ var filename = await download;
+ /*var extract = _download.Extract(filename);
+ await extract;*/
+ await Task.Run(() => _download.Extract(filename));
+ _token.Dispose();
+ await _navigationService.Close(this);
+ }
+
+ private void OnProgressMessage(ProgressMessage obj)
+ {
+ //MyLogger.Log.Debug($"{obj.Filename}: {obj.BytesTransferred}");
+ InfoLabel = obj.Info;
+ FilenameLabel = obj.Filename;
+ Progress = obj.PercentComplete;
+ }
+ }
+}
\ No newline at end of file
diff --git a/auto-creamapi/ViewModels/MainViewModel.cs b/auto-creamapi/ViewModels/MainViewModel.cs
index e42b489..5748753 100644
--- a/auto-creamapi/ViewModels/MainViewModel.cs
+++ b/auto-creamapi/ViewModels/MainViewModel.cs
@@ -3,218 +3,68 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
-using System.Linq;
-using System.Text.RegularExpressions;
using System.Threading.Tasks;
-using System.Windows.Threading;
using auto_creamapi.Models;
using auto_creamapi.Services;
using auto_creamapi.Utils;
-using auto_creamapi.Views;
using Microsoft.Win32;
using MvvmCross.Commands;
+using MvvmCross.Navigation;
using MvvmCross.ViewModels;
namespace auto_creamapi.ViewModels
{
public class MainViewModel : MvxViewModel
{
+ private const string DefaultLanguageSelection = "english";
private readonly ICacheService _cache;
private readonly ICreamConfigService _config;
+
private readonly ICreamDllService _dll;
- private readonly IDownloadCreamApiService _download;
- private bool _mainWindowEnabled;
- private string _dllPath;
- private string _gameName;
+ private readonly IMvxNavigationService _navigationService;
private int _appId;
- private string _lang;
- private bool _offline;
- private bool _extraprotection;
- private bool _unlockall;
- private bool _useSteamDb;
+ private bool _configExists;
private ObservableCollection _dlcs;
private bool _dllApplied;
- private bool _configExists;
- private string _status;
+ private string _dllPath;
+ private bool _extraprotection;
+ private string _gameName;
+ private string _lang;
private ObservableCollection _languages;
- private const string DefaultLanguageSelection = "english";
- private const string DlcRegexPattern = @"(?.*) *= *(?.*)";
+
+ //private readonly IDownloadCreamApiService _download;
+ private bool _mainWindowEnabled;
+ private bool _offline;
+ private string _status;
+ private bool _unlockall;
+
+ private bool _useSteamDb;
+ //private const string DlcRegexPattern = @"(?.*) *= *(?.*)";
public MainViewModel(ICacheService cache, ICreamConfigService config, ICreamDllService dll,
- IDownloadCreamApiService download)
+ IMvxNavigationService navigationService)
{
+ _navigationService = navigationService;
_cache = cache;
_config = config;
_dll = dll;
- _download = download;
- }
-
- public override async Task Initialize()
- {
- await base.Initialize();
- Languages = new ObservableCollection(_cache.Languages);
- ResetForm();
- _download.Initialize();
- _dll.Initialize();
- Lang = DefaultLanguageSelection;
- UseSteamDb = true;
- MainWindowEnabled = true;
- Status = "Ready.";
+ //_download = download;
}
// // COMMANDS // //
public IMvxCommand OpenFileCommand => new MvxCommand(OpenFile);
- private void OpenFile()
- {
- Status = "Waiting for file...";
- var dialog = new OpenFileDialog
- {
- Filter = "SteamAPI DLL|steam_api.dll;steam_api64.dll|" +
- "All files (*.*)|*.*",
- Multiselect = false,
- Title = "Select SteamAPI DLL..."
- };
- if (dialog.ShowDialog() == true)
- {
- var filePath = dialog.FileName;
- DllPath = filePath;
- var dirPath = Path.GetDirectoryName(filePath);
- if (dirPath != null)
- {
- _config.ReadFile(Path.Combine(dirPath, "cream_api.ini"));
- ResetForm();
- _dll.TargetPath = dirPath;
- _dll.CheckIfDllExistsAtTarget();
- CheckExistence();
- Status = "Ready.";
- }
- }
- }
-
- public IMvxCommand SearchCommand => new MvxCommand(Search);
-
- private void Search()
- {
- var app = _cache.GetAppByName(GameName);
- if (app != null)
- {
- GameName = app.Name;
- AppId = app.AppId;
- }
-
- /*else
- {
- var listOfAppsByName = _cache.GetListOfAppsByName(GameName);
- var searchWindow = new SearchResultWindow(listOfAppsByName);
- searchWindow.Show();
- }*/
- }
+ public IMvxCommand SearchCommand => new MvxAsyncCommand(async () => await Search()); //Command(Search);
public IMvxCommand GetListOfDlcCommand => new MvxAsyncCommand(GetListOfDlc);
- private async Task GetListOfDlc()
- {
- Status = "Trying to get DLC...";
- if (AppId > 0)
- {
- var app = new SteamApp() {AppId = AppId, Name = GameName};
- var task = _cache.GetListOfDlc(app, UseSteamDb);
- MainWindowEnabled = false;
- var listOfDlc = await task;
- var result = "";
- if (task.IsCompletedSuccessfully)
- {
- listOfDlc.Sort((app1, app2) => app1.AppId.CompareTo(app2.AppId));
- listOfDlc.ForEach(x => result += $"{x.AppId}={x.Name}\n");
- Dlcs = result;
- Status = $"Got DLC for AppID {AppId}";
- }
- else
- {
- Status = $"Could not get DLC for AppID {AppId}";
- }
-
- MainWindowEnabled = true;
- }
- else
- {
- Status = $"Could not get DLC for AppID {AppId}";
- MyLogger.Log.Error($"GetListOfDlc: Invalid AppID {AppId}");
- }
- }
-
public IMvxCommand SaveCommand => new MvxCommand(Save);
- private void Save()
- {
- Status = "Saving...";
- _config.SetConfigData(
- AppId,
- Lang,
- Unlockall,
- Extraprotection,
- Offline,
- Dlcs
- );
- _config.SaveFile();
- _dll.Save();
- CheckExistence();
- Status = "Saving successful.";
- }
-
public IMvxCommand ResetFormCommand => new MvxCommand(ResetForm);
- private void ResetForm()
- {
- AppId = _config.Config.AppId;
- Lang = _config.Config.Language;
- Unlockall = _config.Config.UnlockAll;
- Extraprotection = _config.Config.ExtraProtection;
- Offline = _config.Config.ForceOffline;
- var configDlcList = _config.Config.DlcList;
- var result = "";
- foreach (var x in configDlcList)
- {
- result += $"{x.AppId}={x.Name}\n";
- }
-
- Dlcs = result;
- }
-
public IMvxCommand GoToForumThreadCommand => new MvxCommand(GoToForumThread);
- private void GoToForumThread()
- {
- Status = "Opening URL...";
- if (AppId > 0)
- {
- var searchTerm = AppId; //$"{GameName.Replace(" ", "+")}+{appId}";
- var destinationUrl =
- "https://cs.rin.ru/forum/search.php?keywords=" +
- searchTerm +
- "&terms=any&fid[]=10&sf=firstpost&sr=topics&submit=Search";
- var uri = new Uri(destinationUrl);
- var process = new ProcessStartInfo(uri.AbsoluteUri)
- {
- UseShellExecute = true
- };
- Process.Start(process);
- }
- else
- {
- MyLogger.Log.Error($"OpenURL: Invalid AppID {AppId}");
- Status = $"Could not open URL: Invalid AppID {AppId}";
- }
- }
-
- private void CheckExistence()
- {
- DllApplied = _dll.CreamApiApplied();
- ConfigExists = _config.ConfigExists();
- }
-
// // ATTRIBUTES // //
public bool MainWindowEnabled
@@ -259,12 +109,6 @@ namespace auto_creamapi.ViewModels
}
}
- private void SetNameById()
- {
- var appById = _cache.GetAppById(_appId);
- GameName = appById != null ? appById.Name : "";
- }
-
public string Lang
{
get => _lang;
@@ -316,53 +160,14 @@ namespace auto_creamapi.ViewModels
}
}
- /*public List Dlcs
+ public ObservableCollection Dlcs
{
get => _dlcs;
set
{
_dlcs = value;
- RaisePropertyChanged(Dlcs);
- MyLogger.Log.Debug($"Dlcs: {value}");
+ RaisePropertyChanged(() => Dlcs);
}
- }*/
-
- public string Dlcs
- {
- get => DlcListToString(_dlcs);
- set
- {
- _dlcs = StringToDlcList(value);
- RaisePropertyChanged();
- //MyLogger.Log.Debug($"Dlcs: {DlcListToString(_dlcs)}");
- }
- }
-
- private static ObservableCollection StringToDlcList(string value)
- {
- var result = new List();
- var expression = new Regex(@"(?.*) *= *(?.*)");
- using var reader = new StringReader(value);
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- var match = expression.Match(line);
- if (match.Success)
- {
- result.Add(new SteamApp
- {
- AppId = int.Parse(match.Groups["id"].Value),
- Name = match.Groups["name"].Value
- });
- }
- }
-
- return new ObservableCollection(result);
- }
-
- private static string DlcListToString(IEnumerable value)
- {
- return value.Aggregate("", (current, steamApp) => current + $"{steamApp}\n");
}
public bool DllApplied
@@ -404,5 +209,179 @@ namespace auto_creamapi.ViewModels
RaisePropertyChanged(() => Languages);
}
}
+
+ public override async Task Initialize()
+ {
+ _config.Initialize();
+ /*await base.Initialize();
+ await _cache.Initialize();
+ if (!File.Exists("steam_api.dll") | !File.Exists("steam_api64.dll"))
+ await _navigationService.Navigate();
+ await _dll.Initialize();*/
+ var tasks = new List {base.Initialize(), _cache.Initialize()};
+ if (!File.Exists("steam_api.dll") | !File.Exists("steam_api64.dll"))
+ tasks.Add(_navigationService.Navigate());
+ tasks.Add(_dll.Initialize());
+ await Task.WhenAll(tasks);
+ Languages = new ObservableCollection(_cache.Languages);
+ ResetForm();
+ Lang = DefaultLanguageSelection;
+ UseSteamDb = true;
+ MainWindowEnabled = true;
+ Status = "Ready.";
+ }
+
+ private void OpenFile()
+ {
+ Status = "Waiting for file...";
+ var dialog = new OpenFileDialog
+ {
+ Filter = "SteamAPI DLL|steam_api.dll;steam_api64.dll|" +
+ "All files (*.*)|*.*",
+ Multiselect = false,
+ Title = "Select SteamAPI DLL..."
+ };
+ if (dialog.ShowDialog() == true)
+ {
+ var filePath = dialog.FileName;
+ DllPath = filePath;
+ var dirPath = Path.GetDirectoryName(filePath);
+ if (dirPath != null)
+ {
+ _config.ReadFile(Path.Combine(dirPath, "cream_api.ini"));
+ ResetForm();
+ _dll.TargetPath = dirPath;
+ _dll.CheckIfDllExistsAtTarget();
+ CheckExistence();
+ Status = "Ready.";
+ }
+ }
+ else
+ {
+ Status = "File selection canceled.";
+ }
+ }
+
+ private async Task Search()
+ {
+ if (!string.IsNullOrEmpty(GameName))
+ {
+ var app = _cache.GetAppByName(GameName);
+ if (app != null)
+ {
+ GameName = app.Name;
+ AppId = app.AppId;
+ }
+ else
+ {
+ var navigate = _navigationService.Navigate, SteamApp>(
+ _cache.GetListOfAppsByName(GameName));
+ await navigate;
+ var navigateResult = navigate.Result;
+ if (navigateResult != null)
+ {
+ GameName = navigateResult.Name;
+ AppId = navigateResult.AppId;
+ }
+ }
+ }
+ else
+ {
+ MyLogger.Log.Warning("Empty game name, cannot initiate search!");
+ }
+ }
+
+ private async Task GetListOfDlc()
+ {
+ Status = "Trying to get DLC...";
+ if (AppId > 0)
+ {
+ var app = new SteamApp {AppId = AppId, Name = GameName};
+ var task = _cache.GetListOfDlc(app, UseSteamDb);
+ MainWindowEnabled = false;
+ var listOfDlc = await task;
+ if (task.IsCompletedSuccessfully)
+ {
+ listOfDlc.Sort((app1, app2) => app1.AppId.CompareTo(app2.AppId));
+ Dlcs = new ObservableCollection(listOfDlc);
+ Status = $"Got DLC for AppID {AppId}";
+ }
+ else
+ {
+ Status = $"Could not get DLC for AppID {AppId}";
+ }
+
+ MainWindowEnabled = true;
+ }
+ else
+ {
+ Status = $"Could not get DLC for AppID {AppId}";
+ MyLogger.Log.Error($"GetListOfDlc: Invalid AppID {AppId}");
+ }
+ }
+
+ private void Save()
+ {
+ Status = "Saving...";
+ _config.SetConfigData(
+ AppId,
+ Lang,
+ Unlockall,
+ Extraprotection,
+ Offline,
+ Dlcs
+ );
+ _config.SaveFile();
+ _dll.Save();
+ CheckExistence();
+ Status = "Saving successful.";
+ }
+
+ private void ResetForm()
+ {
+ AppId = _config.Config.AppId;
+ Lang = _config.Config.Language;
+ Unlockall = _config.Config.UnlockAll;
+ Extraprotection = _config.Config.ExtraProtection;
+ Offline = _config.Config.ForceOffline;
+ Dlcs = new ObservableCollection(_config.Config.DlcList);
+ Status = "Changes have been reset.";
+ }
+
+ private void GoToForumThread()
+ {
+ Status = "Opening URL...";
+ if (AppId > 0)
+ {
+ var searchTerm = AppId; //$"{GameName.Replace(" ", "+")}+{appId}";
+ var destinationUrl =
+ "https://cs.rin.ru/forum/search.php?keywords=" +
+ searchTerm +
+ "&terms=any&fid[]=10&sf=firstpost&sr=topics&submit=Search";
+ var uri = new Uri(destinationUrl);
+ var process = new ProcessStartInfo(uri.AbsoluteUri)
+ {
+ UseShellExecute = true
+ };
+ Process.Start(process);
+ }
+ else
+ {
+ MyLogger.Log.Error($"OpenURL: Invalid AppID {AppId}");
+ Status = $"Could not open URL: Invalid AppID {AppId}";
+ }
+ }
+
+ private void CheckExistence()
+ {
+ DllApplied = _dll.CreamApiApplied();
+ ConfigExists = _config.ConfigExists();
+ }
+
+ private void SetNameById()
+ {
+ var appById = _cache.GetAppById(_appId);
+ GameName = appById != null ? appById.Name : "";
+ }
}
}
\ No newline at end of file
diff --git a/auto-creamapi/ViewModels/SearchResultViewModel.cs b/auto-creamapi/ViewModels/SearchResultViewModel.cs
new file mode 100644
index 0000000..8e26c1f
--- /dev/null
+++ b/auto-creamapi/ViewModels/SearchResultViewModel.cs
@@ -0,0 +1,80 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using auto_creamapi.Models;
+using auto_creamapi.Utils;
+using MvvmCross.Commands;
+using MvvmCross.Logging;
+using MvvmCross.Navigation;
+using MvvmCross.ViewModels;
+
+namespace auto_creamapi.ViewModels
+{
+ public class SearchResultViewModel : MvxNavigationViewModel>,
+ IMvxViewModel, SteamApp>
+ {
+ private readonly IMvxNavigationService _navigationService;
+ private IEnumerable _steamApps;
+
+ /*public override async Task Initialize()
+ {
+ await base.Initialize();
+ }*/
+ public SearchResultViewModel(IMvxLogProvider logProvider, IMvxNavigationService navigationService) : base(
+ logProvider, navigationService)
+ {
+ _navigationService = navigationService;
+ }
+
+ public IEnumerable Apps
+ {
+ get => _steamApps;
+ set
+ {
+ _steamApps = value;
+ RaisePropertyChanged(() => Apps);
+ }
+ }
+
+ public SteamApp Selected
+ {
+ get;
+ set;
+ //RaisePropertyChanged(Selected);
+ }
+
+ public IMvxCommand SaveCommand => new MvxAsyncCommand(Save);
+
+ public IMvxCommand CloseCommand => new MvxCommand(Close);
+
+ public override void Prepare(IEnumerable parameter)
+ {
+ Apps = parameter;
+ }
+
+ public TaskCompletionSource