Skip to content

Commit

Permalink
Merge pull request #183 from DineshSolanki/chore/DataTableToList
Browse files Browse the repository at this point in the history
Change DataTable to List for improved performance, Fix rating digits issue for auto-picked titles
  • Loading branch information
DineshSolanki authored Dec 21, 2023
2 parents 11c1462 + 60a9dcd commit 78934aa
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 63 deletions.
18 changes: 18 additions & 0 deletions FoliCon/Models/Data/PickedListItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace FoliCon.Models.Data;

public class PickedListItem: ListItem
{
private string _folderName;

public string FolderName
{
get => _folderName;
set => SetProperty(ref _folderName, value);
}

public PickedListItem(string title, string year, string rating, string folder, string folderName, string poster)
: base(title, year, rating, "", poster, folder)
{
FolderName = folderName;
}
}
4 changes: 2 additions & 2 deletions FoliCon/Modules/Extension/DialogServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void ShowCustomIconWindow(this IDialogService dialogService, Actio
}

public static void ShowProSearchResult(this IDialogService dialogService, string folderPath,
List<string> fnames, DataTable pickedTable, List<ImageToDownload> imgList, DArt dartObject,
List<string> fnames, List<PickedListItem> pickedTable, List<ImageToDownload> imgList, DArt dartObject,
Action<IDialogResult> callBack)
{
Logger.Trace("ShowProSearchResult called with folderPath: {FolderPath} and fnames: {@Fnames}", folderPath,
Expand Down Expand Up @@ -82,7 +82,7 @@ public static void ShowPosterPicker(this IDialogService dialogService, Tmdb tmdb
public static void ShowPreviewer(this IDialogService dialogService, Action<IDialogResult> callBack)
{
Logger.Trace("ShowPreviewer called");
var p = new DialogParameters {};
var p = new DialogParameters();
dialogService.ShowDialog("Previewer", p, callBack);
}
}
2 changes: 1 addition & 1 deletion FoliCon/Modules/IGDB/IGDBClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public IGDBClient GetClient()
/// <param name="listDataTable">DataTable that stores all the Picked Results.</param>
/// <param name="serviceClient">Initialized IGDB/Twitch Client</param>
/// <param name="imgDownloadList">List that stores all the images to download.</param>
public IgdbClass(ref DataTable listDataTable, ref IGDBClient serviceClient,
public IgdbClass(ref List<PickedListItem> listDataTable, ref IGDBClient serviceClient,
ref List<ImageToDownload> imgDownloadList)
{
_dataTransformer = new IgdbDataTransformer(ref listDataTable, ref imgDownloadList);
Expand Down
4 changes: 2 additions & 2 deletions FoliCon/Modules/IGDB/IgdbDataTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

namespace FoliCon.Modules.IGDB;

public class IgdbDataTransformer(ref DataTable listDataTable, ref List<ImageToDownload> imgDownloadList)
public class IgdbDataTransformer(ref List<PickedListItem> listDataTable, ref List<ImageToDownload> imgDownloadList)
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

private readonly List<ImageToDownload> _imgDownloadList =
imgDownloadList ?? throw new ArgumentNullException(nameof(imgDownloadList));

private readonly DataTable _listDataTable = listDataTable ?? throw new ArgumentNullException(nameof(listDataTable));
private readonly List<PickedListItem> _listDataTable = listDataTable ?? throw new ArgumentNullException(nameof(listDataTable));

public static ObservableCollection<ListItem> ExtractGameDetailsIntoListItem(IEnumerable<Game> games)
{
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/Modules/TMDB/TMDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public TMDbClient GetClient()
/// <param name="serviceClient">Initialized TMDB Client</param>
/// <param name="listDataTable">DataTable that stores all the Picked Results.</param>
/// <param name="imgDownloadList">List that stores all the images to download.</param>
public Tmdb(ref TMDbClient serviceClient, ref DataTable listDataTable,
public Tmdb(ref TMDbClient serviceClient, ref List<PickedListItem> listDataTable,
ref List<ImageToDownload> imgDownloadList)
{
Logger.Debug("Initializing TMDB Helper Class");
Expand Down
4 changes: 2 additions & 2 deletions FoliCon/Modules/TMDB/TmdbDataTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ internal class TmdbDataTransformer
{
private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();

private readonly DataTable _listDataTable;
private readonly List<PickedListItem> _listDataTable;
private readonly List<ImageToDownload> _imgDownloadList;
public TmdbDataTransformer(ref DataTable listDataTable,
public TmdbDataTransformer(ref List<PickedListItem> listDataTable,
ref List<ImageToDownload> imgDownloadList)
{
this._listDataTable = listDataTable;
Expand Down
15 changes: 4 additions & 11 deletions FoliCon/Modules/utils/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,24 +320,17 @@ public static void HandleUnauthorizedAccessException(UnauthorizedAccessException
/// <param name="fullFolderPath">Complete Folder Path</param>
/// <param name="folderName">Short Folder Name</param>
/// <param name="year">Media Year</param>
public static void AddToPickedListDataTable(DataTable dataTable, string poster, string title, string rating,
public static void AddToPickedListDataTable(List<PickedListItem> dataTable, string poster, string title, string rating,
string fullFolderPath, string folderName, string year = "")
{
Logger.Debug("Adding Data to PickedListDataTable");
if (rating == "0")
{
rating = "";
}

var nRow = dataTable.NewRow();
nRow["Poster"] = poster;
nRow["Title"] = title;
nRow["Year"] = year;
nRow["Rating"] = rating;
nRow["Folder"] = fullFolderPath;
nRow["FolderName"] = folderName;
dataTable.Rows.Add(nRow);
Logger.Trace("Data Added to PickedListDataTable: {@Row}",nRow);
PickedListItem pickedListItem = new(title, year, rating, fullFolderPath, folderName,poster);
dataTable.Add(pickedListItem);
Logger.Trace("Data Added to PickedListDataTable: {@Row}",pickedListItem);
}

public static ObservableCollection<ListItem> FetchAndAddDetailsToListView(ResultResponse result, string query,
Expand Down
11 changes: 6 additions & 5 deletions FoliCon/Modules/utils/IconUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FoliCon.Models.Constants;
using FoliCon.Models.Data;
using FoliCon.Models.Enums;
using FoliCon.Modules.Media;
using NLog;
Expand All @@ -13,7 +14,7 @@ public static class IconUtils
/// <summary>
/// Creates Icons from PNG
/// </summary>
public static int MakeIco(string iconMode, string selectedFolder, DataTable pickedListDataTable,
public static int MakeIco(string iconMode, string selectedFolder, List<PickedListItem> pickedListDataTable,
bool isRatingVisible = false, bool isMockupVisible = true)
{
Logger.Debug(
Expand All @@ -24,15 +25,15 @@ public static int MakeIco(string iconMode, string selectedFolder, DataTable pick
var ratingVisibility = isRatingVisible ? "visible" : "hidden";
var mockupVisibility = isMockupVisible ? "visible" : "hidden";

foreach (DataRow row in pickedListDataTable.Rows)
foreach (var item in pickedListDataTable)
{
var folderName = row["FolderName"].ToString();
var folderName = item.FolderName;
var targetFile = $@"{selectedFolder}\{folderName}\{folderName}.ico";
var pngFilePath = $@"{selectedFolder}\{folderName}\{folderName}.png";
if (File.Exists(pngFilePath) && !File.Exists(targetFile))
{
var rating = row["Rating"].ToString();
var mediaTitle = row["Title"].ToString();
var rating = item.Rating;
var mediaTitle = item.Title;

BuildFolderIco(iconMode, pngFilePath, rating, ratingVisibility,
mockupVisibility, mediaTitle);
Expand Down
47 changes: 11 additions & 36 deletions FoliCon/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class MainWindowViewModel : BindableBase, IFileDragDropTarget, IDisposabl
private string _devClientId;
private ListViewData _finalListViewData;
private List<ImageToDownload> _imgDownloadList;
private DataTable _pickedListDataTable;
private List<PickedListItem> _pickedListDataTable;
private bool IsObjectsInitialized { get; set; }

public bool IsPosterWindowShown
Expand Down Expand Up @@ -511,15 +511,9 @@ private async Task ProcessPosterModeAsync()
{
Logger.Debug("Auto picked:{IsAutoPicked}, dialog result : {DialogResult} for {ItemTitle}, " +
"adding to final list", isAutoPicked, dialogResult, itemTitle);
if (_pickedListDataTable is not null && _pickedListDataTable.Rows.Count != 0)
if (_pickedListDataTable is not null && _pickedListDataTable.Count != 0)
{
FinalListViewData.Data.Add(new ListItem
{
Title = _pickedListDataTable.Rows[^1]["Title"].ToString(),
Year = _pickedListDataTable.Rows[^1]["Year"].ToString(),
Rating = _pickedListDataTable.Rows[^1]["Rating"].ToString(),
Folder = _pickedListDataTable.Rows[^1]["Folder"].ToString()
});
FinalListViewData.Data.Add(_pickedListDataTable.Last());
}
// TODO: Set cursor back to arrow here
}
Expand All @@ -539,19 +533,14 @@ private void ProcessProfessionalMode()
StatusBarProperties.AppStatus = "Searching";
_dialogService.ShowProSearchResult(SelectedFolder, Fnames, _pickedListDataTable, _imgDownloadList,
_dArtObject, _ => { });
if (_pickedListDataTable.Rows.Count <= 0) return;
Logger.Debug("ProcessProfessionalMode: found {_pickedListDataTable.Rows.Count} results, adding to final list");
foreach (DataRow v in _pickedListDataTable.Rows)
if (_pickedListDataTable.Count <= 0)
{
FinalListViewData.Data.Add(new ListItem
{
Title = v["Title"].ToString(),
Year = v["Year"].ToString(),
Rating = v["Rating"].ToString(),
Folder = v["Folder"].ToString()
});
return;
}
StatusBarProperties.ProcessedFolder = _pickedListDataTable.Rows.Count;

Logger.Debug("ProcessProfessionalMode: found {_pickedListDataTable.Rows.Count} results, adding to final list");
FinalListViewData.Data.AddRange(_pickedListDataTable);
StatusBarProperties.ProcessedFolder = _pickedListDataTable.Count;
}

private void InitializeDelegates()
Expand Down Expand Up @@ -655,7 +644,7 @@ private void InitializeProperties()
StatusBarProperties.ProgressBarData.Max = 100;
StatusBarProperties.ProgressBarData.Value = 0;
_imgDownloadList = new List<ImageToDownload>();
_pickedListDataTable = new DataTable();
_pickedListDataTable = [];
if (NetworkUtils.IsNetworkAvailable())
{
InitializeClientObjects();
Expand All @@ -674,20 +663,7 @@ private void PrepareForSearch()
public void InitPickedListDataTable()
{
Logger.Debug("Initializing PickedListDataTable.");
_pickedListDataTable.Columns.Clear();
_pickedListDataTable.Rows.Clear();
var column1 = new DataColumn("Poster") { DataType = typeof(string) };
var column2 = new DataColumn("Title") { DataType = typeof(string) };
var column3 = new DataColumn("Year") { DataType = typeof(string) };
var column4 = new DataColumn("Rating") { DataType = typeof(string) };
var column5 = new DataColumn("Folder") { DataType = typeof(string) };
var column6 = new DataColumn("FolderName") { DataType = typeof(string) };
_pickedListDataTable.Columns.Add(column1);
_pickedListDataTable.Columns.Add(column2);
_pickedListDataTable.Columns.Add(column3);
_pickedListDataTable.Columns.Add(column4);
_pickedListDataTable.Columns.Add(column5);
_pickedListDataTable.Columns.Add(column6);
_pickedListDataTable.Clear();
Logger.Debug("PickedListDataTable Initialized.");
}

Expand Down Expand Up @@ -872,7 +848,6 @@ public void OnFileDrop(string[] filePaths, string senderName)
public void Dispose()
{
_tmdbClient?.Dispose();
_pickedListDataTable?.Dispose();
GC.SuppressFinalize(this);
}
}
4 changes: 2 additions & 2 deletions FoliCon/ViewModels/ProSearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ProSearchResultViewModel : BindableBase, IDialogAware
private string _busyContent = LangProvider.GetLang("Searching");
private bool _isBusy;
private DArt _dArtObject;
private DataTable _listDataTable;
private List<PickedListItem> _listDataTable;
private List<ImageToDownload> _imgDownloadList;
private int _index;
private int _totalPosters;
Expand Down Expand Up @@ -233,7 +233,7 @@ public virtual void OnDialogOpened(IDialogParameters parameters)
{
DArtObject = parameters.GetValue<DArt>("dartobject");
Fnames = parameters.GetValue<List<string>>("fnames");
_listDataTable = parameters.GetValue<DataTable>("pickedtable");
_listDataTable = parameters.GetValue<List<PickedListItem>>("pickedtable");
_imgDownloadList = parameters.GetValue<List<ImageToDownload>>("imglist");
_folderPath = parameters.GetValue<string>("folderpath");
PrepareForSearch();
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/Views/SearchResult.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Grid.ColumnSpan="1" Content="{extension:Lang Key={x:Static langs:LangKeys.ShowMore}}" HorizontalAlignment="Stretch" Margin="0,5,0,5" Command="{Binding MouseDoubleClickCommand}" IsEnabled="{Binding Path=SelectedItem.(data:ListItem.Poster), ElementName=ListViewResult, Converter={StaticResource Object2BooleanConverter}}" ToolTip="{extension:Lang Key={x:Static langs:LangKeys.SeeMorePosters}}">
<Button Grid.Column="0" Content="{extension:Lang Key={x:Static langs:LangKeys.ShowMore}}" HorizontalAlignment="Stretch" Margin="0,5,0,5" Command="{Binding MouseDoubleClickCommand}" IsEnabled="{Binding Path=SelectedItem.(data:ListItem.Poster), ElementName=ListViewResult, Converter={StaticResource Object2BooleanConverter}}" ToolTip="{extension:Lang Key={x:Static langs:LangKeys.SeeMorePosters}}">
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource ButtonInfo}">
<Style.Triggers>
Expand Down

0 comments on commit 78934aa

Please sign in to comment.