From ff43c77b2e8a8c7cf46ae4807207ce1348edb1ca Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Thu, 27 May 2021 11:33:45 +0200 Subject: [PATCH] Using WshShell instead of my Shortcut interface, added Shortcut to Start Menu --- .../EZPPClient Installer.csproj | 17 +++++-- EZPPClient Installer/MainWindow.xaml.cs | 46 +++++++++++++------ EZPPClient Installer/Objects/Shortcut.cs | 39 ---------------- 3 files changed, 46 insertions(+), 56 deletions(-) delete mode 100644 EZPPClient Installer/Objects/Shortcut.cs diff --git a/EZPPClient Installer/EZPPClient Installer.csproj b/EZPPClient Installer/EZPPClient Installer.csproj index 0042c6f..af4d409 100644 --- a/EZPPClient Installer/EZPPClient Installer.csproj +++ b/EZPPClient Installer/EZPPClient Installer.csproj @@ -96,7 +96,6 @@ - @@ -138,8 +137,8 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - - 4.1.3.201115164 + + 4.137.4070.201115155 0.9.4 @@ -151,6 +150,16 @@ - + + + {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} + 1 + 0 + 0 + tlbimp + False + True + + \ No newline at end of file diff --git a/EZPPClient Installer/MainWindow.xaml.cs b/EZPPClient Installer/MainWindow.xaml.cs index 15fdec6..9eee763 100644 --- a/EZPPClient Installer/MainWindow.xaml.cs +++ b/EZPPClient Installer/MainWindow.xaml.cs @@ -13,12 +13,13 @@ using ModernWpf.Controls; using System.Windows.Forms; using System.Media; using System.Runtime.InteropServices.ComTypes; -using Shortcut; using Path = System.Windows.Shapes.Path; +using File = System.IO.File; using EZPPClient_Installer.Utils; using Microsoft.Win32; using System.Windows.Controls; using System.Threading; +using IWshRuntimeLibrary; #if DEBUG using MessageBox = System.Windows.MessageBox; @@ -419,18 +420,30 @@ namespace EZPPClient_Installer if (type.Equals("Install")) { - IShellLink link = (IShellLink)new ShellLink(); - - // setup shortcut information - link.SetDescription("Starts the EZPPClient"); - link.SetPath(EZPPFolder + @"\EZPPClient.exe"); - - // save it - IPersistFile file = (IPersistFile)link; string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); - string LinkFile = System.IO.Path.Combine(desktopPath, "Start EZPPClient.lnk"); - Console.Out.WriteLine("Saving Shortcut to " + LinkFile); - file.Save(LinkFile, false); + string desktopLinkFile = System.IO.Path.Combine(desktopPath, "Start EZPPClient.lnk"); + + string startMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); + string startMenuPathPrograms = System.IO.Path.Combine(startMenuPath, "Programs"); + string startMenuLinkFile = System.IO.Path.Combine(startMenuPathPrograms, "Start EZPPClient.lnk"); + + if (!File.Exists(desktopLinkFile)) + { + WshShell shell = new WshShell(); + IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(desktopLinkFile); + shortcut.Description = $"Starts the EZPPClient"; + shortcut.TargetPath = System.IO.Path.Combine(EZPPFolder, "EZPPClient.exe"); + shortcut.Save(); + } + + if (!File.Exists(startMenuLinkFile)) + { + WshShell shell = new WshShell(); + IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(startMenuLinkFile); + shortcut.Description = $"Starts the EZPPClient"; + shortcut.TargetPath = System.IO.Path.Combine(EZPPFolder, "EZPPClient.exe"); + shortcut.Save(); + } } InstallButton.Visibility = prevInstallBtnVis; @@ -586,12 +599,19 @@ namespace EZPPClient_Installer string osuEZPPPath = folderTextbox.Text + @"\EZPPClient"; if (Directory.Exists(osuEZPPPath)) Directory.Delete(osuEZPPPath, true); + string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); string linkFile = System.IO.Path.Combine(desktopPath, "Start EZPPClient.lnk"); if (File.Exists(linkFile)) File.Delete(linkFile); - + + string startMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); + string startMenuPathPrograms = System.IO.Path.Combine(startMenuPath, "Programs"); + string startMenuLinkFile = System.IO.Path.Combine(startMenuPathPrograms, "Start EZPPClient.lnk"); + if (File.Exists(startMenuLinkFile)) + File.Delete(startMenuLinkFile); + _ = new ContentDialog() { Title = "Success!", diff --git a/EZPPClient Installer/Objects/Shortcut.cs b/EZPPClient Installer/Objects/Shortcut.cs deleted file mode 100644 index 5f4b7a0..0000000 --- a/EZPPClient Installer/Objects/Shortcut.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.IO; -using System.Runtime.InteropServices; -using System.Runtime.InteropServices.ComTypes; -using System.Text; - -namespace Shortcut -{ - [ComImport] - [Guid("00021401-0000-0000-C000-000000000046")] - internal class ShellLink - { - } - - [ComImport] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - [Guid("000214F9-0000-0000-C000-000000000046")] - internal interface IShellLink - { - void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, out IntPtr pfd, int fFlags); - void GetIDList(out IntPtr ppidl); - void SetIDList(IntPtr pidl); - void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName); - void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName); - void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath); - void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir); - void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath); - void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs); - void GetHotkey(out short pwHotkey); - void SetHotkey(short wHotkey); - void GetShowCmd(out int piShowCmd); - void SetShowCmd(int iShowCmd); - void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon); - void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon); - void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved); - void Resolve(IntPtr hwnd, int fFlags); - void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile); - } -} \ No newline at end of file