Beispiel #1
0
        /// <summary>
        /// 取得Bundle备份目录(用于SVN备份目录).
        /// </summary>
        /// <returns>Bundle备份目录.</returns>
        /// <param name="iAppVersion">App版本.</param>
        /// <param name="iSubDir">子文件夹.</param>
        private string GetBundleBackDir(string iAppVersion, string iSubDir = null)
        {
            string backUpDir = AssetBundlesManager.BackUpDir;

            if (Directory.Exists(backUpDir) == false)
            {
                Directory.CreateDirectory(backUpDir);
            }
            backUpDir = AssetBundlesManager.BackUpDirOfBundles;
            if (Directory.Exists(backUpDir) == false)
            {
                Directory.CreateDirectory(backUpDir);
            }
            backUpDir = string.Format("{0}/{1}", backUpDir, UploadList.GetInstance().BuildTarget);
            if (Directory.Exists(backUpDir) == false)
            {
                Directory.CreateDirectory(backUpDir);
            }
            backUpDir = string.Format("{0}/{1}", backUpDir, iAppVersion);
            if (Directory.Exists(backUpDir) == false)
            {
                Directory.CreateDirectory(backUpDir);
            }
            if (string.IsNullOrEmpty(iSubDir) == false)
            {
                backUpDir = string.Format("{0}/{1}", backUpDir, iSubDir);
                if (Directory.Exists(backUpDir) == false)
                {
                    Directory.CreateDirectory(backUpDir);
                }
            }
            return(backUpDir);
        }
Beispiel #2
0
        /// <summary>
        /// 上传检测
        /// </summary>
        private IEnumerator UploadCheck()
        {
            // 重置版本
            UploadList.GetInstance().AppVersion    = BuildInfo.GetInstance().BuildVersion;
            UploadList.GetInstance().CenterVersion = BuildInfo.GetInstance().CenterVersion;
            yield return(new WaitForEndOfFrame());

            // 初始化上传进度计数器
            UploadList.GetInstance().InitProgressCounter();
            yield return(new WaitForEndOfFrame());

            // 需要上传
            if (UploadList.GetInstance().isUploadNecessary == true)
            {
                this.UploadPreConfirmNotification(
                    UploadList.GetInstance().GetTotalCount(),
                    UploadList.GetInstance().GetTotalDatasize());
            }
            else
            {
                this.isStarted    = false;
                this._isCompleted = true;

                // 无效上传 重置状态为:OK
                this._State = TRunState.OK;
            }
        }
Beispiel #3
0
        /// <summary>
        /// 上传取消确认.
        /// </summary>
        /// <param name="iYesOrNo">是否取消下载(true:取消下载;false:不取消下载;).</param>
        private void UploadCancelConfirm(bool iYesOrNo)
        {
            if (iYesOrNo == true)
            {
                isCanceled        = true;
                this.isStarted    = false;
                this._isCompleted = false;

                // 清空错误列表
                if (this._errors != null)
                {
                    this._errors.Clear();
                }

                // 导出已上传完成信息
                // 导出最新的下载列表信息
                UploadList.GetInstance().ExportToJsonFile();

                if (this._uploadBar != null)
                {
                    this._uploadBar.Cancel();
                }

                // 取消上传 重置状态:OK
                this._State = TRunState.OK;

                return;
            }

            // 继续上传
            StartCoroutine(UploadContinue());
        }
Beispiel #4
0
        /// <summary>
        /// 向服务器上传Bundle文件.
        /// </summary>
        private bool UpLoadFileToServer()
        {
            if (string.IsNullOrEmpty(this.UploadBaseUrl) == true)
            {
                return(false);
            }
            if (this._target == null)
            {
                return(false);
            }
            if (this._server == null)
            {
                return(false);
            }

            // 上传Bundle文件
            string uploadBundleUrl = string.Format("{0}/{1}", this.UploadBaseUrl, this.FileName);
            string inputFilePath   = UploadList.GetLocalBundleFilePath(
                this._target.ID, this._target.FileType, (TBundleType.Scene == this._target.BundleType));

            if (File.Exists(inputFilePath) == true)
            {
                if (this._onStart != null)
                {
                    this._onStart(this.FileName);
                }

                if (TUploadWay.Ftp == this._uploadWay)
                {
                    this._state = this.UpLoadFileToFtpServer(
                        uploadBundleUrl, inputFilePath, this._server.AccountId, this._server.Pwd);
                    if (TRunState.OK != this._state)
                    {
                        ErrorDetail error = new ErrorDetail();
                        error.Type   = TErrorType.UploadFailed;
                        error.State  = this._state;
                        error.Detail = string.Format("[Upload Failed] {0} -> {1}",
                                                     inputFilePath, uploadBundleUrl);
                        error.Retries = this.Retries;
                        this._errors.Add(error);
                        return(false);
                    }
                    else
                    {
                        if (this._onSuccessed != null)
                        {
                            this._onSuccessed(this, this._target, this.Retries);
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #5
0
        void Awake()
        {
            ManifestUpload = UploadList.GetInstance().ManifestUpload;

            // 设定下载进度条委托
            if (this._uploadBar != null)
            {
                this._uploadBar.SetDelegate(
                    GetUploadedProgress,
                    GetUploadedState,
                    GetUploadTotalCount,
                    GetUploadedCount);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 初始化上传队列.
        /// </summary>
        private IEnumerator InitUploadQueue()
        {
            this._isCompleted = false;

            // 初始化上传信息队列
            List <UploadItem> targets = UploadList.GetInstance().Targets;

            if (this.UploadQueue != null)
            {
                UploadItem[] uploadTargets = targets.
                                             Where(o => (
                                                       (false == o.Uploaded) &&
                                                       (false == o.Scraped)))
                                             .OrderBy(o => o.No)
                                             .ToArray();
                if ((uploadTargets == null) || (uploadTargets.Length <= 0))
                {
                    this._State = TRunState.NoUploadTarget;
                    UtilsLog.Warning("InitUploadQueue", "There is no target to upload!!!");
                }
                yield return(new WaitForEndOfFrame());

                if (TRunState.OK == this._State)
                {
                    this.UploaderCount = 0;
                    int targetsCount = uploadTargets.Length;
                    int maxCount     = ServersConf.GetInstance().ThreadMaxCount;
                    this.UploaderMaxCount = (targetsCount > maxCount) ? maxCount : targetsCount;

                    foreach (UploadItem loop in uploadTargets)
                    {
                        if (loop == null)
                        {
                            continue;
                        }
                        Uploader uploader = Uploader.Create(loop,
                                                            this.OnUploadStart,
                                                            this.OnUploadFailed,
                                                            this.OnUploadSuccessed);
                        if (uploader != null)
                        {
                            this.UploadQueue.Enqueue(uploader);
                        }
                    }
                    yield return(new WaitForEndOfFrame());
                }
            }
            yield return(null);
        }
Beispiel #7
0
        /// <summary>
        /// 上传成功委托.
        /// </summary>
        /// <param name="iUploader">上传器.</param>
        /// <param name="iTargetInfo">下载目标信息.</param>
        /// <param name="iIsManifest">manifest标志位.</param>
        /// <param name="iRetries">剩余重试次数.</param>
        public void OnUploadSuccessed(Uploader iUploader, UploadItem iTargetInfo, int iRetries)
        {
            UtilsLog.Info("OnUploadSuccessed", "No:{0} State:{1} Retries:{2}",
                          iTargetInfo.toString(), this._State, iRetries);

            UploadList.GetInstance().UploadCompleted(iTargetInfo.ID, iTargetInfo.FileType);

            if (null != iUploader)
            {
                iUploader.Dispose();
                GC.Collect();
            }

            lock (_uploaderCountLock) {
                --this.UploaderCount;
            }
        }
Beispiel #8
0
        /// <summary>
        /// 备份本地文件.
        /// </summary>
        private void BackUpBundleFiles()
        {
            foreach (UploadItem loop in UploadList.GetInstance().Targets)
            {
                string subDir = UploadList.AssetBundleDirNameOfNormal;
                if (TBundleType.Scene == loop.BundleType)
                {
                    subDir = UploadList.AssetBundleDirNameOfScenes;
                }

                string filePath = UploadList.GetLocalBundleFilePath(
                    loop.ID, loop.FileType, (TBundleType.Scene == loop.BundleType));
                string manifestFilePath = UploadList.GetLocalBundleFilePath(
                    loop.ID, loop.FileType, (TBundleType.Scene == loop.BundleType));

                // 废弃Bundle
                if (loop.Scraped == true)
                {
                    if (File.Exists(filePath) == true)
                    {
                        File.Delete(filePath);
                    }
                    if (File.Exists(manifestFilePath) == true)
                    {
                        File.Delete(manifestFilePath);
                    }
                }
                else
                {
                    // Bundle 文件备份
                    if (this.BackupFile(filePath, subDir) == false)
                    {
                        break;
                    }

                    // Bundle 文件备份
                    if (this.BackupFile(manifestFilePath, subDir) == false)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// 初始化.
        /// </summary>
        /// <param name="iTarget">上传目标.</param>
        /// <param name="iOnStart">开始上传委托.</param>
        /// <param name="iOnFailed">上传失败委托.</param>
        /// <param name="iOnSuccessed">上传成功委托.</param>
        /// <param name="iUploadWay">上传方式.</param>
        private void Init(
            UploadItem iTarget,
            OnStart iOnStart,
            OnFailed iOnFailed,
            OnSuccessed iOnSuccessed,
            TUploadWay iUploadWay = TUploadWay.Ftp)
        {
            this._target      = iTarget;
            this._onStart     = iOnStart;
            this._onFailed    = iOnFailed;
            this._onSuccessed = iOnSuccessed;
            this._uploadWay   = iUploadWay;
            this.Retries      = ServersConf.GetInstance().NetRetries;

            if (this._server == null)
            {
                this._server = ServersConf.GetInstance().UploadServer;
            }
            this.UploadBaseUrl = ServersConf.GetBundleUploadBaseURL(this._server, this._target);
            this.FileName      = UploadList.GetLocalBundleFileName(this._target.ID, this._target.FileType);
        }
Beispiel #10
0
        /// <summary>
        /// 上传上传列表列表信息.
        /// </summary>
        /// <param name="iServerInfo">服务器信息.</param>
        private string UploadUploadListFile(UploadServerInfo iServerInfo)
        {
            // 导出Json文件,保存至(Resources/Conf)
            string inputFilePath = UploadList.GetInstance().ExportToJsonFile();

            UtilsLog.Info("UploadUploadListFile", "ExportToJsonFile(Path:{0})", inputFilePath);

            // 打包信息URL
            string uploadUrl = ServersConf.GetUploadListBaseUrl(iServerInfo);

            if (File.Exists(inputFilePath) == true)
            {
                int    lastIndex = inputFilePath.LastIndexOf("/");
                string fileName  = inputFilePath.Substring(lastIndex + 1);
                uploadUrl = string.Format("{0}/{1}", uploadUrl, fileName);

                // 上传Bundles列表信息文件
                this._State = UpLoadFileToFtpServer(
                    uploadUrl, inputFilePath, iServerInfo.AccountId, iServerInfo.Pwd);

                if (TRunState.OK != this._State)
                {
                    UtilsLog.Error("UploadUploadListFile", "Upload Failed!!! \n {0} -> {1}", inputFilePath, uploadUrl);
                    return(null);
                }
                else
                {
                    this._uploadState = string.Format("[Upload] {0}", fileName);
                    return(inputFilePath);
                }
            }
            else
            {
                UtilsLog.Error("UploadUploadListFile", "Upload Failed!!! \n Upload file is not exist!!!(Path:{0})", inputFilePath);
                return(null);
            }
        }
Beispiel #11
0
        /// <summary>
        /// 备份文件.
        /// </summary>
        /// <param name="iBackupFilePath">备份文件路径.</param>
        /// <param name="iSubDir">备份文件子目录.</param>
        private bool BackupFile(string iBackupFilePath, string iSubDir = null)
        {
            // 上传文件列表
            if ((string.IsNullOrEmpty(iBackupFilePath) == false) &&
                (File.Exists(iBackupFilePath) == true))
            {
                // 移到备份目录
                string backupDir = this.GetBundleBackDir(UploadList.GetInstance().AppVersion, iSubDir);

                int    lastIndex          = iBackupFilePath.LastIndexOf("/");
                string fileName           = iBackupFilePath.Substring(lastIndex + 1);
                string backUpFileFullPath = string.Format("{0}/{1}", backupDir, fileName);

                UtilsLog.Info("BackupFile", "Successed. {0} -> {1}", iBackupFilePath, backUpFileFullPath);
                File.Copy(iBackupFilePath, backUpFileFullPath, true);
                if (File.Exists(backUpFileFullPath) == false)
                {
                    UtilsLog.Error("BackupFile", "Failed!!! {0} -> {1}", iBackupFilePath, backUpFileFullPath);
                    return(false);
                }
                this._uploadState = string.Format("[BackUp] -> {0}", fileName);
            }
            return(true);
        }
Beispiel #12
0
        /// <summary>
        /// 检测服务器上得各个路径.
        /// </summary>
        /// <returns><c>true</c>, OK, <c>false</c> NG.</returns>
        private IEnumerator CheckDirsOnServer()
        {
            string buildName = BuildInfo.GetInstance().BuildName;

            // 上传服务器信息
            UploadServerInfo server = ServersConf.GetInstance().UploadServer;

            if (server == null)
            {
                this._State = TRunState.GetServerInfoFailed;
                yield return(null);
            }

            // 取得上传URL
            string uploadBaseUrl = ServersConf.GetUploadBaseURL(server);

            int    startIndex = uploadBaseUrl.IndexOf(buildName);
            string dirsInfo   = uploadBaseUrl.Substring(startIndex);

            string[] dirNames = dirsInfo.Split('/');

            string curUrl     = uploadBaseUrl.Substring(0, startIndex - 1);
            string createdDir = null;

            for (int i = 0; i < dirNames.Length; ++i)
            {
                if (this.CheckDirOnServer(server, curUrl, dirNames [i], ref createdDir) == true)
                {
                    curUrl = string.Format("{0}/{1}", curUrl, dirNames [i]);
                    yield return(new WaitForEndOfFrame());
                }
                else
                {
                    this._State = TRunState.CheckDirFailed;
                    yield return(null);
                }
            }

            // 检测目录
            // Url:<ParentUrl>/bundles
            if (this.CheckDirOnServer(server, curUrl, "bundles", ref createdDir) == true)
            {
                curUrl = string.Format("{0}/{1}", curUrl, "bundles");
                yield return(new WaitForEndOfFrame());
            }
            else
            {
                this._State = TRunState.CheckDirFailed;
                yield return(null);
            }

            // Url:<ParentUrl>/<BuildTarget>
            string buildTarget = UploadList.GetInstance().BuildTarget;

            if (this.CheckDirOnServer(server, curUrl, buildTarget, ref createdDir) == true)
            {
                curUrl = string.Format("{0}/{1}", curUrl, buildTarget);
                yield return(new WaitForEndOfFrame());
            }
            else
            {
                this._State = TRunState.CheckDirFailed;
                yield return(null);
            }

            // Url:<ParentUrl>/<AppVersion>
            string appVersion = UploadList.GetInstance().AppVersion;

            if (this.CheckDirOnServer(server, curUrl, appVersion, ref createdDir) == true)
            {
                curUrl = string.Format("{0}/{1}", curUrl, appVersion);
                yield return(new WaitForEndOfFrame());
            }
            else
            {
                this._State = TRunState.CheckDirFailed;
                yield return(null);
            }

            // Url:<ParentUrl>/Normal
            string subUrlTmp        = curUrl;
            string subCreatedDirTmp = createdDir;

            if (this.CheckDirOnServer(server, subUrlTmp,
                                      UploadList.AssetBundleDirNameOfNormal, ref subCreatedDirTmp) == true)
            {
                subUrlTmp = string.Format("{0}/{1}", subUrlTmp, UploadList.AssetBundleDirNameOfNormal);
                yield return(new WaitForEndOfFrame());
            }
            else
            {
                this._State = TRunState.CheckDirFailed;
                yield return(null);
            }

            // Url:<ParentUrl>/Scene
            subUrlTmp        = curUrl;
            subCreatedDirTmp = createdDir;
            if (this.CheckDirOnServer(server, subUrlTmp,
                                      UploadList.AssetBundleDirNameOfScenes, ref subCreatedDirTmp) == true)
            {
                subUrlTmp = string.Format("{0}/{1}", subUrlTmp, UploadList.AssetBundleDirNameOfScenes);
                yield return(new WaitForEndOfFrame());
            }
            else
            {
                this._State = TRunState.CheckDirFailed;
                yield return(null);
            }

            yield return(null);
        }
Beispiel #13
0
 private int GetUploadedCount()
 {
     return(UploadList.GetInstance().GetUploadedCount());
 }
Beispiel #14
0
 private float GetUploadedProgress()
 {
     return(UploadList.GetInstance().GetCompletedProgress());
 }