예제 #1
0
파일: Main.cs 프로젝트: austhomp/resgenEx
        static int Main(string[] args)
        {
            bool compileMultiple = false;
            bool useSourcePath = false;
            ArrayList inputFiles = new ArrayList();
            Options options = new Options(CommentOptions.writeFullComments, false);

            for (int i = 0; i < args.Length; i++) {
                switch (args[i].ToLower()) {
                    case "-h":
                    case "/h":
                    case "-?":
                    case "/?":
                        Usage();
                        return 1;
                    /* this version has been specialized for use converting between '.resx' 
                     * and '.po' files, other formats will now fail! /compile is only used
                     * for '.resources' files.
                    case "/compile":
                    case "-compile":
                        // takes a list of .resX or .txt files to convert to .resources files
                        // in one bulk operation, replacing .ext with .resources for the 
                        // output file name (if not set).

                        if (inputFiles.Count > 0) {
                            // the /compile option should be specified before any files
                            Usage ();
                            return 1;
                        }
                        compileMultiple = true;
                        break;
                    */
                    case "/usesourcepath":
                    case "-usesourcepath":
                        // to resolve relative file paths, use the directory of the resource 
                        // file as current directory.

                        if (compileMultiple) {
                            // the /usesourcepath option should not appear after the
                            // /compile switch on the command-line
                            Console.WriteLine("ResGen : error RG0000: Invalid "
                                + "command line syntax.  Switch: \"/compile\"  Bad value: "
                                + args[i] + ".  Use ResGen /? for usage information.");
                            return 1;
                        }
                        useSourcePath = true;
                        break;

                    case "/nocomments":
                    case "-nocomments":
                        // don't export the rawComments from the source file to the destination 
                        // format, and don't include automatically created comments.

                        if (options.Comments == CommentOptions.writeSourceCommentsOnly) {
                            // the /nocomments option should not appear after the
                            // /sourcecommentsonly switch on the command-line
                            Console.WriteLine("ResGen : error RG0000: Invalid command line syntax.  Switch: \"/nocomments\" cannot be used with \"/sourcecommentsonly\"");
                            return 1;
                        }
                        options.Comments = CommentOptions.writeNoComments;
                        break;

                    case "/sourcecommentsonly":
                    case "-sourcecommentsonly":
                        // only export comments to the destination format that existed in the
                        // source file. Do not include automatically created comments.

                        if (options.Comments == CommentOptions.writeNoComments) {
                            // the /nocomments option should not appear after the
                            // /sourcecommentsonly switch on the command-line
                            Console.WriteLine("ResGen : error RG0000: Invalid command line syntax.  Switch: \"/nocomments\" cannot be used with \"/sourcecommentsonly\"");
                            return 1;
                        }
                        options.Comments = CommentOptions.writeSourceCommentsOnly;
                        break;

                    case "/addformatflags":
                    case "-addformatflags":
                        // Format flags in a .po like csharp-format tells the tools to check that the msgid and msgstr 
                        // contain the same number of format specifications, but if your not using the english 
                        // strings as msgids then this just creates a bunch of erroneous warnings.

                        options.FormatFlags = true;
                        break;

                    default:
                        if (!IsFileArgument(args[i])) {
                            Usage();
                            return 1;
                        }

                        ResourceInfo resInf = new ResourceInfo();
                        if (compileMultiple) {
                            string[] pair = args[i].Split(',');
                            switch (pair.Length) {
                                case 1:
                                    resInf.InputFile = Path.GetFullPath(pair[0]);
                                    resInf.OutputFile = Path.ChangeExtension(resInf.InputFile,
                                        "resx");
                                    break;
                                case 2:
                                    if (pair[1].Length == 0) {
                                        Console.WriteLine(@"error: You must specify an input & outfile file name like this:");
                                        Console.WriteLine("inFile.po,outFile.resx.");
                                        Console.WriteLine("You passed in '{0}'.", args[i]);
                                        return 1;
                                    }
                                    resInf.InputFile = Path.GetFullPath(pair[0]);
                                    resInf.OutputFile = Path.GetFullPath(pair[1]);
                                    break;
                                default:
                                    Usage();
                                    return 1;
                            }
                        } else {
                            if ((i + 1) < args.Length) {
                                resInf.InputFile = Path.GetFullPath(args[i]);
                                // move to next arg, since we assume that one holds
                                // the name of the output file
                                i++;
                                resInf.OutputFile = Path.GetFullPath(args[i]);
                            } else {
                                resInf.InputFile = Path.GetFullPath(args[i]);
                                resInf.OutputFile = Path.ChangeExtension(resInf.InputFile,
                                    "resx");
                            }
                        }
                        inputFiles.Add(resInf);
                        break;
                }
            }

            if (inputFiles.Count == 0) {
                Usage();
                return 1;
            }

            foreach (ResourceInfo res in inputFiles) {
                int ret = CompileResourceFile(res.InputFile, res.OutputFile, useSourcePath, options);
                if (ret != 0)
                    return ret;
            }
            return 0;
        }