예제 #1
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);
        }