Exemplo n.º 1
0
        public void Init()
        {
            if (IsLoading == true || isCancel == true)
            {
                Cancel();
                return;
            }

            IsLoading = true;

            persistentStore = new PersistentDataStorage(Game.None);

            cacheDirectory = persistentStore.GetPersistentDataPath("");

            cache = new Dictionary <string, double>();
            if (persistentStore.FileExists(CacheName))
            {
                string tempOldCache = persistentStore.LoadText(CacheName);
                Log.Debug("old cache text = " + tempOldCache, Log.LogChannel.Download);
                string[] tempOldCacheLines = tempOldCache.Split('\n');
                for (int i = 0; i < tempOldCacheLines.Length; i++)
                {
                    if (!string.IsNullOrEmpty(tempOldCacheLines[i]))
                    {
                        string   rawLine           = tempOldCacheLines[i];
                        string[] rawLineComponents = rawLine.Split(':');
                        cache[rawLineComponents[0]] = double.Parse(rawLineComponents[1]);
                    }
                }
            }

            downloads = new List <string>();

            cloudStorageAPI             = new CloudStorageAPI(monoBehaviour);
            progress                    = new Progress();
            progress.StartingFileCount  = 1;
            progress.FileRemainingCount = 1;
                        #if RC_BUILD
            progress.Sections       = 2;
            progress.CurrentSection = 1;
            UpdateProgress();
            cloudStorageAPI.GetContentList(OnContentList, "");
                        #else
            progress.Sections       = 3;
            progress.CurrentSection = 1;
            UpdateProgress();
            cloudStorageAPI.AuthenticateWithGAE(OnAuthResponse, (downloadPercent) =>
            {
                progress.PercentOfCurrentLoadingFileDownloaded = downloadPercent;
                UpdateProgress();
            });
                        #endif
        }
Exemplo n.º 2
0
        /// <summary>
        /// Raises the auth response event.
        /// </summary>
        /// <param name="res">Res.</param>
        private void OnAuthResponse(Response res)
        {
            if (res == null)
            {
                Cancel();
            }

            progress.CurrentSection = 2;
            UpdateProgress();
            if (isCancel == true)
            {
                return;
            }
            Log.Debug("[DEBUG-AUTH] AppController OnAuthResponse HTTPStatusCode: " + res.HttpStatusCode, Log.LogChannel.General);
            if (res.HttpStatusCode == Response.HttpStatusOK)
            {
                authData = JsonUtility.FromJson <AuthData>(res.Text);
                cloudStorageAPI.GetContentList(OnContentList, authData.access_token, (downloadPercent) =>
                {
                    progress.PercentOfCurrentLoadingFileDownloaded = downloadPercent;
                    UpdateProgress();
                });
            }
            else
            {
                Log.Debug("[DEBUG-AUTH] AppController OnAuthResponse failled with HTTPStatusCode: " + res.HttpStatusCode, Log.LogChannel.General);
                if (res.Request.Attempts < maxAttempts)
                {
                    res.Request.Retry();
                }
                else
                {
                    Cancel();
                }
            }
        }