private void AddNewItem(string scenePath)
        {
            NewItem newItem = new NewItem {
                Visible = scenePath != null
            };

            this.AddItem(newItem);
            newItem.AddNewItem += (sender, e) =>
            {
                bool isShell;
                if (Scene == Scenes.CommandStore)
                {
                    isShell = true;
                }
                else if (Scene == Scenes.DragDrop)
                {
                    isShell = false;
                }
                else
                {
                    using (SelectDialog dlg = new SelectDialog())
                    {
                        dlg.Items    = new[] { "Shell", "ShellEx" };
                        dlg.Title    = AppString.Dialog.SelectNewItemType;
                        dlg.Selected = dlg.Items[0];
                        if (dlg.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        isShell = dlg.SelectedIndex == 0;
                    }
                }
                if (isShell)
                {
                    this.AddNewShellItem(scenePath);
                }
                else
                {
                    this.AddNewShellExItem(scenePath);
                }
            };
        }
        private void AddNewShellExItem(string scenePath)
        {
            bool isDragDrop = Scene == Scenes.DragDrop;

            using (InputDialog dlg1 = new InputDialog {
                Title = AppString.Dialog.InputGuid
            })
            {
                if (GuidEx.TryParse(Clipboard.GetText(), out Guid guid))
                {
                    dlg1.Text = guid.ToString();
                }
                if (dlg1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                if (GuidEx.TryParse(dlg1.Text, out guid))
                {
                    if (isDragDrop)
                    {
                        using (SelectDialog dlg2 = new SelectDialog())
                        {
                            dlg2.Title = AppString.Dialog.SelectGroup;
                            dlg2.Items = new[] { AppString.SideBar.Folder, AppString.SideBar.Directory,
                                                 AppString.SideBar.Drive, AppString.SideBar.AllObjects };
                            dlg2.Selected = dlg2.Items[0];
                            if (dlg2.ShowDialog() != DialogResult.OK)
                            {
                                return;
                            }
                            switch (dlg2.SelectedIndex)
                            {
                            case 0:
                                scenePath = MENUPATH_FOLDER; break;

                            case 1:
                                scenePath = MENUPATH_DIRECTORY; break;

                            case 2:
                                scenePath = MENUPATH_DRIVE; break;

                            case 3:
                                scenePath = MENUPATH_ALLOBJECTS; break;
                            }
                        }
                    }
                    string shellExPath = GetShellExPath(scenePath);
                    if (ShellExItem.GetPathAndGuids(shellExPath, isDragDrop).Values.Contains(guid))
                    {
                        MessageBoxEx.Show(AppString.MessageBox.HasBeenAdded);
                    }
                    else
                    {
                        string part    = isDragDrop ? ShellExItem.DdhParts[0] : ShellExItem.CmhParts[0];
                        string regPath = $@"{shellExPath}\{part}\{guid:B}";
                        Registry.SetValue(regPath, "", guid.ToString("B"));
                        ShellExItem item = new ShellExItem(guid, regPath);
                        for (int i = 0; i < this.Controls.Count; i++)
                        {
                            if (isDragDrop)
                            {
                                if (this.Controls[i] is GroupPathItem groupItem)
                                {
                                    if (groupItem.TargetPath.Equals(shellExPath, StringComparison.OrdinalIgnoreCase))
                                    {
                                        this.InsertItem(item, i + 1);
                                        item.FoldGroupItem = groupItem;
                                        item.Visible       = !groupItem.IsFold;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                if (this.Controls[i] is NewItem)
                                {
                                    this.InsertItem(item, i + 1);
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBoxEx.Show(AppString.MessageBox.MalformedGuid);
                }
            }
        }
 public void ShowLanguageDialog()
 {
     using (UAWebClient client = new UAWebClient())
     {
         string      apiUrl = AppConfig.RequestUseGithub ? AppConfig.GithubLangsApi : AppConfig.GiteeLangsApi;
         XmlDocument doc    = client.GetWebJsonToXml(apiUrl);
         if (doc == null)
         {
             AppMessageBox.Show(AppString.Message.WebDataReadFailed);
             return;
         }
         XmlNodeList list  = doc.FirstChild.ChildNodes;
         string[]    langs = new string[list.Count];
         for (int i = 0; i < list.Count; i++)
         {
             XmlNode nameXN = list.Item(i).SelectSingleNode("name");
             langs[i] = Path.GetFileNameWithoutExtension(nameXN.InnerText);
         }
         if (langs.Length == 0)
         {
             AppMessageBox.Show(AppString.Message.WebDataReadFailed);
             return;
         }
         using (SelectDialog dlg = new SelectDialog())
         {
             dlg.Items = langs;
             dlg.Title = AppString.Dialog.DownloadLanguages;
             string lang = CultureInfo.CurrentUICulture.Name;
             if (dlg.Items.Contains(lang))
             {
                 dlg.Selected = lang;
             }
             else
             {
                 dlg.SelectedIndex = 0;
             }
             if (dlg.ShowDialog() == DialogResult.OK)
             {
                 string fileName = $"{dlg.Selected}.ini";
                 string filePath = $@"{AppConfig.LangsDir}\{fileName}";
                 string dirUrl   = AppConfig.RequestUseGithub ? AppConfig.GithubLangsRawDir : AppConfig.GiteeLangsRawDir;
                 string fileUrl  = $"{dirUrl}/{fileName}";
                 bool   flag     = client.WebStringToFile(filePath, fileUrl);
                 if (!flag)
                 {
                     if (AppMessageBox.Show(AppString.Message.WebDataReadFailed + "\r\n ● " + fileName + "\r\n"
                                            + AppString.Message.OpenWebUrl, MessageBoxButtons.YesNo) == DialogResult.Yes)
                     {
                         ExternalProgram.OpenWebUrl(fileUrl);
                     }
                 }
                 else
                 {
                     this.LoadLanguages();
                     string language = new IniWriter(filePath).GetValue("General", "Language");
                     if (language == "")
                     {
                         language = dlg.Selected;
                     }
                     cmbLanguages.Text = language;
                     ChangeLanguage();
                 }
             }
         }
     }
 }
Example #4
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();
                    }
                }
            };
        }