Exemplo n.º 1
0
    static void move_all(BuildTarget buildTarget)
    {
        delStreamingAssets();
        XPack pack = new XPack();

        pack.setInfo(buildTarget);
        XUtil.copyDirectory(pack.targetDir, "Assets/StreamingAssets", true);
        AssetDatabase.Refresh();

        // publish目录
        string versionDir = pack.getVersionDir(publishDir, "v" + version);

        // 清除所有东西
        XUtil.clearDirectory(versionDir);

        XUtil.copyDirectory(pack.targetDir, versionDir, true);


        build(pack, versionDir);

        // 拷贝单个文件
        XDebug.Log(versionDir + "assets/ver.json" + "=>" + pack.getPublishDir(publishDir) + "ver.json");
        XUtil.copyFile(versionDir + "assets/ver.json", pack.getPublishDir(publishDir) + "ver.json");
    }
Exemplo n.º 2
0
    // 更新流程
    public IEnumerator updateVersion(string publishUrl)
    {
        // 转化下平台接口
        publishUrl = getPlatformPublishUrl(publishUrl);

        // 切换进度条
        XLoading.instance.beginShow(0, this);

        string urlver = XUtil.getUrl(publishUrl, "ver.json");

        WWW wwwver = new WWW(urlver);

        _www     = wwwver;
        _wwwinfo = "获取" + urlver + "中";

        yield return(wwwver);

        XVer ver = new XVer();

        if (!string.IsNullOrEmpty(wwwver.error) || !ver.load(wwwver.text))
        {
            XDebug.LogError("远程版本文件" + urlver + wwwver.error);
            wwwver.Dispose();
            _www    = null;
            _status = XUpdateStatus.FAIL;
            yield break;
        }

        wwwver.Dispose();

        XDebug.Log("更新开始远程版本号:v" + ver.ver + "当前版本号:v" + XLoad.instance.localver);

        if (ver.ver != XLoad.instance.localver)
        {
            string urlversion = XUtil.getUrl(ver.ab, "v" + ver.ver + "/assets/version.json");
            WWW    wwwWebInfo = new WWW(urlversion);

            _www     = wwwWebInfo;
            _wwwinfo = "获取" + urlversion + "中";

            yield return(wwwWebInfo);

            XPackInfo webInfo = new XPackInfo();
            if (!string.IsNullOrEmpty(wwwWebInfo.error) || !webInfo.load(wwwWebInfo.text))
            {
                XDebug.LogError("远程版本文件" + urlver + wwwWebInfo.error);
                wwwWebInfo.Dispose();
                _www    = null;
                _status = XUpdateStatus.FAIL;
                yield break;
            }
            wwwWebInfo.Dispose();

            Dictionary <string, XBundleInfo> modify = XLoad.instance._info.compareWebList(webInfo);
            uint allsize   = 0;
            int  filecount = modify.Count;
            foreach (var bd in modify)
            {
                allsize += (uint)(bd.Value.fileSize);
            }

            if (filecount <= 0)
            {
                XDebug.Log("文件一样无需更新修改版本号");
                XLoad.instance._info._version = ver.ver;
                // 保存文件
                XLoad.instance._info.saveFile(XLoad.getABDataWritePath("assets/version.json"));
                _status = XUpdateStatus.SUCESS;
                // todo 修改版本号
                yield break;
            }

            XDebug.Log(string.Format("一共{0}个文件,大小需要更新{1}", filecount, XUtil.getSizeString(allsize)));

            // 更新目录
            this.oldver = XLoad.instance.localver;
            this.newver = ver.ver;

            string updateDirName  = getUpdateDirName();
            string updateFileName = getUpdateFileName("update.json");
            if (XUtil.isExistDirectory(updateDirName) && XUtil.isExistFile(updateFileName))
            {
                if (!loadFile(updateFileName))
                {
                    alreadyDownloadDict.Clear();
                    XUtil.clearDirectory(updateDirName);
                }
            }

            int fileno = 0;
            foreach (var bd in modify)
            {
                fileno++;
                string ufilename = getUpdateFileName(bd.Key, bd.Value.isDirectory);

                if (alreadyDownloadDict.ContainsKey(bd.Key))
                {
                    XBundleInfo bundleInfo = alreadyDownloadDict[bd.Key];
                    if (bundleInfo.fileSize == bd.Value.fileSize && bundleInfo.hash == bd.Value.hash && XUtil.isExistFile(ufilename))
                    {
                        XDebug.Log("文件已下载完毕,跳过" + ufilename);
                        continue;
                    }
                }

                if (XUtil.isExistFile(ufilename))
                {
                    XUtil.deleteFile(ufilename);
                }
                string webufile = getUpdateWebName(ver.ab, "v" + ver.ver + "/" + bd.Key, bd.Value.isDirectory);
                WWW    wwwufile = new WWW(webufile);

                _www     = wwwufile;
                _wwwinfo = string.Format("下载({0}/{1}){2}", fileno, filecount, bd.Key);

                yield return(wwwufile);

                if (!string.IsNullOrEmpty(wwwufile.error))
                {
                    XDebug.LogError("远程文件" + webufile + wwwufile.error);
                    wwwufile.Dispose();
                    _www    = null;
                    _status = XUpdateStatus.FAIL;
                    yield break;
                }

                if (!XUtil.writeFileAllBytes(ufilename, wwwufile.bytes))
                {
                    XDebug.LogError("写入文件失败" + ufilename);
                    wwwufile.Dispose();
                    _www    = null;
                    _status = XUpdateStatus.FAIL;
                    yield break;
                }

                alreadyDownloadDict[bd.Key] = bd.Value;
                // 保存一下记录
                saveFile(updateFileName);

                wwwufile.Dispose();
                _www = null;
            }

            // 已经成功了,拷贝文件到目标文件
            _wwwinfo = "拷贝文件中";
            foreach (var bd in modify)
            {
                string ufilename = getUpdateFileName(bd.Key, bd.Value.isDirectory);

                string dfilename = XLoad.getABDataWritePath(bd.Key, bd.Value.isDirectory);
                if (!XUtil.copyFile(ufilename, dfilename))
                {
                    XDebug.LogError("拷贝文件失败" + ufilename);
                    _status = XUpdateStatus.FAIL;
                    break;
                }

                XLoad.instance._info.addBundle(bd.Key, bd.Value);
            }


            _wwwinfo = "重新生成版本文件";
            XLoad.instance._info.callDependAllSize();


            // 变更版本
            XLoad.instance._info._version = ver.ver;
            // 保存文件
            if (!XLoad.instance._info.saveFile(XLoad.getABDataWritePath("assets/version.json")))
            {
                _status = XUpdateStatus.FAIL;
                yield break;
            }

            _status = XUpdateStatus.SUCESS;
        }
        else
        {
            // XDebug.Log("版本一致没有什么不同无需更新");
            _status = XUpdateStatus.SUCESS;
        }
    }