diff --git a/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj b/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj
index b0d6f57962..c780c67f69 100644
--- a/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj
+++ b/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj
@@ -61,6 +61,15 @@
false
true
+
+ tlbimp
+ 0
+ 1
+ 50a7e9b0-70ef-11d1-b75a-00a0c90564fe
+ 0
+ false
+ true
+
diff --git a/src/modules/Projects/ProjectsEditor/Utils/ProjectIcon.cs b/src/modules/Projects/ProjectsEditor/Utils/ProjectIcon.cs
index ca752d3075..90ef07bad7 100644
--- a/src/modules/Projects/ProjectsEditor/Utils/ProjectIcon.cs
+++ b/src/modules/Projects/ProjectsEditor/Utils/ProjectIcon.cs
@@ -84,7 +84,12 @@ namespace ProjectsEditor.Utils
public static void SaveIcon(Bitmap icon, string path)
{
- FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate);
+ if (Path.Exists(path))
+ {
+ File.Delete(path);
+ }
+
+ FileStream fileStream = new FileStream(path, FileMode.CreateNew);
using (var memoryStream = new MemoryStream())
{
icon.Save(memoryStream, ImageFormat.Png);
diff --git a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs
index 49d832b5b8..9a9ac441af 100644
--- a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs
+++ b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs
@@ -159,20 +159,36 @@ namespace ProjectsEditor.ViewModels
private void CreateShortcut(Project project)
{
string basePath = AppDomain.CurrentDomain.BaseDirectory;
- string shortcutAddress = FolderUtils.Desktop() + $"\\{project.Name}.lnk";
- string shortcutIconFilename = FolderUtils.Temp() + $"\\{project.Name}.ico";
+ string shortcutAddress = Path.Combine(FolderUtils.Desktop(), project.Name + ".lnk");
+ string shortcutIconFilename = Path.Combine(FolderUtils.Temp(), project.Id + ".ico");
Bitmap icon = ProjectIcon.DrawIcon(ProjectIcon.IconTextFromProjectName(project.Name));
ProjectIcon.SaveIcon(icon, shortcutIconFilename);
- IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
- IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutAddress);
- shortcut.Description = $"Project Launcher {project.Id}";
- shortcut.TargetPath = Path.Combine(basePath, "PowerToys.ProjectsLauncher.exe");
- shortcut.Arguments = project.Id;
- shortcut.WorkingDirectory = basePath;
- shortcut.IconLocation = shortcutIconFilename;
- shortcut.Save();
+ try
+ {
+ // Workaround to be able to create a shortcut with unicode filename
+ File.WriteAllBytes(shortcutAddress, Array.Empty());
+
+ // Create a ShellLinkObject that references the .lnk file
+ Shell32.Shell shl = new Shell32.Shell();
+ Shell32.Folder dir = shl.NameSpace(FolderUtils.Desktop());
+ Shell32.FolderItem itm = dir.Items().Item($"{project.Name}.lnk");
+ Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink;
+
+ // Set the .lnk file properties
+ lnk.Description = $"Project Launcher {project.Id}";
+ lnk.Path = Path.Combine(basePath, "PowerToys.ProjectsLauncher.exe");
+ lnk.Arguments = project.Id.ToString();
+ lnk.WorkingDirectory = basePath;
+ lnk.SetIconLocation(shortcutIconFilename, 0);
+
+ lnk.Save(shortcutAddress);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError($"Shortcut creation error: {ex.Message}");
+ }
}
public void SaveProjectName(Project project)