예제 #1
0
            private IEnumerator Install(string downloadUrl, string installPath, IProgress <float> progress = null)
            {
                var numInstallers = Instance.numInstallers;

                // 同時インストール数待ち.
                while (numInstallers <= installCount)
                {
                    yield return(null);
                }

                installCount++;

                using (Installer = new CriFsWebInstaller())
                {
                    Installer.Copy(downloadUrl, installPath);

                    CriFsWebInstaller.StatusInfo statusInfo;

                    while (true)
                    {
                        statusInfo = Installer.GetStatusInfo();

                        if (progress != null)
                        {
                            progress.Report((float)statusInfo.receivedSize / statusInfo.contentsSize);
                        }

                        if (statusInfo.status != CriFsWebInstaller.Status.Busy)
                        {
                            break;
                        }

                        yield return(null);
                    }

                    if (statusInfo.error != CriFsWebInstaller.Error.None)
                    {
                        throw new Exception(string.Format("[Download Error] {0}\n{1}", AssetInfo.ResourcePath, statusInfo.error));
                    }
                }

                installCount--;
            }
예제 #2
0
        //--------------------------------------------
        // Public API
        //--------------------------------------------
        #region ===== PUBLIC_API =====


        /// <summary>
        /// Download 実行
        /// </summary>
        /// <param name="_cpkName">CPK名</param>
        /// <param name="_versionHashName">CPKのHash値文字列</param>
        /// <param name="_onComplete">ダウンロード完了コールバック</param>
        /// <returns></returns>
        public IEnumerator DonwloadCPK(string _cpkName, string _versionHashName, OnCompleteDownload _onComplete)
        {
            string url = CriPackageUtility.GetPackegeURL(_cpkName);

            // 無効なURL
            if (string.IsNullOrEmpty(url))
            {
                if (_onComplete != null)
                {
                    _onComplete.Invoke(false);
                }
                yield break;
            }
            // Cache上に存在している
            if (CriPackageCacheController.IsCached(_cpkName, _versionHashName))
            {
                if (_onComplete != null)
                {
                    _onComplete.Invoke(true);
                }
                yield break;
            }

            CriFsWebInstaller installer = GetEmptyInstaller();

            // 空くまで待機
            while (installer == null)
            {
                installer = GetEmptyInstaller();
                yield return(null);
            }
            string outputPath = CriPackageCacheController.GetOutputPath(_cpkName, _versionHashName);

            // Directory 生成
            CriPackageCacheController.CreateAssetCacheDir(_cpkName);
            // 古いバージョンのキャッシュがあれば削除
            CriPackageCacheController.DeleteTargetOtherVersionPackage(_cpkName, _versionHashName);

            // Download 開始
            installer.Copy(url, outputPath);
            // 終了まで待機
            CriFsWebInstaller.StatusInfo info = installer.GetStatusInfo();
            while (info.status == CriFsWebInstaller.Status.Busy)
            {
                info = installer.GetStatusInfo();
                yield return(null);
            }

            info = installer.GetStatusInfo();
            switch (info.status)
            {
            case CriFsWebInstaller.Status.Error:
            {
                //エラーによる失敗
                if (_onComplete != null)
                {
                    _onComplete.Invoke(false);
                }
            } break;

            case CriFsWebInstaller.Status.Stop:
            {
                // 誰かに止められた
                if (_onComplete != null)
                {
                    _onComplete.Invoke(false);
                }
            } break;

            case CriFsWebInstaller.Status.Complete:
            {
                // 成功
                if (_onComplete != null)
                {
                    _onComplete.Invoke(true);
                }
            } break;
            }
        }