Skip to content

Commit eb5e32e

Browse files
committed
refactor: Apply various code improvements and fixes
Refined method visibility, improved formatting, and fixed minor logical issues. Specifically, adjusted method access modifiers to `static`, used concise collection initializations, and corrected string formatting issues. Reorganized namespaces and fixed inconsistency in the handling of media types and file attributes.
1 parent 6ee179f commit eb5e32e

18 files changed

+78
-88
lines changed

FoliCon/App.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ protected override void RegisterTypes(IContainerRegistry containerRegistry)
4444
containerRegistry.RegisterDialog<Previewer, PreviewerViewModel>("Previewer");
4545
containerRegistry.RegisterDialogWindow<HandyWindow>();
4646
}
47-
48-
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
47+
48+
private static void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
4949
{
5050
SentrySdk.CaptureException(e.Exception);
5151

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
namespace FoliCon.Models.Constants;
22

3+
[Localizable(false)]
34
public static class PosterSize
45
{
5-
public static string W92 { get; } = "w92";
6-
public static string W154 { get; } = "w154";
7-
public static string W185 { get; } = "w185";
8-
public static string W342 { get; } = "w342";
9-
public static string W500 { get; } = "w500";
10-
public static string W780 { get; } = "w780";
11-
public static string Original { get; } = "original";
6+
public static string W92 => "w92";
7+
public static string W154 => "w154";
8+
public static string W185 => "w185";
9+
public static string W342 => "w342";
10+
public static string W500 => "w500";
11+
public static string W780 => "w780";
12+
public static string Original => "original";
1213
}

FoliCon/Models/Data/Dialog/PosterPickerDialogParams.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using FoliCon.Models.Data.Dialog;
2-
3-
namespace FoliCon.Models.Data;
1+
namespace FoliCon.Models.Data.Dialog;
42

53
public class PosterPickerDialogParams : DialogParamContainer
64
{

FoliCon/Models/Usings.cs

-2
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
global using System.Collections.ObjectModel;
2727
global using System.Collections.Specialized;
2828
global using System.ComponentModel;
29-
global using System.Data;
3029
global using System.Diagnostics;
3130
global using System.Drawing;
3231
global using System.Drawing.IconLib;
3332
global using System.Globalization;
3433
global using System.IO;
3534
global using System.Linq;
36-
global using System.Net;
3735
global using System.Net.Http;
3836
global using System.Net.NetworkInformation;
3937
global using System.Reflection;

FoliCon/Modules/DeviantArt/DArt.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public async Task<DArtDownloadResponse> Download(string deviationId)
118118
return dArtDownloadResponse;
119119
}
120120

121-
private async Task<DArtDownloadResponse> TryExtraction(string deviationId,
121+
private static async Task<DArtDownloadResponse> TryExtraction(string deviationId,
122122
DArtDownloadResponse dArtDownloadResponse, CancellationToken cancellationToken,
123123
IProgress<ProgressInfo> progressCallback)
124124
{
@@ -156,15 +156,15 @@ public async Task<DArtDownloadResponse> GetDArtDownloadResponseAsync(string devi
156156
return JsonConvert.DeserializeObject<DArtDownloadResponse>(jsonData);
157157
}
158158

159-
private async Task ProcessCompressedFiles(HttpResponseMessage downloadResponse, string targetDirectoryPath,
159+
private static async Task ProcessCompressedFiles(HttpResponseMessage downloadResponse, string targetDirectoryPath,
160160
CancellationToken cancellationToken,
161161
IProgress<ProgressInfo> progressCallback)
162162
{
163163
await using var stream = await downloadResponse.Content.ReadAsStreamAsync(cancellationToken);
164164
stream.ExtractPngAndIcoToDirectory(targetDirectoryPath, cancellationToken, progressCallback);
165165
}
166166

167-
private async Task FileStreamToDestination(HttpResponseMessage downloadResponse, string targetDirectoryPath,
167+
private static async Task FileStreamToDestination(HttpResponseMessage downloadResponse, string targetDirectoryPath,
168168
string filename)
169169
{
170170
await using var fileStream = await downloadResponse.Content.ReadAsStreamAsync();

FoliCon/Modules/Extension/StreamExtension.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ public static void ExtractPngAndIcoToDirectory(this Stream archiveStream, string
4747

4848
private static bool IsValidFile(IEntry entry)
4949
{
50-
return !entry.IsDirectory && !FileUtils.isExcludedFileIdentifier(entry.Key) && FileUtils.IsPngOrIco(entry.Key);
50+
return !entry.IsDirectory && !FileUtils.IsExcludedFileIdentifier(entry.Key) && FileUtils.IsPngOrIco(entry.Key);
5151
}
5252
}

FoliCon/Modules/IGDB/IgdbDataTransformer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private static ListItem MakeListItemFromGame(Game game)
3333
Poster = poster,
3434
Id = id.ToString(),
3535
Rating = placeholder,
36-
Folder = placeholder,
36+
Folder = placeholder
3737
};
3838
}
3939

@@ -90,7 +90,7 @@ private void HandleGamePosterPath(Game game, string fullFolderPath, string local
9090
var temporaryImage = new ImageToDownload
9191
{
9292
LocalPath = localPosterPath,
93-
RemotePath = new Uri(posterUrl),
93+
RemotePath = new Uri(posterUrl)
9494
};
9595
_imgDownloadList.Add(temporaryImage);
9696
}

FoliCon/Modules/TMDB/TMDBService.cs

+22-22
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public TmdbService(TMDbClient serviceClient)
2020
_ = _serviceClient.GetConfigAsync().Result;
2121
_mediaTypeHandlers = new Dictionary<string, Func<int, Task<object>>>
2222
{
23-
{ MediaTypes.Movie, async (id) => await _serviceClient.GetMovieAsync(id) },
24-
{ MediaTypes.Collection, async (id) => await _serviceClient.GetCollectionAsync(id) },
25-
{ MediaTypes.Tv, async (id) => await _serviceClient.GetTvShowAsync(id) }
23+
{ MediaTypes.Movie, async id => await _serviceClient.GetMovieAsync(id) },
24+
{ MediaTypes.Collection, async id => await _serviceClient.GetCollectionAsync(id) },
25+
{ MediaTypes.Tv, async id => await _serviceClient.GetTvShowAsync(id) }
2626
};
2727
}
2828

@@ -104,14 +104,14 @@ public async Task<ResultResponse> SearchAsync(string query, string searchMode)
104104
private async Task<(object Result, string MediaType)> SearchTvShowAsync(string query)
105105
{
106106
var r = await _serviceClient.SearchTvShowAsync(query);
107-
var mediaType = MediaTypes.Tv;
107+
const string mediaType = MediaTypes.Tv;
108108
return (r, mediaType);
109109
}
110110

111111
private async Task<(object Result, string MediaType)> SearchMultiAsync(string query)
112112
{
113113
var r = await _serviceClient.SearchMultiAsync(query);
114-
var mediaType = MediaTypes.Mtv;
114+
const string mediaType = MediaTypes.Mtv;
115115
return (r, mediaType);
116116
}
117117

@@ -122,24 +122,24 @@ public async Task<ResultResponse> SearchWithParamsAsync(ParsedTitle parsedTitle,
122122
var mediaType = "";
123123
object? searchResult = null;
124124

125-
if (searchMode == MediaTypes.Movie)
125+
switch (searchMode)
126126
{
127-
searchResult = parsedTitle.Title.ToLower(CultureInfo.InvariantCulture).Contains("collection")
128-
? await SearchCollection(parsedTitle)
129-
: await SearchMovie(parsedTitle);
130-
mediaType = parsedTitle.Title.ToLower(CultureInfo.InvariantCulture).Contains("collection")
131-
? MediaTypes.Collection
132-
: MediaTypes.Movie;
133-
}
134-
else if (searchMode == MediaTypes.Tv)
135-
{
136-
searchResult = await SearchTvShow(parsedTitle);
137-
mediaType = MediaTypes.Tv;
138-
}
139-
else if (searchMode == MediaTypes.Mtv)
140-
{
141-
searchResult = await SearchMulti(parsedTitle);
142-
mediaType = MediaTypes.Mtv;
127+
case MediaTypes.Movie:
128+
searchResult = parsedTitle.Title.ToLower(CultureInfo.InvariantCulture).Contains("collection")
129+
? await SearchCollection(parsedTitle)
130+
: await SearchMovie(parsedTitle);
131+
mediaType = parsedTitle.Title.ToLower(CultureInfo.InvariantCulture).Contains("collection")
132+
? MediaTypes.Collection
133+
: MediaTypes.Movie;
134+
break;
135+
case MediaTypes.Tv:
136+
searchResult = await SearchTvShow(parsedTitle);
137+
mediaType = MediaTypes.Tv;
138+
break;
139+
case MediaTypes.Mtv:
140+
searchResult = await SearchMulti(parsedTitle);
141+
mediaType = MediaTypes.Mtv;
142+
break;
143143
}
144144

145145
return new ResultResponse

FoliCon/Modules/UI/ClickBehavior.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public ClickBehavior()
1414
DependencyProperty.Register(nameof(ClickCommand), typeof(ICommand), typeof(ClickBehavior));
1515
public static readonly DependencyProperty CommandParameterProperty =
1616
DependencyProperty.Register(nameof(CommandParameter), typeof(object), typeof(ClickBehavior));
17-
public Object CommandParameter
17+
public object CommandParameter
1818
{
1919
get => GetValue(CommandParameterProperty);
2020
set => SetValue(CommandParameterProperty, value);

FoliCon/Modules/utils/FileUtils.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ private static bool EndsIn(string value, IEnumerable<string> fileExtensions)
4545
}
4646

4747
public static bool IsPngOrIco(string fileName) =>
48-
fileName != null && EndsIn(fileName, new[] { ".png", ".ico" });
48+
fileName != null && EndsIn(fileName, [".png", ".ico"]);
4949

50-
public static bool isExcludedFileIdentifier(string fileName) =>
50+
public static bool IsExcludedFileIdentifier(string fileName) =>
5151
fileName != null && ExcludedFileIdentifiers.Any(fileName.Contains);
5252

5353
/// <summary>
@@ -199,11 +199,9 @@ public static void HideFile(string icoFile)
199199
}
200200

201201
// Set file attribute to "System"
202-
if ((File.GetAttributes(icoFile) & FileAttributes.System) != FileAttributes.System)
203-
{
204-
Logger.Debug("Setting File Attribute to System");
205-
File.SetAttributes(icoFile, File.GetAttributes(icoFile) | FileAttributes.System);
206-
}
202+
if ((File.GetAttributes(icoFile) & FileAttributes.System) == FileAttributes.System) return;
203+
Logger.Debug("Setting File Attribute to System");
204+
File.SetAttributes(icoFile, File.GetAttributes(icoFile) | FileAttributes.System);
207205
}
208206

209207
public static void SaveMediaInfo(int id, string mediaType, string folderPath)

FoliCon/Modules/utils/LogUtils.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ internal static SentryTarget GetSentryTarget()
8585
AutoSessionTracking = true,
8686
User = new SentryNLogUser { Username = Environment.MachineName }
8787
},
88-
IncludeEventDataOnBreadcrumbs = true,
88+
IncludeEventDataOnBreadcrumbs = true
8989
};
9090
sentryTarget.Options.AddExceptionFilterForType<UnauthorizedAccessException>();
9191
sentryTarget.Tags.Add(new TargetPropertyWithContext("exception", "${exception:format=shorttype}"));

FoliCon/Modules/utils/ProcessUtils.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static void RefreshIconCache()
9898

9999
using (var process = new Process())
100100
{
101-
process.StartInfo = new ProcessStartInfo()
101+
process.StartInfo = new ProcessStartInfo
102102
{
103103
FileName = exePath,
104104
Arguments = "-ClearIconCache",

FoliCon/ViewModels/CustomIconControlViewModel.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public class CustomIconControlViewModel : BindableBase, IDialogAware, IFileDragD
2525
private bool _stopSearch;
2626
public string Title => LangProvider.GetLang("CustomIconSetter");
2727

28-
private ObservableCollection<string> _undoDirectories = new();
29-
private ObservableCollection<string> _backupDirectories = new();
30-
private ObservableCollection<string> _backupIcons = new();
28+
private ObservableCollection<string> _undoDirectories = [];
29+
private ObservableCollection<string> _backupDirectories = [];
30+
private ObservableCollection<string> _backupIcons = [];
3131
private string _busyContent = LangProvider.GetLang("CreatingIcons");
3232
private int _index;
3333
private int _totalIcons;
@@ -125,8 +125,8 @@ public string BusyContent
125125

126126
public CustomIconControlViewModel()
127127
{
128-
Directories = new ObservableCollection<string>();
129-
Icons = new ObservableCollection<string>();
128+
Directories = [];
129+
Icons = [];
130130
LoadDirectory = new DelegateCommand(LoadDirectoryMethod);
131131
StopSearchCommand = new DelegateCommand(() => StopSearch = true);
132132
LoadIcons = new DelegateCommand(LoadIconsMethod);

FoliCon/ViewModels/MainWindowViewModel.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ private void DeleteMediaInfo()
816816
private async Task InitializeProperties()
817817
{
818818
Logger.Debug("Initializing Properties for MainWindow.");
819-
Fnames = new List<string>();
819+
Fnames = [];
820820
BusyIndicatorProperties = new ProgressBarData
821821
{
822822
Max = 100,
@@ -832,13 +832,13 @@ private async Task InitializeProperties()
832832
};
833833
FinalListViewData = new ListViewData
834834
{
835-
Data = new ObservableCollection<ListItem>(),
835+
Data = [],
836836
SelectedItem = new ListItem(),
837837
SelectedCount = 0
838838
};
839839
StatusBarProperties.ProgressBarData.Max = 100;
840840
StatusBarProperties.ProgressBarData.Value = 0;
841-
_imgDownloadList = new List<ImageToDownload>();
841+
_imgDownloadList = [];
842842
_pickedListDataTable = [];
843843
if (NetworkUtils.IsNetworkAvailable())
844844
{

FoliCon/ViewModels/ManualExplorerViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private void CancelMethod()
5050
}
5151

5252

53-
private void OpenImageMethod(object parameter)
53+
private static void OpenImageMethod(object parameter)
5454
{
5555
Logger.Debug("Opening Image {Image}", parameter);
5656
var link = (string)parameter;

FoliCon/ViewModels/ProSearchResultViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public ProSearchResultViewModel(IDialogService dialogService)
9393
_dialogService = dialogService;
9494
}
9595

96-
private void OpenImageMethod(object parameter)
96+
private static void OpenImageMethod(object parameter)
9797
{
9898
Logger.Debug("Opening Image {Image}", parameter);
9999
var link = (string)parameter;

FoliCon/ViewModels/SearchResultViewModel.cs

+21-23
Original file line numberDiff line numberDiff line change
@@ -388,25 +388,23 @@ private async void PerformSelectionChanged()
388388

389389
var itemId = ResultListViewData.SelectedItem.Id;
390390

391-
if (SearchResult.MediaType == MediaTypes.Game)
391+
switch (SearchResult.MediaType)
392392
{
393-
await HandleMediaType(itemId, GetGameTrailer);
394-
}
395-
else if (SearchResult.MediaType == MediaTypes.Movie)
396-
{
397-
await HandleMediaType(itemId, GetMovieTrailer);
398-
}
399-
else if (SearchResult.MediaType == MediaTypes.Tv)
400-
{
401-
await HandleMediaType(itemId, GetTvTrailer);
402-
}
403-
else if (SearchResult.MediaType == MediaTypes.Mtv)
404-
{
405-
await HandleMtvMediaType(itemId);
406-
}
407-
else
408-
{
409-
Logger.Warn("Unknown media type {MediaType}", SearchResult.MediaType);
393+
case MediaTypes.Game:
394+
await HandleMediaType(itemId, GetGameTrailer);
395+
break;
396+
case MediaTypes.Movie:
397+
await HandleMediaType(itemId, GetMovieTrailer);
398+
break;
399+
case MediaTypes.Tv:
400+
await HandleMediaType(itemId, GetTvTrailer);
401+
break;
402+
case MediaTypes.Mtv:
403+
await HandleMtvMediaType(itemId);
404+
break;
405+
default:
406+
Logger.Warn("Unknown media type {MediaType}", SearchResult.MediaType);
407+
break;
410408
}
411409
}
412410

@@ -426,7 +424,7 @@ private async Task HandleMtvMediaType(string itemId)
426424
}
427425
}
428426

429-
private async Task HandleMediaType(string itemId, Func<string, Task> handleAction)
427+
private static async Task HandleMediaType(string itemId, Func<string, Task> handleAction)
430428
{
431429
await handleAction(itemId);
432430
}
@@ -456,7 +454,7 @@ private async Task GetMovieTrailer(string itemId)
456454

457455
if (result != null)
458456
{
459-
var trailer = ChooseTrailer(result.Results);
457+
var trailer = SearchResultViewModel.ChooseTrailer(result.Results);
460458
if (trailer != null)
461459
{
462460
SetTrailer(trailer.Key);
@@ -482,7 +480,7 @@ private async Task GetTvTrailer(string itemId)
482480
return;
483481
}
484482

485-
var i = ChooseTrailer(result.Results);
483+
var i = SearchResultViewModel.ChooseTrailer(result.Results);
486484

487485
if (i != null)
488486
{
@@ -494,9 +492,9 @@ private async Task GetTvTrailer(string itemId)
494492
}
495493
}
496494

497-
private dynamic? ChooseTrailer(IReadOnlyCollection<dynamic> results)
495+
private static dynamic? ChooseTrailer(IReadOnlyCollection<dynamic> results)
498496
{
499-
var trailerYouTube = results.FirstOrDefault(item => item?.Type == "Trailer" && item?.Site == "YouTube");
497+
var trailerYouTube = results.FirstOrDefault(item => item?.Type == "Trailer" && item.Site == "YouTube");
500498
return trailerYouTube != null ? trailerYouTube : results.FirstOrDefault();
501499
}
502500

FoliCon/Views/ManualExplorer.xaml

-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:prism="http://prismlibrary.com/"
55
xmlns:hc="https://handyorg.github.io/handycontrol"
6-
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
76
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8-
xmlns:ui="clr-namespace:FoliCon.Modules.UI"
97
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10-
xmlns:convertor="clr-namespace:FoliCon.Modules.Convertor"
118
mc:Ignorable="d"
129
xmlns:viewModels="clr-namespace:FoliCon.ViewModels"
1310
xmlns:langs="clr-namespace:FoliCon.Properties.Langs"

0 commit comments

Comments
 (0)