Beispiel #1
0
        /// <summary>
        /// 创建初始资源文件或增量更新文件的index file文件到NewVersion目录中
        /// </summary>
        private static void BuildZipFileIndex()
        {
            string       newFilePath = Path.Combine(Application.dataPath, "NewVersion/files.txt");
            string       srcName     = Path.Combine(Application.dataPath, "NewVersion", KTConfigs.kSrcName);
            FileStream   fs          = new FileStream(newFilePath, FileMode.Create);
            StreamWriter sw          = new StreamWriter(fs);
            string       md5         = Util.md5file(srcName);

            sw.WriteLine(KTConfigs.kSrcName + "|" + md5);
            sw.Close();
            fs.Close();
        }
Beispiel #2
0
        /// <summary>
        /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
        /// </summary>
        IEnumerator OnUpdateResource()
        {
            if (!AppConst.UpdateMode)
            {
                OnResourceInited();
                yield break;
            }
            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl;
            string message  = string.Empty;
            string random   = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl  = url + "files.txt?v=" + random;

            Debug.LogWarning("LoadUpdate---->>>" + listUrl);

            WWW www = new WWW(listUrl); yield return(www);

            if (www.error != null)
            {
                OnUpdateFailed(string.Empty);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", www.bytes);
            string filesText = www.text;

            string[] files = filesText.Split('\n');

            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl   = url + f + "?v=" + random;
                bool   canUpdate = !File.Exists(localfile);
                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);
                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }
                if (canUpdate)     //本地缺少文件
                {
                    Debug.Log(fileUrl);
                    message = "downloading>>" + fileUrl;
                    facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

                    /*
                     * www = new WWW(fileUrl); yield return www;
                     * if (www.error != null) {
                     *  OnUpdateFailed(path);   //
                     *  yield break;
                     * }
                     * File.WriteAllBytes(localfile, www.bytes);
                     */
                    //这里都是资源文件,用线程下载
                    BeginDownload(fileUrl, localfile);
                    while (!(IsDownOK(localfile)))
                    {
                        yield return(new WaitForEndOfFrame());
                    }
                }
            }
            yield return(new WaitForEndOfFrame());

            message = "更新完成!!";
            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

            OnResourceInited();
        }
Beispiel #3
0
        /// <summary>
        /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
        /// </summary>
        IEnumerator OnUpdateResource()
        {
#pragma warning disable 0162
            if (!AppConst.UpdateMode)
            {
                OnResourceInited();
                yield break;
            }
            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl;
            //string message = string.Empty;
            string random = DateTime.Now.ToString("yyyymmddhhmmss");
#pragma warning restore 0162
            #region lorry2-9,获取服务器版本,更新对应版本的资源
            //TODO:这个version也可以向Server服务器请求获得
            string          versionUrl  = url + "server_version.txt?v=" + random;
            UnityWebRequest verDownload = UnityWebRequest.Get(versionUrl);
            yield return(verDownload.Send());

            if (verDownload.isError)
            {
                Debug.Log(verDownload.error);
                facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, "获得server_version.txt失败!热更中断:" + verDownload.error);
                yield break;
            }
            string version = verDownload.downloadHandler.text;
            url = AppConst.WebUrl + version + "/" + Util.GetPlatformName() + "/";
            #endregion
            string listUrl = url + "files.txt?v=" + random;
            Debug.LogWarning("Down files.txt -->>" + listUrl);

            UnityWebRequest www = UnityWebRequest.Get(listUrl);
            yield return(www.Send());

            if (www.isError)
            {
                facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, "更新files.txt失败!热更中断:" + www.error);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            //首先把files.txt写到数据目录。
            File.WriteAllBytes(dataPath + "files.txt", www.downloadHandler.data);
            string   filesText = www.downloadHandler.text;
            string[] files     = filesText.Split('\n');
            Debug.LogWarning("Write files.txt To-->>" + dataPath);
            m_DataVersion = files[0];
            //这里修改了luaFramework的原始流程,先把所有的操作动作存下来。
            List <string> willDownLoadUrl         = new List <string>(); //from
            List <string> willDownLoadFileName    = new List <string>();
            List <string> willDownLoadDestination = new List <string>(); //to
            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, "分析需要更新的文件");
            Debug.LogWarning("分析需要更新的文件:" + files.Length);
            int totalSize = 0;
            for (int i = 1; i < files.Length; i++)
            {//分析每一个文件是否需要更新
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl   = url + f + "?v=" + random;
                bool   canUpdate = !File.Exists(localfile); //本地文件不存在,肯定要更新。
                if (!canUpdate)
                {                                           //本地存在fileUrl的这个文件,这里进行md5的对比,如果相同就不更新了。
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);
                    if (PlayerPrefs.GetString(localfile) == version)//判断本地是否有已经下载的信息
                    {
                        canUpdate = false;
                        willDownLoadDestination.Add(localfile);//有下载信息也要下载
                    }
                    if (canUpdate)
                    {
                        File.Delete(localfile);            //md5码不同,把本地文件删除,接下来会下载这个文件。
                    }
                }
                if (canUpdate)
                {
                    int fileSize = int.Parse(keyValue[2]);
                    totalSize += fileSize;
                    willDownLoadUrl.Add(fileUrl);           //下载地址
                    willDownLoadFileName.Add(f);
                    willDownLoadDestination.Add(localfile); //目标文件路径
                    //这里本来是使用了线程下载,但是我测试中总是卡在第一个下载,暂时换www来进行下载。
                    //等到需要在游戏中边运行边下载,再考虑线程下载。ThreadManager不成功,总是在OnDownloadFile中WebClient.DownloadFileAsync后就没有反应了
                    //添加的DownloadProgressChangedEventHandler(ProgressChanged)无法进入,而且异常也没捕获。
                }
            }

            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, "开始下载更新文件" + Util.FormatFileSize(totalSize));
            if (willDownLoadUrl.Count > 0)
            {
                facade.SendMessageCommand(NotiConst.UPDATE_ALL_COUNT, willDownLoadUrl.Count);
            }
            else
            {
                Debug.LogWarning("分析完毕,没有文件需要更新!");
                needHotFix = false;
            }
            //这里是对比后需要更新的资源文件,TODO:用线程下载
            len = willDownLoadUrl.Count;
            num = 0;
            for (int i = 0; i < willDownLoadUrl.Count; i++)
            {
                Debug.Log("下载:" + willDownLoadUrl[i]);
                facade.SendMessageCommand(NotiConst.UPDATE_FILE_NAME, willDownLoadFileName[i]);
                PlayerPrefs.SetString(willDownLoadDestination[i], version);//如果已经下载设置值为版本号
                HadDownLoadDestination.Add(willDownLoadDestination[i]);
                Thread thread = new Thread(new ParameterizedThreadStart(Down));
                thread.Start(willDownLoadUrl[i] + "|" + willDownLoadDestination[i] + "|" + willDownLoadFileName[i]);
            }
            yield return(new WaitForEndOfFrame());
        }
Beispiel #4
0
        /// <summary>
        /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
        /// </summary>
        IEnumerator OnUpdateResource()
        {
            if (!AppConst.UpdateMode)
            {
                OnResourceInited();
                yield break;
            }
            LuaHelper.SetLoading("正在检测更新", 0);
            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl;
            string message  = string.Empty;
            string random   = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl  = url + "files.txt?v=" + random;

            Debug.LogWarning("LoadUpdate---->>>" + listUrl);

            WWW www = new WWW(listUrl); yield return(www);

            if (www.error != null)
            {
                OnUpdateFailed(string.Empty);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", www.bytes);
            string filesText = www.text;

            string[] files = filesText.Split('\n');

            int packgeSize            = 0;
            int loadSize              = 0;
            List <PackgeInfo> packges = new List <PackgeInfo>();

            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                int      size      = int.Parse(keyValue[2]);
                string   localfile = (dataPath + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl   = url + f + "?v=" + random;
                bool   canUpdate = !File.Exists(localfile);
                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);
                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }
                if (canUpdate)     //本地缺少文件
                {
                    packgeSize += size;
                    packges.Add(new PackgeInfo()
                    {
                        size = size, fileUrl = fileUrl, localfile = localfile
                    });
                }
            }

            float  rate      = 1024;
            string dw        = "kb";
            float  downSpeed = 0;

            if (packgeSize > 10485760)
            {
                dw   = "mb";
                rate = 1048576;
            }
            float startTime = Time.time;

            foreach (var item in packges)
            {
                message = "downloading>>" + item.fileUrl;
                facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
                #region 注释

                /*
                 * www = new WWW(fileUrl); yield return www;
                 * if (www.error != null) {
                 *  OnUpdateFailed(path);   //
                 *  yield break;
                 * }
                 * File.WriteAllBytes(localfile, www.bytes);
                 */
                //这里都是资源文件,用线程下载
                #endregion
                BeginDownload(item.fileUrl, item.localfile);
                while (!(IsDownOK(item.localfile)))
                {
                    float load = loadSize + downSpeed * (Time.time - startTime); // 预测下载进度
                    if (load > (loadSize + item.size))
                    {
                        load = item.size;
                    }
                    if (load < loadSize)
                    {
                        load = loadSize;
                    }
                    float fill = load / packgeSize;
                    Debug.Log(load / rate);
                    Debug.Log(packgeSize / rate);
                    Debug.Log(dw);
                    Debug.Log(fill * 100);

                    string state = string.Format("更新中   {3:F}%   {0:F}{2}/{1:F}{2}", load / rate, packgeSize / rate, dw, fill * 100);
                    LuaHelper.SetLoading(state, fill);
                    yield return(new WaitForEndOfFrame());
                }
                loadSize += item.size;
                downSpeed = loadSize / (Time.time - startTime); // 记录文件下载速度
            }
            yield return(new WaitForEndOfFrame());

            LuaHelper.Loading.SetActive(false);
            message = "更新完成!!";
            LuaHelper.SetLoading("更新完成!!", 0, false);
            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

            OnResourceInited();
        }
Beispiel #5
0
        IEnumerator UpdateResourceCount()
        {
            if (!AppFacade.Instance.IsUpdate)
            {
                ResManager.initialize(OnResourceInited);
                yield break;
            }
            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl + "ios/v" + dirVersion + "/";

            if (Application.platform == RuntimePlatform.Android)
            {
                url = AppConst.WebUrl + "android/v" + dirVersion + "/";
            }
            else if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                url = AppConst.WebUrl + "ios/v" + dirVersion + "/";
            }
            else if (Application.platform == RuntimePlatform.OSXEditor)
            {
                url = AppConst.WebUrl + "ios/v" + dirVersion + "/";
            }
            else if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                url = AppConst.WebUrl + "android/v" + dirVersion + "/";
            }
            if (url == "")
            {
                yield break;
            }
            string random  = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl = url + "files.txt?v=" + random;
            WWW    www     = new WWW(listUrl); yield return(www);

            if (www.error != null)
            {
                OnUpdateFailed(string.Empty);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", www.bytes);
            long   downlen   = 0;
            string filesText = www.text;

            string[] files = filesText.Split('\n');
            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl   = url + keyValue[0] + "?v=" + random;
                bool   canUpdate = !File.Exists(localfile);
                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);
                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }
                if (canUpdate)
                {
                    downlen += long.Parse(keyValue[2]);
                    assetKey.Add(localfile);
                    updateAsset.Add(localfile, fileUrl);
                }
            }
            yield return(new WaitForEndOfFrame());

            // 数据网络
            if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
            {
                if (downlen > 1024)
                {
                    _loadassets.showDownSize(CountSize(downlen));
                }
                else
                {
                    StartCoroutine(StartUpdateResource());
                }
            }

            // 无线
            if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
            {
                StartCoroutine(StartUpdateResource());
            }
        }
Beispiel #6
0
        /// <summary>
        /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
        /// </summary>
        IEnumerator OnUpdateResource()
        {
            if (!AppConst.UpdateMode)
            {
                OnResourceInited();
                yield break;
            }
            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl;
            string message  = string.Empty;
            string random   = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl  = url + "files.txt?v=" + random;

            //string listUrl = url + "files.txt";
            LogManager.Warning("正在检测更新---->>>" + listUrl);
            message = "正在检测更新---->>>" + listUrl;
            facade.SendMessageCommand(NotiConst.CHECK_UPDATE, message);
            WWW www = new WWW(listUrl); yield return(www);

            if (www.error != null)
            {
                OnUpdateFailed(string.Empty);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", www.bytes);
            string filesText = www.text;

            string[] files = filesText.Split('\n');

            List <string> willDownLoadUrl         = new List <string>(); //from
            List <string> willDownLoadFileName    = new List <string>();
            List <string> willDownLoadDestination = new List <string>(); //to


            float countLength = 0;

            System.Net.HttpWebRequest request = null;
            System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                         System.Security.Cryptography.X509Certificates.X509Chain chain,
                         System.Net.Security.SslPolicyErrors sslPolicyErrors)
            {
                return(true);        // **** Always accept
            };
            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl = url + f + "?v=" + random;
                //string fileUrl = url + f ;
                bool canUpdate = !File.Exists(localfile);

                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);

                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }
                if (canUpdate)     //本地缺少文件

                //message = "正在检查更新>>" + fileUrl;
                //facade.SendMessageCommand(NotiConst.CHECK_UPDATE, message);

                /*
                 * www = new WWW(fileUrl);
                 * loadProgress.value = www.progress;
                 * progressText.text = Mathf.Round(loadProgress.value * 100).ToString() + "/100";
                 * yield return www;
                 * if (www.error != null) {
                 *  OnUpdateFailed(path);   //
                 *  yield break;
                 * }
                 * File.WriteAllBytes(localfile, www.bytes);
                 */
                //这里都是资源文件,用线程下载
                //BeginDownload(fileUrl, localfile);
                //while (!(IsDownOK(localfile))) { yield return new WaitForEndOfFrame(); }

                {
                    willDownLoadUrl.Add(fileUrl);           //下载地址
                    willDownLoadFileName.Add(keyValue[0]);
                    willDownLoadDestination.Add(localfile); //目标文件路径

                    //计算文件大小
                    request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(fileUrl);
                    request.UseDefaultCredentials = true;
                    request.Method = "HEAD";
                    countLength   += request.GetResponse().ContentLength;
                }
            }

            //System.Net.HttpWebRequest request=null;
            ////计算文件大小
            //for (int i = 0; i < willDownLoadUrl.Count; i++)
            //{
            //    request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(willDownLoadUrl[i]);
            //    request.UseDefaultCredentials = true;
            //    request.Method = "HEAD";
            //    countLength += request.GetResponse().ContentLength;
            //    //UnityWebRequest uwr = UnityWebRequest.Head(willDownLoadUrl[i]);
            //    //yield return uwr.Send();
            //    //string size = uwr.GetResponseHeader("Content-Length");
            //    //if (!string.IsNullOrEmpty(size)) //{ OnUpdateFailed(null); yield break; }
            //    //    countLength += float.Parse(size);
            //}

            string value = string.Format("{0}", Math.Round(countLength / 1024, 2));

            facade.SendMessageCommand(NotiConst.UPDATE_ALL_COUNTLENGTH, value);
            if (willDownLoadUrl.Count > 0)
            {
                facade.SendMessageCommand(NotiConst.UPDATE_ALL_COUNT, willDownLoadUrl.Count);
            }
            for (int i = 0; i < willDownLoadUrl.Count; i++)
            {
                LogManager.Debug("要下载的文件:" + willDownLoadUrl[i]);
                //这里都是资源文件,用线程下载
                facade.SendMessageCommand(NotiConst.UPDATE_FILE_NAME, willDownLoadFileName[i]);
                BeginDownload(willDownLoadUrl[i], willDownLoadDestination[i]);
                while (!(IsDownOK(willDownLoadDestination[i])))
                {
                    yield return(new WaitForEndOfFrame());
                }
            }

            yield return(new WaitForEndOfFrame());

            //yield return new WaitForSeconds(0.1f);
            message = "更新完成!";
            facade.SendMessageCommand(NotiConst.CHECK_UPDATE, message);
            OnResourceInited();
        }
        /// <summary>
        /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
        /// </summary>
        IEnumerator OnUpdateResource()
        {
            if (!AppConst.UpdateMode)
            {
                OnResourceInited();
                yield break;
            }

            // Text progressName = GameObject.Find("progressName").GetComponent<Text>();
            // Slider progressBar = GameObject.Find("progressBar").GetComponent<Slider>();

            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl;
            string message  = string.Empty;
            string random   = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl  = url + "files.txt?v=" + random;

            Debug.LogWarning("LoadUpdate---->>>" + listUrl);

            UnityWebRequest request = UnityWebRequest.Get(listUrl);

            yield return(request.SendWebRequest());

            if (request.isNetworkError)
            {
                OnUpdateFailed(string.Empty);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", request.downloadHandler.data);
            string filesText = request.downloadHandler.text;

            string[] files = filesText.Split('\n');

            float totleFiles = files.Length;

            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                Debug.Log(localfile);
                string path = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl   = url + f + "?v=" + random;
                bool   canUpdate = !File.Exists(localfile);
                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);
                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }
                if (canUpdate)     //本地缺少文件
                {
                    Debug.Log(fileUrl);
                    message = "downloading>>" + fileUrl;
                    facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

                    /*
                     * www = new WWW(fileUrl); yield return www;
                     * if (www.error != null) {
                     *  OnUpdateFailed(path);   //
                     *  yield break;
                     * }
                     * File.WriteAllBytes(localfile, www.bytes);
                     */
                    //这里都是资源文件,用线程下载
                    BeginDownload(fileUrl, localfile);
                    while (!(IsDownOK(localfile)))
                    {
// #if GP
//                         progressName.text = "正在加載...(2/2)";
// #else
//                         progressName.text = "正在加载...(1/2)";
// #endif
//                         progressBar.value = i / totleFiles;
                        yield return(new WaitForEndOfFrame());
                    }
                }
            }
            yield return(new WaitForEndOfFrame());

            message = "更新完成!!";
            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

            OnResourceInited();
        }
Beispiel #8
0
        /// <summary>
        /// 检测对比文件是否要更新
        /// </summary>
        IEnumerator OnCheckUpdate()
        {
            if (!AppConst.UpdateMode)
            {
                //ResManager.initialize(Facade.m_GameManager.OnResourceInited);
                yield break;
            }
            to_download_files.Clear();

            this.AddEvent(UPDATE_CHECK, "begin");

            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl;
            string random   = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl  = url + "files.txt?v=" + random;

            Debug.LogWarning("LoadUpdate---->>>" + listUrl);

            WWW www = new WWW(listUrl); yield return(www);

            if (www.error != null)
            {
                string message = "下载版本信息失败!>files.txt";
                this.AddEvent(UPDATE_CHECK, "error|" + message);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", www.bytes);

            string filesText = www.text;

            string[] files = filesText.Split('\n');

            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl   = url + keyValue[0] + "?v=" + random;
                bool   canUpdate = !File.Exists(localfile);
                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);
                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }
                //本地缺少文件
                if (canUpdate)
                {
                    to_download_files[fileUrl] = localfile;
                }
            }
            yield return(new WaitForEndOfFrame());

            // "检查更新完成!!"
            this.AddEvent(UPDATE_CHECK, "end|" + to_download_files.Count);
            // 对比完成 是否去下载
            if (to_download_files.Count > 0)
            {
                StartCoroutine(OnUpdateResource());
            }
        }
Beispiel #9
0
        /// <summary>
        /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
        /// </summary>
        IEnumerator OnUpdateResource()
        {
            if (!AppConst.UpdateMode)
            {
                OnResourceInited();
                yield break;
            }
            string dataPath = Util.DataPath;  //数据目录
            string message  = string.Empty;
            string random   = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl  = url + "files.txt?v=" + random;

            Debug.LogWarning("LoadUpdate---->>>" + listUrl);

            WWW www = new WWW(listUrl); yield return(www);

            if (www.error != null)
            {
                OnUpdateFailed(string.Empty);
                ShowNetTip();
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", www.bytes);
            string filesText = www.text;

            string[] files = filesText.Split('\n');

            txtInfo.text      = "正在检查更新...";
            txtPer.text       = "0%";
            pgsPer.fillAmount = 0;
            //SetFillAmountPos(0);

            List <string> needUpdateFiles = new List <string>();
            List <int>    fileLens        = new List <int>();

            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                // string fileUrl = url + f + "?v=" + random;
                bool canUpdate = !File.Exists(localfile);
                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);
                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }
                if (canUpdate)
                {   //本地缺少文件
                    int fl = int.Parse(keyValue[2].Trim());
                    bytesTotal += fl;
                    needUpdateFiles.Add(f);
                    fileLens.Add(fl);
                    // Debug.Log(fileUrl);
                    // message = "downloading>>" + fileUrl;
                    // facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

                    /*
                     * www = new WWW(fileUrl); yield return www;
                     * if (www.error != null) {
                     *  OnUpdateFailed(path);   //
                     *  yield break;
                     * }
                     * File.WriteAllBytes(localfile, www.bytes);
                     */
                    //这里都是资源文件,用线程下载
                    // BeginDownload(fileUrl, localfile);
                    // while (!(IsDownOK(localfile))) { yield return new WaitForEndOfFrame(); }
                }
            }

            if (AppConst.getNetType() == 2)
            {
                int needDown = bytesTotal / 1024 / 1024;
                if (needDown > 0)
                {
                    ShowUpdateTip(needDown + "MB");
                    while (!isUpdate)
                    {
                        yield return(new WaitForEndOfFrame());
                    }
                }
            }

            txtInfo.text = "准备下载更新...";
            for (int i = 0; i < needUpdateFiles.Count; i++)
            {
                string file      = needUpdateFiles[i];
                int    size      = fileLens[i];
                string localfile = (dataPath + file).Trim();
                string fileUrl   = url + file + "?v=" + random;

                Debug.Log(fileUrl);
                message = "downloading>>" + fileUrl;
                facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

                www = new WWW(fileUrl);
                while (!www.isDone)
                {
                    int loaded = bytesLoaded + (int)(www.progress * size);
                    txtPer.text       = (int)((float)loaded / bytesTotal * 100) + "%";
                    pgsPer.fillAmount = (float)loaded / bytesTotal;
                    //SetFillAmountPos((float)loaded / bytesTotal);
                    txtInfo.text = "正在下载更新...(" + loaded / 1024 + "KB)";
                    yield return(new WaitForEndOfFrame());
                }
                bytesLoaded += size;
                if (www.error != null)
                {
                    OnUpdateFailed(fileUrl);   //
                    ShowNetTip();
                    yield break;
                }
                File.WriteAllBytes(localfile, www.bytes);
                // BeginDownload(fileUrl, localfile);
                // while (!(IsDownOK(localfile))) {
                //     txtPer.text = (bytesLoaded*100/bytesTotal) + "%";
                //     pgsPer.fillAmount = (float)bytesLoaded / bytesTotal;
                //     yield return new WaitForEndOfFrame();
                // }
            }
            yield return(new WaitForEndOfFrame());

            message           = "更新完成!!";
            txtPer.text       = "100%";
            pgsPer.fillAmount = 1;
            //SetFillAmountPos(1);
            AppConst.version = verNum;

            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

            OnResourceInited();
        }
Beispiel #10
0
        /// <summary>
        /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
        /// </summary>
        IEnumerator OnUpdateResource()
        {
            Debug.LogError("OnUpdateResource");
            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl;
            string message  = string.Empty;
            string random   = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl  = url + "files.txt?v=" + random;
            //Debug.LogWarning("LoadUpdate---->>>" + listUrl);

            WWW www = new WWW(listUrl); yield return(www);

            if (www.error != null && www.error.Length != 0)
            {
                Debug.LogError("OnUpdateFailed");
                OnUpdateFailed(string.Empty);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", www.bytes);
            string filesText = www.text;

            string[] files = filesText.Split('\n');

            List <DownLoadInfo> list = new List <DownLoadInfo> ();

            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl   = url + f + "?v=" + random;
                bool   canUpdate = !File.Exists(localfile);

                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);
                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }

//              canUpdate = true;
                if (canUpdate)
                {
                    DownLoadInfo info;
                    info.fileUrl   = fileUrl;
                    info.localfile = localfile;
                    list.Add(info);
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                Debug.Log(list [i].fileUrl);
                Debug.Log(list [i].localfile);

                AppView.Message msg = new AppView.Message();
                msg.current = i;
                msg.total   = list.Count;

                facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, msg);
                //这里都是资源文件,用线程下载
                BeginDownload(list[i].fileUrl, list[i].localfile);
                while (!(IsDownOK(list[i].localfile)))
                {
                    yield return(new WaitForEndOfFrame());
                }
            }


            yield return(new WaitForEndOfFrame());

            message = "更新完成!!";
            facade.SendMessageCommand(NotiConst.UPDATE_DOWNLOAD_OVER, message);

            //StartCoroutine (ReInitResource ());
            OnResourceInited();
        }
Beispiel #11
0
        /// <summary>
        /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
        /// </summary>

        IEnumerator OnUpdateResource()
        {
            if (!AppConst.UpdateMode)
            {
                OnResourceInited();
                yield break;
            }
            string dataPath   = Util.DataPath; //数据目录
            string updatePath = Application.dataPath + "/" + AppConst.AiraUpdate;
            string message    = string.Empty;
            string random     = DateTime.Now.ToString("yyyymmddhhmmss");

            Debug.Log("LoadUpdate---->>>" + Util.DataPath);
            Debug.Log("LoadUpdate---->>>" + updatePath);

            if (!Directory.Exists(updatePath))
            {
                OnResourceInited();
                yield break;
            }

            string fileText = File.ReadAllText(updatePath + "/files.txt");

            string[] files = fileText.Split('\n');
            for (int i = 0; i < files.Length; ++i)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    break;
                }
                string[] keyValue = files[i].Split('|');
                //去除空格
                string localPath = (dataPath + keyValue[0]).Trim();
                Debug.Log("LocalPath ==  " + localPath);

                string path = Path.GetDirectoryName(localPath);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                bool canUpdate = !File.Exists(localPath);
                if (!canUpdate)
                {
                    //文件存在 对比md5
                    string updateMd5 = keyValue[1];
                    string oldMd5    = Util.md5file(localPath);
                    if (!updateMd5.Equals(oldMd5))
                    {
                        //删除文件
                        canUpdate = true;
                        Debug.Log("删除了文件 ==  " + localPath);
                        File.Delete(localPath);
                    }
                }
                if (canUpdate)
                {
                    //文件拷贝过来
                    Debug.Log("开始拷贝文件 ==  " + localPath);
                    File.Copy(updatePath + "/" + keyValue[0], localPath);
                }
            }

            Debug.Log("ab更新完成");
            message = "更新完成!!";
            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);

            OnResourceInited();
        }
Beispiel #12
0
        IEnumerator OnUpdateResource(string url)
        {
            downloadFiles.Clear();
            string dataPath = Util.DataPath;  //数据目录

            if (url == "")
            {
                yield break;
            }
            string random  = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl = url + "files.txt?v=" + random;
            //Debug.LogWarning("LoadUpdate---->>>" + listUrl);
            //Debug.Log("LoadUpdate---->>>" + listUrl);
            WWW www = new WWW(listUrl); yield return(www);

            if (www.error != null)
            {
                OnUpdateFailed(string.Empty);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", www.bytes);

            string filesText = www.text;

            //Debug.Log(dataPath + "filesText---->>>" + filesText);
            string[] files   = filesText.Split('\n');
            string   message = string.Empty;

            loadCount = files.Length;
            loadIndex = 1;

            for (int i = 0; i < loadCount; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                //Debug.Log("localfile---->>>" + f);
                string path = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl   = url + keyValue[0] + "?v=" + random;
                bool   canUpdate = !File.Exists(localfile);
                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);
                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                    else
                    {
                        //updateLoadPos("正在比对资源...");
                    }
                }
                if (canUpdate)
                {   //本地缺少文件
                    message = "downloading>>" + fileUrl;
                    facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
                    BeginDownload(fileUrl, localfile);
                    while (!(IsDownOK(localfile)))
                    {
                        yield return(new WaitForEndOfFrame());
                    }
                }
            }
            yield return(new WaitForEndOfFrame());

            message = "更新完成!!";
            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
            //ResManager.initialize(OnResourceInited);
        }