Esempio n. 1
0
/// <summary>
/// 生成md5文本文件
/// </summary>
    static void BuildFileIndex()
    {
        string resPath = Application.dataPath + "/StreamingAssets/";
        ///----------------------创建文件列表-----------------------
        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"))
            {
                continue;
            }

            string md5   = LuaConst.md5file(file);
            string value = file.Replace(resPath, string.Empty);
            sw.WriteLine(value + "|" + md5);
        }
        sw.Close(); fs.Close();
    }
Esempio n. 2
0
    /// <summary>
    /// 是否要更新?
    /// </summary>
    IEnumerator OnCheckUpdateResource()
    {
        if (!LuaConst.UpdateMode)
        {
            OnResourceInited();
            yield break;
        }

        string dataPath = LuaConst.DataPath;  //数据目录
        string url      = LuaConst.WedUrl;
        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)
        {
            OnResourceInited();
            Debug.Log("连接更新服务器失败");
            yield return(new WaitForSeconds(1.5f));

            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  = LuaConst.md5file(localfile);
                canUpdate = !remoteMd5.Equals(localMd5);
                if (canUpdate)
                {
                    File.Delete(localfile);
                }
            }
            if (canUpdate)
            {
                willDownLoadUrl.Add(fileUrl);           //下载地址
                willDownLoadDestination.Add(localfile); //目标文件路径
                totalSize += GetHttpLength(fileUrl);
            }
        }

        if (willDownLoadUrl.Count > 0)
        {
            double tokbsize = Math.Round((float)totalSize / 1024, 2);
            Debug.Log("是否要下载文件大小为" + tokbsize);
            CommonUI.Instance.ShowCheck("是否更新", () => StartCoroutine(UpdateResources()), () => OnResourceInited());
            //TODO
        }
        else
        {
            CommonUI.Instance.ShowTips("已是最新版本");
            Debug.Log("已经是最新版本");
            OnResourceInited();
        }
    }