Refactor PersistAppIcon to use optional parameter

DRY both PersistAppIcon functions, also handle exceptions if trying to copy an icon for an app with encrypted icon when the SteamGridDB integration is disabled, defaulting to the app.Icon itself
pull/100/head
Brian Lima 2 years ago
parent f1dac8e92e
commit 903619ba0b

@ -435,7 +435,8 @@ namespace UWPHook
}
});
}
else {
else
{
icon = PersistAppIcon(app);
}
@ -525,38 +526,38 @@ namespace UWPHook
/// Copies an apps icon to a intermediate location
/// Due to some apps changing the icon location when they update, which causes icons to be "lost"
/// </summary>
/// <param name="app">App to copy the icon from</param>
/// <returns></returns>
private string PersistAppIcon(AppEntry app)
/// <param name="app">App to copy the icon to</param>
/// <param name="forcedIcon">Overwrites the app.icon to be copied</param>
/// <returns>string, the path to the usable and persisted icon</returns>
private string PersistAppIcon(AppEntry app, string forcedIcon = "")
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string icons_path = path + @"\Briano\UWPHook\icons\";
// If we do not have an specific icon to copy, copy app.icon, if we do, copy the specified icon
string icon_to_copy = String.IsNullOrEmpty(forcedIcon) ? app.Icon : forcedIcon;
if (!Directory.Exists(icons_path))
{
Directory.CreateDirectory(icons_path);
}
string destFile = String.Join(String.Empty, icons_path, app.Aumid + Path.GetFileName(app.Icon));
File.Copy(app.Icon, destFile, true);
return destFile;
}
private string PersistAppIcon(AppEntry app, string iconDownloadedPath)
string dest_file = String.Join(String.Empty, icons_path, app.Aumid + Path.GetFileName(icon_to_copy));
try
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string icons_path = path + @"\Briano\UWPHook\icons\";
if (!Directory.Exists(icons_path))
File.Copy(icon_to_copy, dest_file, true);
}
catch (System.IO.IOException)
{
Directory.CreateDirectory(icons_path);
// This file is most likely encrypted or does not exist, so we return the app.Icon itself
// but this app is now prone to #90 unfortunately, if we return String.empty, Steam will default
// to UWPHook's icon
Log.Warning("File could not be copied: " + icon_to_copy);
dest_file = app.Icon;
}
string destFile = String.Join(String.Empty, icons_path, app.Aumid + Path.GetFileName(iconDownloadedPath));
File.Copy(iconDownloadedPath, destFile, true);
return destFile;
return dest_file;
}
/// <summary>

Loading…
Cancel
Save