Ejemplo n.º 1
0
        private static void convert(string path, string path2, int conversionType = 0)
        {
            // Get ConvertType
            XMLType convertType = (XMLType)conversionType;
            if (!Enum.IsDefined(typeof(XMLType), conversionType))
            {
                Console.WriteLine("ERROR: Could not figure out the conversion type!");
                return;
            }

            // Load File
            XmlFile file = new XmlFile(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read));
            Console.WriteLine("INFO: Converting file {0} from {1} to {2} format.", Path.GetFileName(path), file.type, convertType);

            // Make sure File Type and Conversion Type are different
            if (file.type == convertType)
            {
                while (true)
                {
                    Console.WriteLine("WARNING: Invalid conversion type entered because the file is already in this format!");
                    Console.WriteLine("0 -- Text, 1 -- Bin Xml, 2 -- BXML Big, 3 -- BXML Little");
                    Console.WriteLine("Please enter the conversion type (excluding {0}), or type 'Exit' to quit: ", (int)file.type);

                    string cType = Console.ReadLine();
                    if (cType == "Exit")
                    {
                        return;
                    }

                    if (Int32.TryParse(cType, out conversionType) &&
                        conversionType != (int)file.type &&
                        Enum.IsDefined(typeof(XMLType), conversionType))
                    {
                        convertType = (XMLType)conversionType;
                        break;
                    }
                }
            }

            // Convert
            try
            {
                file.Write(File.Open(path2, FileMode.Create, FileAccess.Write, FileShare.Read), convertType);
                Console.WriteLine("Success!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
            }
        }
Ejemplo n.º 2
0
        private static void convert(string path, string path2, int conversionType = 0)
        {
            // Get ConvertType
            XMLType convertType = XMLType.Text;
            if (convertType > 0 && !IntToXmlType(conversionType, out convertType))
            {
                Console.WriteLine("ERROR: Could not figure out the conversion type!");
                return;
            }

            // Load File
            XmlFile file = new XmlFile(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read));
            Console.WriteLine("INFO: Converting file {0} from {1} to {2} format.", Path.GetFileName(path), file.type, convertType);

            // Make sure File Type and Conversion Type are different
            if (file.type == convertType)
            {
                do
                {
                    Console.WriteLine("WARNING: Invalid conversion type entered because the file is already in this format!");
                    Console.WriteLine("Please enter the conversion type (excluding {0}), or type 'Exit' to quit: ", (int)file.type);
                    string cType = Console.ReadLine();
                    if (cType == "Exit")
                    {
                        return;
                    }
                    if (Int32.TryParse(cType, out conversionType) && !IntToXmlType(conversionType, out convertType, (int)file.type))
                    {
                        // If changing the Convert Type failed, reset it to its default value because IntToXmlType function
                        // changed it to XmlType.Text
                        convertType = file.type;
                        //Console.WriteLine("{0}", convertType);
                    }
                } while (file.type == convertType);
            }

            // Convert
            try
            {
                file.Write(File.Open(path2, FileMode.Create, FileAccess.Write, FileShare.Read), convertType);
                Console.WriteLine("Success!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
            }
        }
Ejemplo n.º 3
0
 public XmlElement CreateElement(XmlDocument doc, XmlFile file)
 {
     XmlElement element = doc.CreateElement(file.xmlStrings[elementNameID]);
     for (int i = attributeStartID; i < attributeStartID + attributeCount; i++)
     {
         element.Attributes.Append(file.xmlAttributes[i].CreateAttribute(doc, file));
     }
     for (int i = childElementStartID; i < childElementStartID + childElementCount; i++)
     {
         element.AppendChild(file.xmlElements[i].CreateElement(doc, file));
     }
     // Don't allow TextNode if the Element has ChildElements
     if (elementValueID > 0 && childElementCount == 0)
     {
         element.AppendChild(doc.CreateTextNode(file.xmlStrings[elementValueID]));
     }
     return element;
 }
Ejemplo n.º 4
0
 public XmlAttribute CreateAttribute(XmlDocument doc, XmlFile file)
 {
     XmlAttribute attr = doc.CreateAttribute(file.xmlStrings[nameID]);
     attr.Value = file.xmlStrings[valueID];
     return attr;
 }