/// <summary> /// CTor, initialize member. /// </summary> /// <param name="theOutputForm">The form to write console output.</param> public ResourceParser(ResourceGeneratorForm theOutputForm) { mOutputForm = theOutputForm; mErrorString = ""; }
/// <summary> /// CTor, initialize member. /// </summary> /// <param name="theOutputForm">The form to write console output.</param> public CodeWriter(ResourceGeneratorForm theOutputForm) { mOutputForm = theOutputForm; mErrorString = ""; mFunctionPrefix = ""; }
/// <summary> /// Start parsing the resource XML file. /// </summary> /// <param name="theResFile">The file with the resource definitions.</param> /// <returns>False in case of any error, otherwise true.</returns> public bool ParseResource(String theResFile) { if (theResFile == "") { mErrorString = "Please specify a XML Resource File!"; return(false); } try { if (File.Exists(theResFile)) { aXMLReader = new XmlTextReader(ResourceGeneratorForm.OpenStreamReaderWithEncoding(theResFile)); // find ResourceManifest tag while (aXMLReader.Read()) { if (aXMLReader.NodeType == XmlNodeType.Element) { if (aXMLReader.Name.ToLower() == "resourcemanifest") { mOutputForm.WriteLine("Found ResourceManifest"); Application.DoEvents(); break; } } } if (aXMLReader.EOF == true) { aXMLReader.Close(); mErrorString = "Expecting tag ResourceManifest"; return(false); } // start parsing the nodes while (aXMLReader.Read()) { switch (aXMLReader.NodeType) { case XmlNodeType.Element: // The node is an element. // each resource group is an element if (aXMLReader.Name.ToLower() == "resources") { String aResGroup = aXMLReader.GetAttribute("id"); if (aResGroup == null) { mErrorString = "No id for resources specified"; if (aXMLReader.HasLineInfo() == true) { mErrorString += " - Line: " + aXMLReader.LineNumber + " Position: " + aXMLReader.LinePosition; } return(false); } // create a new dictionary for the resource group mCurrentResGroup = new SortedDictionary <String, BaseRes>(); mResGroups.Add(aResGroup, mCurrentResGroup); mOutputForm.WriteLine("Parsing Group " + aResGroup); Application.DoEvents(); // start parsing the group if (ParseResources() == false) { break; } } else { mErrorString = "Invalid Section '" + aXMLReader.Name + "'"; break; } break; } if (mErrorString != "") { // an error occured, try to get line information from xml parser if (aXMLReader.HasLineInfo() == true) { mErrorString += " - Line: " + aXMLReader.LineNumber + " Position: " + aXMLReader.LinePosition; } break; } } mOutputForm.WriteLine("Closing Reader"); Application.DoEvents(); aXMLReader.Close(); } else { mErrorString = "File not found: " + theResFile; return(false); } } catch (Exception aException) { mErrorString += aException.Message; return(false); } return(mErrorString == ""); }