Exemplo n.º 1
0
            private void AddNewItem()
            {
                using (var shellKey = RegistryEx.GetRegistryKey(ShellPath, true, true))
                {
                    string keyName = ItemText.Replace("\\", "").Trim();
                    NewItemRegPath = ObjectPath.GetNewPathWithIndex($@"{ShellPath}\{keyName}", ObjectPath.PathType.Registry);
                    keyName        = RegistryEx.GetKeyName(NewItemRegPath);

                    using (var key = shellKey.CreateSubKey(keyName, true))
                    {
                        key.SetValue("MUIVerb", ItemText);
                        if (rdoMulti.Checked)
                        {
                            key.SetValue("SubCommands", "");
                        }
                        else
                        {
                            if (!string.IsNullOrWhiteSpace(ItemCommand))
                            {
                                key.CreateSubKey("command", true).SetValue("", ItemCommand);
                            }
                        }
                    }
                }
            }
                private void AddFromParentMenu()
                {
                    if (!SubShellTypeItem.CanAddMore(this))
                    {
                        return;
                    }
                    using (ShellStoreDialog dlg = new ShellStoreDialog
                    {
                        ShellPath = this.ParentShellPath,
                        IgnoredKeyNames = new List <string> {
                            this.ParentKeyName
                        }
                    })
                    {
                        if (dlg.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        dlg.SelectedKeyNames.ForEach(keyName =>
                        {
                            if (!SubShellTypeItem.CanAddMore(this))
                            {
                                return;
                            }
                            string srcPath = $@"{dlg.ShellPath}\{keyName}";
                            string dstPath = ObjectPath.GetNewPathWithIndex($@"{ShellPath}\{keyName}", ObjectPath.PathType.Registry);

                            RegistryEx.CopyTo(srcPath, dstPath);
                            this.AddItem(new SubShellItem(this, dstPath));
                        });
                    }
                }
                public void MoveItem(MyListItem item, bool isUp)
                {
                    int        index     = this.GetItemIndex(item);
                    MyListItem otherItem = null;

                    if (isUp)
                    {
                        if (index > 1)
                        {
                            otherItem = (MyListItem)this.Controls[index - 1];
                            this.SetItemIndex(item, index - 1);
                        }
                    }
                    else
                    {
                        if (index < this.Controls.Count - 1)
                        {
                            otherItem = (MyListItem)this.Controls[index + 1];
                            this.SetItemIndex(item, index + 1);
                        }
                    }
                    if (otherItem != null)
                    {
                        string path1    = GetItemRegPath(item);
                        string path2    = GetItemRegPath(otherItem);
                        string tempPath = ObjectPath.GetNewPathWithIndex(path1, ObjectPath.PathType.Registry);
                        RegistryEx.MoveTo(path1, tempPath);
                        RegistryEx.MoveTo(path2, path1);
                        RegistryEx.MoveTo(tempPath, path2);
                        SetItemRegPath(item, path2);
                        SetItemRegPath(otherItem, path1);
                    }
                }
Exemplo n.º 4
0
            private void AddNewItem()
            {
                using (var shellKey = RegistryEx.GetRegistryKey(ShellPath, true, true))
                {
                    string keyName = "Item";
                    NewItemRegPath = ObjectPath.GetNewPathWithIndex($@"{ShellPath}\{keyName}", ObjectPath.PathType.Registry, 0);
                    keyName        = RegistryEx.GetKeyName(NewItemRegPath);

                    using (var key = shellKey.CreateSubKey(keyName, true))
                    {
                        key.SetValue("MUIVerb", ItemText);
                        if (rdoMulti.Checked)
                        {
                            key.SetValue("SubCommands", "");
                        }
                        else
                        {
                            if (!ItemCommand.IsNullOrWhiteSpace())
                            {
                                string command;
                                if (!chkSE.Checked)
                                {
                                    command = ItemCommand;
                                }
                                else
                                {
                                    command = ShellExecuteDialog.GetCommand(ItemFilePath, Arguments, chkSE.Verb, chkSE.WindowStyle);
                                }
                                key.CreateSubKey("command", true).SetValue("", command);
                            }
                        }
                    }
                }
            }
Exemplo n.º 5
0
        private void AddNewItem()
        {
            NewItem newItem = new NewItem();

            this.InsertItem(newItem, 0);
            newItem.AddNewItem += (sender, e) =>
            {
                using (NewLnkFileDialog dlg = new NewLnkFileDialog())
                {
                    dlg.FileFilter = $"{AppString.Dialog.Program}|*.exe;*.bat;*.cmd;*.vbs;*.vbe;*.js;*.jse;*.wsf";
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    string lnkPath = $@"{SendToPath}\{ObjectPath.RemoveIllegalChars(dlg.ItemText)}.lnk";
                    lnkPath = ObjectPath.GetNewPathWithIndex(lnkPath, ObjectPath.PathType.File);
                    using (ShellLink shellLink = new ShellLink(lnkPath))
                    {
                        shellLink.TargetPath       = dlg.ItemFilePath;
                        shellLink.WorkingDirectory = Path.GetDirectoryName(dlg.ItemFilePath);
                        shellLink.Arguments        = dlg.Arguments;
                        shellLink.Save();
                    }
                    DesktopIni.SetLocalizedFileNames(lnkPath, dlg.ItemText);
                    this.InsertItem(new SendToItem(lnkPath), 2);
                }
            };
        }
                private void AddFromParentMenu()
                {
                    if (!SubShellTypeItem.CanAddMore(this))
                    {
                        return;
                    }
                    using (ShellStoreDialog dlg = new ShellStoreDialog())
                    {
                        dlg.IsReference = false;
                        dlg.ShellPath   = this.ParentShellPath;
                        dlg.Filter      = new Func <string, bool>(itemName => !itemName.Equals(this.ParentKeyName, StringComparison.OrdinalIgnoreCase));
                        if (dlg.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        foreach (string keyName in dlg.SelectedKeyNames)
                        {
                            if (!SubShellTypeItem.CanAddMore(this))
                            {
                                return;
                            }
                            string srcPath = $@"{dlg.ShellPath}\{keyName}";
                            string dstPath = ObjectPath.GetNewPathWithIndex($@"{ShellPath}\{keyName}", ObjectPath.PathType.Registry);

                            RegistryEx.CopyTo(srcPath, dstPath);
                            this.AddItem(new SubShellItem(this, dstPath));
                        }
                    }
                }
Exemplo n.º 7
0
        private static string[] GetSortedPaths(string groupPath, out bool sorted)
        {
            sorted = false;
            List <string> sortedPaths = new List <string>();

            string[] paths = Directory.GetFiles(groupPath, "*.lnk");
            for (int i = paths.Length - 1; i >= 0; i--)
            {
                string srcPath = paths[i];
                string name    = Path.GetFileName(srcPath);
                int    index   = name.IndexOf(" - ");
                if (index >= 2 && int.TryParse(name.Substring(0, index), out int num) && num == i + 1)
                {
                    sortedPaths.Add(srcPath); continue;
                }
                string dstPath = $@"{groupPath}\{(i + 1).ToString().PadLeft(2, '0')} - {name.Substring(index + 3)}";
                dstPath = ObjectPath.GetNewPathWithIndex(dstPath, ObjectPath.PathType.File);
                string value = DesktopIni.GetLocalizedFileNames(srcPath);
                DesktopIni.DeleteLocalizedFileNames(srcPath);
                if (value != string.Empty)
                {
                    DesktopIni.SetLocalizedFileNames(dstPath, value);
                }
                File.Move(srcPath, dstPath);
                sortedPaths.Add(dstPath);
                sorted = true;
            }
            return(sortedPaths.ToArray());
        }
Exemplo n.º 8
0
            private void CreateShellExItem(ShellExCommonItem item)
            {
                if (!item.IsSelected)
                {
                    return;
                }
                string regPath = ObjectPath.GetNewPathWithIndex
                                     ($@"{ShellExPath}\ContextMenuHandlers\{item.DefaultKeyName}", ObjectPath.PathType.Registry);

                SetValue(regPath, "", item.Guid.ToString("B"));
                SelectedShellExPathAndGuids.Add(regPath, item.Guid);
            }
Exemplo n.º 9
0
            private void CreateShellItem(ShellCommonItem item)
            {
                if (!item.IsSelected)
                {
                    return;
                }
                string regPath = ObjectPath.GetNewPathWithIndex
                                     ($@"{ShellPath}\{item.DefaultKeyName}", ObjectPath.PathType.Registry);

                ShellCommonItem.WriteSubKeysValue(item.ItemXE, regPath);
                SelectedShellPaths.Add(regPath);
            }
Exemplo n.º 10
0
        private void CreateNewGroup()
        {
            string dirPath = ObjectPath.GetNewPathWithIndex($@"{WinXPath}\Group", ObjectPath.PathType.Directory, 1);

            Directory.CreateDirectory(dirPath);
            string iniPath = $@"{dirPath}\desktop.ini";

            File.WriteAllText(iniPath, string.Empty, Encoding.Unicode);
            File.SetAttributes(dirPath, File.GetAttributes(dirPath) | FileAttributes.ReadOnly);
            File.SetAttributes(iniPath, File.GetAttributes(iniPath) | FileAttributes.Hidden | FileAttributes.System);
            this.InsertItem(new WinXGroupItem(dirPath), 1);
        }
Exemplo n.º 11
0
            private void AddNewItem()
            {
                FilePath = $@"{SendToList.SendToPath}\{ObjectPath.RemoveIllegalChars(ItemText)}.lnk";
                FilePath = ObjectPath.GetNewPathWithIndex(FilePath, ObjectPath.PathType.File);

                IWshRuntimeLibrary.IWshShortcut shortcut = WshShell.CreateShortcut(FilePath);
                shortcut.TargetPath = ItemCommand;
                if (rdoFile.Checked)
                {
                    shortcut.WorkingDirectory = Path.GetDirectoryName(ItemCommand);
                }
                shortcut.Save();
                DesktopIniHelper.SetLocalizedFileName(FilePath, ItemText);
            }
Exemplo n.º 12
0
            private void AddNewItem()
            {
                FilePath = $@"{SendToList.SendToPath}\{ObjectPath.RemoveIllegalChars(ItemText)}.lnk";
                FilePath = ObjectPath.GetNewPathWithIndex(FilePath, ObjectPath.PathType.File);
                WshShortcut shortcut = new WshShortcut
                {
                    FullName         = FilePath,
                    TargetPath       = Command,
                    WorkingDirectory = Path.GetDirectoryName(Command),
                    Arguments        = Arguments
                };

                shortcut.Save();
                SendToList.DesktopIniWriter.SetValue("LocalizedFileNames", Path.GetFileName(FilePath), ItemText);
            }
Exemplo n.º 13
0
        private static string[] GetSortedPaths(string groupPath, out bool sorted)
        {
            sorted = false;
            List <string> sortedPaths = new List <string>();

            string[] paths = Directory.GetFiles(groupPath, "*.lnk");
            for (int i = paths.Length - 1; i >= 0; i--)
            {
                string srcPath = paths[i];
                string name    = Path.GetFileName(srcPath);
                int    index   = name.IndexOf(" - ");
                if (index >= 2 && int.TryParse(name.Substring(0, index), out int num) && num == i + 1)
                {
                    sortedPaths.Add(srcPath); continue;
                }
                if (index >= 0)
                {
                    name = name.Substring(index + 3);
                }
                string dstPath = $@"{groupPath}\{(i + 1).ToString().PadLeft(2, '0')} - {name}";
                dstPath = ObjectPath.GetNewPathWithIndex(dstPath, ObjectPath.PathType.File);

                string value;
                using (ShellLink srcLnk = new ShellLink(srcPath))
                {
                    value = srcLnk.Description?.Trim();
                }
                if (string.IsNullOrEmpty(value))
                {
                    value = DesktopIni.GetLocalizedFileNames(srcPath);
                }
                if (string.IsNullOrEmpty(value))
                {
                    value = Path.GetFileNameWithoutExtension(name);
                }
                DesktopIni.DeleteLocalizedFileNames(srcPath);
                DesktopIni.SetLocalizedFileNames(dstPath, value);
                File.Move(srcPath, dstPath);
                using (ShellLink dstLnk = new ShellLink(dstPath))
                {
                    dstLnk.Description = value;
                    dstLnk.Save();
                }
                sortedPaths.Add(dstPath);
                sorted = true;
            }
            return(sortedPaths.ToArray());
        }
                private void AddSeparator()
                {
                    string regPath = null;

                    if (this.Controls.Count > 1)
                    {
                        regPath = GetItemRegPath((MyListItem)Controls[Controls.Count - 1]);
                    }
                    else
                    {
                        regPath = $@"{ShellPath}\Item";
                    }
                    regPath = ObjectPath.GetNewPathWithIndex(regPath, ObjectPath.PathType.Registry);
                    SetValue(regPath, "CommandFlags", 0x8);
                    this.AddItem(new SeparatorItem(this, regPath));
                }
Exemplo n.º 15
0
 public DeleteMeMenuItem(ITsiDeleteItem item) : base(AppString.Menu.Delete)
 {
     this.Click += (sender, e) =>
     {
         if (MessageBoxEx.Show(AppString.MessageBox.ConfirmDeletePermanently,
                               MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             if (item is ITsiRegDeleteItem regItem && AppConfig.AutoBackup)
             {
                 string date     = DateTime.Today.ToString("yyyy-MM-dd");
                 string fileName = ObjectPath.RemoveIllegalChars(regItem.ItemText);
                 string filePath = $@"{AppConfig.BackupDir}\{date}\{fileName}.reg";
                 filePath = ObjectPath.GetNewPathWithIndex(filePath, ObjectPath.PathType.File);
                 Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                 RegistryEx.Export(regItem.RegPath, filePath);
             }
             item.DeleteMe();
         }
     };
 }
Exemplo n.º 16
0
            private void AddNewItem()
            {
                FilePath = $@"{SendToList.SendToPath}\{ObjectPath.RemoveIllegalChars(ItemText)}.lnk";
                FilePath = ObjectPath.GetNewPathWithIndex(FilePath, ObjectPath.PathType.File);

                IWshRuntimeLibrary.IWshShortcut shortcut = WshShell.CreateShortcut(FilePath);
                if (rdoFile.Checked)
                {
                    ItemCommand         = Environment.ExpandEnvironmentVariables(ItemCommand);
                    shortcut.TargetPath = ObjectPath.ExtractFilePath(ItemCommand, out string shortPath);
                    string str = ItemCommand.Substring(ItemCommand.IndexOf(shortPath) + shortPath.Length);
                    shortcut.Arguments        = str.Substring(str.IndexOf(" ") + 1);
                    shortcut.WorkingDirectory = Path.GetDirectoryName(shortcut.TargetPath);
                }
                else
                {
                    shortcut.TargetPath = ItemCommand;
                }
                shortcut.Save();
                DesktopIniHelper.SetLocalizedFileName(FilePath, ItemText);
            }