Exemplo n.º 1
0
    public static void BuildFileIndex()
    {
        string resPath = (ResourcePath.GetBaseURL() + UUtility.GetPlatformName() + "/").Remove(0, 7);
        ///----------------------创建文件列表-----------------------
        string newFilePath = resPath + "files.txt";

        if (File.Exists(newFilePath))
        {
            File.Delete(newFilePath);
        }

        paths.Clear(); files.Clear();
        Recursive(resPath);

        FileStream   fs = new FileStream(newFilePath, FileMode.CreateNew);
        StreamWriter sw = new StreamWriter(fs);

        for (int i = 0; i < files.Count; i++)
        {
            string file = files[i];
            string ext  = Path.GetExtension(file);
            if (file.EndsWith(".meta") || file.Contains(".DS_Store") || file.Contains(".exe"))
            {
                continue;
            }

            string md5   = LuaUtil.md5file(file);
            string value = file.Replace(resPath, string.Empty);
            sw.WriteLine(value + "|" + md5 + "|" + filesLength[i]);
        }
        sw.Close(); fs.Close();
    }
Exemplo n.º 2
0
    /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
    /// </summary>
    IEnumerator <object> OnUpdateResource(System.Action Complete)
    {
        //if (!Define.UpdateMode)
        //{
        //    OnResourceInited();
        //    yield break;
        //}
        if (!GameProxy.Instance.m_IsStart)
        {
            yield return(null);
        }

        TotalUpdateLength = 0;

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

        if (!Define.UpdateMode)
        {
            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');
        List <string> loaderFiles      = new List <string>();
        List <string> loaderLocalFiles = new List <string>();

        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  = LuaUtil.md5file(localfile);
                canUpdate = !remoteMd5.Equals(localMd5);
                if (canUpdate)
                {
                    File.Delete(localfile);
                }
            }
            if (canUpdate)
            {   //本地缺少文件
                if (!Define.UpdateMode)
                {
                    Debug.Log(fileUrl);
                }
                TotalUpdateLength += int.Parse(keyValue[2]);

                loaderFiles.Add(fileUrl);
                loaderLocalFiles.Add(localfile);
            }
        }

        int cnt = loaderFiles.Count;

        for (int i = 0; i < cnt; i++)
        {
            string fileUrl   = loaderFiles[i];
            string localfile = loaderLocalFiles[i];
            message = "downloading>>" + fileUrl;
            Facade.Instance.SendNotification(NotificationID.UPDATE_MESSAGE, message);

            BeginDownload(fileUrl, localfile);

            while (!(IsDownOK(localfile)))
            {
                yield return(new WaitForEndOfFrame());
            }
        }

        yield return(new WaitForEndOfFrame());

        message    = "更新完成!!";
        loadingstr = message;

        string curl  = LuaUtil.GetRelativePath();
        int    index = curl.LastIndexOf("/");

        AssetManager.BaseDownloadingURL = curl.Substring(0, index);
        m_openLoginUI = true;

        Complete();
        GameProxy.Instance.Init_TextManager();
        Facade.Instance.SendNotification(NotificationID.UPDATE_MESSAGE, message);

        OnResourceInited();
    }