Advertisement
Guest User

quick fix

a guest
Jul 30th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8. using System.Xml;
  9.  
  10. namespace StructureWriter
  11. {
  12.     sealed class XMLConverter
  13.     {
  14.         private ArrayList Structure;
  15.         private readonly string Header;
  16.         private readonly int ObjectCounter;
  17.         private readonly int LoopCounter;
  18.  
  19.         internal XMLConverter(int ObjectCounter, int LoopCounter, string Header, ArrayList Structure)
  20.         {
  21.             this.ObjectCounter = ObjectCounter;
  22.             this.LoopCounter = LoopCounter;
  23.             this.Structure = Structure;
  24.  
  25.             this.Header = Header;
  26.             CreateXMLFile();
  27.         }
  28.  
  29.         internal void CreateXMLFile()
  30.         {
  31.             using (XmlWriter writer = XmlWriter.Create("" + Header + "_structure_" + Program.Release + ".xml"))
  32.             {
  33.                 writer.WriteStartDocument();
  34.                 writer.WriteStartElement("Facts");
  35.  
  36.                 writer.WriteStartElement("Fact");
  37.                 writer.WriteAttributeString("id", "release");
  38.                 writer.WriteString(Program.Release);
  39.                 writer.WriteEndElement();
  40.  
  41.                 writer.WriteStartElement("Fact");
  42.                 writer.WriteAttributeString("id", "packet header");
  43.                 writer.WriteString(Header);
  44.                 writer.WriteEndElement();
  45.  
  46.                 foreach (string Struct in Structure)
  47.                 {
  48.                     writer.WriteStartElement("Structure");
  49.                     writer.WriteAttributeString("type", !Struct.Contains("OBJ") && !Struct.Contains("loop") ? ConvertCharToString(Struct) : Struct);
  50.                     writer.WriteString(!Struct.Contains("OBJ") && !Struct.Contains("loop") ? ConvertCharToString(Struct) : Struct);
  51.                     writer.WriteEndElement();
  52.                 }
  53.  
  54.                 writer.WriteEndElement();
  55.  
  56.                 writer.WriteEndDocument();
  57.             }
  58.         }
  59.  
  60.         internal string ConvertCharToString(string nChar)
  61.         {
  62.             if (nChar == "S")
  63.                 return "String";
  64.             else if (nChar == "I")
  65.                 return "Integer";
  66.             else if (nChar == "B")
  67.                 return "Boolean";
  68.             else if (nChar == "F")
  69.                 return "Float";
  70.             else if (nChar == "SH")
  71.                 return "Short";
  72.             else if (nChar == "BYTE")
  73.                 return "Byte";
  74.             else
  75.                 return "Undefined";
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement