Ejemplo n.º 1
0
        public Dictionary <string, PatchData> GetUpdateList(string jsonData)
        {
            if (string.IsNullOrEmpty(jsonData))
            {
                return(null);
            }

            var json = new JsonUnity(jsonData);

            if (json == null)
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(json.GetError()))
            {
                return(null);
            }

            var newDatas = GetPatchDatas(json);

            if (newDatas == null)
            {
                Debug.LogError("Failed to get the PatchList");
                return(null);
            }

            var path = Path.Combine(Application.temporaryCachePath, "PatchList.pat");

            if (!File.Exists(path))
            {
                return(newDatas);
            }
            else
            {
                var text = File.ReadAllText(path);
                if (string.IsNullOrEmpty(text))
                {
                    return(newDatas);
                }
                else
                {
                    return(GetCompareDatas(newDatas, text));
                }
            }
        }
Ejemplo n.º 2
0
        private Dictionary <string, PatchData> GetPatchDatas(JsonUnity json)
        {
            var datas = new Dictionary <string, PatchData>();
            var array = json.GetArrayWithKey("Datas");

            JsonObject obj  = null;
            PatchData  data = null;

            for (var i = default(int); i < array.GetCount(); ++i)
            {
                obj  = array.GetObjectWithIndex(i);
                data = new PatchData(obj);
                datas.Add(string.Format("{0}{1}", data.Path, data.Name), data);
            }

            return(datas);
        }
Ejemplo n.º 3
0
        public PatchList(string jsonData)
        {
            if (string.IsNullOrEmpty(jsonData))
            {
                return;
            }

            var json = new JsonUnity(jsonData);

            if (json == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(json.GetError()))
            {
                return;
            }

            if (mDatas == null)
            {
                mDatas = new Dictionary <string, PatchData>();
            }

            mDatas.Clear();

            var array = json.GetArrayWithKey("Datas");

            if (array == null)
            {
                return;
            }

            JsonObject obj  = null;
            PatchData  data = null;

            for (var i = default(int); i < array.GetCount(); ++i)
            {
                obj  = array.GetObjectWithIndex(i);
                data = new PatchData(obj);

                mDatas.Add(string.Format("{0}{1}", data.Path, data.Name), data);
            }
        }
Ejemplo n.º 4
0
        public void Parse(ref JsonReader reader)
        {
            if (reader == null)
            {
                Debug.LogError("Invalid json reader.");
                return;
            }

            while (true)
            {
                var valueBase = JsonUnity.ParseValueFromReader(ref reader);
                if (valueBase == null)
                {
                    break;
                }
                else
                {
                    mValues.Add(valueBase);
                }
            }
        }
Ejemplo n.º 5
0
        private Dictionary <string, PatchData> GetCompareDatas(Dictionary <string, PatchData> newDatas, string text)
        {
            var json = new JsonUnity(text);

            if (json == null)
            {
                return(newDatas);
            }

            var error = json.GetError();

            if (!string.IsNullOrEmpty(error))
            {
                Debug.LogError(error);
                return(newDatas);
            }

            var array = json.GetArrayWithKey("Datas");

            if (array == null)
            {
                return(newDatas);
            }

            JsonObject obj  = null;
            PatchData  info = null;

            mDatas = new Dictionary <string, PatchData>();
            for (var i = default(int); i < array.GetCount(); ++i)
            {
                obj  = array.GetObjectWithIndex(i);
                info = new PatchData(obj);
                mDatas.Add(info.Name, info);
            }

            var       updateDatas = new Dictionary <string, PatchData>();
            PatchData data        = null;
            var       path        = string.Empty;
            var       name        = string.Empty;

            foreach (KeyValuePair <string, PatchData> pair in newDatas)
            {
                data = pair.Value;
                name = data.Name.Replace(".lzf", ".asset");
                path = string.Format("{0}/{1}{2}", Application.persistentDataPath, data.Path, name);
                if (File.Exists(path))
                {
                    if (mDatas.ContainsKey(data.Name))
                    {
                        if (data.Path.Contains("data/"))
                        {
                            if (data.Name[default(int)].Equals(mDatas[data.Name].Names[default(int)]))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (data.CRC.Equals(mDatas[data.Name].CRC))
                            {
                                continue;
                            }
                        }

                        updateDatas.Add(data.Name, data);
                    }
                    else
                    {
                        updateDatas.Add(data.Name, data);
                    }
                }
                else
                {
                    updateDatas.Add(data.Name, data);
                }
            }

            return(updateDatas);
        }
Ejemplo n.º 6
0
        public void LoadHashes()
        {
            mHashes.Clear();

            var temp = string.Format("{0}/hashes.hsh", mOutPath);

            if (!File.Exists(temp))
            {
                return;
            }

            var data = File.ReadAllText(temp);

            if (string.IsNullOrEmpty(data))
            {
                Debug.LogError("Invalid data.");
                return;
            }

            var json = new JsonUnity(data);

            if (json == null)
            {
                Debug.LogError("Failed to create a json.");
                return;
            }

            temp = json.GetError();
            if (!string.IsNullOrEmpty(temp))
            {
                Debug.LogError(temp);
                return;
            }

            var key   = "Hashes";
            var array = json.GetArrayWithKey(key);

            if (array == null)
            {
                Debug.LogError("Failed to get the Hashes.");
                return;
            }

            var subKey        = string.Empty;
            var keyString     = "key";
            var subKeyString  = "subKey";
            var fileKeyString = "Files";
            var hashKeyString = "Hash";
            var hashstring    = string.Empty;

            JsonObject obj    = null;
            JsonObject subObj = null;
            JsonArray  sub    = null;
            FileHash   file   = null;
            HashInfo   hash   = null;
            Dictionary <string, FileHash> files = new Dictionary <string, FileHash>();

            for (var i = default(int); i < array.GetCount(); ++i)
            {
                files.Clear();

                obj = array.GetObjectWithIndex(i);
                key = obj.GetValueWithKey(keyString);
                sub = obj.GetArrayWithKey(fileKeyString);

                for (var j = default(int); j < sub.GetCount(); ++j)
                {
                    subObj     = sub.GetObjectWithIndex(j);
                    subKey     = subObj.GetValueWithKey(subKeyString);
                    hashstring = subObj.GetValueWithKey(hashKeyString);
                    file       = new FileHash(subKey, hashstring);

                    files.Add(subKey, file);
                    Debug.Log(subKey);
                }

                hash = new HashInfo(HashInfo.NOT_CHANGED, key, files);

                mHashes.Add(key, hash);
            }

            Debug.Log("Load hashes complete.");
        }