Esempio n. 1
0
        /// <summary>
        /// 获取下载资源数据
        /// </summary>
        /// <param name="serverUrl"></param>
        /// <param name="localSaveAssetsPath"></param>
        /// <param name="platform"></param>
        /// <param name="serverVersionInfo"></param>
        /// <param name="localVersionInfo"></param>
        /// <returns>err, suc, 服务器数据, 本地数据,服务器数据内容 </returns>
        public (string, string, List <AssetItem>, List <AssetItem>, string) GetDownloadAssetsData(string serverUrl, RuntimePlatform platform, AssetsVersionInfo serverVersionInfo, AssetsVersionInfo localVersionInfo)
        {
            //返回数据
            string err = null;
            string suc = null;
            var    serverAssetsInfoList = new List <AssetItem>();
            var    localAssetsInfoList  = new List <AssetItem>();
            var    serverAssetsContent  = "";

            //1.判断版本号
            if (localVersionInfo.Version == serverVersionInfo.Version)
            {
                suc = "【版本控制】全量版本一致,无需下载!";
                BDebug.Log(suc);
                return(err, suc, null, null, null);
            }

            //2.获取Assets.info
            BDebug.Log($"【版本控制】全量下载模式! server:{serverVersionInfo.Version} local:{localVersionInfo.Version} ", "red");
            {
                //服务器路径
                var serverAssetInfosUrl = BResources.GetAssetsInfoPath(serverUrl, platform);
                //下载服务器Assets.info
                (err, serverAssetsInfoList, serverAssetsContent) = LoadServerAssetInfo(serverAssetInfosUrl);
            }
            //加载本地SubPackage配置
            localAssetsInfoList = LoadLocalSubPacakgeAssetInfo(platform, localVersionInfo);

            //加载本地asset.info
            var localAssetsInfo = this.LoadLocalAssetInfo(platform);

            localAssetsInfoList.AddRange(localAssetsInfo);
            //去重
            localAssetsInfoList = localAssetsInfoList.Distinct().ToList();
            localAssetsInfoList.Sort((a, b) =>
            {
                if (a.Id < b.Id)
                {
                    return(-1);
                }
                else if (a.Id == b.Id)
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            });
            //返回
            return(err, suc, serverAssetsInfoList, localAssetsInfoList, serverAssetsContent);
        }
Esempio n. 2
0
        /// <summary>
        /// 加载本地的Asset.info
        /// </summary>
        private List <AssetItem> LoadLocalAssetInfo(RuntimePlatform platform)
        {
            var retList = new List <AssetItem>();
            //优先加载persistent的Assets.info
            var persistentAssetInfoPath = BResources.GetAssetsInfoPath(BApplication.persistentDataPath, platform);

            if (File.Exists(persistentAssetInfoPath))
            {
                var content = File.ReadAllText(persistentAssetInfoPath);
                retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content);
            }
            //streaming 和其他的Assets.info
            else
            {
                //根据加载模式不同,寻找不同目录下的其他配置
                //打包时,本地会带一份ServerAssets.info以标记当前包携带的资源
                var loadArtRoot = BDLauncher.Inst.GameConfig.ArtRoot;
                switch (loadArtRoot)
                {
                case AssetLoadPathType.Persistent:
                case AssetLoadPathType.StreamingAsset:
                {
                    //TODO :BSA 读取,不需要Streaming前缀
                    var steamingAssetsInfoPath = IPath.Combine(BApplication.GetPlatformPath(platform), BResources.ASSETS_INFO_PATH);
                    //var steamingAssetsInfoPath = GetAssetsInfoPath(BDApplication.streamingAssetsPath, platform);
                    if (BetterStreamingAssets.FileExists(steamingAssetsInfoPath))
                    {
                        var content = BetterStreamingAssets.ReadAllText(steamingAssetsInfoPath);
                        retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content);
                    }
                }
                break;

                case AssetLoadPathType.DevOpsPublish:
                {
                    var path = GameConfig.GetLoadPath(loadArtRoot);
                    var devopsAssetInfoPath = BResources.GetAssetsInfoPath(path, platform);
                    if (File.Exists(devopsAssetInfoPath))
                    {
                        var content = File.ReadAllText(devopsAssetInfoPath);
                        retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content);
                    }
                }
                break;
                }
            }

            return(retList);
        }
Esempio n. 3
0
        /// <summary>
        /// 开始版本控制逻辑
        /// </summary>
        /// <param name="serverUrl">服务器配置根目录</param>
        /// <param name="localSaveAssetsPath">本地根目录</param>
        /// <param name="onDownloadProccess">任务进度通知(下载完不等于任务完成!)</param>
        /// <param name="onTaskEndCallback">任务成功\失败通知!</param>
        /// 返回码: -1:error  0:success
        async private Task StartVersionControl(UpdateMode updateMode, string serverUrl, string localSaveAssetsPath, string subPackageName, Action <AssetItem, List <AssetItem> > onDownloadProccess,
                                               Action <RetStatus, string> onTaskEndCallback)
        {
            var platform = BApplication.RuntimePlatform;
            //目录准备
            var platformStr           = BApplication.GetRuntimePlatformPath();
            var localSavePlatformPath = IPath.Combine(localSaveAssetsPath, platformStr);

            if (!Directory.Exists(localSavePlatformPath))
            {
                Directory.CreateDirectory(localSavePlatformPath);
            }

            //子包模式判断
            bool isDownloadSubPackageMode = !string.IsNullOrEmpty(subPackageName);


            //1.下载服务器version config
            var serverVersionInfo = new AssetsVersionInfo();
            var localVersionInfo  = new AssetsVersionInfo();

            #region AssetVersion.info下载
            BDebug.Log("【版本控制】1.获取版本信息~", "red");
            {
                var ret = await DownloadAssetVersionInfo(serverUrl, localSaveAssetsPath);

                if (ret.Item1 != null)
                {
                    await UniTask.SwitchToMainThread();

                    onTaskEndCallback?.Invoke(RetStatus.Error, ret.Item1);
                    return;
                }

                serverVersionInfo = ret.Item2;
                localVersionInfo  = ret.Item3;
            }

            #endregion

            //2.对比版本、获取对应数据
            BDebug.Log("【版本控制】2.对比版本信息~", "red");
            string err = null;
            string suc = null;
            var    serverAssetsInfoList = new List <AssetItem>();
            var    localAssetsInfoList  = new List <AssetItem>();
            var    serverAssetsContent  = "";
            //
            switch (updateMode)
            {
            case UpdateMode.Compare:
            case UpdateMode.CompareWithRepair:     //CP模式对比版本与Compare一致
            {
                if (isDownloadSubPackageMode)
                {
                    //分包模式
                    (err, suc, serverAssetsInfoList, localAssetsInfoList, serverAssetsContent) = GetDownloadSubPackageData(serverUrl, subPackageName, platform, serverVersionInfo, localVersionInfo);
                }
                else
                {
                    //全量下载
                    (err, suc, serverAssetsInfoList, localAssetsInfoList, serverAssetsContent) = GetDownloadAssetsData(serverUrl, platform, serverVersionInfo, localVersionInfo);
                }
            }
            break;

            case UpdateMode.Repair:
            {
                //服务器路径
                var serverAssetInfosUrl = BResources.GetAssetsInfoPath(serverUrl, platform);
                //下载服务器Assets.info
                (err, serverAssetsInfoList, serverAssetsContent) = LoadServerAssetInfo(serverAssetInfosUrl);
            }
            break;
            }

            //返回返回结果,是否继续下载
            if (err != null)
            {
                BDebug.LogError(err);
                await UniTask.SwitchToMainThread();

                onTaskEndCallback?.Invoke(RetStatus.Error, err);
                return;
            }

            if (suc != null)
            {
                BDebug.Log(suc);
                await UniTask.SwitchToMainThread();

                onTaskEndCallback?.Invoke(RetStatus.Success, suc);
                return;
            }


            //3.生成差异列表
            BDebug.Log("【版本控制】3.获取差异列表~", "red");
            Queue <AssetItem> diffDownloadQueue = null;

            #region 生成差异文件

            switch (updateMode)
            {
            case UpdateMode.Compare:
            {
                diffDownloadQueue = Compare(localAssetsInfoList, serverAssetsInfoList, platform);
            }
            break;

            case UpdateMode.Repair:
            case UpdateMode.CompareWithRepair:     //CP 获取差异模式与Repair一致
            {
                diffDownloadQueue = Repair(serverAssetsInfoList, platform);
            }
            break;
            }

            BDebug.Log($"【版本控制】 配置数量:{serverAssetsInfoList.Count} ,本地存在{serverAssetsInfoList.Count - diffDownloadQueue.Count},下载文件数量{diffDownloadQueue.Count}", "yellow");

            #endregion

            //4.开始下载

            #region 根据差异文件下载
            BDebug.Log("【版本控制】4.下载资源~", "red");
            {
                var failDownloadList = await DownloadAssets(serverUrl, localSaveAssetsPath, diffDownloadQueue, onDownloadProccess);

                if (failDownloadList.Count > 0)
                {
                    onTaskEndCallback(RetStatus.Error, "部分资源未下载完毕!");
                    return;
                }
            }

            #endregion


            //5.写入配置到本地

            #region 存储配置到本地
            BDebug.Log("【版本控制】5.写入配置~", "red");
            string localAssetInfoPath = "";
            if (isDownloadSubPackageMode)
            {
                localAssetInfoPath = BResources.GetAssetsSubPackageInfoPath(BApplication.persistentDataPath, platform, subPackageName);
            }
            else
            {
                localAssetInfoPath = BResources.GetAssetsInfoPath(BApplication.persistentDataPath, platform);
            }

            //写入Asset.Info
            File.WriteAllText(localAssetInfoPath, serverAssetsContent);
            BDebug.Log($"【版本控制】写入{Path.GetFileName(localAssetInfoPath)}  \n {serverAssetsContent}");

            //写入Version.Info
            if (isDownloadSubPackageMode)
            {
                localVersionInfo.Platfrom = serverVersionInfo.Platfrom;
                //子包版本信息
                localVersionInfo.SubPckMap[subPackageName] = serverVersionInfo.SubPckMap[subPackageName];
            }
            else
            {
                localVersionInfo.Platfrom = serverVersionInfo.Platfrom;
                //全量包信息
                localVersionInfo.Version = serverVersionInfo.Version;
            }

            var localAssetsVersionInfoPath = BResources.GetServerAssetsVersionInfoPath(localSaveAssetsPath, platform);
            File.WriteAllText(localAssetsVersionInfoPath, JsonMapper.ToJson(localVersionInfo));
            BDebug.Log($"【版本控制】写入{Path.GetFileName(localAssetsVersionInfoPath)}");

            #endregion
            // 6.删除过期资源
            BDebug.Log("【版本控制】6.冗余资源检查~", "red");
            if (!isDownloadSubPackageMode)
            {
                var artAssetsPath       = IPath.Combine(localSavePlatformPath, BResources.ART_ASSET_ROOT_PATH);
                var persistentArtAssets = Directory.GetFiles(artAssetsPath, "*", SearchOption.AllDirectories);
                var replacePath         = localSavePlatformPath + "/";
                foreach (var assetPath in persistentArtAssets)
                {
                    var localPath = assetPath.Replace(replacePath, "").Replace("\\", "/");
                    var ret       = serverAssetsInfoList.FirstOrDefault((info) => info.LocalPath.Equals(localPath));
                    if (ret == null)
                    {
                        BDebug.Log("【版本控制】删除过期资源:" + localPath);
                        File.Delete(assetPath);
                    }
                }
            }
            // 7.资源校验文件
            BDebug.Log("【版本控制】7.整包资源校验~", "red");
            err = null;
            foreach (var serverAssetItem in serverAssetsInfoList)
            {
                var ret = BResources.IsExsitAssetWithCheckHash(platform, serverAssetItem.LocalPath, serverAssetItem.HashName);
                if (!ret)
                {
                    if (string.IsNullOrEmpty(err))
                    {
                        err = "资源不存在:";
                    }

                    err += $"\n {serverAssetItem.LocalPath}";
                }
            }

            //the end.
            BDebug.Log("【版本控制】end.完成~", "red");
            await UniTask.SwitchToMainThread();

            if (err == null)
            {
                onTaskEndCallback?.Invoke(RetStatus.Success, null);
            }
            else
            {
                onTaskEndCallback?.Invoke(RetStatus.Error, err);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 构建所有资源
        /// </summary>
        /// <param name="platform">平台</param>
        /// <param name="outputPath">输出目录</param>
        /// <param name="setNewVersionNum">新版本号</param>
        static public void BuildAllAssets(RuntimePlatform platform, string outputPath, string setNewVersionNum = null)
        {
            var newVersionNum = "";
            //触发事件
            var lastPackageBuildInfo = GlobalAssetsHelper.GetPackageBuildInfo(outputPath, platform);
            var lastVersionNum       = lastPackageBuildInfo.Version;

            //没有指定版本号,则需要触发版本号的实现逻辑
            if (string.IsNullOrEmpty(setNewVersionNum))
            {
                BDFrameworkPipelineHelper.OnBeginBuildAllAssets(platform, outputPath, lastVersionNum, out newVersionNum);
            }

            //项目没有实现提供新的版本号,则内部提供一个版本号
            if (string.IsNullOrEmpty(newVersionNum) || lastVersionNum == newVersionNum)
            {
                //没指定版本号
                if (string.IsNullOrEmpty(setNewVersionNum))
                {
                    newVersionNum = VersionNumHelper.AddVersionNum(lastVersionNum, add: 1);
                }
                //指定版本号
                else
                {
                    newVersionNum = VersionNumHelper.AddVersionNum(lastVersionNum, setNewVersionNum);
                }
            }


            //开始构建资源
            var _outputPath = Path.Combine(outputPath, BApplication.GetPlatformPath(platform));

            if (!Directory.Exists(_outputPath))
            {
                Directory.CreateDirectory(_outputPath);
            }

            //1.编译脚本
            try
            {
                EditorWindow_ScriptBuildDll.RoslynBuild(outputPath, platform, ScriptBuildTools.BuildMode.Release);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }

            //2.打包表格
            try
            {
                Excel2SQLiteTools.AllExcel2SQLite(outputPath, platform);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }

            //3.打包资源
            try
            {
                //var config = BDEditorApplication.BDFrameWorkFrameEditorSetting.BuildAssetBundle;
                AssetBundleEditorToolsV2.GenAssetBundle(outputPath, platform);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }

            //4.生成母包资源信息
            GlobalAssetsHelper.GenBasePackageAssetBuildInfo(outputPath, platform, version: newVersionNum);

            //5.生成本地Assets.info配置
            //这个必须最后生成!!!!
            //这个必须最后生成!!!!
            //这个必须最后生成!!!!
            var allServerAssetItemList = PublishPipelineTools.GetAssetItemList(outputPath, platform);
            var csv            = CsvSerializer.SerializeToString(allServerAssetItemList);
            var assetsInfoPath = BResources.GetAssetsInfoPath(outputPath, platform);

            FileHelper.WriteAllText(assetsInfoPath, csv);
            //
            Debug.Log($"<color=yellow>{ BApplication.GetPlatformPath(platform)} - 旧版本:{lastPackageBuildInfo.Version} 新版本号:{newVersionNum} </color> ");
            //完成回调通知
            BDFrameworkPipelineHelper.OnEndBuildAllAssets(platform, outputPath, newVersionNum);
        }