Exemplo n.º 1
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);
                }
            };
        }
Exemplo n.º 2
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.º 3
0
        public DesktopIni ToIni()
        {
            var ini = new DesktopIni
            {
                Name       = Name,
                Screenshot = @"" //TODO Gute Zeile
            };

            return(ini);
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
0
        private void AddNewItem()
        {
            NewItem newItem = new NewItem();

            this.AddItem(newItem);
            PictureButton btnCreateDir = new PictureButton(AppImage.NewFolder);

            MyToolTip.SetToolTip(btnCreateDir, AppString.Tip.CreateGroup);
            newItem.AddCtr(btnCreateDir);
            btnCreateDir.MouseDown += (sender, e) => CreateNewGroup();
            newItem.AddNewItem     += (sender, e) =>
            {
                using (NewLnkFileDialog dlg1 = new NewLnkFileDialog())
                {
                    if (dlg1.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    using (SelectDialog dlg2 = new SelectDialog())
                    {
                        dlg2.Title = AppString.Dialog.SelectGroup;
                        dlg2.Items = GetGroupNames();
                        if (dlg2.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        string dirName    = dlg2.Selected;
                        string dirPath    = $@"{WinXPath}\{dirName}";
                        string itemText   = dlg1.ItemText;
                        string targetPath = dlg1.ItemFilePath;
                        string arguments  = dlg1.Arguments;
                        string workDir    = Path.GetDirectoryName(targetPath);
                        string extension  = Path.GetExtension(targetPath).ToLower();
                        string fileName   = Path.GetFileNameWithoutExtension(targetPath);
                        int    count      = Directory.GetFiles(dirPath, "*.lnk").Length;
                        string index      = (count + 1).ToString().PadLeft(2, '0');
                        string lnkName    = $"{index} - {fileName}.lnk";
                        string lnkPath    = $@"{dirPath}\{lnkName}";
                        using (ShellLink shellLink = new ShellLink(lnkPath))
                        {
                            if (extension == ".lnk")
                            {
                                File.Copy(targetPath, lnkPath);
                                shellLink.Load();
                            }
                            else
                            {
                                shellLink.TargetPath       = targetPath;
                                shellLink.Arguments        = arguments;
                                shellLink.WorkingDirectory = workDir;
                            }
                            shellLink.Description = itemText;
                            shellLink.Save();
                        }
                        DesktopIni.SetLocalizedFileNames(lnkPath, itemText);
                        foreach (MyListItem ctr in this.Controls)
                        {
                            if (ctr is WinXGroupItem groupItem && groupItem.Text == dirName)
                            {
                                WinXItem item = new WinXItem(lnkPath, groupItem)
                                {
                                    Visible = !groupItem.IsFold
                                };
                                item.BtnMoveDown.Visible = item.BtnMoveUp.Visible = AppConfig.WinXSortable;
                                this.InsertItem(item, this.GetItemIndex(groupItem) + 1);
                                break;
                            }
                        }
                        WinXHasher.HashLnk(lnkPath);
                        ExplorerRestarter.Show();
                    }
                }
            };
        }
Exemplo n.º 6
0
 public static void SerializeDesktopIni(DesktopIni desktopIni, string path) =>
 File.WriteAllText(path, JsonConvert.SerializeObject(desktopIni));