Summary description for ShellLink.
Inheritance: IDisposable
        public void Expand(FileListViewModel _rootModel, ExModel dirModel)
        {
            if (_rootModel != null)
            {
                if (EmbeddedModel is DirectoryModel)
                //////{ }
                    _rootModel.CurrentDirectory = (EmbeddedModel as DirectoryModel).EmbeddedDirectoryEntry;
                else
                {
                    try
                    {
                        FileSystemInfoEx entry = EmbeddedModel.EmbeddedEntry;
                        if (PathEx.GetExtension(entry.Name).ToLower() == ".lnk")
                            using (ShellLink sl = new ShellLink(entry.FullName))
                            {
                                string linkPath = sl.Target;
                                if (DirectoryEx.Exists(linkPath) && sl.Arguments == "")
                                    _rootModel.CurrentDirectory = FileSystemInfoEx.FromString(linkPath) as DirectoryInfoEx;
                                else Run(linkPath, sl.Arguments);
                            }
                        else
                            Run(entry.FullName, "");
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message, "Expand Failed");
                    }
                }

            }

        }
Exemplo n.º 2
0
        private void btnSendTo_Click(object sender, EventArgs e)
        {
            string sendToPath = Environment.GetFolderPath(Environment.SpecialFolder.SendTo);
            string linkPath = Path.Combine(sendToPath, Application.ProductName + ".lnk");

            using (ShellLink shortcut = new ShellLink())
            {
                shortcut.Target = Application.ExecutablePath;
                shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
                shortcut.Description = Application.ProductName;
                shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
                shortcut.Save(linkPath);
            }
            SendToLinkCheck();
        }
 /// <summary>
 /// Registers the specified assembly to be launched at startup.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="commandLine">The command line.</param>
 public void RegisterStartup(Assembly assembly, string commandLine = null)
 {
     using (var shortcut = new ShellLink())
     {
         var location = assembly.Location;
         shortcut.Target = location;
         shortcut.WorkingDirectory = Path.GetDirectoryName(location);
         shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
         shortcut.IconPath = location;
         shortcut.IconIndex = 0;
         if (commandLine != null)
             shortcut.Arguments = commandLine;
         shortcut.Save(GetShortcutPath(assembly));
     }
 }
Exemplo n.º 4
0
        private void UpdateUserShortcuts()
        {
            try
            {

                UpdateStatus("Updating Links...");
                var newWorkingDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "OCTGN",
                                           "OCTGN");
                var newTarget = Path.Combine(newWorkingDirectory, "octgn.exe");

                var fileList = new List<string>();

                var sPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
                if(Directory.Exists(sPath))
                    fileList.AddRange(Directory.GetFiles(sPath, "*.lnk", SearchOption.AllDirectories));

                sPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                if(Directory.Exists(sPath))
                    fileList.AddRange(Directory.GetFiles(sPath, "*.lnk", SearchOption.AllDirectories));

                //I guess doing a recursive search covers all pinned shortcuts in the taskbar and start menu as well in 7 and above
                sPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"Microsoft","Internet Explorer","Quick Launch");
                if(Directory.Exists(sPath))
                    fileList.AddRange(Directory.GetFiles(sPath, "*.lnk", SearchOption.AllDirectories));

                //Look through files for an octgn link
                foreach( var fs in fileList)
                {
                    try
                    {
                        using(var s = new ShellLink(fs))
                        {
                            var finfo = new FileInfo(s.Target);
                            if (finfo.Name.ToLowerInvariant() != "octgn.exe")
                                continue;
                            if (s.Target.ToLowerInvariant() == newTarget.ToLowerInvariant() &&
                                s.WorkingDirectory.ToLowerInvariant() == newWorkingDirectory.ToLowerInvariant()) continue;
                            s.Target = newTarget;
                            s.WorkingDirectory = newWorkingDirectory;
                            s.Save();
                        }
                    }
                    catch (Exception e)
                    {
            #if(DEBUG)
                        UpdateStatus(String.Format("[UpdateLink Failure] {0}",e.Message));
            #endif
                    }
                }
            }
            catch (Exception e )
            {
                new ErrorWindow(e).Show();
            }
        }
Exemplo n.º 5
0
        public void MakeDesktopShortcut()
        {
            using (ShellLink shortcut = new ShellLink())
            {
                var fi = new FileInfo(Assembly.GetExecutingAssembly().Location);
                string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

                shortcut.Target = fi.FullName;
                shortcut.Arguments = "-run";
                shortcut.WorkingDirectory = RootPath;
                if (this.LatestManifest != null)
                    shortcut.Description = this.LatestManifest.title;
                else
                    shortcut.Description = fi.Name + " - run";
                shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;

                shortcut.IconPath = AppPath + "\\favicon.ico";

                var fname = new string(shortcut.Description.Where(ch => !Path.GetInvalidFileNameChars().Contains(ch)).ToArray());
                shortcut.Save(desktopPath + "/" + fname + ".lnk");
            }
        }
        /// <summary>
        /// Return the Bitmap that represent the specified key and size.
        /// </summary>
        protected  Bitmap KeyToBitmap(string key, IconSize size)
        {
            try
            {
                bool isDiskFolder = key.EndsWith(":\\");
                bool isTemp = key.Equals(tempPath);

                string ext = PathEx.GetExtension(key).ToLower();

                if (!ext.StartsWith("."))
                {
                    if (specialExtFilter.Split(',').Contains(key))
                    {
                        switch (ext)
                        {
                            case ".exe":
                                ShellDll.PIDL pidlLookup = FileSystemInfoEx.FromString(key).PIDL;
                                try
                                {
                                    return GetFileIcon(pidlLookup.Ptr, size);
                                }
                                finally { if (pidlLookup != null) pidlLookup.Free(); }

                            case ".lnk":
                                using (ShellLink sl = new ShellLink(key))
                                    switch (size)
                                    {
                                        case IconSize.small:
                                            return sl.SmallIcon.ToBitmap();
                                        default: return sl.LargeIcon.ToBitmap();
                                    }
                        }
                    }
                }



                if (fileBasedFSFilter.Split(',').Contains(key))
                    return GetFileBasedFSBitmap(key, size);
                else
                    if (key == "" || key.StartsWith(".")) //Extension 
                    {
                        return GetFileIcon(key, size);
                    }
                    else
                        if (IsSpecialFolder(key))
                        {
                            ShellDll.PIDL pidlLookup = FileSystemInfoEx.FromString(key).PIDL;
                            try
                            {
                                Bitmap bm = GetFileIcon(pidlLookup.Ptr, size);
                                //BitmapImage bm2 =Imaging.CreateBitmapSourceFromHBitmap(
                                return bm;
                            }
                            finally { if (pidlLookup != null) pidlLookup.Free(); }
                        }
                        else
                            switch (size)
                            {
                                case IconSize.thumbnail:
                                    return loadThumbnail(key, isDiskFolder || isTemp);
                                //case IconSize.jumbo:
                                //case IconSize.extraLarge:
                                //    return loadJumbo(key, isDiskFolder || isTemp, size);
                                //case IconSize.large :
                                //    _imgList.ImageListSize = SysImageListSize.largeIcons;
                                //    return _imgList.Icon(_imgList.IconIndex(key, isDiskFolder)).ToBitmap();
                                //case IconSize.small :
                                //    _imgList.ImageListSize = SysImageListSize.smallIcons;
                                //    return _imgList.Icon(_imgList.IconIndex(key, isDiskFolder)).ToBitmap();
                                default:
                                    try
                                    {
                                        return GetFileIcon(key, size);
                                    }
                                    catch { return KeyToBitmap(UCUtils.GetProgramPath(), size); }
                            }
            }
            catch { return new Bitmap(1, 1); }
            ////bool isDiskFolder = key.EndsWith(":\\");

            ////string ext = PathEx.GetExtension(key);
            ////if ((ext != "" && ext != key && imageFilter.IndexOf(ext) != -1))
            ////{
            ////    return GetFileIcon(FileSystemInfoEx.FromString(key).PIDL.Ptr, size);
            ////}
            ////else

            ////    if (key == "" || key.StartsWith(".")) //Extension 
            ////    {
            ////        return GetFileIcon(key, size);
            ////    }
            ////    else
            ////        switch (size)
            ////        {
            ////            case IconSize.thumbnail:
            ////            case IconSize.jumbo:
            ////                return loadJumbo(key, isDiskFolder);
            ////            case IconSize.extraLarge:
            ////                _imgList.ImageListSize = SysImageListSize.extraLargeIcons;
            ////                return _imgList.Icon(_imgList.IconIndex(key, isDiskFolder)).ToBitmap();
            ////            //case IconSize.large :
            ////            //    _imgList.ImageListSize = SysImageListSize.largeIcons;
            ////            //    return _imgList.Icon(_imgList.IconIndex(key, isDiskFolder)).ToBitmap();
            ////            //case IconSize.small :
            ////            //    _imgList.ImageListSize = SysImageListSize.smallIcons;
            ////            //    return _imgList.Icon(_imgList.IconIndex(key, isDiskFolder)).ToBitmap();
            ////            default:
            ////                try
            ////                {
            ////                    return GetFileIcon(key, size);
            ////                }
            ////                catch { return KeyToBitmap(UCUtils.GetProgramPath(), size); }
            ////        }
        }
Exemplo n.º 7
0
 private void mnu_Click(object sender, System.EventArgs e)
 {
     if ((sender == mnuNew) || (sender == mnuClose))
     {
         link = new ShellLink();
         showDetails();
     }
     else if (sender == mnuOpen)
     {
         openShortcut();
     }
     else if (sender == mnuSave)
     {
         if (link.ShortCutFile.Length == 0)
         {
             saveShortcutAs();
         }
         else
         {
             link.Save();
         }
     }
     else if (sender == mnuSaveAs)
     {
         saveShortcutAs();
     }
     else if (sender == mnuExit)
     {
         this.Close();
     }
     else if (sender == mnuAbout)
     {
         frmAbout a = new frmAbout();
         a.ShowDialog(this);
         a.Dispose();
     }
 }
        void CreateShortcutFor(string fileName, string description)
        {
            using (ShellLink shortcut = new ShellLink())
            {
                // The file that the .lnk file links to
                string target = ComponentStorage.GetValue<string>(FrbdkSetupComponent.Path) + fileName;
                shortcut.Target = target;
                shortcut.WorkingDirectory = Path.GetDirectoryName(target);
                shortcut.Description = description;
                shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;

                // Where to save the .lnk file
                shortcut.Save(StartMenuFolder + FileManager.RemovePath(FileManager.RemoveExtension(fileName)) + ".lnk");
            }
        }
Exemplo n.º 9
0
        private void finalize()
        {
            log("Clearing temporary directory...");
            Directory.Delete(tempDir, true);

            log("Adding autostart reg entry...");
            RegistryKey regkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
            if (regkey != null)
            {
                regkey.SetValue("Devel VM", mainexe);
                regkey.Close();
            }

            string smDir = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
            if (Directory.Exists(Path.Combine(smDir, "Devel VM")))
            {
                log("Clearing [" + Path.Combine(smDir, "Devel VM") + "]...");
                Directory.Delete(Path.Combine(smDir, "Devel VM"), true);
            }
            smDir = Path.Combine(smDir, "Devel VM");
            log("Creating [" + Path.Combine(smDir, "Devel VM") + "]...");
            Directory.CreateDirectory(smDir);

            log("Create StartMenu shortcut...");
            try
            {
                ShellLink link = new ShellLink();
                link.Target = mainexe;
                link.WorkingDirectory = Path.GetDirectoryName(mainexe);
                link.IconPath = mainexe;
                link.IconIndex = 0;
                link.Description = "Devel VM Manager";
                link.Save(Path.Combine(smDir, "Devel VM.lnk"));
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not create DeskTop Shortcut...\r\n" +
                                "App_Path = " + mainexe + "\r\n" +
                                "Exception: " + ex.Message.ToString(),
                                "ShortCut Creation Error:");
                Program.Exterminate();
            }

            pb.Value = 100;

            if (rebootRequired)
            {
                log("Finished! Reboot required...");
                MessageBox.Show("Uruchom ponownie komputer aby korzystać z Devela! W razie problemów z uruchomieniem maszyny po restarcie, skontaktuj się z administratorami.", "Devel VM Installer", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                log("Finished! Starting app...");
                Program.execute(mainexe, "/r", true, true);
            }
        }
Exemplo n.º 10
0
        public static void UpdateMenu(ContextMenuStrip menu)
        {
            menu.Items.Clear();

            foreach (var plan in PowerPlanManager.FindAll())
            {
                var item = new ToolStripMenuItem
                    {
                        Text = plan.Name,
                        Tag = plan.Guid,
                        Checked = (plan.Guid == PowerPlanManager.Active.Guid)
                    };

                item.Click += delegate(object sender, EventArgs e)
                    {
                        PowerPlanManager.Active = new PowerPlan
                            {
                                Name = null,
                                Guid = (Guid) ((ToolStripMenuItem) sender).Tag
                            };
                    };

                menu.Items.Add(item);
            }

            menu.Items.Add(new ToolStripSeparator());

            // Charge indicator
            var charge = new ToolStripMenuItem {Text = ChargeString(), Enabled = false};

            menu.Items.Add(charge);

            // Version info
            var version = new ToolStripMenuItem {Text = String.Format(Strings.VersionString, Version), Enabled = false};

            menu.Items.Add(version);

            menu.Items.Add(new ToolStripSeparator());

            // Control panel shortcut
            var cpanel = new ToolStripMenuItem {Text = Strings.MoreSettings};
            cpanel.Click += (sender, e) => Process.Start(ControlExe, "/name Microsoft.PowerOptions");

            menu.Items.Add(cpanel);

            // Autostart
            var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup),
                                            "PowerPlanSwitcher.lnk");

            var autostart = new ToolStripMenuItem
                {
                    Text = Strings.Autostart,
                    Checked = File.Exists(shortcutPath),
                    CheckOnClick = true
                };

            autostart.Click += (sender, args) =>
                {
                    if (((ToolStripMenuItem) sender).Checked)
                    {
                        File.Delete(shortcutPath);
                        var shortcut = new ShellLink
                            {
                                Target = Application.ExecutablePath,
                                WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath),
                                Description = "Power Plan Switcher",
                                DisplayMode = ShellLink.LinkDisplayMode.edmNormal
                            };
                        shortcut.Save(shortcutPath);
                    }
                    else
                    {
                        File.Delete(shortcutPath);
                    }
                };

            menu.Items.Add(autostart);

            // Exit
            var exit = new ToolStripMenuItem {Text = Strings.Exit};
            exit.Click += delegate
                {
                    _trayIcon.Visible = false;
                    Application.Exit();
                };

            menu.Items.Add(exit);
        }
Exemplo n.º 11
0
 private void CreateStartMenuIcon(string path)
 {
     var startPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs");
     using (ShellLink shortcut = new ShellLink())
     {
         shortcut.Target = Path.Combine(path, "MediaCrush.exe");
         shortcut.Description = "MediaCrush";
         shortcut.WorkingDirectory = path;
         shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
         shortcut.Save(Path.Combine(startPath, "MediaCrush.lnk"));
     }
 }