Esempio n. 1
0
        private static void MainScan(List <string> args)
        {
            // Extract options, leaving only files/directories in place
            for (int a = 0, aLen = args.Count; a < aLen; a++)
            {
                string arg = args[a];
                if (arg.StartsWith("--"))
                {
                    switch (arg.Substring(2))
                    {
                    case "no-exitcode":
                        Options.NoExitcode = true;
                        break;

                    case "relaxed":
                        Options.Relaxed = true;
                        break;

                    default:
                        Report($"Unknown option '{arg}'");
                        return;
                    }
                    args.RemoveAt(a--);
                    aLen--;
                }
            }

            // if started without arguments, check current directory
            if (args.Count == 0)
            {
                args.Add(".");
            }

            Console.Write("Scanning files...");

            List <string> files = new List <string>();

            foreach (string arg in args)
            {
                FileAttributes attributes;
                try
                {
                    attributes = File.GetAttributes(arg);
                }
                catch
                {
                    Report($"ERROR: Cannot access '{arg}' attributes");
                    return;
                }

                // TODO (Linux): `ScanMsg /root` results in crash

                if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    files.AddRange(Directory.GetFiles(arg, "*.*", SearchOption.AllDirectories).Where(file => file.ToLower().EndsWith(".msg")).OrderBy(f => f));
                }
                else if (File.Exists(arg))
                {
                    files.Add(arg);
                }
                else
                {
                    Report($"ERROR: Invalid target '{arg}'");
                    return;
                }
            }
            Console.WriteLine($" {files.Count} found");

            foreach (string fname in files)
            {
                string report = "";
                string file   = fname.Replace('\\', '/').Replace('/', Path.DirectorySeparatorChar);
                if (file.StartsWith(".\\") || file.StartsWith("./"))
                {
                    file = file.Substring(2);
                }

                FalloutMsg            msg    = new FalloutMsg(file);
                FalloutMsg.LoadStatus status = msg.Load(ref report);

                if (report.Length > 0)
                {
                    Report(report);
                }
                else if (status != FalloutMsg.LoadStatus.OK)
                {
                    Report($"WARNING: missing report for error<{status.ToString()}> [{file}]");
                }
            }
        }
Esempio n. 2
0
        private static void MainLang(List <string> args)
        {
            string usage = "USAGE: ScanMsg --language-base [path/to/text/language] --translations [path/to/text/translation1] <path/to/text/translation2> ...";

            if (args.Count < 4)
            {
                Report(usage);
                return;
            }
            else if (args[0] != "--language-base" || args[2] != "--translations")
            {
                Report(usage);
                return;
            }

            args.RemoveAt(0);   // --language-base
            args.RemoveAt(1);   // --translations

            for (int d = 0, dLen = args.Count; d < dLen; d++)
            {
                if (!Directory.Exists(args[d]))
                {
                    Report($"ERROR: Invalid directory {args[d]}");
                    return;
                }
                args[d] = args[d].Replace('\\', '/').Replace('/', Path.DirectorySeparatorChar);
            }

            Console.Write("Scanning files...");

            string baseDir = args[0];

            args.RemoveAt(0);   // base language

            List <string> baseFiles = Directory.GetFiles(baseDir, "*.*", SearchOption.AllDirectories).Where(file => file.ToLower().EndsWith(".msg")).OrderBy(f => f).Select(file => { return(file.Substring(baseDir.Length).TrimStart('/', '\\')); }).ToList();

            Console.WriteLine($" {baseFiles.Count} found");

            Dictionary <string, FalloutMsg> baseLang = new Dictionary <string, FalloutMsg>();

            foreach (string langDir in args)
            {
                foreach (string baseFile in baseFiles)
                {
                    string file = Path.Combine(langDir, baseFile);
                    if (file.StartsWith(".\\") || file.StartsWith("./"))
                    {
                        file = file.Substring(2);
                    }

                    if (!File.Exists(file))
                    {
                        Report($"file does not exists [{file}]");
                        continue;
                    }

                    string report = "";

                    FalloutMsg            baseMsg, langMsg;
                    FalloutMsg.LoadStatus status;

                    if (baseLang.ContainsKey(baseFile))
                    {
                        baseMsg = baseLang[baseFile];
                    }
                    else
                    {
                        baseMsg = new FalloutMsg(Path.Combine(baseDir, baseFile));
                        status  = baseMsg.Load(ref report);

                        if (report.Length > 0)
                        {
                            Report(report);
                        }
                        else if (status != FalloutMsg.LoadStatus.OK)
                        {
                            Report($"WARNING: missing report for error<{status.ToString()}> [{file}]");
                        }

                        // cannot continue if base language .msg contains errors
                        if (report.Length > 0 || status != FalloutMsg.LoadStatus.OK)
                        {
                            continue;
                        }

                        baseLang[baseFile] = baseMsg;
                        report             = "";
                    }

                    langMsg = new FalloutMsg(file);
                    status  = langMsg.Load(ref report);

                    if (report.Length > 0)
                    {
                        Report(report);
                    }
                    else if (status != FalloutMsg.LoadStatus.OK)
                    {
                        Report($"WARNING: missing report for error<{status.ToString()}> [{file}]");
                    }

                    // cannot continue if translation .msg contains errors
                    if (report.Length > 0 || status != FalloutMsg.LoadStatus.OK)
                    {
                        continue;
                    }

                    //

                    foreach (KeyValuePair <uint, FalloutMsg.MsgEntry> kvp in baseMsg.Msg)
                    {
                        if (!langMsg.Msg.ContainsKey(kvp.Key))
                        {
                            Report($"message id {{{kvp.Key}}} missing [{file}]");
                            continue;
                        }

                        string textBase = string.Join(" ", kvp.Value.Text.ToArray());
                        string textLang = string.Join(" ", langMsg.Msg[kvp.Key].Text.ToArray());

                        if (string.IsNullOrEmpty(textBase) && !string.IsNullOrEmpty(textLang))
                        {
                            Report($"message id {{{kvp.Key}}} should be empty [{file}]");
                            // Report( $"base  {textBase}" );
                            // Report( $"lang  {textLang}" );
                        }
                        else if (!string.IsNullOrEmpty(textBase) && string.IsNullOrEmpty(textLang))
                        {
                            Report($"message id {{{kvp.Key}}} should not be empty [{file}]");
                            // Report( $"base  {textBase}" );
                            // Report( $"lang  {textLang}" );
                        }
                    }
                }
            }
        }