コード例 #1
0
        public void DownloadIcons()
        {
            var units = Database.I.Units;

            foreach (var unit in units)
            {
                var name = (unit.Id + (unit.IsUnlockRarity6 ? 6 : 3) * RarityCoefficient).ToString();

                //既にあればスルーする
                if (File.Exists($"{DownloadLocation}{name}.png"))
                {
                    continue;
                }
                //未変換だったら変換だけする
                if (File.Exists($"{DownloadLocation}{name}.webp"))
                {
                    ConvertWebpToPng(name);
                    continue;
                }

                var webClient = new WebClient();
                webClient.DownloadFileCompleted += (sender, args) =>
                {
                    ConvertWebpToPng(name);
                    File.Delete($"{DownloadLocation}{name}.webp");
                    OnCompleteDownload?.Invoke();
                };
                webClient.DownloadFileAsync(new Uri(string.Format(Url, name)), $"{DownloadLocation}{name}.webp");
            }
        }
コード例 #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;
            }
        }