コード例 #1
0
        public override void Initialize(Config config)
        {
            endPoint = new HttpEndPoint(config.ApiEndpoint, new EndPointOptions()
            {
                Key       = config.ApiKey.Value,
                KeepAlive = false
            });

            api = new LoginAPI(endPoint);
        }
コード例 #2
0
        IEnumerator DoDownload(Hashtable info)
        {
            var version = Dot.Integer("cl", info, 0);
            var files   = Dot.Array("files", info, null);

            if (files == null || files.Count == 0)
            {
                EB.Debug.LogError("missing file list!");
                yield break;
            }

            var pack = new ContentPack();

            pack.version = version;
            pack.folder  = Path.Combine(BasePath, version.ToString());
            pack.packs   = new List <string>();

            try
            {
                Directory.CreateDirectory(pack.folder);
            }
            catch (System.Exception ex)
            {
                EB.Debug.LogError("failed to create directory  " + pack.folder + " " + ex);
                yield break;
            }

            // write the info file
            if (!WriteJsonFile(Path.Combine(pack.folder, "info.txt"), info))
            {
                yield break;
            }

            var cdn = Dot.String("cdn", info, string.Empty);

            using (var endpoint = new HttpEndPoint(cdn, new EndPointOptions()))
            {
                var filesToDownload = new ArrayList();

                foreach (var file in files)
                {
                    var url       = Dot.String("url", file, string.Empty);
                    var size      = Dot.Long("size", file, 0);
                    var filename  = Path.GetFileName(url);
                    var localPath = Path.Combine(pack.folder, filename);
                    if (!CheckFile(localPath, size))
                    {
                        filesToDownload.Add(file);
                    }

                    pack.packs.Add(Dot.String("pack", file, string.Empty));
                }

                // download all the files
                for (int i = 0; i < filesToDownload.Count; ++i)
                {
                    var file = filesToDownload[i];
                    var url  = Dot.String("url", file, string.Empty);
                    var size = Dot.Long("size", file, 0);
                    //var md5 = Dot.String("md5", file, string.Empty);

                    var filename  = Path.GetFileName(url);
                    var localPath = Path.Combine(pack.folder, filename);

                    // download
                    yield return(Coroutines.Run(DoDownloadFile(i, filesToDownload.Count, size, endpoint, localPath, url)));

                    if (!CheckFile(localPath, size))
                    {
                        EB.Debug.LogError("Failed to download file! " + url);
                        yield break;
                    }
                }
            }

            Notify(Localizer.GetString("ID_SPARX_CONTENT_EXTRACTING"));
            yield return(new WaitForFixedUpdate());

            if (_pool == null)
            {
                _pool = new ThreadPool(1);
            }
            ThreadPool.AsyncTask async = _pool.Queue(this.ThreadTask, pack);

            while (!async.done)
            {
                yield return(new WaitForFixedUpdate());
            }

            if (async.exception != null)
            {
                Error = "ID_SPARX_CONTENT_FAILED_EXTRACT";
                Notify(Localizer.GetString("ID_SPARX_CONTENT_FAILED_EXTRACT"));
                yield break;
            }

            // mount it!
            Mount(pack);

            yield break;
        }