Skip to content

Commit

Permalink
feature: Add progress tracking and localization for icon creation and…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
DineshSolanki committed Jul 27, 2024
1 parent 7c54bda commit 0ff53c8
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 25 deletions.
6 changes: 6 additions & 0 deletions FoliCon/Modules/LangProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions FoliCon/Modules/utils/IconUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static string GetImageName()
/// Creates Icons from PNG
/// </summary>
public static int MakeIco(string iconMode, string selectedFolder, List<PickedListItem> pickedListDataTable,
bool isRatingVisible, bool isMockupVisible)
bool isRatingVisible, bool isMockupVisible, IProgress<ProgressBarData> progressCallback)
{
Logger.Debug(
"Creating Icons from PNG, Icon Mode: {IconMode}, Selected Folder: {SelectedFolder}, isRatingVisible: {IsRatingVisible}, isMockupVisible: {IsMockupVisible}",
Expand All @@ -27,6 +27,9 @@ public static int MakeIco(string iconMode, string selectedFolder, List<PickedLis
var ratingVisibility = isRatingVisible ? "visible" : "hidden";
var mockupVisibility = isMockupVisible ? "visible" : "hidden";

var max = pickedListDataTable.Count;
var extractionProgress = new ProgressBarData(0, max, Lang.CreatingIconWithCount.Format(0, max));
progressCallback.Report(extractionProgress);
foreach (var item in pickedListDataTable)
{
var parent = Directory.GetParent(item.Folder);
Expand Down Expand Up @@ -57,8 +60,13 @@ public static int MakeIco(string iconMode, string selectedFolder, List<PickedLis

FileUtils.HideFile(targetFile);
FileUtils.SetFolderIcon($"{ImageName}.ico", $@"{parentFolder}\{folderName}");

extractionProgress.Value = iconProcessedCount;
extractionProgress.Text = Lang.CreatingIconWithCount.Format(iconProcessedCount, max);
progressCallback.Report(extractionProgress);
}

extractionProgress.Text = Lang.RefreshingFolder;
progressCallback.Report(extractionProgress);
FileUtils.ApplyChanges(selectedFolder);
SHChangeNotify(SHCNE.SHCNE_UPDATEITEM, SHCNF.SHCNF_PATHW, selectedFolder);
return iconProcessedCount;
Expand Down
50 changes: 33 additions & 17 deletions FoliCon/Properties/Langs/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions FoliCon/Properties/Langs/Lang.ar.resx
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,10 @@
<data name="Downloading" xml:space="preserve">
<value>جارٍ التنزيل...</value>
</data>
<data name="CreatingIconWithCount" xml:space="preserve">
<value>جارٍ إنشاء الأيقونة {0}/{1}...</value>
</data>
<data name="RefreshingFolder" xml:space="preserve">
<value>تحديث المجلد</value>
</data>
</root>
6 changes: 6 additions & 0 deletions FoliCon/Properties/Langs/Lang.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,10 @@ Esto ayuda a folicon a identificar los medios sin tener que elegir entre título
<data name="Downloading" xml:space="preserve">
<value>Descargando...</value>
</data>
<data name="CreatingIconWithCount" xml:space="preserve">
<value>Creando icono {0}/{1}...</value>
</data>
<data name="RefreshingFolder" xml:space="preserve">
<value>Actualizando carpeta</value>
</data>
</root>
6 changes: 6 additions & 0 deletions FoliCon/Properties/Langs/Lang.hi.resx
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,10 @@
<data name="Downloading" xml:space="preserve">
<value>डाउनलोड हो रहा है...</value>
</data>
<data name="CreatingIconWithCount" xml:space="preserve">
<value>आइकन बना रहा है {0}/{1}...</value>
</data>
<data name="RefreshingFolder" xml:space="preserve">
<value>फ़ोल्डर रीफ्रेश हो रहा है</value>
</data>
</root>
6 changes: 6 additions & 0 deletions FoliCon/Properties/Langs/Lang.pt.resx
Original file line number Diff line number Diff line change
Expand Up @@ -656,4 +656,10 @@ e renovar o cache dos Ícones?</value>
<data name="Downloading" xml:space="preserve">
<value>Baixando...</value>
</data>
<data name="CreatingIconWithCount" xml:space="preserve">
<value>Criando ícone {0}/{1}...</value>
</data>
<data name="RefreshingFolder" xml:space="preserve">
<value>Atualizando pasta</value>
</data>
</root>
6 changes: 6 additions & 0 deletions FoliCon/Properties/Langs/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,10 @@ and refresh Icon Cache?</value>
<data name="Downloading" xml:space="preserve">
<value>Downloading...</value>
</data>
<data name="CreatingIconWithCount" xml:space="preserve">
<value>Creating Icon {0}/{1}...</value>
</data>
<data name="RefreshingFolder" xml:space="preserve">
<value>Refreshing folder</value>
</data>
</root>
6 changes: 6 additions & 0 deletions FoliCon/Properties/Langs/Lang.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,10 @@
<data name="Downloading" xml:space="preserve">
<value>Загрузка...</value>
</data>
<data name="CreatingIconWithCount" xml:space="preserve">
<value>Создание значка {0}/{1}...</value>
</data>
<data name="RefreshingFolder" xml:space="preserve">
<value>Обновление папки</value>
</data>
</root>
16 changes: 11 additions & 5 deletions FoliCon/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageToDownload> _imgDownloadList = [];
Expand Down Expand Up @@ -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<string> Fnames { get; set; } = [];

public bool IsMakeEnabled
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<ProgressBarData>(value => BusyIndicatorProperties = value)));
StatusBarProperties.ProcessedIcon = iconProcessedCount;
IsBusy = false;
var info = new GrowlInfo
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<StackPanel Margin="4">
<TextBlock
Text="{Binding Path=DataContext.BusyIndicatorProperties.Text, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />
<ProgressBar Style="{DynamicResource ProgressBarFlat}"
<ProgressBar Style="{DynamicResource ProgressBarSuccessStripe}"
Value="{Binding Path=DataContext.BusyIndicatorProperties.Value, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
Maximum="{Binding Path=DataContext.BusyIndicatorProperties.Max, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
Height="15" />
Expand Down

0 comments on commit 0ff53c8

Please sign in to comment.