corrections in the snippet tool.

extending icon handling in the editor: for packaged apps look for the exe in the current path
adding shortcut icon creation.
This commit is contained in:
donlaci
2024-05-31 19:09:45 +02:00
parent 7e80c1bf73
commit cb2a4ec6e9
6 changed files with 233 additions and 64 deletions

View File

@@ -12,8 +12,11 @@ using System.IO;
using System.Linq;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using ManagedCommon;
using Windows.ApplicationModel.Core;
using Windows.Management.Deployment;
namespace ProjectsEditor.Models
{
@@ -78,7 +81,18 @@ namespace ProjectsEditor.Models
{
try
{
_icon = Icon.ExtractAssociatedIcon(AppPath);
if (!File.Exists(AppPath) && IsPackagedApp)
{
Task<AppListEntry> task = Task.Run<AppListEntry>(async () => await GetAppByPackageFamilyNameAsync());
AppListEntry packApp = task.Result;
string filename = Path.GetFileName(AppPath);
string newExeLocation = Path.Combine(packApp.AppInfo.Package.InstalledPath, filename);
_icon = Icon.ExtractAssociatedIcon(newExeLocation);
}
else
{
_icon = Icon.ExtractAssociatedIcon(AppPath);
}
}
catch (Exception e)
{
@@ -91,6 +105,31 @@ namespace ProjectsEditor.Models
}
}
public async Task<AppListEntry> GetAppByPackageFamilyNameAsync()
{
var pkgManager = new PackageManager();
var pkg = pkgManager.FindPackagesForUser(string.Empty, PackagedId).FirstOrDefault();
if (pkg == null)
{
return null;
}
var apps = await pkg.GetAppListEntriesAsync();
if (apps == null || apps.Count == 0)
{
return null;
}
AppListEntry firstApp = apps[0];
// RandomAccessStreamReference stream = firstApp.AppInfo.DisplayInfo.GetLogo(new Windows.Foundation.Size(64, 64));
// IRandomAccessStreamWithContentType content = await stream.OpenReadAsync();
// BitmapImage bitmapImage = new BitmapImage();
// bitmapImage.StreamSource = (Stream)content;
return firstApp;
}
private BitmapImage _iconBitmapImage;
public BitmapImage IconBitmapImage