Example #1
0
    //下载并写入文件
    private IEnumerator CoDownloadAndWriteFile(string url, string filePath)
    {
        print("=======" + url + "=======" + filePath);

        yield return(null);

        using (WWW www = new WWW(url))
        {
            yield return(www);

            if (www.error != null)
            {
                UnityEngine.Debug.Log("[download error]" + string.Format("Read {0} failed: {1}", url, www.error));
                mBundleCount++;
                yield break;
            }

            ES2.SaveRaw(www.bytes, filePath);

            UnityEngine.Debug.Log("[download start]" + url);

            www.Dispose();

            mBundleCount++;

            print("当前已经下载文件的数量为" + mBundleCount + " total=" + mTotalBundleCount);
        }
    }
Example #2
0
        // save
        public void SaveVideo(ProtoBattleVideoInfo video, WarRecordIOInfo info)
        {
            video.uid_local = info.GetNewId();
            info.Add(video.uid_local);

            byte[] bytes = GetVideoBytes(video);
            string file  = GetVideoPath(video.uid_local);

            Debug.LogFormat("video.uid_local = {0}, bytes.Length={1}, file={2}", video.uid_local, bytes.Length, file);


            ES2.SaveRaw(bytes, file);
            SetWatchCount(video.uid_local, 0);

            while (info.Count > info.MaxNum)
            {
                int itemId = info.ids[0];
                DeleteVideoFile(itemId);
                info.ids.Remove(itemId);
            }


            SaveInfo(info);
        }
Example #3
0
 public void SaveInfo(WarRecordIOInfo info)
 {
     byte[] bytes = info.GetBytes();
     ES2.SaveRaw(bytes, InfoPath);
 }
Example #4
0
 public void SaveToFile(string identifier, ES2Settings settings)
 {
     ES2.Delete(identifier);
     ES2.SaveRaw(data, identifier, settings.Clone(identifier));
 }
Example #5
0
 public void SaveToFile(string identifier)
 {
     ES2.Delete(identifier);
     ES2.SaveRaw(data, identifier);
 }
Example #6
0
    IEnumerator Start()
    {
        Application.RegisterLogCallback(HandleLog);
        print("开始检查软件更新");

        WWW www = new WWW(serverurl + "filesClient.txt" + "?time=" + UnityEngine.Random.Range(0.1f, 1000f));

        print(www.url);
        yield return(www);

        if (www.error != null)
        {
            //0.net off ,Open the App
            //StartCoroutine(StartApp());
            print(www.error);

            print("更新完成,正在启动中");
            StartCoroutine(StartApp());
        }
        if (www.isDone)
        {
            //0.net on , Check Update

            appPath = MyPath.Combine(Application.dataPath, "Application");

            ES2.SaveRaw(www.bytes, MyPath.Combine(appPath, "filesServer.txt"));

            GetDirs(appPath);

            //1.get Local file
            saveFileDictionary(filesClient);
            print("======fileClient======");
            string temp = "";
            foreach (var i in filesClient)
            {
                temp += i;
                temp += "\n\r\n\r";
            }
            print(temp);


            //2.get server file
            print("======fileServer======");
            filesServer = ES2.LoadDictionary <string, string>(MyPath.Combine(appPath, "filesServer.txt"));
            temp        = "";
            foreach (var i in filesServer)
            {
                temp += i;
                temp += "\n\r\n\r";
            }
            print(temp);


            //3.compare with file
            print("======Server don't have Client have,Should Delete======");
            IEnumerable <string> filesDelete = filesClient.Keys.Except(filesServer.Keys);
            temp = "";
            foreach (var i in filesDelete)
            {
                temp += i;
                temp += "\n\r\n\r";
                File.Delete(MyPath.Combine(appPath, filesClient[i]));
            }
            print(temp);


            //4.compare with file
            print("======Server have Client don't have,Should Download======");
            IEnumerable <string> filesDownload = filesServer.Keys.Except(filesClient.Keys);
            temp = "";

            mTotalBundleCount = filesDownload.Count();


            foreach (var i in filesDownload)
            {
                temp += i;
                temp += "\n\r\n\r";

                StartCoroutine(CoDownloadAndWriteFile(MyPath.Combine(serverurl, filesServer[i]), MyPath.Combine(appPath, filesServer[i])));
            }
            print(temp);

            //5.检查是否下载完毕
            StartCoroutine(CheckLoadFinish());
        }
    }
Example #7
0
 //save server file
 void saveServerData(Byte[] bytes)
 {
     ES2.SaveRaw(bytes, MyPath.Combine(appPath, "filesServer.txt"));
 }