From 8352aeaba634eaea181804037760a02c8628e72b Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+dineshsolanki@users.noreply.github.com> Date: Sun, 14 Jul 2024 00:13:49 +0530 Subject: [PATCH 01/13] Add Dummy image context menu --- FoliCon/Views/ProSearchResult.xaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/FoliCon/Views/ProSearchResult.xaml b/FoliCon/Views/ProSearchResult.xaml index ebc61881..da87bad7 100644 --- a/FoliCon/Views/ProSearchResult.xaml +++ b/FoliCon/Views/ProSearchResult.xaml @@ -13,6 +13,9 @@ mc:Ignorable="d" prism:ViewModelLocator.AutoWireViewModel="True" d:DataContext="{d:DesignInstance viewModels:ProSearchResultViewModel }"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FoliCon/Views/ManualExplorer.xaml.cs b/FoliCon/Views/ManualExplorer.xaml.cs new file mode 100644 index 00000000..b62556b7 --- /dev/null +++ b/FoliCon/Views/ManualExplorer.xaml.cs @@ -0,0 +1,32 @@ +using System.Windows.Controls; + +namespace FoliCon.Views +{ + /// + /// Interaction logic for ManualExplorer + /// + public partial class ManualExplorer : UserControl + { + private bool _autoScroll = true; + + public ManualExplorer() + { + InitializeComponent(); + } + + private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) + { + if (e.ExtentHeightChange == 0) + { + + _autoScroll = ScrollViewer.VerticalOffset == ScrollViewer.ScrollableHeight; + } + + + if (_autoScroll && e.ExtentHeightChange != 0) + { + ScrollViewer.ScrollToVerticalOffset(ScrollViewer.ExtentHeight); + } + } + } +} From b17c74f5c62168f310b9442656930ce887da5d05 Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+dineshsolanki@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:25:06 +0530 Subject: [PATCH 07/13] fix: change target directory path identifier Changed the identifier for the target directory path from the dArtDownloadResponse.Filename to the deviationId for fixing the potential long path issue. --- FoliCon/Modules/DeviantArt/DArt.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FoliCon/Modules/DeviantArt/DArt.cs b/FoliCon/Modules/DeviantArt/DArt.cs index 76984fc8..f554daa7 100644 --- a/FoliCon/Modules/DeviantArt/DArt.cs +++ b/FoliCon/Modules/DeviantArt/DArt.cs @@ -97,7 +97,7 @@ public async Task Download(string deviationId) { GetClientAccessTokenAsync(); var dArtDownloadResponse = await GetDArtDownloadResponseAsync(deviationId); - var targetDirectoryPath = FileUtils.CreateDirectoryInFoliConTemp(dArtDownloadResponse.Filename); + var targetDirectoryPath = FileUtils.CreateDirectoryInFoliConTemp(deviationId); dArtDownloadResponse.localDownloadPath = targetDirectoryPath; var downloadResponse = await Services.HttpC.GetAsync(dArtDownloadResponse.Src); From 345f3a6db6cc01681fc17be714803c60350cdc97 Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+dineshsolanki@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:44:34 +0530 Subject: [PATCH 08/13] Complete pickMethod for ManualExtraction A check has been added to differentiate between local and remote image paths when downloading images as files are local in case of ManualExtraction. The "FrameworkElement_OnUnloaded" event has been added to ensure image sources are properly released and no lock is present on them. --- FoliCon/Modules/utils/FileUtils.cs | 19 ++++++- FoliCon/ViewModels/MainWindowViewModel.cs | 11 +++- FoliCon/ViewModels/ManualExplorerViewModel.cs | 24 +++++++-- .../ViewModels/ProSearchResultViewModel.cs | 7 ++- FoliCon/Views/ManualExplorer.xaml | 11 ++-- FoliCon/Views/ManualExplorer.xaml.cs | 50 +++++++++++-------- 6 files changed, 82 insertions(+), 40 deletions(-) diff --git a/FoliCon/Modules/utils/FileUtils.cs b/FoliCon/Modules/utils/FileUtils.cs index 78ebb3bd..ddfa991a 100644 --- a/FoliCon/Modules/utils/FileUtils.cs +++ b/FoliCon/Modules/utils/FileUtils.cs @@ -482,7 +482,7 @@ public static bool CreateDirectory(string path) public static string CreateDirectoryInFoliConTemp(string path) { - var foliConTempPath = FoliConTempPath(); + var foliConTempPath = FoliConTempDeviationsPath(); var fullPath = Path.Combine(foliConTempPath, path); CreateDirectory(fullPath); return fullPath; @@ -504,8 +504,25 @@ public static void DeleteDirectoryIfEmpty(string targetDirectoryPath) } } + public static void DeleteFoliConTempDeviationDirectory(bool ifEmpty = false) + { + if (ifEmpty) + { + DeleteDirectoryIfEmpty(FoliConTempDeviationsPath()); + } + else + { + Directory.Delete(FoliConTempDeviationsPath(), true); + } + } + private static string FoliConTempPath() { return Path.Combine(Path.GetTempPath(), "FoliCon"); } + + private static string FoliConTempDeviationsPath() + { + return Path.Combine(FoliConTempPath(), "Deviations"); + } } \ No newline at end of file diff --git a/FoliCon/ViewModels/MainWindowViewModel.cs b/FoliCon/ViewModels/MainWindowViewModel.cs index a8a30429..164ade62 100644 --- a/FoliCon/ViewModels/MainWindowViewModel.cs +++ b/FoliCon/ViewModels/MainWindowViewModel.cs @@ -806,7 +806,14 @@ private async Task DownloadAndMakeIconsAsync() try { - await NetworkUtils.DownloadImageFromUrlAsync(img.RemotePath, img.LocalPath); + if (img.RemotePath.IsFile) + { + File.Move(img.RemotePath.AbsolutePath, img.LocalPath); + } + else + { + await NetworkUtils.DownloadImageFromUrlAsync(img.RemotePath, img.LocalPath); + } } catch (UnauthorizedAccessException e) { @@ -834,6 +841,7 @@ private async Task DownloadAndMakeIconsAsync() } IsMakeEnabled = true; + FileUtils.DeleteFoliConTempDeviationDirectory(); } private void MakeIcons() @@ -911,5 +919,6 @@ public void Dispose() { _tmdbClient?.Dispose(); GC.SuppressFinalize(this); + FileUtils.DeleteFoliConTempDeviationDirectory(); } } \ No newline at end of file diff --git a/FoliCon/ViewModels/ManualExplorerViewModel.cs b/FoliCon/ViewModels/ManualExplorerViewModel.cs index ece36bda..b6c8654c 100644 --- a/FoliCon/ViewModels/ManualExplorerViewModel.cs +++ b/FoliCon/ViewModels/ManualExplorerViewModel.cs @@ -15,12 +15,13 @@ public ManualExplorerViewModel() OpenImageCommand = new DelegateCommand(OpenImageMethod); } - private void PickMethod(object obj) + private void PickMethod(object localImagePath) { - + Logger.Debug("Picking Image {Image}", localImagePath); + CloseDialog(ButtonResult.OK, (string)localImagePath); } - private string _title = LangProvider.GetLang("SearchResult"); + private string _title = "Manual Explorer"; private bool _isBusy; private ObservableCollection _directory; private DArt _dArtObject; @@ -58,7 +59,22 @@ public virtual bool CanCloseDialog() public virtual void OnDialogClosed() { Directory.Clear(); - + } + + protected virtual void CloseDialog(ButtonResult result, string localPath) + { + Logger.Info("Close Dialog called with result {Result}, localImagePath {LocalImagePath}", result, localPath); + var dialogParams = new DialogParameters() + { + {"localPath", localPath} + }; + + RaiseRequestClose(new DialogResult(result, dialogParams)); + } + + public virtual void RaiseRequestClose(IDialogResult dialogResult) + { + RequestClose?.Invoke(dialogResult); } public virtual void OnDialogOpened(IDialogParameters parameters) diff --git a/FoliCon/ViewModels/ProSearchResultViewModel.cs b/FoliCon/ViewModels/ProSearchResultViewModel.cs index 24633062..7fd96fba 100644 --- a/FoliCon/ViewModels/ProSearchResultViewModel.cs +++ b/FoliCon/ViewModels/ProSearchResultViewModel.cs @@ -96,10 +96,9 @@ private void ExtractManually(object parameter) var deviationId = (string)parameter; _dialogService.ShowManualExplorer(deviationId, DArtObject, result => { - if (result.Result == ButtonResult.OK) - { - Logger.Debug("Manual Extraction Completed"); - } + if (result.Result != ButtonResult.OK) return; + Logger.Debug("Manual Extraction Completed"); + PickMethod(result.Parameters.GetValue("localPath")); }); } private async void PrepareForSearch() diff --git a/FoliCon/Views/ManualExplorer.xaml b/FoliCon/Views/ManualExplorer.xaml index 3fbbd1ca..0cddfb11 100644 --- a/FoliCon/Views/ManualExplorer.xaml +++ b/FoliCon/Views/ManualExplorer.xaml @@ -3,9 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:prism="http://prismlibrary.com/" xmlns:hc="https://handyorg.github.io/handycontrol" - xmlns:extension="clr-namespace:FoliCon.Modules.Extension" - xmlns:langs="clr-namespace:FoliCon.Properties.Langs" - xmlns:b="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ui="clr-namespace:FoliCon.Modules.UI" @@ -37,13 +34,11 @@ - - - - - diff --git a/FoliCon/Views/ManualExplorer.xaml.cs b/FoliCon/Views/ManualExplorer.xaml.cs index b62556b7..82bef6ae 100644 --- a/FoliCon/Views/ManualExplorer.xaml.cs +++ b/FoliCon/Views/ManualExplorer.xaml.cs @@ -1,32 +1,38 @@ -using System.Windows.Controls; + +using Image = System.Windows.Controls.Image; -namespace FoliCon.Views +namespace FoliCon.Views; + +/// +/// Interaction logic for ManualExplorer +/// +public partial class ManualExplorer : UserControl { - /// - /// Interaction logic for ManualExplorer - /// - public partial class ManualExplorer : UserControl - { - private bool _autoScroll = true; + private bool _autoScroll = true; - public ManualExplorer() - { - InitializeComponent(); - } + public ManualExplorer() + { + InitializeComponent(); + } - private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) + private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) + { + if (e.ExtentHeightChange == 0) { - if (e.ExtentHeightChange == 0) - { - _autoScroll = ScrollViewer.VerticalOffset == ScrollViewer.ScrollableHeight; - } + _autoScroll = ScrollViewer.VerticalOffset == ScrollViewer.ScrollableHeight; + } - if (_autoScroll && e.ExtentHeightChange != 0) - { - ScrollViewer.ScrollToVerticalOffset(ScrollViewer.ExtentHeight); - } + if (_autoScroll && e.ExtentHeightChange != 0) + { + ScrollViewer.ScrollToVerticalOffset(ScrollViewer.ExtentHeight); } } -} + + private void FrameworkElement_OnUnloaded(object sender, RoutedEventArgs e) + { + var image = (Image)sender; + image.Source = null; + } +} \ No newline at end of file From 494ee0642d7a725b0d04453f5f7372bba94880e0 Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+dineshsolanki@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:46:11 +0530 Subject: [PATCH 09/13] Refactor: Cleanup tempDeviation directory at FoliCon close event --- FoliCon/ViewModels/MainWindowViewModel.cs | 2 -- FoliCon/Views/MainWindow.xaml | 2 +- FoliCon/Views/MainWindow.xaml.cs | 5 +++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/FoliCon/ViewModels/MainWindowViewModel.cs b/FoliCon/ViewModels/MainWindowViewModel.cs index 164ade62..83b334e7 100644 --- a/FoliCon/ViewModels/MainWindowViewModel.cs +++ b/FoliCon/ViewModels/MainWindowViewModel.cs @@ -841,7 +841,6 @@ private async Task DownloadAndMakeIconsAsync() } IsMakeEnabled = true; - FileUtils.DeleteFoliConTempDeviationDirectory(); } private void MakeIcons() @@ -919,6 +918,5 @@ public void Dispose() { _tmdbClient?.Dispose(); GC.SuppressFinalize(this); - FileUtils.DeleteFoliConTempDeviationDirectory(); } } \ No newline at end of file diff --git a/FoliCon/Views/MainWindow.xaml b/FoliCon/Views/MainWindow.xaml index 92d89829..336904d2 100644 --- a/FoliCon/Views/MainWindow.xaml +++ b/FoliCon/Views/MainWindow.xaml @@ -18,7 +18,7 @@ Icon="/Resources/icons/folicon Icon.ico" ui:FolderDragDropHelper.IsFileDragDropEnabled="True" ui:FolderDragDropHelper.FileDragDropTarget="{Binding}" AllowDrop="True" - d:DataContext="{d:DesignInstance viewModels:MainWindowViewModel}"> + d:DataContext="{d:DesignInstance viewModels:MainWindowViewModel}" Closed="MainWindow_OnClosed"> diff --git a/FoliCon/Views/MainWindow.xaml.cs b/FoliCon/Views/MainWindow.xaml.cs index 3bbe4ba6..be660cb0 100644 --- a/FoliCon/Views/MainWindow.xaml.cs +++ b/FoliCon/Views/MainWindow.xaml.cs @@ -81,4 +81,9 @@ private void Sort(string sortBy, ListSortDirection direction) dataView.SortDescriptions.Add(sd); dataView.Refresh(); } + + private void MainWindow_OnClosed(object sender, EventArgs e) + { + FileUtils.DeleteFoliConTempDeviationDirectory(); + } } \ No newline at end of file From 023bfcf4c4ad03cfa29e16cb1f54f74c7a93f60e Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+dineshsolanki@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:01:30 +0530 Subject: [PATCH 10/13] Chore: Fix Codacy issues This commit includes several crucial refactorings across multiple files in the project. Redundant code has been replaced by more efficient functions, such as the replacement of the entire GetFileSizeHumanReadable() method with the ConvertHelper.ToFileSize() function. The DArtImageList now uses base constructors for improved cleanliness. Also, the 'if' statement formatting of ProSearchResultViewModel.cs, and FileUtils.cs are streamlined, and a more descriptive method in StreamExtension.cs makes the flow of control more visible. --- FoliCon/Models/Api/DArtDownloadResponse.cs | 15 +------- FoliCon/Models/Data/DArtImageList.cs | 4 +- FoliCon/Modules/DeviantArt/DArt.cs | 2 +- FoliCon/Modules/Extension/StreamExtension.cs | 21 +++++++---- FoliCon/Modules/utils/FileUtils.cs | 37 +++++++++++-------- FoliCon/ViewModels/ManualExplorerViewModel.cs | 2 +- .../ViewModels/ProSearchResultViewModel.cs | 6 ++- 7 files changed, 45 insertions(+), 42 deletions(-) diff --git a/FoliCon/Models/Api/DArtDownloadResponse.cs b/FoliCon/Models/Api/DArtDownloadResponse.cs index ca1cc5fc..79751007 100644 --- a/FoliCon/Models/Api/DArtDownloadResponse.cs +++ b/FoliCon/Models/Api/DArtDownloadResponse.cs @@ -18,21 +18,10 @@ public record DArtDownloadResponse public int FileSizeBytes { get; init; } [JsonIgnore] - public string localDownloadPath { get; set; } + public string LocalDownloadPath { get; set; } public string GetFileSizeHumanReadable() { - if (FileSizeBytes < 1024) - return $"{FileSizeBytes} bytes"; - - int i; - double fileSizeToDouble = FileSizeBytes; - - for (i = 0; i < 8 && fileSizeToDouble >= 1024; ++i) - { - fileSizeToDouble /= 1024; - } - - return $"{fileSizeToDouble:0.##} {new[] {"bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}[i]}"; + return ConvertHelper.ToFileSize(FileSizeBytes); } } \ No newline at end of file diff --git a/FoliCon/Models/Data/DArtImageList.cs b/FoliCon/Models/Data/DArtImageList.cs index f9af99f1..27746ed1 100644 --- a/FoliCon/Models/Data/DArtImageList.cs +++ b/FoliCon/Models/Data/DArtImageList.cs @@ -12,10 +12,8 @@ public DArtImageList(string url, BitmapSource bmp) Image = bmp ?? throw new ArgumentNullException(nameof(bmp)); } - public DArtImageList(string url, BitmapSource bmp, string deviationId) + public DArtImageList(string url, BitmapSource bmp, string deviationId) : this(url, bmp) { - Url = url ?? throw new ArgumentNullException(nameof(url)); - Image = bmp ?? throw new ArgumentNullException(nameof(bmp)); DeviationId = deviationId ?? throw new ArgumentNullException(nameof(deviationId)); } diff --git a/FoliCon/Modules/DeviantArt/DArt.cs b/FoliCon/Modules/DeviantArt/DArt.cs index f554daa7..6a67b9db 100644 --- a/FoliCon/Modules/DeviantArt/DArt.cs +++ b/FoliCon/Modules/DeviantArt/DArt.cs @@ -98,7 +98,7 @@ public async Task Download(string deviationId) GetClientAccessTokenAsync(); var dArtDownloadResponse = await GetDArtDownloadResponseAsync(deviationId); var targetDirectoryPath = FileUtils.CreateDirectoryInFoliConTemp(deviationId); - dArtDownloadResponse.localDownloadPath = targetDirectoryPath; + dArtDownloadResponse.LocalDownloadPath = targetDirectoryPath; var downloadResponse = await Services.HttpC.GetAsync(dArtDownloadResponse.Src); if (FileUtils.IsCompressedArchive(dArtDownloadResponse.Filename)) diff --git a/FoliCon/Modules/Extension/StreamExtension.cs b/FoliCon/Modules/Extension/StreamExtension.cs index c8ecdc17..1655efa3 100644 --- a/FoliCon/Modules/Extension/StreamExtension.cs +++ b/FoliCon/Modules/Extension/StreamExtension.cs @@ -12,13 +12,10 @@ public static void ExtractPngAndIcoToDirectory(this Stream archiveStream, string while (reader.MoveToNextEntry()) { var entryKey = reader.Entry.Key; - - if (entryKey != null && (reader.Entry.IsDirectory || - entryKey.Contains("ResourceForks") || - entryKey.Contains("__MACOSX") || - entryKey.StartsWith("._") || - entryKey.Equals(".DS_Store") || - entryKey.Equals("Thumbs.db"))) continue; + if (IsUnwantedDirectoryOrFileType(entryKey, reader)) + { + continue; + } if (FileUtils.IsPngOrIco(entryKey)) { @@ -30,4 +27,14 @@ public static void ExtractPngAndIcoToDirectory(this Stream archiveStream, string } } } + + private static bool IsUnwantedDirectoryOrFileType(string entryKey, IReader reader) + { + return entryKey != null && (reader.Entry.IsDirectory || + entryKey.Contains("ResourceForks") || + entryKey.Contains("__MACOSX") || + entryKey.StartsWith("._") || + entryKey.Equals(".DS_Store") || + entryKey.Equals("Thumbs.db")); + } } \ No newline at end of file diff --git a/FoliCon/Modules/utils/FileUtils.cs b/FoliCon/Modules/utils/FileUtils.cs index ddfa991a..1a29bbe1 100644 --- a/FoliCon/Modules/utils/FileUtils.cs +++ b/FoliCon/Modules/utils/FileUtils.cs @@ -15,7 +15,7 @@ namespace FoliCon.Modules.utils; public static class FileUtils { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private static readonly List _compressedExtensions = [ + private static readonly List CompressedExtensions = [ ".zip", ".rar", ".gz", @@ -244,7 +244,11 @@ public static DirectoryPermissionsResult CheckDirectoryPermissions(string dirPat { var permissions = new DirectoryPermissionsResult(); - if (!Directory.Exists(dirPath)) return permissions; + if (!Directory.Exists(dirPath)) + { + return permissions; + } + var identity = WindowsIdentity.GetCurrent(); var principal = new WindowsPrincipal(identity); @@ -256,7 +260,11 @@ public static DirectoryPermissionsResult CheckDirectoryPermissions(string dirPat { var securityIdentifier = (SecurityIdentifier) rule.IdentityReference; - if (!principal.IsInRole(securityIdentifier)) continue; + if (!principal.IsInRole(securityIdentifier)) + { + continue; + } + if ((FileSystemRights.Read & rule.FileSystemRights) != 0 && rule.AccessControlType == AccessControlType.Allow) { permissions.CanRead = true; @@ -491,31 +499,28 @@ public static string CreateDirectoryInFoliConTemp(string path) public static bool IsCompressedArchive(string fileName) { var fileExtension = Path.GetExtension(fileName)?.ToLower(); - return _compressedExtensions.Contains(fileExtension); + return CompressedExtensions.Contains(fileExtension); } public static void DeleteDirectoryIfEmpty(string targetDirectoryPath) { - if (!Directory.Exists(targetDirectoryPath)) return; - + if (!Directory.Exists(targetDirectoryPath)) + { + return; + } + if (Directory.GetFiles(targetDirectoryPath).Length == 0) { Directory.Delete(targetDirectoryPath); } } - - public static void DeleteFoliConTempDeviationDirectory(bool ifEmpty = false) + + public static void DeleteFoliConTempDeviationDirectory() { - if (ifEmpty) - { - DeleteDirectoryIfEmpty(FoliConTempDeviationsPath()); - } - else - { - Directory.Delete(FoliConTempDeviationsPath(), true); - } + Directory.Delete(FoliConTempDeviationsPath(), true); } + private static string FoliConTempPath() { return Path.Combine(Path.GetTempPath(), "FoliCon"); diff --git a/FoliCon/ViewModels/ManualExplorerViewModel.cs b/FoliCon/ViewModels/ManualExplorerViewModel.cs index b6c8654c..ec5c4045 100644 --- a/FoliCon/ViewModels/ManualExplorerViewModel.cs +++ b/FoliCon/ViewModels/ManualExplorerViewModel.cs @@ -86,7 +86,7 @@ public virtual void OnDialogOpened(IDialogParameters parameters) { Logger.Debug("Downloaded Image from Deviation ID {DeviationId}", deviationId); var dArtDownloadResponse = task.Result; - dArtDownloadResponse.localDownloadPath.ToDirectoryInfo().GetFiles() + dArtDownloadResponse.LocalDownloadPath.ToDirectoryInfo().GetFiles() .ForEach(info => { Directory.AddOnUI(info.FullName); }); IsBusy = false; }); diff --git a/FoliCon/ViewModels/ProSearchResultViewModel.cs b/FoliCon/ViewModels/ProSearchResultViewModel.cs index 7fd96fba..e121704b 100644 --- a/FoliCon/ViewModels/ProSearchResultViewModel.cs +++ b/FoliCon/ViewModels/ProSearchResultViewModel.cs @@ -96,7 +96,11 @@ private void ExtractManually(object parameter) var deviationId = (string)parameter; _dialogService.ShowManualExplorer(deviationId, DArtObject, result => { - if (result.Result != ButtonResult.OK) return; + if (result.Result != ButtonResult.OK) + { + return; + } + Logger.Debug("Manual Extraction Completed"); PickMethod(result.Parameters.GetValue("localPath")); }); From 513ace696b4612c01ea02e6fe5f9dfa258fec3e2 Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+dineshsolanki@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:45:48 +0530 Subject: [PATCH 11/13] remove redundant code --- FoliCon/ViewModels/ManualExplorerViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FoliCon/ViewModels/ManualExplorerViewModel.cs b/FoliCon/ViewModels/ManualExplorerViewModel.cs index ec5c4045..8df32c12 100644 --- a/FoliCon/ViewModels/ManualExplorerViewModel.cs +++ b/FoliCon/ViewModels/ManualExplorerViewModel.cs @@ -64,7 +64,7 @@ public virtual void OnDialogClosed() protected virtual void CloseDialog(ButtonResult result, string localPath) { Logger.Info("Close Dialog called with result {Result}, localImagePath {LocalImagePath}", result, localPath); - var dialogParams = new DialogParameters() + var dialogParams = new DialogParameters { {"localPath", localPath} }; From 6c880371034c4382698efb55dd005e79c4e9b067 Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+dineshsolanki@users.noreply.github.com> Date: Tue, 16 Jul 2024 23:48:19 +0530 Subject: [PATCH 12/13] Add translation strings for the manual extraction feature --- FoliCon/Modules/LangProvider.cs | 66 ++++++++++--------- FoliCon/Properties/Langs/Lang.Designer.cs | 18 +++++ 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/ManualExplorerViewModel.cs | 2 +- FoliCon/Views/ProSearchResult.xaml | 2 +- 10 files changed, 92 insertions(+), 32 deletions(-) diff --git a/FoliCon/Modules/LangProvider.cs b/FoliCon/Modules/LangProvider.cs index e377a0d3..13ec3558 100644 --- a/FoliCon/Modules/LangProvider.cs +++ b/FoliCon/Modules/LangProvider.cs @@ -33,16 +33,16 @@ public static CultureInfo Culture private void UpdateLangs() { + OnPropertyChanged(nameof(APIKeysConfiguration)); + OnPropertyChanged(nameof(APIKeysNotProvided)); OnPropertyChanged(nameof(About)); OnPropertyChanged(nameof(Action)); OnPropertyChanged(nameof(AddToContextMenu)); OnPropertyChanged(nameof(All)); OnPropertyChanged(nameof(AlwaysShowPosterWindow)); OnPropertyChanged(nameof(AmbiguousTitleTooltip)); - OnPropertyChanged(nameof(APIKeysConfiguration)); - OnPropertyChanged(nameof(APIKeysNotProvided)); - OnPropertyChanged(nameof(Apply)); OnPropertyChanged(nameof(AppWillClose)); + OnPropertyChanged(nameof(Apply)); OnPropertyChanged(nameof(Arabic)); OnPropertyChanged(nameof(Auto)); OnPropertyChanged(nameof(BestSuitedForHorizontal)); @@ -76,18 +76,19 @@ private void UpdateLangs() OnPropertyChanged(nameof(DeleteMediaInfoTooltip)); OnPropertyChanged(nameof(DevelopedByDinesh)); OnPropertyChanged(nameof(DirectoryIsEmpty)); - OnPropertyChanged(nameof(DownloadingIcons)); - OnPropertyChanged(nameof(DownloadingIconWithCount)); OnPropertyChanged(nameof(DownloadIt)); + OnPropertyChanged(nameof(DownloadingIconWithCount)); + OnPropertyChanged(nameof(DownloadingIcons)); OnPropertyChanged(nameof(EmptyDirectory)); - OnPropertyChanged(nameof(Enabled)); OnPropertyChanged(nameof(EnableErrorReporting)); OnPropertyChanged(nameof(EnableErrorReportingTip)); OnPropertyChanged(nameof(EnableSubfolderProcessing)); + OnPropertyChanged(nameof(Enabled)); OnPropertyChanged(nameof(English)); OnPropertyChanged(nameof(EnterTitlePlaceholder)); OnPropertyChanged(nameof(EnterValidRegexPlaceholder)); OnPropertyChanged(nameof(ExplorerIntegration)); + OnPropertyChanged(nameof(ExtractManually)); OnPropertyChanged(nameof(FailedFileAccessAt)); OnPropertyChanged(nameof(FailedToSaveMediaInfoAt)); OnPropertyChanged(nameof(FileIsInUse)); @@ -121,6 +122,7 @@ private void UpdateLangs() OnPropertyChanged(nameof(Load)); OnPropertyChanged(nameof(LoadingPosters)); OnPropertyChanged(nameof(MakeIcons)); + OnPropertyChanged(nameof(ManualExplorer)); OnPropertyChanged(nameof(MediaRating)); OnPropertyChanged(nameof(MediaTitle)); OnPropertyChanged(nameof(Movie)); @@ -160,11 +162,11 @@ private void UpdateLangs() OnPropertyChanged(nameof(RestartExplorerTooltip)); OnPropertyChanged(nameof(Russian)); OnPropertyChanged(nameof(Save)); + OnPropertyChanged(nameof(SearchMode)); + OnPropertyChanged(nameof(SearchResult)); OnPropertyChanged(nameof(Searching)); OnPropertyChanged(nameof(SearchingWithCount)); OnPropertyChanged(nameof(SearchingWithName)); - OnPropertyChanged(nameof(SearchMode)); - OnPropertyChanged(nameof(SearchResult)); OnPropertyChanged(nameof(SeeMorePosters)); OnPropertyChanged(nameof(SelectFolder)); OnPropertyChanged(nameof(SelectIconsDirectory)); @@ -180,6 +182,8 @@ private void UpdateLangs() OnPropertyChanged(nameof(Spanish)); OnPropertyChanged(nameof(StopSearching)); OnPropertyChanged(nameof(SubfolderProcessing)); + OnPropertyChanged(nameof(TMDBAPIKey)); + OnPropertyChanged(nameof(TV)); OnPropertyChanged(nameof(Test)); OnPropertyChanged(nameof(Theme)); OnPropertyChanged(nameof(ThemeDark)); @@ -187,9 +191,7 @@ private void UpdateLangs() OnPropertyChanged(nameof(ThemeSystem)); OnPropertyChanged(nameof(ThisIsLatestVersion)); OnPropertyChanged(nameof(Title)); - OnPropertyChanged(nameof(TMDBAPIKey)); OnPropertyChanged(nameof(ToForceReload)); - OnPropertyChanged(nameof(TV)); OnPropertyChanged(nameof(UnauthorizedAccess)); OnPropertyChanged(nameof(Undo)); OnPropertyChanged(nameof(UndoSuccessful)); @@ -204,16 +206,16 @@ private void UpdateLangs() OnPropertyChanged(nameof(Year)); } + public string APIKeysConfiguration => Lang.APIKeysConfiguration; + public string APIKeysNotProvided => Lang.APIKeysNotProvided; public string About => Lang.About; public string Action => Lang.Action; public string AddToContextMenu => Lang.AddToContextMenu; public string All => Lang.All; public string AlwaysShowPosterWindow => Lang.AlwaysShowPosterWindow; public string AmbiguousTitleTooltip => Lang.AmbiguousTitleTooltip; - public string APIKeysConfiguration => Lang.APIKeysConfiguration; - public string APIKeysNotProvided => Lang.APIKeysNotProvided; - public string Apply => Lang.Apply; public string AppWillClose => Lang.AppWillClose; + public string Apply => Lang.Apply; public string Arabic => Lang.Arabic; public string Auto => Lang.Auto; public string BestSuitedForHorizontal => Lang.BestSuitedForHorizontal; @@ -247,19 +249,20 @@ private void UpdateLangs() public string DeleteMediaInfoTooltip => Lang.DeleteMediaInfoTooltip; public string DevelopedByDinesh => Lang.DevelopedByDinesh; public string DirectoryIsEmpty => Lang.DirectoryIsEmpty; - public string DownloadingIcons => Lang.DownloadingIcons; - public string DownloadingIconWithCount => Lang.DownloadingIconWithCount; public string DownloadIt => Lang.DownloadIt; + public string DownloadingIconWithCount => Lang.DownloadingIconWithCount; + public string DownloadingIcons => Lang.DownloadingIcons; public string EmptyDirectory => Lang.EmptyDirectory; - public string Enabled => Lang.Enabled; public string EnableErrorReporting => Lang.EnableErrorReporting; public string EnableErrorReportingTip => Lang.EnableErrorReportingTip; public string EnableSubfolderProcessing => Lang.EnableSubfolderProcessing; + public string Enabled => Lang.Enabled; public string English => Lang.English; public string EnterTitlePlaceholder => Lang.EnterTitlePlaceholder; public string EnterValidRegexPlaceholder => Lang.EnterValidRegexPlaceholder; public string ExceptionOccurred => Lang.ExceptionOccurred; public string ExplorerIntegration => Lang.ExplorerIntegration; + public string ExtractManually => Lang.ExtractManually; public string FailedFileAccessAt => Lang.FailedFileAccessAt; public string FailedToSaveMediaInfoAt => Lang.FailedToSaveMediaInfoAt; public string FileIsInUse => Lang.FileIsInUse; @@ -293,6 +296,7 @@ private void UpdateLangs() public string Load => Lang.Load; public string LoadingPosters => Lang.LoadingPosters; public string MakeIcons => Lang.MakeIcons; + public string ManualExplorer => Lang.ManualExplorer; public string MediaRating => Lang.MediaRating; public string MediaTitle => Lang.MediaTitle; public string Movie => Lang.Movie; @@ -332,11 +336,11 @@ private void UpdateLangs() public string RestartExplorerTooltip => Lang.RestartExplorerTooltip; public string Russian => Lang.Russian; public string Save => Lang.Save; + public string SearchMode => Lang.SearchMode; + public string SearchResult => Lang.SearchResult; public string Searching => Lang.Searching; public string SearchingWithCount => Lang.SearchingWithCount; public string SearchingWithName => Lang.SearchingWithName; - public string SearchMode => Lang.SearchMode; - public string SearchResult => Lang.SearchResult; public string SeeMorePosters => Lang.SeeMorePosters; public string SelectFolder => Lang.SelectFolder; public string SelectIconsDirectory => Lang.SelectIconsDirectory; @@ -352,6 +356,8 @@ private void UpdateLangs() public string Spanish => Lang.Spanish; public string StopSearching => Lang.StopSearching; public string SubfolderProcessing => Lang.SubfolderProcessing; + public string TMDBAPIKey => Lang.TMDBAPIKey; + public string TV => Lang.TV; public string Test => Lang.Test; public string Theme => Lang.Theme; public string ThemeDark => Lang.ThemeDark; @@ -359,9 +365,7 @@ private void UpdateLangs() public string ThemeSystem => Lang.ThemeSystem; public string ThisIsLatestVersion => Lang.ThisIsLatestVersion; public string Title => Lang.Title; - public string TMDBAPIKey => Lang.TMDBAPIKey; public string ToForceReload => Lang.ToForceReload; - public string TV => Lang.TV; public string UnauthorizedAccess => Lang.UnauthorizedAccess; public string Undo => Lang.Undo; public string UndoSuccessful => Lang.UndoSuccessful; @@ -384,16 +388,16 @@ protected virtual void OnPropertyChanged(string propertyName) => public class LangKeys { + public static string APIKeysConfiguration = nameof(APIKeysConfiguration); + public static string APIKeysNotProvided = nameof(APIKeysNotProvided); public static string About = nameof(About); public static string Action = nameof(Action); public static string AddToContextMenu = nameof(AddToContextMenu); public static string All = nameof(All); public static string AlwaysShowPosterWindow = nameof(AlwaysShowPosterWindow); public static string AmbiguousTitleTooltip = nameof(AmbiguousTitleTooltip); - public static string APIKeysConfiguration = nameof(APIKeysConfiguration); - public static string APIKeysNotProvided = nameof(APIKeysNotProvided); - public static string Apply = nameof(Apply); public static string AppWillClose = nameof(AppWillClose); + public static string Apply = nameof(Apply); public static string Arabic = nameof(Arabic); public static string Auto = nameof(Auto); public static string BestSuitedForHorizontal = nameof(BestSuitedForHorizontal); @@ -427,19 +431,20 @@ public class LangKeys public static string DeleteMediaInfoTooltip = nameof(DeleteMediaInfoTooltip); public static string DevelopedByDinesh = nameof(DevelopedByDinesh); public static string DirectoryIsEmpty = nameof(DirectoryIsEmpty); - public static string DownloadingIcons = nameof(DownloadingIcons); - public static string DownloadingIconWithCount = nameof(DownloadingIconWithCount); public static string DownloadIt = nameof(DownloadIt); + public static string DownloadingIconWithCount = nameof(DownloadingIconWithCount); + public static string DownloadingIcons = nameof(DownloadingIcons); public static string EmptyDirectory = nameof(EmptyDirectory); - public static string Enabled = nameof(Enabled); public static string EnableErrorReporting = nameof(EnableErrorReporting); public static string EnableErrorReportingTip = nameof(EnableErrorReportingTip); public static string EnableSubfolderProcessing = nameof(EnableSubfolderProcessing); + public static string Enabled = nameof(Enabled); public static string English = nameof(English); public static string EnterTitlePlaceholder = nameof(EnterTitlePlaceholder); public static string EnterValidRegexPlaceholder = nameof(EnterValidRegexPlaceholder); public static string ExceptionOccurred = nameof(ExceptionOccurred); public static string ExplorerIntegration = nameof(ExplorerIntegration); + public static string ExtractManually = nameof(ExtractManually); public static string FailedFileAccessAt = nameof(FailedFileAccessAt); public static string FailedToSaveMediaInfoAt = nameof(FailedToSaveMediaInfoAt); public static string FileIsInUse = nameof(FileIsInUse); @@ -473,6 +478,7 @@ public class LangKeys public static string Load = nameof(Load); public static string LoadingPosters = nameof(LoadingPosters); public static string MakeIcons = nameof(MakeIcons); + public static string ManualExplorer = nameof(ManualExplorer); public static string MediaRating = nameof(MediaRating); public static string MediaTitle = nameof(MediaTitle); public static string Movie = nameof(Movie); @@ -512,11 +518,11 @@ public class LangKeys public static string RestartExplorerTooltip = nameof(RestartExplorerTooltip); public static string Russian = nameof(Russian); public static string Save = nameof(Save); + public static string SearchMode = nameof(SearchMode); + public static string SearchResult = nameof(SearchResult); public static string Searching = nameof(Searching); public static string SearchingWithCount = nameof(SearchingWithCount); public static string SearchingWithName = nameof(SearchingWithName); - public static string SearchMode = nameof(SearchMode); - public static string SearchResult = nameof(SearchResult); public static string SeeMorePosters = nameof(SeeMorePosters); public static string SelectFolder = nameof(SelectFolder); public static string SelectIconsDirectory = nameof(SelectIconsDirectory); @@ -532,6 +538,8 @@ public class LangKeys public static string Spanish = nameof(Spanish); public static string StopSearching = nameof(StopSearching); public static string SubfolderProcessing = nameof(SubfolderProcessing); + public static string TMDBAPIKey = nameof(TMDBAPIKey); + public static string TV = nameof(TV); public static string Test = nameof(Test); public static string Theme = nameof(Theme); public static string ThemeDark = nameof(ThemeDark); @@ -539,9 +547,7 @@ public class LangKeys public static string ThemeSystem = nameof(ThemeSystem); public static string ThisIsLatestVersion = nameof(ThisIsLatestVersion); public static string Title = nameof(Title); - public static string TMDBAPIKey = nameof(TMDBAPIKey); public static string ToForceReload = nameof(ToForceReload); - public static string TV = nameof(TV); public static string UnauthorizedAccess = nameof(UnauthorizedAccess); public static string Undo = nameof(Undo); public static string UndoSuccessful = nameof(UndoSuccessful); diff --git a/FoliCon/Properties/Langs/Lang.Designer.cs b/FoliCon/Properties/Langs/Lang.Designer.cs index c4436494..8660b6cd 100644 --- a/FoliCon/Properties/Langs/Lang.Designer.cs +++ b/FoliCon/Properties/Langs/Lang.Designer.cs @@ -573,6 +573,15 @@ public static string ExplorerIntegration { } } + /// + /// Looks up a localized string similar to Extract manually. + /// + public static string ExtractManually { + get { + return ResourceManager.GetString("ExtractManually", resourceCulture); + } + } + /// /// Looks up a localized string similar to Failed to access file at {0}. You may not have permission to access this file. Try running as admin.. /// @@ -872,6 +881,15 @@ public static string MakeIcons { } } + /// + /// Looks up a localized string similar to Manual Explorer. + /// + public static string ManualExplorer { + get { + return ResourceManager.GetString("ManualExplorer", resourceCulture); + } + } + /// /// Looks up a localized string similar to Media Rating. /// diff --git a/FoliCon/Properties/Langs/Lang.ar.resx b/FoliCon/Properties/Langs/Lang.ar.resx index d4fe55cd..e40c8ec6 100644 --- a/FoliCon/Properties/Langs/Lang.ar.resx +++ b/FoliCon/Properties/Langs/Lang.ar.resx @@ -645,4 +645,10 @@ نمط + + المستكشف اليدوي + + + استخراج يدوي + \ No newline at end of file diff --git a/FoliCon/Properties/Langs/Lang.es.resx b/FoliCon/Properties/Langs/Lang.es.resx index 610264b8..88cca05e 100644 --- a/FoliCon/Properties/Langs/Lang.es.resx +++ b/FoliCon/Properties/Langs/Lang.es.resx @@ -645,4 +645,10 @@ Esto ayuda a folicon a identificar los medios sin tener que elegir entre título Patrón + + Explorador manual + + + Extraer manualmente + \ No newline at end of file diff --git a/FoliCon/Properties/Langs/Lang.hi.resx b/FoliCon/Properties/Langs/Lang.hi.resx index 0be6a140..0ee7b913 100644 --- a/FoliCon/Properties/Langs/Lang.hi.resx +++ b/FoliCon/Properties/Langs/Lang.hi.resx @@ -645,4 +645,10 @@ पैटर्न + + मैनुअल एक्सप्लोरर + + + एक्सट्रेक्ट करे + \ No newline at end of file diff --git a/FoliCon/Properties/Langs/Lang.pt.resx b/FoliCon/Properties/Langs/Lang.pt.resx index ab57e301..f66bb8b8 100644 --- a/FoliCon/Properties/Langs/Lang.pt.resx +++ b/FoliCon/Properties/Langs/Lang.pt.resx @@ -644,4 +644,10 @@ e renovar o cache dos Ícones? Padrão + + Explorador manual + + + Extrair manualmente + \ No newline at end of file diff --git a/FoliCon/Properties/Langs/Lang.resx b/FoliCon/Properties/Langs/Lang.resx index 79dccf36..791fb085 100644 --- a/FoliCon/Properties/Langs/Lang.resx +++ b/FoliCon/Properties/Langs/Lang.resx @@ -649,4 +649,10 @@ and refresh Icon Cache? Pattern + + Manual Explorer + + + Extract manually + \ No newline at end of file diff --git a/FoliCon/Properties/Langs/Lang.ru.resx b/FoliCon/Properties/Langs/Lang.ru.resx index 63be38e6..44bad9d7 100644 --- a/FoliCon/Properties/Langs/Lang.ru.resx +++ b/FoliCon/Properties/Langs/Lang.ru.resx @@ -648,4 +648,10 @@ Шаблон + + Ручной проводник + + + Извлечь вручную + \ No newline at end of file diff --git a/FoliCon/ViewModels/ManualExplorerViewModel.cs b/FoliCon/ViewModels/ManualExplorerViewModel.cs index 8df32c12..2a1b3c83 100644 --- a/FoliCon/ViewModels/ManualExplorerViewModel.cs +++ b/FoliCon/ViewModels/ManualExplorerViewModel.cs @@ -21,7 +21,7 @@ private void PickMethod(object localImagePath) CloseDialog(ButtonResult.OK, (string)localImagePath); } - private string _title = "Manual Explorer"; + private string _title = LangProvider.GetLang("ManualExplorer"); private bool _isBusy; private ObservableCollection _directory; private DArt _dArtObject; diff --git a/FoliCon/Views/ProSearchResult.xaml b/FoliCon/Views/ProSearchResult.xaml index 6781301b..622f11b3 100644 --- a/FoliCon/Views/ProSearchResult.xaml +++ b/FoliCon/Views/ProSearchResult.xaml @@ -82,7 +82,7 @@ From d5991d38e2cac96a631fab9af579956ac68890ab Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+dineshsolanki@users.noreply.github.com> Date: Wed, 17 Jul 2024 00:04:23 +0530 Subject: [PATCH 13/13] Add comments to DeviantArt and StreamExtension methods Added docstrings to the `Download` method in the `DArt.cs` and `ExtractPngAndIcoToDirectory` method in `StreamExtension.cs` to provide more clarity about their usage and output. --- FoliCon/Modules/DeviantArt/DArt.cs | 7 ++++++- FoliCon/Modules/Extension/StreamExtension.cs | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/FoliCon/Modules/DeviantArt/DArt.cs b/FoliCon/Modules/DeviantArt/DArt.cs index 6a67b9db..a4118f75 100644 --- a/FoliCon/Modules/DeviantArt/DArt.cs +++ b/FoliCon/Modules/DeviantArt/DArt.cs @@ -92,7 +92,12 @@ public async Task Browse(string query, int offset = 0) return result; } - + + /// + /// Downloads a file from the DeviantArt API. + /// + /// The ID of the deviation. + /// The DArtDownloadResponse object containing the download details. public async Task Download(string deviationId) { GetClientAccessTokenAsync(); diff --git a/FoliCon/Modules/Extension/StreamExtension.cs b/FoliCon/Modules/Extension/StreamExtension.cs index 1655efa3..9acf14b7 100644 --- a/FoliCon/Modules/Extension/StreamExtension.cs +++ b/FoliCon/Modules/Extension/StreamExtension.cs @@ -6,6 +6,11 @@ namespace FoliCon.Modules.Extension; public static class StreamExtensions { + /// + /// Extracts PNG and ICO files from a compressed stream and writes them to a directory. + /// + /// The compressed stream containing the PNG and ICO files. + /// The path of the directory where the extracted files should be written. public static void ExtractPngAndIcoToDirectory(this Stream archiveStream, string targetPath) { using var reader = ReaderFactory.Open(archiveStream);