private void button5_Click(object sender, EventArgs e) { //read some part of icu data IcuDataParser icuDataParser = new IcuDataParser(); Dictionary <string, string> short_to_lang = new Dictionary <string, string>(); Dictionary <string, string> lang_to_short = new Dictionary <string, string>(); //------- Dictionary <string, string> short_to_script = new Dictionary <string, string>(); Dictionary <string, string> script_to_short = new Dictionary <string, string>(); using (FileStream fs = new FileStream("icu_data/data/lang/en.txt", FileMode.Open)) { icuDataParser.ParseData(fs); IcuDataTree tree = icuDataParser.ResultTree; IcuDataNode node = tree.RootNode; { //lang node IcuDataNode langNode = node?.GetFirstChildNode("Languages"); if (langNode != null) { //now we can get data from the node //get all lang //collect all data to int count = langNode.ChildCount; for (int i = 0; i < count; ++i) { IcuDataNode childNode = langNode.GetNode(i); short_to_lang.Add(childNode.Name, childNode.TextValue); lang_to_short.Add(childNode.TextValue, childNode.Name); } } } { //script node IcuDataNode scriptNode = node?.GetFirstChildNode("Scripts"); if (scriptNode != null) { int count = scriptNode.ChildCount; for (int i = 0; i < count; ++i) { IcuDataNode childNode = scriptNode.GetNode(i); short_to_script.Add(childNode.Name, childNode.TextValue); script_to_short.Add(childNode.TextValue, childNode.Name); } } } } //--------------------------------- LoadUnicode13Ranges(); //try mapping exact lang and script Dictionary <string, MappingLangAndScript> mappingLangAndScripts = new Dictionary <string, MappingLangAndScript>(); //since we have script < lang, so //match name List <string> notFoundList = new List <string>(); foreach (var kv in script_to_short) { string script_name = kv.Key; string script_tag = kv.Value; if (lang_to_short.TryGetValue(script_name, out string lang_short)) { //try map script name with lang //found mappingLangAndScripts.Add(script_name, new MappingLangAndScript() { FullLangName = script_name, ShortScript = script_tag, ShortLang = lang_short }); } else { if (_unicode13Dic.TryGetValue(script_name, out UnicodeRangeInfo rangeInfo)) { mappingLangAndScripts.Add(script_name, new MappingLangAndScript() { FullLangName = rangeInfo.RangeName, ShortScript = script_tag, ShortLang = "?" }); } else { //not found notFoundList.Add(script_name); } } } //--------------------------------- //--------------------------------- //write notFoundList { using (FileStream fs = new FileStream("not_found_langs.txt", FileMode.Create)) using (StreamWriter w = new StreamWriter(fs)) { foreach (string notFoundLang in notFoundList) { w.WriteLine(notFoundLang); } w.Close(); } } }
public static int Main(string[] args) { LogFile.AddLine("================= Start of process ================="); LogFile.AddLine("Command line: <" + Environment.CommandLine + ">"); bool testedLock = false; ErrorCodes ret = ErrorCodes.None; try { CommandLineParser argParser = new CommandLineParser(); CommandLineParser.ParseResult parseResult = argParser.Parse(args); switch (parseResult) { case CommandLineParser.ParseResult.error: ret = ErrorCodes.CommandLine; int iRet = (int)ErrorCodes.CommandLine; LogFile.Release(); return(iRet); case CommandLineParser.ParseResult.stop: LogFile.Release(); // no error - success return((int)(ErrorCodes.Success)); } // tests the command line parser to make sure we have valid data if (argParser.FlagUsed(CommandLineParser.Flag.dontDoAnything)) { foreach (CommandLineParser.Flag flag in argParser.FlagsUsed()) { Console.Write("{0}:{1}, ", flag.ToString(), argParser.FlagData(flag)); } Console.WriteLine(); return((int)ErrorCodes.Success); } // don't restrict the GUI bool runSilent = false; if (argParser.FlagUsed(CommandLineParser.Flag.q)) { runSilent = true; } bool slow = false; // Use the old slower file reading method if (argParser.FlagUsed(CommandLineParser.Flag.slow)) { slow = true; } if (argParser.FlagUsed(CommandLineParser.Flag.testMainParserRoutine)) { LocaleFileClass localeObject = new LocaleFileClass(); bool successParsing = localeObject.TestBaseLocaleParsers(false); if (successParsing) { ret = ErrorCodes.Success; } else { ret = ErrorCodes.LDParsingError; } } if (argParser.FlagUsed(CommandLineParser.Flag.testICUDataParser)) { try { IcuDataNode.TestIcuDataNode(argParser.FlagData(CommandLineParser.Flag.testICUDataParser)); ret = ErrorCodes.Success; } catch (LDExceptions e) { ret = e.ec; LogFile.AddErrorLine("LDException: " + e.ec.ToString() + "-" + Error.Text(e.ec)); if (e.HasConstructorText) { LogFile.AddErrorLine("LDException Msg: " + e.ConstructorText); } } catch (System.Exception e) { ret = ErrorCodes.NonspecificError; LogFile.AddErrorLine(e.Message); LogFile.AddErrorLine(e.StackTrace); } } if (argParser.FlagUsed(CommandLineParser.Flag.s)) { LocaleFileClass localeObject = new LocaleFileClass(); localeObject.RunSilent = runSilent; ret = localeObject.ShowCustomLocales(); } if (argParser.FlagUsed(CommandLineParser.Flag.customLanguages)) { LocaleFileClass localeObject = new LocaleFileClass(); localeObject.RunSilent = runSilent; ret = localeObject.ShowCustomLanguages(); } if (argParser.FlagUsed(CommandLineParser.Flag.o)) // restore origs' { CallingID cid = CallingID.CID_RESTORE; if (argParser.FlagUsed(CommandLineParser.Flag.newlang)) { cid = CallingID.CID_NEW; // internal new lang case } if (!CheckForIcuLocked(null, runSilent, cid)) { return((int)ErrorCodes.CancelAccessFailure); } testedLock = true; // only perform this command by itself even if given with other options LocaleFileClass restoreFiles = new LocaleFileClass(); restoreFiles.RunSlow = slow; restoreFiles.RunSilent = runSilent; // Restore all the original files, installing the PUA characters if requested. ret = restoreFiles.RestoreOrigFiles(true); // LT-5374 : wasn't moving the res files from the Icu34 dir to the Icudt34l dir if (ret == ErrorCodes.Success) { // remove the backup files from the undo/recover file name list restoreFiles.RemoveBackupFiles(); } restoreFiles.RemoveTempFiles(); restoreFiles.MoveNewResFilesToSubDir(); } if (argParser.FlagUsed(CommandLineParser.Flag.r)) // remove locale { if (!testedLock && !CheckForIcuLocked(argParser.FlagData(CommandLineParser.Flag.r), runSilent, CallingID.CID_REMOVE)) { return((int)ErrorCodes.CancelAccessFailure); } testedLock = true; string deleteLocale = argParser.FlagData(CommandLineParser.Flag.r); argParser.RemoveFlag(CommandLineParser.Flag.r); bool rUsed = argParser.FlagUsed(CommandLineParser.Flag.r); LocaleFileClass removeLocaleObject = new LocaleFileClass(); try { removeLocaleObject.RunSilent = runSilent; ret = removeLocaleObject.RemoveLocale(deleteLocale); removeLocaleObject.MoveNewResFilesToSubDir(); } catch (System.Exception e) { ret = ErrorCodes.NonspecificError; LogFile.AddErrorLine(e.Message); LogFile.AddErrorLine(e.StackTrace); LogFile.AddErrorLine("Exception: " + ret.ToString() + "-" + Error.Text(ret)); removeLocaleObject.RestoreFiles(); // copy backup files to original files. } } // install locale if ((ret == ErrorCodes.Success || ret == ErrorCodes.None) && argParser.FlagUsed(CommandLineParser.Flag.i)) { CallingID cid = CallingID.CID_INSTALL; if (argParser.FlagUsed(CommandLineParser.Flag.newlang)) { cid = CallingID.CID_NEW; // internal new lang case } if (!testedLock && !CheckForIcuLocked( argParser.FlagData(CommandLineParser.Flag.i), runSilent, cid)) { return((int)ErrorCodes.CancelAccessFailure); } testedLock = true; LocaleFileClass localeFileObject = new LocaleFileClass(); localeFileObject.RunSilent = runSilent; localeFileObject.RunSlow = slow; try { string addLocale = argParser.FlagData(CommandLineParser.Flag.i); localeFileObject.InstallLDFile(addLocale); ret = ErrorCodes.Success; } catch (LDExceptions e) { localeFileObject.RestoreFiles(); // copy backup files to original files. ret = e.ec; LogFile.AddErrorLine("LDException: " + e.ec.ToString() + "-" + Error.Text(e.ec)); if (e.HasConstructorText) { LogFile.AddErrorLine("LDException Msg: " + e.ConstructorText); } } catch (System.Exception e) { ret = ErrorCodes.NonspecificError; LogFile.AddErrorLine(e.Message); LogFile.AddErrorLine(e.StackTrace); LogFile.AddErrorLine("Exception: " + ret.ToString() + "-" + Error.Text(ret)); localeFileObject.RestoreFiles(); // copy backup files to original files. } if (ret == ErrorCodes.Success) { // remove the backup files from the undo/recover file name list localeFileObject.RemoveBackupFiles(); } localeFileObject.RemoveTempFiles(); localeFileObject.MoveNewResFilesToSubDir(); } //Add PUA Character if ((ret == ErrorCodes.Success || ret == ErrorCodes.None) && argParser.FlagUsed(CommandLineParser.Flag.c)) { if (!testedLock && !CheckForIcuLocked(argParser.FlagData(CommandLineParser.Flag.c), runSilent, CallingID.CID_UNKNOWN)) { return((int)ErrorCodes.CancelAccessFailure); } LocaleFileClass localeFileObject = new LocaleFileClass(); localeFileObject.RunSilent = runSilent; try { string addLocale = argParser.FlagData(CommandLineParser.Flag.c); localeFileObject.InstallPUACharacters(addLocale); ret = ErrorCodes.Success; } catch (LDExceptions e) { // copy backup files to original files. localeFileObject.RestoreFiles(); ret = e.ec; LogFile.AddErrorLine("LDException: " + e.ec.ToString() + "-" + Error.Text(e.ec)); if (e.HasConstructorText) { LogFile.AddErrorLine("LDException Msg: " + e.ConstructorText); } } catch (System.Exception e) { ret = ErrorCodes.NonspecificError; LogFile.AddErrorLine("Exception: " + e.Message); LogFile.AddErrorLine(e.StackTrace); LogFile.AddErrorLine("Error Code: " + ret.ToString() + "-" + Error.Text(ret)); localeFileObject.RestoreFiles(); // copy backup files to original files. } if (ret == ErrorCodes.Success) { // remove the backup files from the undo/recover file name list localeFileObject.RemoveBackupFiles(); } localeFileObject.RemoveTempFiles(); } if (ret == ErrorCodes.Success) { if (argParser.FlagUsed(CommandLineParser.Flag.q)) { LogFile.AddLine("--- Success ---"); } else { LogFile.AddErrorLine("--- Success ---"); } } } catch (System.Exception e) { ret = ErrorCodes.NonspecificError; LogFile.AddErrorLine("Exception: " + e.Message + " " + e.StackTrace); LogFile.AddErrorLine("Exception: " + ret.ToString() + "-" + Error.Text(ret)); } finally { LogFile.Release(); } int nret = (int)ret; return(nret); }