Beispiel #1
0
        public DataTbls()
        {
            dataOptions      = new List <IDataOptions>();
            selectedFighters = new List <Fighter>();
            selectedBattle   = new Battle();
            config           = new Config();
            tabStorage       = new Stack <TabPage>();

            // If there is no labels file, ask the user if they would like one.
            if (!FileHelper.FileExists(config.labels_file_location) && UiHelper.PopUpQuestion("No Labels file found.  Would you like to download now?"))
            {
                NetworkHelper.DownloadParamLabels(config.labels_file_location);
            }

            var results = XmlHelper.ReadXML(config.file_location, config.labels_file_location);

            foreach (Type child in DataTbl.GetChildrenTypes())
            {
                IDataOptions opt = results.GetDataOptionsFromUnderlyingType(child);

                if (opt != null)
                {
                    dataOptions.Add(opt);
                }
            }
        }
Beispiel #2
0
        public static DataOptions ReadXML(string fileName, string fileLocationLabels = "", OrderedDictionary <ulong, string> hashes = null)
        {
            bool     parseData = false;
            bool     firstPass = false;
            bool     sharedXmlName;
            IDataTbl dataTable;
            var      results = new DataOptions();

            var stream = GetStreamFromFile(fileName);

            if (stream == null)
            {
                return(results);
            }

            var reader = GetXmlReaderFromStream(stream);

            // Try to read.  If we can't read - it might be encrypted.  Try to decrypt.
            try
            {
                reader.Read();
            }
            catch
            {
                try
                {
                    // Close and dispose reader and stream.
                    reader.Dispose();
                    stream = GetStreamFromEncryptedFile(fileName, fileLocationLabels);
                    reader = GetXmlReaderFromStream(stream);
                    reader.Read();
                }
                catch
                {
                    return(results);
                }
            }

            // Read through entire file, and determine type.
            try
            {
                // Read the whole file.
                while (!reader.EOF)
                {
                    var attribute = reader?.GetAttribute("hash");
                    dataTable = attribute == null? null :  DataTbl.GetDataTblFromXmlName(attribute);

                    if (dataTable != null)
                    {
                        parseData     = true;
                        firstPass     = true;
                        sharedXmlName = dataTable.GetType() == typeof(DataTbl);

                        if (sharedXmlName)
                        {
                            // Store the position, read from the beginning, restore the position.
                            var position = stream.Position;
                            stream.Position = 0;
                            dataTable       = DataTbl.DetermineXmlTypeFromFirstLevel(stream);
                            stream.Position = position;

                            if (dataTable == null)
                            {
                                parseData = false;
                            }
                        }
                    }

                    if (parseData)
                    {
                        // Read until start of data.
                        XmlHelper.ReadUntilName(reader, stopper: "struct");

                        // Lists have index values, so keep reading until we've left the list.
                        // Added first pass to handle when a struct is not in a list.
                        while (firstPass || reader.GetAttribute("index") != null)
                        {
                            dataTable = (IDataTbl)Activator.CreateInstance(dataTable.GetType());
                            dataTable.BuildFromXml(reader);

                            results.AddDataTbl(dataTable);

                            XmlHelper.ReadUntilNodeType(reader, node: XmlNodeType.Element);

                            firstPass = false;
                        }

                        //Left the list.  Don't parse the next lines.
                        parseData = false;
                        Console.WriteLine("{0} Table Complete.", dataTable.GetType().ToString());

                        continue;
                    }

                    reader.Read();
                }
                reader.Dispose();
                stream.Dispose();
                return(results);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }