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); } }
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); } }