Example #1
0
        /// <summary>
        /// Writes the manifest version.
        /// </summary>
        /// <param name="version">Version.</param>
        public static void WriteManifestVersion(string version)
        {
            version = version.Replace("\"", "");
            version = version.TrimStart('0');
            PersistentDataStorage persistentDataStorage = new PersistentDataStorage(Game.None);

            persistentDataStorage.SaveText(ManifestVersionFile, version, false);
        }
Example #2
0
        /// <summary>
        /// Appends the manifest version.
        /// </summary>
        /// <param name="version">Version.</param>
        public static void AppendManifestVersion(string version)
        {
            PersistentDataStorage persistentDataStorage = new PersistentDataStorage(Game.None);

            if (persistentDataStorage.FileExists(ManifestVersionFile))
            {
                version = version.Replace("\"", "");
                version = version.TrimStart('0');
                string existingVersion = persistentDataStorage.LoadText(ManifestVersionFile);
                if (existingVersion != version)
                {
                    string[] parts = existingVersion.Split(',');
                    existingVersion = parts[0];
                    persistentDataStorage.SaveText(ManifestVersionFile, existingVersion + "," + version, false);
                }
            }
            else
            {
                WriteManifestVersion(version);
            }
        }
Example #3
0
        /// <summary>
        /// Purges the cpipe cache.
        /// Called when app starts and runs if the app version on disk is older then the app verison.
        /// The purge will delete any english or non loc specific files and update the cache with all of the latest version from the embedded manifest.
        /// </summary>
        public static void PurgeCpipeCache()
        {
            bool doPurge = false;
            Dictionary <string, string> cache = new Dictionary <string, string>();
            PersistentDataStorage       persistentDataStorage  = new PersistentDataStorage(Game.None);
            StreamingAssetsStorage      streamingAssetsStorage = new StreamingAssetsStorage(Game.None, null);

            //if app version has increased, do purge
            AppVersion appVersion = new AppVersion(Application.version);

            if (persistentDataStorage.FileExists(appVerisonFile))
            {
                AppVersion storedVersion = new AppVersion(persistentDataStorage.LoadText(appVerisonFile));
                if (storedVersion.Major > appVersion.Major)
                {
                    doPurge = true;
                }
                else if (storedVersion.Major >= appVersion.Major && storedVersion.Minor > appVersion.Minor)
                {
                    doPurge = true;
                }
                else if (storedVersion.Major >= appVersion.Major && storedVersion.Minor >= appVersion.Minor && storedVersion.Revision > appVersion.Revision)
                {
                    doPurge = true;
                }
            }
            else
            {
                doPurge = true;
            }
            Log.Debug("dopurge " + doPurge, Log.LogChannel.General);

            if (doPurge == false)
            {
                return;
            }

            string oldCache = "";

            if (persistentDataStorage.FileExists(CacheName))
            {
                oldCache = persistentDataStorage.LoadText(CacheName);
                string[] tempOldCacheLines = oldCache.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]] = rawLineComponents[1];
                    }
                }
            }

            Log.Debug("load manifest from streaming at " + Application.streamingAssetsPath + "/" + Game.ForceVision + "/" + EmbeddedCpipeManifestFile, Log.LogChannel.General);
            //load streaming assets manifest and write cache file of embedded content
            streamingAssetsStorage.LoadStreamingAssetsText(Game.ForceVision + "/" + EmbeddedCpipeManifestFile, (error, text) =>
            {
                if (string.IsNullOrEmpty(error))
                {
                    try
                    {
                        JSONObject manifest = new JSONObject(text);

                        WriteManifestVersion(manifest["version"].ToString());

                        JSONObject paths      = manifest["paths"];
                        string newCacheString = "";
                        for (int i = 0; i < paths.keys.Count; i++)
                        {
                            string folder = paths.keys[i];
                            string v      = paths[i]["v"].ToString();

                            //update english only
                            bool isEnglishFile = true;
                            foreach (string languageFolder in Localizer.LanguageFolders)
                            {
                                if (folder.Contains("GeneratedSoundBanks") && folder.Contains("/" + languageFolder + "/") && languageFolder != Localizer.LanguageFolders[0])
                                {
                                    isEnglishFile = false;
                                    Log.Debug("non english file found. path = " + folder, Log.LogChannel.Download);
                                }
                            }

                            if (isEnglishFile)
                            {
                                if (cache.ContainsKey(folder))
                                {
                                    //if in cache already then update to local version and delete local file
                                    if (persistentDataStorage.FileExists(folder))
                                    {
                                        persistentDataStorage.DeleteFile(folder);
                                        Log.Debug("deleteing file in " + folder, Log.LogChannel.Download);
                                    }
                                }
                                newCacheString += folder + ":" + v + "\n";
                            }
                            else
                            {
                                if (cache.ContainsKey(folder))
                                {
                                    newCacheString += folder + ":" + v + "\n";
                                }
                            }
                        }
                        persistentDataStorage.SaveText(CacheName, newCacheString, false);

                        persistentDataStorage.SaveText(appVerisonFile, Application.version, false);
                    }
                    catch (System.Exception e)
                    {
                        Log.Exception(e);
                    }
                }
                else
                {
                                        #if !UNITY_EDITOR
                    Log.Error("error loading manifest from streamingassets. " + error);
                                        #endif
                }
            }, true);
        }
Example #4
0
        /// <summary>
        /// Raises the download event.
        /// </summary>
        /// <param name="res">Res.</param>
        private void OnDownload(Response res)
        {
            if (isCancel == true)
            {
                return;
            }
            Log.Debug("[DEBUG-AUTH] AppController OnDownload " + res.ID + "  HTTPStatusCode: " + res.HttpStatusCode, Log.LogChannel.Download);
            if (res.HttpStatusCode == Response.HttpStatusOK)
            {
                //cache += res.ID + ":" + manifest["paths"][res.ID]["v"] + "\n";
                if (cache.ContainsKey(res.ID))
                {
                    cache[res.ID] = double.Parse(manifest["paths"][res.ID]["v"].ToString());
                }
                else
                {
                    cache.Add(res.ID, double.Parse(manifest["paths"][res.ID]["v"].ToString()));
                }

                if (res.ID.IndexOf(".json") > -1 || res.ID.IndexOf(".txt") > -1)
                {
                    persistentStore.SaveText(res.ID, res.Text, false);
                }
                else
                {
                    persistentStore.SaveBytes(res.ID, res.Bytes);
                }

                string downloadedFilePath = "";
                for (int i = 0; i < downloads.Count; i++)
                {
                    if (downloads[i] == res.ID)
                    {
                        downloadedFilePath = downloads[i];
                        downloads.Remove(res.ID);
                    }
                }

                StringBuilder result = new StringBuilder();
                foreach (KeyValuePair <string, double> entry in cache)
                {
                    result.Append(entry.Key);
                    result.Append(":");
                    result.Append(entry.Value);
                    result.Append("\n");
                }
                persistentStore.SaveText(CacheName, result.ToString(), false);
                result = null;

                if (downloads.Count <= 0)
                {
                    Log.Debug("[DEBUG-AUTH] AppController OnDownload downloads complete!", Log.LogChannel.Download);
                    Destroy();
                }
                else if (downloadedFilePath.Equals("ForceVision/languages.txt"))
                {
                    Log.Debug("Downloaded Languages file, update loc and reparse donwloads!", Log.LogChannel.Download);
                    Localizer.Load(true);
                    ParseDownloads();
                    DownloadNextFile();
                }
                else
                {
                    DownloadNextFile();
                }
            }
            else
            {
                Log.Debug("[DEBUG-AUTH] AppController OnDownload failed: " + res.ID + " with HTTPStatusCode: " + res.HttpStatusCode, Log.LogChannel.Download);
                if (res.Request.Attempts < maxAttempts)
                {
                    res.Request.Retry();
                }
                else
                {
                    Cancel();
                }
            }
        }
		public void SaveQuality(int quality)
		{
			storage.SaveText(QualitySettingsFileName, quality.ToString(), false);
		}