Exemple #1
0
            protected override void InitializeComponents()
            {
                base.InitializeComponents();
                this.Controls.AddRange(new Control[] { rdoFile, rdoFolder });
                rdoFile.Top    = rdoFolder.Top = btnOK.Top + (btnOK.Height - rdoFile.Height) / 2;
                rdoFile.Left   = lblCommand.Left;
                rdoFolder.Left = rdoFile.Right + 20.DpiZoom();

                btnBrowse.Click += (sender, e) =>
                {
                    if (rdoFile.Checked)
                    {
                        BrowseFile();
                    }
                    else
                    {
                        BrowseFolder();
                    }
                };

                btnOK.Click += (sender, e) =>
                {
                    if (ItemText.IsNullOrWhiteSpace())
                    {
                        AppMessageBox.Show(AppString.Message.TextCannotBeEmpty);
                    }
                    else if (ItemFilePath.IsNullOrWhiteSpace())
                    {
                        AppMessageBox.Show(AppString.Message.CommandCannotBeEmpty);
                    }
                    else if (rdoFile.Checked && !ObjectPath.GetFullFilePath(ItemFilePath, out _))
                    {
                        AppMessageBox.Show(AppString.Message.FileNotExists);
                    }
                    else if (rdoFolder.Checked && !Directory.Exists(ItemFilePath))
                    {
                        AppMessageBox.Show(AppString.Message.FolderNotExists);
                    }
                    else
                    {
                        DialogResult = DialogResult.OK;
                    }
                };

                txtFilePath.TextChanged += (sender, e) =>
                {
                    if (Path.GetExtension(ItemFilePath).ToLower() == ".lnk")
                    {
                        using (ShellLink shortcut = new ShellLink(ItemFilePath))
                        {
                            if (File.Exists(shortcut.TargetPath))
                            {
                                ItemFilePath = shortcut.TargetPath;
                            }
                        }
                    }
                };
            }
Exemple #2
0
 public static string GetCommand(string fileName, string arguments, string verb, int windowStyle, string directory = null)
 {
     arguments = arguments.Replace("\"", "\"\"");
     if (directory == null)
     {
         ObjectPath.GetFullFilePath(fileName, out string filePath);
         directory = Path.GetDirectoryName(filePath);
     }
     return("mshta vbscript:createobject(\"shell.application\").shellexecute" +
            $"(\"{fileName}\",\"{arguments}\",\"{directory}\",\"{verb}\",{windowStyle})(close)");
 }
            protected override void InitializeComponents()
            {
                base.InitializeComponents();
                this.Text = AppString.Dialog.NewSendToItem;
                this.Controls.AddRange(new Control[] { rdoFile, rdoFolder });
                rdoFile.Top    = rdoFolder.Top = btnOk.Top;
                rdoFile.Left   = lblCommand.Left;
                rdoFolder.Left = rdoFile.Right + 20.DpiZoom();

                btnBrowse.Click += (sender, e) =>
                {
                    if (rdoFile.Checked)
                    {
                        BrowseFile();
                    }
                    else
                    {
                        BrowseFolder();
                    }
                };

                btnOk.Click += (sender, e) =>
                {
                    if (ItemText.IsNullOrWhiteSpace())
                    {
                        MessageBoxEx.Show(AppString.MessageBox.TextCannotBeEmpty);
                        return;
                    }
                    if (Command.IsNullOrWhiteSpace())
                    {
                        MessageBoxEx.Show(AppString.MessageBox.CommandCannotBeEmpty);
                        return;
                    }
                    if (rdoFile.Checked && !ObjectPath.GetFullFilePath(Command, out _))
                    {
                        MessageBoxEx.Show(AppString.MessageBox.FileNotExists);
                        return;
                    }
                    if (rdoFolder.Checked && !Directory.Exists(Command))
                    {
                        MessageBoxEx.Show(AppString.MessageBox.FolderNotExists);
                        return;
                    }
                    AddNewItem();
                    DialogResult = DialogResult.OK;
                };
            }