Ejemplo n.º 1
0
        /// <summary>
        /// if Target is a file, launch explorer to file
        /// if target is a folder, launch explorer to open said folder
        /// </summary>
        /// <param name="Target"></param>
        static void Explore(string Target)
        {
            StringBuilder NewTarget = new StringBuilder();
            string        ShellCmd  = ArgumentExpander.ExpandVars(ExploreCmd);
            bool          FileMode  = false;

            if (File.Exists(Target) == false)
            {
                if (Directory.Exists(Target) == false)
                {
                    MessageBox.Show(string.Format("Error: {0} not found", Target));
                }
                else
                {
                    FileMode = false;
                }
            }
            else
            {
                FileMode = true;
            }

            if (FileMode)
            {
                NewTarget.Append(Path.GetDirectoryName(Target));
            }
            else
            {
                NewTarget.Append(Target);
            }
            LaunchExternCommand(ShellCmd, NewTarget.ToString(), false);
        }
Ejemplo n.º 2
0
        private void ButtonChooseFile_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(TextBoxFilePath.Text))
            {
                openFileDialog1.FileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            }
            else
            {
                if ((File.Exists(TextBoxFilePath.Text) == true) ||
                    (Directory.Exists(TextBoxFilePath.Text) == true))
                {
                    openFileDialog1.FileName = TextBoxFilePath.Text;
                }
                else
                {
                    if (TextBoxFilePath.Text.Contains("$"))
                    {
                        string Expand; // and try again
                        Expand = ArgumentExpander.ExpandVars(TextBoxFilePath.Text);
                        if ((File.Exists(Expand) == true) ||
                            (Directory.Exists(Expand) == true))
                        {
                            openFileDialog1.FileName = Expand;
                        }
                        else
                        {
                            openFileDialog1.FileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        }
                    }
                }
            }

            if (Directory.Exists(openFileDialog1.FileName))
            {
                openFileDialog1.InitialDirectory = openFileDialog1.FileName;
                openFileDialog1.FileName         = string.Empty;
                openFileDialog1.RestoreDirectory = true;
            }
            else
            {
                if (File.Exists(openFileDialog1.FileName))
                {
                    openFileDialog1.InitialDirectory = Path.GetDirectoryName(openFileDialog1.FileName);
                    openFileDialog1.FileName         = Path.GetFileName(openFileDialog1.FileName);
                    openFileDialog1.RestoreDirectory = true;
                }
                else
                {
                    openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    openFileDialog1.RestoreDirectory = true;
                    openFileDialog1.FileName         = string.Empty;
                }
            }


            openFileDialog1.FileOk += OpenFileDialog1_FileOk;
            openFileDialog1.ShowDialog();
        }
Ejemplo n.º 3
0
        static void CopyToOneDrive(string source)
        {
            StringBuilder Target = new StringBuilder();

            if (File.Exists(source))
            {
                Target.Append(ArgumentExpander.Query(ArgumentExpanderSupported.OneDrive));
                if (Target[Target.Length] != '\\')
                {
                    Target.Append('\\');
                }
                Target.Append(Path.GetFileName(source));
                CopyFile(Target.ToString(), source);
            }
        }
Ejemplo n.º 4
0
        static void LaunchCmd(string Target, bool TryAdmin)
        {
            StringBuilder cmd;
            string        CmdArg;
            string        NewTarget;

            if (string.IsNullOrEmpty(Target))
            {
                return;
            }
            if (File.Exists(Target))
            {
                NewTarget = Path.GetDirectoryName(Target);
            }
            else
            {
                if (Directory.Exists(Target))
                {
                    NewTarget = Target;
                }
                else
                {
                    NewTarget = string.Empty;
                }
            }
            if (string.IsNullOrEmpty(NewTarget))
            {
                MessageBox.Show(string.Format("{0} Does not appear to exist. . .", Target));
            }
            else
            {
                cmd = new StringBuilder();
                cmd.AppendFormat(ArgumentExpander.ExpandVars(LaunchCmdPrompt), NewTarget, string.Empty);
                CmdArg = string.Format(LaunchCmdPromptArgString, Path.GetDirectoryName(ArgumentExpander.ExpandVars(Target)));
                if (TryAdmin)
                {
                    LaunchExternCommand(cmd.ToString(), CmdArg, true, "runas", Target);
                }
                else
                {
                    LaunchExternCommand(cmd.ToString(), CmdArg, true);
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // the first non self non '/' command
            // beocmes this.
            string TargetFileObject;

            ArgumentExpander.BuildEnv();

            TargetFileObject = string.Empty;

            for (int step = 0; step < args.Length; step++)
            {
                {
                    switch (args[step].ToLower().Replace('-', '/'))
                    {
                    case "/safemode":
                    case "/safe":
                    case "/readonly":
                    case "/s":
                        ToolFunction.SafeMode = true;
                        break;

                    case "/ovewrite":
                    case "/o":
                    case "/write":
                    case "/allowwrite":
                        ToolFunction.SafeMode = false;
                        break;

                    case "/exploreresults":
                    case "/showresults":
                    case "/results":
                        ToolFunction.ShowResults = true;
                        break;

                    case "/target":
                    case "/t":
                        if (step + 1 >= args.Length)
                        {
                            Console.WriteLine("Error: Encounted end of argument list looking for /target [File System Item]");
                            break;
                        }
                        else
                        {
                            step++;
                            TargetFileObject = args[step];
                        }
                        break;

                    case "/usage":
                    case "/help":
                    case "/?":
                        Usage();
                        break;

                    case "/showenv":
                        ArgumentExpander.ShowEnv();
                        break;

                    case "/install":
                        break;

                    case "/uninstall":
                        break;

                    case "/extract":
                    case "/expand":
                        if (string.IsNullOrEmpty(TargetFileObject))
                        {
                            Console.WriteLine(string.Format("{0} needs a target file system item. Fizzles....", args[step]));
                            break;
                        }
                        ToolFunction.Invoke(ToolFunctionCommand.UnZipContents, TargetFileObject);
                        break;

                    case "/zip":
                    case "/compress":
                        if (string.IsNullOrEmpty(TargetFileObject))
                        {
                            Console.WriteLine(string.Format("{0} needs a target file system item. Fizzles....", args[step]));
                            break;
                        }
                        ToolFunction.Invoke(ToolFunctionCommand.ZipContents, TargetFileObject);
                        break;

                    case "/extras":
                    {
                        ToolFunction.Invoke(ToolFunctionCommand.ExtrasMenu, TargetFileObject);
                        break;
                    }

                    case "/filename":
                    {
                        if (string.IsNullOrEmpty(TargetFileObject))
                        {
                            Console.WriteLine(string.Format("{0} needs a target file system item. Fizzles....", args[step]));
                            break;
                        }

                        ToolFunction.Invoke(ToolFunctionCommand.SetClipboardFileName, TargetFileObject);
                        break;
                    }

                    case "/filepath":
                    {
                        if (string.IsNullOrEmpty(TargetFileObject))
                        {
                            Console.WriteLine(string.Format("{0} needs a target file system item. Fizzles....", args[step]));
                            break;
                        }

                        ToolFunction.Invoke(ToolFunctionCommand.SetClipboardFilePath, TargetFileObject);
                        break;
                    }

                    case "/cfilename":
                    {
                        if (string.IsNullOrEmpty(TargetFileObject))
                        {
                            Console.WriteLine(string.Format("{0} needs a target file system item. Fizzles....", args[step]));
                            break;
                        }

                        ToolFunction.Invoke(ToolFunctionCommand.SetClipboardCompleteLocation, TargetFileObject);
                        break;
                    }

                    case "/quotedfilename":
                    {
                        if (string.IsNullOrEmpty(TargetFileObject))
                        {
                            Console.WriteLine(string.Format("{0} needs a target file system item. Fizzles....", args[step]));
                            break;
                        }

                        ToolFunction.Invoke(ToolFunctionCommand.SetClipboardQuotedCodeCompletePath, TargetFileObject);
                        break;
                    }

                    case "/codefriendlyfilename":
                    {
                        if (string.IsNullOrEmpty(TargetFileObject))
                        {
                            Console.WriteLine(string.Format("{0} needs a target file system item. Fizzles....", args[step]));
                            break;
                        }

                        ToolFunction.Invoke(ToolFunctionCommand.SetClipboardQuotedCodeCompletePath, TargetFileObject);
                        break;
                    }

                    case "/findme":
                        ToolFunction.Invoke(ToolFunctionCommand.FindMe, TargetFileObject);
                        break;

                    case "/explore":
                    {
                        if (string.IsNullOrEmpty(TargetFileObject))
                        {
                            Console.WriteLine(string.Format("{0} needs a target file system item. Fizzles....", args[step]));
                            break;
                        }

                        ToolFunction.Invoke(ToolFunctionCommand.Explore, TargetFileObject);
                        break;
                    }

                    case "/command.com":
                    case "/cmd":
                    case "/prompt":
                    {
                        if (string.IsNullOrEmpty(TargetFileObject))
                        {
                            Console.WriteLine(string.Format("{0} needs a target file system item. Fizzles....", args[step]));
                            break;
                        }

                        ToolFunction.Invoke(ToolFunctionCommand.LaunchCmdWithSetCurrentDirectory, TargetFileObject);
                        break;
                    }

                    case "/admincmd":
                    case "/cmdadmin":
                    {
                        if (string.IsNullOrEmpty(TargetFileObject))
                        {
                            Console.WriteLine(string.Format("{0} needs a target file system item. Fizzles....", args[step]));
                            break;
                        }

                        ToolFunction.Invoke(ToolFunctionCommand.AdminLaunchCmdWithSetCurrentDirectory, TargetFileObject);
                        break;
                    }

                    default:
                        //MessageBox.Show(string.Format("Unknown Command {0}", args[step]));
                        Console.WriteLine(string.Format("Unknown Command {0}", args[step]));
                        break;
                    }
                }
            }

            /*
             * Application.EnableVisualStyles();
             * Application.SetCompatibleTextRenderingDefault(false);
             * Application.Run(new Form1());*/
            Console.ReadKey();
        }