Ejemplo n.º 1
0
 //讀Json -> 開放給外界使用
 public void LoadJson(byte[] byteArray)
 {
     byteArray = TFile.XOR(byteArray);
     using (MemoryStream stream = new MemoryStream(byteArray))
     {
         using (StreamReader reader = new StreamReader(stream, System.Text.UTF8Encoding.UTF8))
         {
             string str = reader.ReadToEnd();
             if (str.Trim() == "[]")
             {
                 return;
             }
             LoadJson(str);
         }
     }
     Analyze();
 }
Ejemplo n.º 2
0
        protected IEnumerator IGetDownloadList(string ip, string hostName, string versionName, string version)
        {
            string path = GetLocation(ip, hostName) + TinyContext.Instance.LanguagePath + "/" + "Versions/";
            string name = versionName;

            mStatus = eStatus.Updating;

            yield return(null);

            using (WWW bundle = new WWW(path + name))
            {
                yield return(bundle);

                //檢查下載錯誤訊息
                if (bundle.error != null)
                {
                    mStatus = eStatus.Error;
                    mOnError.InvokeGracefully(bundle.error);
                    mLogger.Log(bundle.error);
                    yield break;
                }

                //檢查是否下載完成
                if (bundle.isDone == true)
                {
                    byte[] xor   = TFile.XOR(bundle.bytes);
                    string json  = System.Text.UTF8Encoding.UTF8.GetString(xor);
                    rRes[] datas = TJson.DeserializeObject <rRes[]>(json);

                    if (datas[0].Version != version)
                    {
                        mStatus = eStatus.Error;
                        mOnError.InvokeGracefully("版本不符");
                        mLogger.Log("版本不符");
                        yield break;
                    }

                    if (mDownloadList == null)
                    {
                        mDownloadList = new List <rRes>();
                    }
                    else
                    {
                        mDownloadList.Clear();
                    }

                    mTotalSize = 0;;
                    for (int i = 0; i < datas.Length; i++)
                    {
                        if (!CheckNeedUpdate(datas [i]))
                        {
                            continue;
                        }

                        mDownloadList.Add(datas[i]);
                        mTotalSize += datas[i].FileSize;
                    }
                }
                else
                {
                    mStatus = eStatus.Error;
                    mOnError.InvokeGracefully(string.Format("更新失敗 -> {0}", bundle.url));
                    mLogger.Log(string.Format("更新失敗 -> {0}", bundle.url));
                    yield break;
                }
            }
        }