コード例 #1
0
        private bool ParseJson(string fn)
        {
            JToken rootToken = JToken.ReadFrom(new JsonTextReader(File.OpenText(fn)));

            if (rootToken == null)
            {
                Console.WriteLine("root is null");
                return(false);
            }
            if (rootToken.Type != JTokenType.Array)
            {
                MessageBox.Show(this, " isn't an array (is " + rootToken.Type + ").");
                return(false);
            }

            JArray root = (JArray)rootToken;

            instructionsList = new List <Instruction>();
            Dictionary <UInt32, AElement> objects = new Dictionary <uint, AElement>();

            foreach (JObject it in root)
            {
                if ((string)it["type"] == "instruction")
                {
                    Instruction instruction = new Instruction(it);
                    instruction.Load(objects);
                    instructionsList.Add(instruction);
                }
                else if ((string)it["type"] == "object")
                {
                    UInt32 addr    = AObject.StrToAddr((string)it["address"]);
                    JToken content = it["content"];
                    if (content != null)
                    {
                        objects[addr] = AElement.Create(content);
                    }
                    else
                    {
                        //Console.WriteLine("Invalid object " + addr + ": content is null.");
                        objects[addr] = new Null();
                    }
                }
            }

            grid.ItemsSource = instructionsList;
            return(true);
        }
コード例 #2
0
ファイル: Element.cs プロジェクト: brliron/Thcrap-patches
        public static AElement Create(JToken obj)
        {
            switch (obj.Type)
            {
            case JTokenType.Null:
                return(new Null());

            case JTokenType.Boolean:
                return(new Boolean(obj));

            case JTokenType.Integer:
                return(new Integer(obj));

            case JTokenType.Float:
                return(new Float(obj));

            case JTokenType.String:
                if (AObject.IsAddr((string)obj))
                {
                    return(new Reference(obj));
                }
                else
                {
                    return(new String(obj));
                }

            case JTokenType.Object:
                JToken objectType = obj["ObjectType"];
                if (objectType != null && objectType.Type == JTokenType.String && (string)objectType == "SQTable")
                {
                    return(new SQTable(obj));
                }
                return(new JsonObject(obj));

            case JTokenType.Array:
                return(new JsonArray(obj));

            default:
                return(new String(obj.ToString()));
            }
        }
コード例 #3
0
ファイル: Element.cs プロジェクト: brliron/Thcrap-patches
 public Reference(JToken obj)
 {
     addr        = AObject.StrToAddr((string)obj);
     target      = null;
     isRecursing = false;
 }