From 0ff53c88c80b94abb3f9db8c819d2b6b2ed3cc0d Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+dineshsolanki@users.noreply.github.com> Date: Sun, 28 Jul 2024 01:12:49 +0530 Subject: [PATCH] feature: Add progress tracking and localization for icon creation and change the style of the MainWindow progressBar Enhanced the icon creation process to include progress tracking and updated the localization files accordingly. Also, made several UI adjustments and refactored the code to accommodate these changes. Fixed UI hang when icons were being created after downloading --- FoliCon/Modules/LangProvider.cs | 6 +++ FoliCon/Modules/utils/IconUtils.cs | 12 +++++- FoliCon/Properties/Langs/Lang.Designer.cs | 50 +++++++++++++++-------- FoliCon/Properties/Langs/Lang.ar.resx | 6 +++ FoliCon/Properties/Langs/Lang.es.resx | 6 +++ FoliCon/Properties/Langs/Lang.hi.resx | 6 +++ FoliCon/Properties/Langs/Lang.pt.resx | 6 +++ FoliCon/Properties/Langs/Lang.resx | 6 +++ FoliCon/Properties/Langs/Lang.ru.resx | 6 +++ FoliCon/ViewModels/MainWindowViewModel.cs | 16 +++++--- FoliCon/Views/MainWindow.xaml | 2 +- 11 files changed, 97 insertions(+), 25 deletions(-) diff --git a/FoliCon/Modules/LangProvider.cs b/FoliCon/Modules/LangProvider.cs index 1f1c130..591de4d 100644 --- a/FoliCon/Modules/LangProvider.cs +++ b/FoliCon/Modules/LangProvider.cs @@ -72,6 +72,7 @@ private void UpdateLangs() OnPropertyChanged(nameof(ConfirmIconDeletion)); OnPropertyChanged(nameof(ConfirmMediaInfoDeletion)); OnPropertyChanged(nameof(ConfirmToOpenFolder)); + OnPropertyChanged(nameof(CreatingIconWithCount)); OnPropertyChanged(nameof(CreatingIcons)); OnPropertyChanged(nameof(CustomIconSetter)); OnPropertyChanged(nameof(CustomRating)); @@ -164,6 +165,7 @@ private void UpdateLangs() OnPropertyChanged(nameof(Previewer)); OnPropertyChanged(nameof(Professional)); OnPropertyChanged(nameof(Rating)); + OnPropertyChanged(nameof(RefreshingFolder)); OnPropertyChanged(nameof(RemoveFromContextMenu)); OnPropertyChanged(nameof(ResetDefaultPoster)); OnPropertyChanged(nameof(RestartAsAdmin)); @@ -247,6 +249,7 @@ private void UpdateLangs() public string ConfirmIconDeletion => Lang.ConfirmIconDeletion; public string ConfirmMediaInfoDeletion => Lang.ConfirmMediaInfoDeletion; public string ConfirmToOpenFolder => Lang.ConfirmToOpenFolder; + public string CreatingIconWithCount => Lang.CreatingIconWithCount; public string CreatingIcons => Lang.CreatingIcons; public string CustomIconSetter => Lang.CustomIconSetter; public string CustomRating => Lang.CustomRating; @@ -340,6 +343,7 @@ private void UpdateLangs() public string Previewer => Lang.Previewer; public string Professional => Lang.Professional; public string Rating => Lang.Rating; + public string RefreshingFolder => Lang.RefreshingFolder; public string RemoveFromContextMenu => Lang.RemoveFromContextMenu; public string ResetDefaultPoster => Lang.ResetDefaultPoster; public string RestartAsAdmin => Lang.RestartAsAdmin; @@ -431,6 +435,7 @@ public class LangKeys public static string ConfirmIconDeletion = nameof(ConfirmIconDeletion); public static string ConfirmMediaInfoDeletion = nameof(ConfirmMediaInfoDeletion); public static string ConfirmToOpenFolder = nameof(ConfirmToOpenFolder); + public static string CreatingIconWithCount = nameof(CreatingIconWithCount); public static string CreatingIcons = nameof(CreatingIcons); public static string CustomIconSetter = nameof(CustomIconSetter); public static string CustomRating = nameof(CustomRating); @@ -524,6 +529,7 @@ public class LangKeys public static string Previewer = nameof(Previewer); public static string Professional = nameof(Professional); public static string Rating = nameof(Rating); + public static string RefreshingFolder = nameof(RefreshingFolder); public static string RemoveFromContextMenu = nameof(RemoveFromContextMenu); public static string ResetDefaultPoster = nameof(ResetDefaultPoster); public static string RestartAsAdmin = nameof(RestartAsAdmin); diff --git a/FoliCon/Modules/utils/IconUtils.cs b/FoliCon/Modules/utils/IconUtils.cs index aef7e43..d0ea846 100644 --- a/FoliCon/Modules/utils/IconUtils.cs +++ b/FoliCon/Modules/utils/IconUtils.cs @@ -17,7 +17,7 @@ public static string GetImageName() /// Creates Icons from PNG /// public static int MakeIco(string iconMode, string selectedFolder, List pickedListDataTable, - bool isRatingVisible, bool isMockupVisible) + bool isRatingVisible, bool isMockupVisible, IProgress progressCallback) { Logger.Debug( "Creating Icons from PNG, Icon Mode: {IconMode}, Selected Folder: {SelectedFolder}, isRatingVisible: {IsRatingVisible}, isMockupVisible: {IsMockupVisible}", @@ -27,6 +27,9 @@ public static int MakeIco(string iconMode, string selectedFolder, List //------------------------------------------------------------------------------ -using System.CodeDom.Compiler; -using System.Diagnostics.CodeAnalysis; -using System.Resources; -using System.Runtime.CompilerServices; - namespace FoliCon.Properties.Langs { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -20,27 +18,27 @@ namespace FoliCon.Properties.Langs { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [DebuggerNonUserCode()] - [CompilerGenerated()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Lang { - private static ResourceManager resourceMan; + private static global::System.Resources.ResourceManager resourceMan; - private static CultureInfo resourceCulture; + private static global::System.Globalization.CultureInfo resourceCulture; - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Lang() { } /// /// Returns the cached ResourceManager instance used by this class. /// - [EditorBrowsable(EditorBrowsableState.Advanced)] - public static ResourceManager ResourceManager { + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { get { - if (ReferenceEquals(resourceMan, null)) { - ResourceManager temp = new ResourceManager("FoliCon.Properties.Langs.Lang", typeof(Lang).Assembly); + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FoliCon.Properties.Langs.Lang", typeof(Lang).Assembly); resourceMan = temp; } return resourceMan; @@ -51,8 +49,8 @@ public static ResourceManager ResourceManager { /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// - [EditorBrowsable(EditorBrowsableState.Advanced)] - public static CultureInfo Culture { + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -358,6 +356,15 @@ public static string CreatingIcons { } } + /// + /// Looks up a localized string similar to Creating Icon {0}/{1}.... + /// + public static string CreatingIconWithCount { + get { + return ResourceManager.GetString("CreatingIconWithCount", resourceCulture); + } + } + /// /// Looks up a localized string similar to Custom icon setter. /// @@ -1201,6 +1208,15 @@ public static string Rating { } } + /// + /// Looks up a localized string similar to Refreshing folder. + /// + public static string RefreshingFolder { + get { + return ResourceManager.GetString("RefreshingFolder", resourceCulture); + } + } + /// /// Looks up a localized string similar to Remove from context menu. /// diff --git a/FoliCon/Properties/Langs/Lang.ar.resx b/FoliCon/Properties/Langs/Lang.ar.resx index 61553b6..88dd5c2 100644 --- a/FoliCon/Properties/Langs/Lang.ar.resx +++ b/FoliCon/Properties/Langs/Lang.ar.resx @@ -657,4 +657,10 @@ جارٍ التنزيل... + + جارٍ إنشاء الأيقونة {0}/{1}... + + + تحديث المجلد + \ No newline at end of file diff --git a/FoliCon/Properties/Langs/Lang.es.resx b/FoliCon/Properties/Langs/Lang.es.resx index 07c7f6a..e492d7b 100644 --- a/FoliCon/Properties/Langs/Lang.es.resx +++ b/FoliCon/Properties/Langs/Lang.es.resx @@ -657,4 +657,10 @@ Esto ayuda a folicon a identificar los medios sin tener que elegir entre título Descargando... + + Creando icono {0}/{1}... + + + Actualizando carpeta + \ No newline at end of file diff --git a/FoliCon/Properties/Langs/Lang.hi.resx b/FoliCon/Properties/Langs/Lang.hi.resx index 165ab2e..612ceb5 100644 --- a/FoliCon/Properties/Langs/Lang.hi.resx +++ b/FoliCon/Properties/Langs/Lang.hi.resx @@ -657,4 +657,10 @@ डाउनलोड हो रहा है... + + आइकन बना रहा है {0}/{1}... + + + फ़ोल्डर रीफ्रेश हो रहा है + \ No newline at end of file diff --git a/FoliCon/Properties/Langs/Lang.pt.resx b/FoliCon/Properties/Langs/Lang.pt.resx index 3b84164..74ea3c1 100644 --- a/FoliCon/Properties/Langs/Lang.pt.resx +++ b/FoliCon/Properties/Langs/Lang.pt.resx @@ -656,4 +656,10 @@ e renovar o cache dos Ícones? Baixando... + + Criando ícone {0}/{1}... + + + Atualizando pasta + \ No newline at end of file diff --git a/FoliCon/Properties/Langs/Lang.resx b/FoliCon/Properties/Langs/Lang.resx index dc66b76..c053bed 100644 --- a/FoliCon/Properties/Langs/Lang.resx +++ b/FoliCon/Properties/Langs/Lang.resx @@ -661,4 +661,10 @@ and refresh Icon Cache? Downloading... + + Creating Icon {0}/{1}... + + + Refreshing folder + \ No newline at end of file diff --git a/FoliCon/Properties/Langs/Lang.ru.resx b/FoliCon/Properties/Langs/Lang.ru.resx index 75cdec4..fb30529 100644 --- a/FoliCon/Properties/Langs/Lang.ru.resx +++ b/FoliCon/Properties/Langs/Lang.ru.resx @@ -660,4 +660,10 @@ Загрузка... + + Создание значка {0}/{1}... + + + Обновление папки + \ No newline at end of file diff --git a/FoliCon/ViewModels/MainWindowViewModel.cs b/FoliCon/ViewModels/MainWindowViewModel.cs index e5da75b..1ca09a2 100644 --- a/FoliCon/ViewModels/MainWindowViewModel.cs +++ b/FoliCon/ViewModels/MainWindowViewModel.cs @@ -26,6 +26,7 @@ public sealed class MainWindowViewModel : BindableBase, IFileDragDropTarget, IDi private DArt _dArtObject; private bool _isPosterWindowShown; private bool _enableErrorReporting; + private ProgressBarData _busyIndicatorProperties; private ListViewData _finalListViewData; private List _imgDownloadList = []; @@ -68,7 +69,7 @@ public ListViewData FinalListViewData private FoliconThemes _theme; private DirectoryPermissionsResult _directoryPermissionResult; public StatusBarData StatusBarProperties { get; set; } - public ProgressBarData BusyIndicatorProperties { get; set; } + public ProgressBarData BusyIndicatorProperties { get => _busyIndicatorProperties; set => SetProperty(ref _busyIndicatorProperties, value); } public List Fnames { get; set; } = []; public bool IsMakeEnabled @@ -875,7 +876,7 @@ private async Task DownloadAndMakeIconsAsync() if (StopIconDownload) { Logger.Debug("StopIconDownload is true, breaking loop and making icons."); - MakeIcons(); + await MakeIcons(); IsMakeEnabled = true; StatusBarProperties.ProgressBarData.Value = StatusBarProperties.ProgressBarData.Max; return; @@ -914,16 +915,21 @@ private async Task DownloadAndMakeIconsAsync() { Logger.Debug("All Icons Downloaded, Making Icons."); IsBusy = true; - MakeIcons(); + await MakeIcons(); } IsMakeEnabled = true; } - private void MakeIcons() + private async Task MakeIcons() { IsBusy = true; - var iconProcessedCount = IconUtils.MakeIco(IconMode, SelectedFolder, _pickedListDataTable, IsRatingVisible, IsPosterMockupUsed); + var iconProcessedCount = await Task.Run(()=>IconUtils.MakeIco(IconMode, + SelectedFolder, + _pickedListDataTable, + IsRatingVisible, + IsPosterMockupUsed, + new Progress(value => BusyIndicatorProperties = value))); StatusBarProperties.ProcessedIcon = iconProcessedCount; IsBusy = false; var info = new GrowlInfo diff --git a/FoliCon/Views/MainWindow.xaml b/FoliCon/Views/MainWindow.xaml index cdf67a9..d52cef0 100644 --- a/FoliCon/Views/MainWindow.xaml +++ b/FoliCon/Views/MainWindow.xaml @@ -35,7 +35,7 @@ -