From 73baa27245b10af23c48e5444c676e0223816bf2 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Mon, 28 Dec 2020 15:27:37 +0100 Subject: [PATCH] SearchResultView and DownloadView implemented; Ignore whitespaces and special chars when looking for games; --- auto-creamapi/App.xaml.cs | 5 +- .../Converters/ListOfDLcToStringConverter.cs | 31 +- auto-creamapi/Core/App.cs | 2 - auto-creamapi/DownloadWindow.xaml | 21 - auto-creamapi/DownloadWindow.xaml.cs | 32 -- auto-creamapi/MainWindow.xaml.cs | 2 - auto-creamapi/Messenger/ProgressMessage.cs | 40 ++ auto-creamapi/Models/CreamConfigModel.cs | 23 +- auto-creamapi/Models/CreamDllModel.cs | 8 +- auto-creamapi/Models/SteamAppModel.cs | 15 +- auto-creamapi/SearchResultWindow.xaml | 26 -- auto-creamapi/Services/CacheService.cs | 72 ++- auto-creamapi/Services/CreamConfigService.cs | 83 ++-- auto-creamapi/Services/CreamDllService.cs | 78 ++-- .../Services/DownloadCreamApiService.cs | 134 ++---- auto-creamapi/Utils/Misc.cs | 40 ++ auto-creamapi/Utils/Secrets.EXAMPLE.cs | 8 +- auto-creamapi/ViewModels/DownloadViewModel.cs | 87 ++++ auto-creamapi/ViewModels/MainViewModel.cs | 417 +++++++++--------- .../ViewModels/SearchResultViewModel.cs | 80 ++++ auto-creamapi/Views/DownloadView.xaml | 27 ++ auto-creamapi/Views/DownloadView.xaml.cs | 23 + auto-creamapi/Views/MainView.xaml | 101 +++-- auto-creamapi/Views/SearchResultView.xaml | 34 ++ .../SearchResultView.xaml.cs} | 35 +- auto-creamapi/auto-creamapi.csproj | 1 + 26 files changed, 783 insertions(+), 642 deletions(-) delete mode 100644 auto-creamapi/DownloadWindow.xaml delete mode 100644 auto-creamapi/DownloadWindow.xaml.cs create mode 100644 auto-creamapi/Messenger/ProgressMessage.cs delete mode 100644 auto-creamapi/SearchResultWindow.xaml create mode 100644 auto-creamapi/Utils/Misc.cs create mode 100644 auto-creamapi/ViewModels/DownloadViewModel.cs create mode 100644 auto-creamapi/ViewModels/SearchResultViewModel.cs create mode 100644 auto-creamapi/Views/DownloadView.xaml create mode 100644 auto-creamapi/Views/DownloadView.xaml.cs create mode 100644 auto-creamapi/Views/SearchResultView.xaml rename auto-creamapi/{SearchResultWindow.xaml.cs => Views/SearchResultView.xaml.cs} (54%) 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 @@ - - - - - - - -