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

@ -58,7 +58,7 @@ namespace UWPHook
if (args?.Length > 1)
{
// When length is 1, the only argument is the path where the app is installed
_ = LauncherAsync(args); // Launches the requested game
_ = LauncherAsync(args); // Launches the requested game
}
else
@ -177,11 +177,11 @@ namespace UWPHook
await RestartSteam(restartSteam);
msg = "Your apps were successfuly exported!";
if(!restartSteam)
if (!restartSteam)
{
msg += " Please restart Steam in order to see them.";
}
else if(result)
else if (result)
{
msg += " Steam has been restarted.";
}
@ -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 (!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);
// 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;
return destFile;
}
private string PersistAppIcon(AppEntry app, string iconDownloadedPath)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string icons_path = path + @"\Briano\UWPHook\icons\";
if (!Directory.Exists(icons_path))
{
Directory.CreateDirectory(icons_path);
}
string destFile = String.Join(String.Empty, icons_path, app.Aumid + Path.GetFileName(iconDownloadedPath));
File.Copy(iconDownloadedPath, destFile, true);
string dest_file = String.Join(String.Empty, icons_path, app.Aumid + Path.GetFileName(icon_to_copy));
try
{
File.Copy(icon_to_copy, dest_file, true);
}
catch (System.IO.IOException)
{
// 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;
}
return destFile;
return dest_file;
}
/// <summary>

Loading…
Cancel
Save