예제 #1
0
 public InstallContext(string logFilePath, string[] commandLine)
 {
     this.parameters = InstallContext.ParseCommandLine(commandLine);
     if (this.Parameters["logfile"] == null && logFilePath != null)
     {
         this.Parameters["logfile"] = logFilePath;
     }
 }
예제 #2
0
 public InstallContext(string logFilePath, string[] commandLine)
 {
     Parameters = InstallContext.ParseCommandLine(commandLine);
     if (Parameters["logfile"] != null || logFilePath == null)
     {
         return;
     }
     Parameters["logfile"] = logFilePath;
 }
예제 #3
0
        // Run the installation process.
        private int Install()
        {
            // Scan the command-line options in groups.
            int    posn = 0;
            int    start;
            String arg;
            bool   both;

            uninstall = false;
            if (args.Length == 0)
            {
                Usage();
                return(1);
            }
            while (posn < args.Length)
            {
                // Extract the next group of options.
                start = posn;
                while (posn < args.Length)
                {
                    arg = args[posn];
                    if (arg.Length == 0)
                    {
                        break;
                    }
                    if (arg[0] == '-')
                    {
                        // Option that starts with "-".
                        ++posn;
                        if (arg.Length == 2 && arg[1] == '-')
                        {
                            // We use "--" to terminate the option
                            // list just prior to a filename that
                            // starts with "-" or "/".
                            break;
                        }
                    }
                    else if (arg[0] == '/')
                    {
                        // Compatibility option that starts with "/".
                        ++posn;
                    }
                    else if (arg[0] == '=')
                    {
                        // May be specifying a value for a previous option.
                        ++posn;
                    }
                    else if (posn > start && args[posn - 1].EndsWith("="))
                    {
                        // Specifying a value for a previous option name.
                        ++posn;
                    }
                    else
                    {
                        // This is a filename.
                        break;
                    }
                }

                // Parse the command line options that we just received.
                optionDict = InstallContext.ParseCommandLine
                                 (args, start, posn - start, out options);

                // Extract the filename.
                if (posn < args.Length)
                {
                    filename = args[posn++];
                }
                else
                {
                    filename = null;
                }

                // Create an install context for this option group.
                context = new InstallContext(optionDict);

                // Check for the "uninstall" and "install" flags.
                both = false;
                if (context.IsParameterTrue("uninstall") ||
                    context.IsParameterTrue("u"))
                {
                    uninstall = true;
                    both      = true;
                }
                if (context.IsParameterTrue("install") ||
                    context.IsParameterTrue("i"))
                {
                    if (both)
                    {
                                                #if !CONFIG_SMALL_CONSOLE
                        Console.Error.WriteLine
                            ("{0}: cannot specify both `--install' and " +
                            "`--uninstall'", program);
                                                #else
                        Console.WriteLine
                            ("{0}: cannot specify both `--install' and " +
                            "`--uninstall'", program);
                                                #endif
                        return(1);
                    }
                    uninstall = false;
                }

                // Check for the version flag.
                if (context.IsParameterTrue("version") ||
                    context.IsParameterTrue("v"))
                {
                    Version();
                    return(0);
                }

                // Check for the help flag.
                if (context.IsParameterTrue("help") ||
                    context.IsParameterTrue("h") ||
                    context.IsParameterTrue("?"))
                {
                    if (filename == null)
                    {
                        Usage();
                    }
                    else
                    {
                        PrintHelpFor(filename);
                    }
                    continue;
                }

                // If we don't have a filename, then print the usage.
                if (filename == null)
                {
                    Usage();
                    return(1);
                }

                // Run the installation/uninstallation process.
                if (uninstall)
                {
                    RunUninstall(filename);
                }
                else
                {
                    RunInstall(filename);
                }
            }
            return(0);
        }