public RCFileItem GetStringLineForName(string aStringResourceName, HeaderId aStringResourceID) { if (aStringResourceID.Value == Constants.kNotFoundID.Value) { foreach (var idx in StringTableContent.Keys) { foreach (var element in StringTableContent[idx]) { if (element.Name == aStringResourceName) { return(element); } } } } else { var stringTableIndex = StringTableIndexCalculator.CalculateIndex(aStringResourceID); if (!StringTableContent.ContainsKey(stringTableIndex)) { return(null); } foreach (var element in StringTableContent[stringTableIndex]) { if (element.Name == aStringResourceName) { return(element); } } } return(null); }
public static void AddItem(TestItem aTestItem, RCFileContent aRCFileContent, HeaderContent aHeaderContent) { var stringTableContent = aRCFileContent.StringTableContent; var stringTableIndexOrder = aRCFileContent.StringTableIndexOrder; var determinedStringTableIndex = StringTableIndexCalculator.CalculateIndex(aTestItem.ID); // Check if StringTable with index currentIdx exists if (!stringTableContent.ContainsKey(determinedStringTableIndex)) { stringTableContent.Add(determinedStringTableIndex, new List <RCFileItem>()); stringTableIndexOrder.Add(determinedStringTableIndex); } var printStyle = StringTablePrintStyleDeterminer.DeterminePrintStyle(aTestItem.Name, aTestItem.Value); bool notYetAdded = true; var startIndex = (stringTableContent[determinedStringTableIndex].Count / Constants.kStringTableCapacity) * Constants.kStringTableCapacity; int testItemID; if (aTestItem.ID.IsHexa) { testItemID = Convert.ToInt32(aTestItem.ID.Value, 16); } else { testItemID = Convert.ToInt32(aTestItem.ID.Value); } for (int i = startIndex; i < stringTableContent[determinedStringTableIndex].Count; ++i) { var currentName = stringTableContent[determinedStringTableIndex][i].Name; if (!aHeaderContent.NameToID.TryGetValue(currentName, out var currentIDString)) { continue; } if (!int.TryParse(currentIDString.Value, out var currentID)) { continue; } if (testItemID < currentID) { stringTableContent[determinedStringTableIndex].Insert(i, new RCFileItem { Name = aTestItem.Name, Value = aTestItem.Value, ID = aTestItem.ID, PrintStyle = printStyle }); notYetAdded = false; break; } } if (!notYetAdded) { return; } stringTableContent[determinedStringTableIndex].Add( new RCFileItem { Name = aTestItem.Name, Value = aTestItem.Value, ID = aTestItem.ID, PrintStyle = printStyle }); notYetAdded = false; }
private void ParseRCFile(string aPath, Encoding aCodePage, HeaderContent aHeaderContent) { using (var stringTableParser = new RCFileParser(aPath, aCodePage)) { int currentStringTableIndex = Constants.kNotDiscovered; // Index of current STable int previousStringTableIndex = Constants.kNotDiscovered; // Index of previous STable int unusedSTableIndex = 0; List <RCFileItem> unusedElements = new List <RCFileItem>(); while (stringTableParser.HasNext()) { var obj = stringTableParser.GetNext(); if (obj.Name == "BEGIN") { continue; } if (obj.Name == "END") // End of the current STable { if (currentStringTableIndex != Constants.kNotDiscovered && previousStringTableIndex != currentStringTableIndex) // If index has been calculated and it is new { mRCFileContent.StringTableIndexOrder.Add(currentStringTableIndex); // Add current index to the order list // Add unused to the beginning mRCFileContent.StringTableContent[currentStringTableIndex].InsertRange(0, unusedElements); } else if (currentStringTableIndex == Constants.kNotDiscovered) { // Assign a meaningless STable index currentStringTableIndex = --unusedSTableIndex; // Add to StringTableIndexOrder mRCFileContent.StringTableIndexOrder.Add(currentStringTableIndex); // Add all unused to STable mRCFileContent.StringTableContent.Add(currentStringTableIndex, new List <RCFileItem>()); mRCFileContent.StringTableContent[currentStringTableIndex].AddRange(unusedElements); } unusedElements.Clear(); previousStringTableIndex = currentStringTableIndex; currentStringTableIndex = Constants.kNotDiscovered; // Reset index of current STable } else // Found new object from current STable { if (!aHeaderContent.NameToID.ContainsKey(obj.Name)) // If there's no ID for the current Name in current RC's headers { if (currentStringTableIndex == Constants.kNotDiscovered) { unusedElements.Add(obj); } obj.ID = Constants.kNotFoundID; mHeaderContent.NameToID[obj.Name] = obj.ID; } else { obj.ID = aHeaderContent.NameToID[obj.Name]; } if (currentStringTableIndex == Constants.kNotDiscovered && obj.ID != Constants.kNotFoundID) // If index is not yet calculated and ID exists { currentStringTableIndex = StringTableIndexCalculator.CalculateIndex(aHeaderContent.NameToID[obj.Name]); // Get index of current STable } if (currentStringTableIndex == Constants.kNotDiscovered) { continue; // Could not calculate index of current STable } if (!mRCFileContent.StringTableContent.ContainsKey(currentStringTableIndex)) // In case current STable is not registered in the Dictionary { mRCFileContent.StringTableContent.Add(currentStringTableIndex, new List <RCFileItem>()); // Register STable in Dictionary } mRCFileContent.StringTableContent[currentStringTableIndex].Add(obj); // Add current object to its STable } } } }