private void ImportProject_Click(object sender, RoutedEventArgs e) { OpenFileDialog tmpDialog = new OpenFileDialog(); tmpDialog.Multiselect = false; tmpDialog.Filter = "Shortcuts|*.lnk"; DialogResult tmpDialogResult = tmpDialog.ShowDialog(); if (tmpDialogResult == System.Windows.Forms.DialogResult.OK) { string tmpLink = tmpDialog.FileName; try { ConsoleProjectViewModel tmpProject; using (WindowsShortcut tmpShellLink = new WindowsShortcut(tmpLink)) { tmpProject = new ConsoleProjectViewModel(); tmpProject.Arguments = tmpShellLink.Arguments; tmpProject.Executable = tmpShellLink.Target; tmpProject.Name = System.IO.Path.GetFileNameWithoutExtension(tmpShellLink.ShortCutFile); tmpProject.WorkingDir = tmpShellLink.WorkingDirectory; } this.CreateNewProject(tmpProject); } catch (Exception ex) { SimpleFileLogger.Instance.LogError("Unable to import the project", ex); System.Windows.MessageBox.Show("Unable to import the project. You can find more details about this in the application log."); } } }
private void Load() { // TODO: Remove shortcut if it does not exist! if (this.ShortcutPath == null || !File.Exists(this.ShortcutPath)) { this.Icon = null; this.Action = null; this.SearchableName = string.Empty; return; } var shellFile = ShellFile.FromFilePath(this.ShortcutPath); this.RealPath = shellFile.Properties.System.Link.TargetParsingPath.Value; var icon = WindowsShortcut.GetIconForFile(this.RealPath, ShellIconSize.LargeIcon); if (icon == null) { icon = WindowsShortcut.GetIconForFile(this.ShortcutPath, ShellIconSize.LargeIcon); // try getting the icon from shortcut if failed getting from target } if (icon != null) { this.Icon = icon.ToImageSource(); } this.SearchableName = Path.GetFileNameWithoutExtension(this.ShortcutPath); this.Action = s => Process.Start(this.ShortcutPath); }
public static void Execute() { using var shortcut = new WindowsShortcut { Path = Program.ExecutablePath, Description = "Startup link for game tracker" }; shortcut.Save(GameTrackerStartupLinkPath); SystemTrayForm.ShowBalloonInfo($"Startup link was added: {GameTrackerStartupLinkPath}"); }
public void ShortcutTest() { string linkFileFullName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "ShortcutTest.lnk"); File.Delete(linkFileFullName); Assert.IsTrue(string.IsNullOrEmpty(WindowsShortcut.GetTargetPath(linkFileFullName))); WindowsShortcut.CreateShortcut(linkFileFullName, VirtualRoot.AppFileFullName, "this is a test"); Assert.AreEqual(VirtualRoot.AppFileFullName, WindowsShortcut.GetTargetPath(linkFileFullName)); string testFileFullName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "notepad.exe"); WindowsShortcut.CreateShortcut(linkFileFullName, testFileFullName, "this is a test"); Assert.AreEqual(testFileFullName, WindowsShortcut.GetTargetPath(linkFileFullName), ignoreCase: true); File.Delete(linkFileFullName); }