Ejemplo n.º 1
0
        public static void CreateLink(string pathToApplication, string description, string linkname = "MyApplication.lnk", string arguments = "")
        {
            IShellLink shortcut = (IShellLink) new ShellLink();
            string     desktop  = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            shortcut.SetDescription(description);
            shortcut.SetPath(pathToApplication);
            shortcut.SetArguments(arguments);
            shortcut.SetShowCmd(7);//SW_SHOWMINNOACTIVE
            System.Runtime.InteropServices.ComTypes.IPersistFile f = (System.Runtime.InteropServices.ComTypes.IPersistFile)shortcut;
            f.Save(Path.Combine(desktop, $"{linkname}.lnk"), false);
        }
Ejemplo n.º 2
0
        private void appShortcutToDesktop(string linkName, string pathToExe)
        {
            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetDescription(linkName);
            link.SetPath(pathToExe);
            link.SetWorkingDirectory(Path.GetDirectoryName(pathToExe));

            // save it
            System.Runtime.InteropServices.ComTypes.IPersistFile file = (System.Runtime.InteropServices.ComTypes.IPersistFile)link;
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            file.Save(Path.Combine(desktopPath, linkName + ".lnk"), false);
        }
Ejemplo n.º 3
0
        private async void BtnCreate_Click(object sender, RoutedEventArgs e)
        {
            if (!File.Exists(ViewModel.Path))
            {
                MessageBox.Show("文件不存在。", Title, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            var fileName = FileExtension.TryValidateFileName(ViewModel.Name, out var trueName)
                ? trueName
                : Path.GetFileNameWithoutExtension(ViewModel.Path);
            var ext = Path.GetExtension(ViewModel.Path);

            if (ViewModel.UseShortcut)
            {
                IShellLink link = (IShellLink) new ShellLink();

                //link.SetDescription(fileName);
                link.SetPath(ViewModel.Path);
                System.Runtime.InteropServices.ComTypes.IPersistFile file =
                    (System.Runtime.InteropServices.ComTypes.IPersistFile)link;
                file.Save(Path.Combine(_baseConsole.RomDirectoryPath, fileName + ".lnk"), false);
            }
            else
            {
                File.Copy(ViewModel.Path, Path.Combine(_baseConsole.RomDirectoryPath, fileName + ext));
            }

            await _baseConsole.Refresh();

            var game = _baseConsole.Games.FirstOrDefault(k => k.NameWithoutExtension == fileName);

            if (File.Exists(ViewModel.IconPath))
            {
                game?.SetIcon(ViewModel.IconPath);
            }
            game?.RaisePropertyChanged(nameof(game.IconPath));
            _baseWindow.Close();
        }