예제 #1
0
        /// <summary>
        /// Validates that a commandline parameter is a valid file or directory name, 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 GetFileOrDirectory(string commandlineSwitch, ConsoleMessageHandler messageHandler, string[] args, int index)
        {
            commandlineSwitch = String.Concat("-", commandlineSwitch);

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

            return(VerifyPath(messageHandler, args[index]));
        }
예제 #2
0
        /// <summary>
        /// Validates that a string is a valid directory name, 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>
        /// <param name="allowPrefix">Indicates if a colon-delimited prefix is allowed.</param>
        /// <returns>The string if it is valid, null if it is invalid.</returns>
        public static string GetDirectory(string commandlineSwitch, ConsoleMessageHandler messageHandler, string[] args, int index, bool allowPrefix)
        {
            commandlineSwitch = String.Concat("-", commandlineSwitch);

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

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

            return(VerifyPath(messageHandler, args[index], allowPrefix));
        }
예제 #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
 /// <summary>
 /// Parse the commandline arguments.
 /// </summary>
 /// <param name="args">Commandline arguments.</param>
 /// <param name="consoleMessageHandler">The console message handler.</param>
 public abstract StringCollection ParseCommandLine(string[] args, ConsoleMessageHandler consoleMessageHandler);
예제 #5
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>
 /// <returns>The string if it is valid, null if it is invalid.</returns>
 public static string VerifyPath(ConsoleMessageHandler messageHandler, string path)
 {
     return(VerifyPath(messageHandler, path, false));
 }
예제 #6
0
 /// <summary>
 /// Validates that a string is a valid directory name, 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 GetDirectory(string commandlineSwitch, ConsoleMessageHandler messageHandler, string[] args, int index)
 {
     return(GetDirectory(commandlineSwitch, messageHandler, args, index, false));
 }