コード例 #1
0
        /// <summary>
        /// Validates that a string is a valid filename, and throws appropriate warnings/errors if not
        /// </summary>
        /// <param name="commandlineSwitch">The commandline switch we're parsing (for error display purposes).</param>
        /// <param name="messageHandler">The messagehandler to report warnings/errors to.</param>
        /// <param name="args">The list of strings to check.</param>
        /// <param name="index">The index (in args) of the commandline parameter to be parsed.</param>
        /// <returns>The string if it is valid, null if it is invalid.</returns>
        public static string GetFile(string commandlineSwitch, ConsoleMessageHandler messageHandler, string[] args, int index)
        {
            commandlineSwitch = String.Concat("-", commandlineSwitch);

            if (!IsValidArg(args, index))
            {
                messageHandler.Display(null, WixErrors.FilePathRequired(commandlineSwitch));
                return(null);
            }

            if (Directory.Exists(args[index]))
            {
                messageHandler.Display(null, WixErrors.ExpectedFileGotDirectory(commandlineSwitch, args[index]));
                return(null);
            }

            return(VerifyPath(messageHandler, args[index]));
        }
コード例 #2
0
ファイル: CommandLine.cs プロジェクト: zooba/wix3
        /// <summary>
        /// Validates that a string is a valid filename, and throws appropriate warnings/errors if not
        /// </summary>
        /// <param name="commandlineSwitch">The commandline switch we're parsing (for error display purposes).</param>
        /// <param name="messageHandler">The messagehandler to report warnings/errors to.</param>
        /// <param name="args">The list of strings to check.</param>
        /// <param name="index">The index (in args) of the commandline parameter to be parsed.</param>
        /// <returns>The string if it is valid, null if it is invalid.</returns>
        public static string GetFile(string commandlineSwitch, ConsoleMessageHandler messageHandler, string[] args, int index)
        {
            commandlineSwitch = String.Concat("-", commandlineSwitch);

            if (!IsValidArg(args, index))
            {
                messageHandler.Display(null, WixErrors.FilePathRequired(commandlineSwitch));
                return null;
            }

            if (Directory.Exists(args[index]))
            {
                messageHandler.Display(null, WixErrors.ExpectedFileGotDirectory(commandlineSwitch, args[index]));
                return null;
            }

            return VerifyPath(messageHandler, args[index]);
        }
コード例 #3
0
        /// <summary>
        /// Validates that a commandline parameter is a valid file or directory name, and throws appropriate warnings/errors if not
        /// </summary>
        /// <param name="messageHandler">The messagehandler to report warnings/errors to.</param>
        /// <param name="path">The path to test.</param>
        /// <param name="allowPrefix">Indicates if a colon-delimited prefix is allowed.</param>
        /// <returns>The full path if it is valid, null if it is invalid.</returns>
        public static string VerifyPath(ConsoleMessageHandler messageHandler, string path, bool allowPrefix)
        {
            string fullPath;

            if (0 <= path.IndexOf('\"'))
            {
                messageHandler.Display(null, WixErrors.PathCannotContainQuote(path));
                return(null);
            }

            try
            {
                string prefix = null;
                if (allowPrefix)
                {
                    int prefixLength = path.IndexOf('=') + 1;
                    if (0 != prefixLength)
                    {
                        prefix = path.Substring(0, prefixLength);
                        path   = path.Substring(prefixLength);
                    }
                }

                if (String.IsNullOrEmpty(prefix))
                {
                    fullPath = Path.GetFullPath(path);
                }
                else
                {
                    fullPath = String.Concat(prefix, Path.GetFullPath(path));
                }
            }
            catch (Exception e)
            {
                messageHandler.Display(null, WixErrors.InvalidCommandLineFileName(path, e.Message));
                return(null);
            }

            return(fullPath);
        }
コード例 #4
0
ファイル: CommandLine.cs プロジェクト: Jeremiahf/wix3
        /// <summary>
        /// Validates that a commandline parameter is a valid file or directory name, and throws appropriate warnings/errors if not
        /// </summary>
        /// <param name="messageHandler">The messagehandler to report warnings/errors to.</param>
        /// <param name="path">The path to test.</param>
        /// <param name="allowPrefix">Indicates if a colon-delimited prefix is allowed.</param>
        /// <returns>The full path if it is valid, null if it is invalid.</returns>
        public static string VerifyPath(ConsoleMessageHandler messageHandler, string path, bool allowPrefix)
        {
            string fullPath;

            if (0 <= path.IndexOf('\"'))
            {
                messageHandler.Display(null, WixErrors.PathCannotContainQuote(path));
                return null;
            }

            try
            {
                string prefix = null;
                if (allowPrefix)
                {
                    int prefixLength = path.IndexOf('=') + 1;
                    if (0 != prefixLength)
                    {
                      prefix = path.Substring(0, prefixLength);
                      path = path.Substring(prefixLength);
                    }
                }

                if (String.IsNullOrEmpty(prefix))
                {
                    fullPath = Path.GetFullPath(path);
                }
                else
                {
                    fullPath = String.Concat(prefix, Path.GetFullPath(path));
                }
            }
            catch (Exception e)
            {
                messageHandler.Display(null, WixErrors.InvalidCommandLineFileName(path, e.Message));
                return null;
            }

            return fullPath;
        }
コード例 #5
0
ファイル: Binder.cs プロジェクト: zooba/wix3
        public override StringCollection ParseCommandLine(string[] args, ConsoleMessageHandler consoleMessageHandler)
        {
            for (int i = 0; i < args.Length; ++i)
            {
                string arg = args[i];
                if (null == arg || 0 == arg.Length) // skip blank arguments
                {
                    continue;
                }

                if ('-' == arg[0] || '/' == arg[0])
                {
                    string parameter = arg.Substring(1);
                    if (parameter.Equals("bcgg", StringComparison.Ordinal))
                    {
                        consoleMessageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch(parameter));
                        this.backwardsCompatibleGuidGen = true;
                    }
                    else if (parameter.Equals("cc", StringComparison.Ordinal))
                    {
                        this.cabCachePath = CommandLine.GetDirectory(parameter, consoleMessageHandler, args, ++i);

                        if (String.IsNullOrEmpty(this.cabCachePath))
                        {
                            return this.invalidArgs;
                        }
                    }
                    else if (parameter.Equals("ct", StringComparison.Ordinal))
                    {
                        if (!CommandLine.IsValidArg(args, ++i))
                        {
                            consoleMessageHandler.Display(this, WixErrors.IllegalCabbingThreadCount(String.Empty));
                            return this.invalidArgs;
                        }

                        try
                        {
                            this.cabbingThreadCount = Convert.ToInt32(args[i], CultureInfo.InvariantCulture.NumberFormat);

                            if (0 >= this.cabbingThreadCount)
                            {
                                consoleMessageHandler.Display(this, WixErrors.IllegalCabbingThreadCount(args[i]));
                            }

                            consoleMessageHandler.Display(this, WixVerboses.SetCabbingThreadCount(this.cabbingThreadCount.ToString()));
                        }
                        catch (FormatException)
                        {
                            consoleMessageHandler.Display(this, WixErrors.IllegalCabbingThreadCount(args[i]));
                        }
                        catch (OverflowException)
                        {
                            consoleMessageHandler.Display(this, WixErrors.IllegalCabbingThreadCount(args[i]));
                        }
                    }
                    else if (parameter.Equals("cub", StringComparison.Ordinal))
                    {
                        string cubeFile = CommandLine.GetFile(parameter, consoleMessageHandler, args, ++i);

                        if (String.IsNullOrEmpty(cubeFile))
                        {
                            return this.invalidArgs;
                        }

                        this.validator.AddCubeFile(cubeFile);
                    }
                    else if (parameter.StartsWith("dcl:", StringComparison.Ordinal))
                    {
                        string defaultCompressionLevel = arg.Substring(5);

                        if (String.IsNullOrEmpty(defaultCompressionLevel))
                        {
                            return this.invalidArgs;
                        }

                        this.defaultCompressionLevel = WixCreateCab.CompressionLevelFromString(defaultCompressionLevel);
                    }
                    else if (parameter.Equals("eav", StringComparison.Ordinal))
                    {
                        this.exactAssemblyVersions = true;
                    }
                    else if (parameter.Equals("fv", StringComparison.Ordinal))
                    {
                        this.setMsiAssemblyNameFileVersion = true;
                    }
                    else if (parameter.StartsWith("ice:", StringComparison.Ordinal))
                    {
                        this.ices.Add(parameter.Substring(4));
                    }
                    else if (parameter.Equals("contentsfile", StringComparison.Ordinal))
                    {
                        this.contentsFile = CommandLine.GetFile(parameter, consoleMessageHandler, args, ++i);

                        if (String.IsNullOrEmpty(this.contentsFile))
                        {
                            return this.invalidArgs;
                        }
                    }
                    else if (parameter.Equals("outputsfile", StringComparison.Ordinal))
                    {
                        this.outputsFile = CommandLine.GetFile(parameter, consoleMessageHandler, args, ++i);

                        if (String.IsNullOrEmpty(this.outputsFile))
                        {
                            return this.invalidArgs;
                        }
                    }
                    else if (parameter.Equals("builtoutputsfile", StringComparison.Ordinal))
                    {
                        this.builtOutputsFile = CommandLine.GetFile(parameter, consoleMessageHandler, args, ++i);

                        if (String.IsNullOrEmpty(this.builtOutputsFile))
                        {
                            return this.invalidArgs;
                        }
                    }
                    else if (parameter.Equals("wixprojectfile", StringComparison.Ordinal))
                    {
                        this.wixprojectFile = CommandLine.GetFile(parameter, consoleMessageHandler, args, ++i);

                        if (String.IsNullOrEmpty(this.wixprojectFile))
                        {
                            return this.invalidArgs;
                        }
                    }
                    else if (parameter.Equals("O1", StringComparison.Ordinal))
                    {
                        consoleMessageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("O1"));
                    }
                    else if (parameter.Equals("O2", StringComparison.Ordinal))
                    {
                        consoleMessageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("O2"));
                    }
                    else if (parameter.Equals("pdbout", StringComparison.Ordinal))
                    {
                        this.pdbFile = CommandLine.GetFile(parameter, consoleMessageHandler, args, ++i);

                        if (String.IsNullOrEmpty(this.pdbFile))
                        {
                            return this.invalidArgs;
                        }
                    }
                    else if (parameter.Equals("reusecab", StringComparison.Ordinal))
                    {
                        this.reuseCabinets = true;
                    }
                    else if (parameter.Equals("sa", StringComparison.Ordinal))
                    {
                        consoleMessageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch(parameter));
                        this.suppressAssemblies = true;
                    }
                    else if (parameter.Equals("sacl", StringComparison.Ordinal))
                    {
                        this.suppressAclReset = true;
                    }
                    else if (parameter.Equals("sbuildinfo", StringComparison.Ordinal))
                    {
                        consoleMessageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch(parameter));
                    }
                    else if (parameter.Equals("sf", StringComparison.Ordinal))
                    {
                        consoleMessageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch(parameter));
                        this.suppressAssemblies = true;
                        this.suppressFileHashAndInfo = true;
                    }
                    else if (parameter.Equals("sh", StringComparison.Ordinal))
                    {
                        consoleMessageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch(parameter));
                        this.suppressFileHashAndInfo = true;
                    }
                    else if (parameter.StartsWith("sice:", StringComparison.Ordinal))
                    {
                        this.suppressICEs.Add(parameter.Substring(5));
                    }
                    else if (parameter.Equals("sl", StringComparison.Ordinal))
                    {
                        this.suppressLayout = true;
                    }
                    else if (parameter.Equals("spdb", StringComparison.Ordinal))
                    {
                        this.suppressWixPdb = true;
                    }
                    else if (parameter.Equals("spsd", StringComparison.Ordinal))
                    {
                        this.suppressPatchSequenceData = true;
                    }
                    else if (parameter.Equals("sval", StringComparison.Ordinal))
                    {
                        this.suppressValidation = true;
                    }
                    else
                    {
                        this.invalidArgs.Add(arg);
                    }
                }
                else
                {
                    this.invalidArgs.Add(arg);
                }
            }

            this.pdbFile = this.suppressWixPdb ? null : this.pdbFile;

            return this.invalidArgs;
        }