Пример #1
0
        public override bool Run()
        {
            if (!CanRun)
            {
                return(true);
            }
            this.CommandStatus = CommandStatus.Running;
            Watch?.SetStep("创建快捷方式");
            if (!Directory.Exists(iconDir))
            {
                Directory.CreateDirectory(iconDir);
                this.createIconDir = true;
            }

            foreach (var shortcut in shortCutInfos)
            {
                var name = shortcut.Name;
                if (!name.EndsWith(".url", StringComparison.OrdinalIgnoreCase) && !name.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase))
                {
                    name += ".lnk";
                }
                var targetPath = InstallContext.ConvertPath(shortcut.TargetDir);
                if (Directory.Exists(targetPath))
                {
                    var path = Path.Combine(targetPath, name);
                    FileHelper.RemoveReadonly(path);
                    if (name.EndsWith(".url", StringComparison.OrdinalIgnoreCase))
                    {
                        ShortcutHelper.CreateWebShortcutFile(path, shortcut.TargetDir);
                    }
                    else
                    {
                        var target = InstallContext.ConvertPath(shortcut.Target);
                        ShortcutHelper.CreateShortcutFile(path, target, shortcut.Args);
                    }

                    Watch?.Info("-->" + path);
                    Watch?.AddValue(1);
                    InstallContext.UninstallData.Shortcuts.Add(path);
                }
            }

            this.CommandStatus = CommandStatus.Complete;
            return(true);
        }
Пример #2
0
        public void CreateShortcutFile()
        {
            var dir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/test.lnk";

            ShortcutHelper.CreateShortcutFile(dir, "C:/windows/notepad.exe");
        }