Exemplo n.º 1
0
        /// <summary>
        /// This program calculates the MD5 hashes for the given input files
        /// </summary>
        /// <param name="args"></param>
        private void Run(string[] args)
        {
            Console.OutputEncoding = Encoding.GetEncoding(Encoding.Default.CodePage);
            Args = new InputArgs("md5sums", string.Format(resource.IDS_TITLE, AppVersion.Get()) + "\r\n" + resource.IDS_COPYRIGHT);

            Args.Add(InputArgType.Flag, "recursive", false, Presence.Optional, resource.IDS_CMD_recursive_doc);
            Args.Add(InputArgType.RemainingParameters, "DIR {DIR}", null, Presence.Optional, resource.IDS_CMD_dir_doc);

            if (Args.Process(args))
            {
                Recursive = Args.GetFlag("recursive");

                List <string> directories = Args.GetStringList("DIR {DIR}");
                if (directories == null)
                {
                    Read(Directory.GetCurrentDirectory());
                }
                else
                {
                    foreach (string directory in directories)
                    {
                        Read(SanitizeInput(directory));
                    }
                }
            }
        }
Exemplo n.º 2
0
Arquivo: ddupe.cs Projeto: jwg4/gtools
        /// <summary>
        /// This program finds an executable on the PATH. It can also find other stuff on the path, but
        /// mostly it finds the executable.s
        /// </summary>
        /// <param name="args"></param>
        private void Run(string[] args)
        {
            Console.OutputEncoding = Encoding.GetEncoding(Encoding.Default.CodePage);
            Args = new InputArgs("ddupe", string.Format(resource.IDS_TITLE, AppVersion.Get()) + "\r\n" + resource.IDS_COPYRIGHT);

            Args.Add(InputArgType.Flag, "recursive", false, Presence.Optional, resource.IDS_CMD_recursive_doc);
            Args.Add(InputArgType.Flag, "rename", false, Presence.Optional, resource.IDS_CMD_rename_doc);
            Args.Add(InputArgType.Parameter, "cache", null, Presence.Optional, resource.IDS_CMD_cache_doc);
            Args.Add(InputArgType.Flag, "delete", false, Presence.Optional, resource.IDS_CMD_delete_doc);
            Args.Add(InputArgType.SizeInBytes, "minsize", 0, Presence.Optional, resource.IDS_CMD_minsize_doc);
            Args.Add(InputArgType.RemainingParameters, "DIR {DIR}", null, Presence.Required, resource.IDS_CMD_dir_doc);

            if (Args.Process(args))
            {
                UseDatabase = DatabaseCache.Initialize(Args.GetString("cache"), Cache);
                Recursive   = Args.GetFlag("recursive");
                RenameFiles = Args.GetFlag("rename");
                DeleteFiles = Args.GetFlag("delete");
                MinSize     = Args.GetSizeInBytes("minsize");

                foreach (string directory in Args.GetStringList("DIR {DIR}"))
                {
                    Read(SanitizeInput(directory));
                }
            }
            if (FilesChecked > 0)
            {
                DatabaseCache.Flush();

                TimeSpan elapsed = DateTime.Now - StartupTime;

                Console.WriteLine("____________________________________________________________________________________");
                Console.WriteLine(resource.IDS_finished, elapsed);

                Console.WriteLine(resource.IDS_total_checked,
                                  FilesChecked,
                                  BytesAsString(BytesChecked),
                                  HashesRead,
                                  TimeSpentCalculatingMD5s);

                if (RenameFiles)
                {
                    Console.WriteLine(resource.IDS_total_renamed,
                                      FilesRenamed,
                                      BytesAsString(BytesRenamed));

                    Console.WriteLine(resource.IDS_total_hashes,
                                      RenamedHashes,
                                      BytesAsString(RenamedBytes));
                }

                Console.WriteLine(resource.IDS_total_dupes,
                                  FilesDetected,
                                  BytesAsString(BytesDetected),
                                  ((double)FilesDetected) / ((double)FilesChecked),
                                  ((double)BytesDetected) / ((double)BytesChecked));
            }
        }
Exemplo n.º 3
0
Arquivo: su.cs Projeto: jwg4/gtools
        /// <summary>
        /// This program finds an executable on the PATH. It can also find other stuff on the path, but
        /// mostly it finds the executable.s
        /// </summary>
        /// <param name="args"></param>
        private void Run(string[] args)
        {
            Console.OutputEncoding = Encoding.GetEncoding(Encoding.Default.CodePage);

            Args = new InputArgs("su", string.Format(resource.IDS_TITLE, AppVersion.Get()) + "\r\n" + resource.IDS_COPYRIGHT);

            Args.Add(InputArgType.Parameter, "cmd", "cmd.exe", Presence.Optional, resource.IDS_DOC_cmd_param);

            if (Args.Process(args))
            {
                string command = Args.GetString("cmd");
                if (command.Equals("cmd.exe", StringComparison.OrdinalIgnoreCase))
                {
                    if (!IsAdministrator())
                    {
                        ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(Environment.SystemDirectory, "cmd.exe"));
                        startInfo.Verb             = "runas";
                        startInfo.WorkingDirectory = Environment.CurrentDirectory;
                        startInfo.Arguments        = string.Format("/K \"cd /d {0}\"", startInfo.WorkingDirectory);

                        System.Diagnostics.Process.Start(startInfo);
                    }
                    else
                    {
                        Console.WriteLine(resource.IDS_ERR_AlreadyRunningAsAdministrator);
                    }
                }
                else
                {
                    string exe;
                    if (ProcessInfoTools.FindExecutable(command, out exe))
                    {
                        ProcessStartInfo startInfo = new ProcessStartInfo(exe);
                        startInfo.Verb             = "runas";
                        startInfo.WorkingDirectory = Environment.CurrentDirectory;

                        System.Diagnostics.Process.Start(startInfo);
                    }
                    else
                    {
                        Console.WriteLine(resource.IDS_ERR_UnableToFindFile, command);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// This program calculates the MD5 hashes for the given input files
        /// </summary>
        /// <param name="args"></param>
        private void Run(string[] args)
        {
            Console.OutputEncoding = Encoding.GetEncoding(Encoding.Default.CodePage);
            Args = new InputArgs("touch", string.Format(resource.IDS_TITLE, AppVersion.Get()) + "\r\n" + resource.IDS_COPYRIGHT);

            Args.Add(InputArgType.Parameter, "date", "", Presence.Optional, resource.IDS_CMD_date_doc);
            Args.Add(InputArgType.Parameter, "time", "", Presence.Optional, resource.IDS_CMD_time_doc);
            Args.Add(InputArgType.Flag, "recursive", false, Presence.Optional, resource.IDS_CMD_recursive_doc);
            Args.Add(InputArgType.RemainingParameters, "DIR {DIR}", null, Presence.Optional, resource.IDS_CMD_dir_doc);

            if (Args.Process(args))
            {
                DateTime dateSpec = DateTime.Now;
                DateTime timeSpec = DateTime.Now;
                string   date     = Args.GetString("DATE");
                if (!string.IsNullOrEmpty(date))
                {
                    try
                    {
                        dateSpec = DateTime.Parse(date);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        Console.WriteLine(e.StackTrace);
                        Console.WriteLine(resource.IDS_ERR_unable_to_decode_date, date);
                        return;
                    }
                }
                string time = Args.GetString("TIME");
                if (!string.IsNullOrEmpty(time))
                {
                    try
                    {
                        timeSpec = DateTime.Parse(time);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        Console.WriteLine(e.StackTrace);
                        Console.WriteLine(resource.IDS_ERR_unable_to_decode_time, time);
                        return;
                    }
                }
                TimeStamp = new DateTime(dateSpec.Year, dateSpec.Month, dateSpec.Day, timeSpec.Hour, timeSpec.Minute, timeSpec.Second);

                Recursive = Args.GetFlag("recursive");

                List <string> directories = Args.GetStringList("DIR {DIR}");
                if (directories == null)
                {
                    Read(Directory.GetCurrentDirectory());
                }
                else
                {
                    foreach (string directory in directories)
                    {
                        Read(SanitizeInput(directory));
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// This program finds an executable on the PATH. It can also find other stuff on the path, but
        /// mostly it finds the executable.s
        /// </summary>
        /// <param name="args"></param>
        private void Run(string[] args)
        {
            Console.OutputEncoding = Encoding.GetEncoding(Encoding.Default.CodePage);

            Args = new InputArgs("which", string.Format(resource.IDS_TITLE, AppVersion.Get()) + "\r\n" + resource.IDS_COPYRIGHT);


            Args.Add(InputArgType.StringList, "extension", null, Presence.Optional, resource.IDS_CMD_extension_doc);
            Args.Add(InputArgType.StringList, "dir", null, Presence.Optional, resource.IDS_CMD_dir_doc);
            Args.Add(InputArgType.Flag, "recursive", false, Presence.Optional, resource.IDS_CMD_recursive_doc);
            Args.Add(InputArgType.Flag, "single", false, Presence.Optional, resource.IDS_CMD_single_doc);
            Args.Add(InputArgType.RemainingParameters, "FILE {FILE}", null, Presence.Required, resource.IDS_CMD_file_doc);
            Args.Add(InputArgType.Parameter, "env", "PATH", Presence.Optional, resource.IDS_CMD_env_doc);

            if (Args.Process(args))
            {
                Filenames   = Args.GetStringList("FILE {FILE}");
                Directories = Args.FindOrCreateStringList("dir");

                string EnvironmentVariableName = Args.GetString("env");
                if (!string.IsNullOrEmpty(EnvironmentVariableName))
                {
                    string env = Environment.GetEnvironmentVariable(EnvironmentVariableName, EnvironmentVariableTarget.User);
                    if (string.IsNullOrEmpty(env))
                    {
                        env = Environment.GetEnvironmentVariable(EnvironmentVariableName);
                    }
                    EnvironmentVariablesAlreadyChecked[EnvironmentVariableName] = true;
                    if (string.IsNullOrEmpty(env))
                    {
                        Console.WriteLine(resource.IDS_ERR_invalid_env_var, EnvironmentVariableName);
                    }
                    else
                    {
                        foreach (string token in env.Split(';'))
                        {
                            Directories.Add(token);
                        }
                    }
                }

                if (FilenamesAreIncludes())
                {
                    AddEnvBasedDirectories("INCLUDE");
                }
                else if (FilenamesAreLibs())
                {
                    AddEnvBasedDirectories("LIB");
                }
                else
                {
                    // default: use standard windows lookup
                    Directories.Add(Directory.GetCurrentDirectory());
                    Directories.Add(PathSanitizer.GetWindowsDirectory());
                    Directories.Add(PathSanitizer.Get32BitSystemDirectory());
                    Directories.Add(Environment.SystemDirectory);
                    Directories.Add(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName));
                    Directories.Add(Environment.GetFolderPath(Environment.SpecialFolder.System));
                    Directories.Add(Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.System)));
                    AddEnvBasedDirectories("PATH");
                }

                Directories.MakeUnique(StringComparison.OrdinalIgnoreCase);

                List <string> Extensions = Args.FindOrCreateStringList("extension");
                if (Extensions.Count == 0)
                {
                    foreach (string path in Environment.GetEnvironmentVariable("PATHEXT").Split(';'))
                    {
                        Extensions.Add(path);
                    }
                }

                List <string> FoundItems = new List <string>();
                foreach (string filename in Filenames)
                {
                    bool found = false;
                    foreach (string foundname in Locate(filename))
                    {
                        if (!Contains(FoundItems, foundname))
                        {
                            FileInfo fi = new FileInfo(foundname);

                            Console.WriteLine(resource.IDS_RESULT_PATTERN,
                                              foundname, fi.LastWriteTime, fi.Length);
                            FoundItems.Add(foundname);
                            if (Args.GetFlag("single"))
                            {
                                break;
                            }

                            found = true;
                        }
                    }
                    if (!found)
                    {
                        Console.WriteLine(resource.IDS_ERR_not_found, filename);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// This program allows you to view and modify the PATH environment.
        /// </summary>
        /// <param name="args"></param>
        private void Run(string[] args)
        {
            Console.OutputEncoding = Encoding.GetEncoding(Encoding.Default.CodePage);
            Args = new InputArgs("pathed", string.Format(resource.IDS_TITLE, AppVersion.Get()) + "\r\n" + resource.IDS_COPYRIGHT);

            Args.Add(InputArgType.Flag, "machine", false, Presence.Optional, resource.IDS_CMD_machine_doc);
            Args.Add(InputArgType.Flag, "user", false, Presence.Optional, resource.IDS_CMD_user_doc);
            Args.Add(InputArgType.ExistingDirectory, "add", "", Presence.Optional, resource.IDS_CMD_add_doc);
            Args.Add(InputArgType.ExistingDirectory, "append", "", Presence.Optional, resource.IDS_CMD_append_doc);
            Args.Add(InputArgType.StringList, "remove", null, Presence.Optional, resource.IDS_CMD_remove_doc);
            Args.Add(InputArgType.Flag, "slim", false, Presence.Optional, resource.IDS_CMD_slim_doc);
            Args.Add(InputArgType.Parameter, "env", "PATH", Presence.Optional, resource.IDS_CMD_env_doc);

            if (Args.Process(args))
            {
                EnvironmentVariableName = Args.GetString("env");

                if (Args.GetFlag("slim"))
                {
                    SlimPath();
                }

                if (Args.GetFlag("machine"))
                {
                    EnvironmentVariableTarget = EnvironmentVariableTarget.Machine;
                }

                else if (Args.GetFlag("user"))
                {
                    EnvironmentVariableTarget = EnvironmentVariableTarget.User;
                }

                try
                {
                    List <string> removeItems = Args.GetStringList("remove");
                    if (removeItems != null)
                    {
                        Remove(removeItems);
                    }

                    string add = Args.GetString("add");
                    if (!string.IsNullOrEmpty(add))
                    {
                        AddHead(SanitizePath(add));
                    }

                    string append = Args.GetString("append");
                    if (!string.IsNullOrEmpty(append))
                    {
                        AddTail(SanitizePath(append));
                    }
                }
                catch (SecurityException ex)
                {
                    if (EnvironmentVariableTarget == EnvironmentVariableTarget.Machine)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(resource.IDS_ERR_access_denied);
                        return;
                    }
                    else
                    {
                        throw;
                    }
                }

                ListPath();
            }
        }