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 }
/// <summary> /// Gets the manifest verison. /// If multiple entries appear in the string[], then each manifest file has been loaded but its contents not completely downlaoded, in the order that they were downloaded. /// </summary> /// <returns>The manifest verison.</returns> public static string[] GetManifestVersion() { PersistentDataStorage persistentDataStorage = new PersistentDataStorage(Game.None); if (persistentDataStorage.FileExists(ManifestVersionFile)) { string existingVersion = persistentDataStorage.LoadText(ManifestVersionFile); return(existingVersion.Split(',')); } return(new string[1] { "1" }); }
public Quality GetQuality() { int storeadQuality = (int)Enum.GetValues(typeof(Quality)).Cast<Quality>().Last(); if (storage.FileExists(QualitySettingsFileName) == true) { storeadQuality = int.Parse(storage.LoadText(QualitySettingsFileName)); Log.Debug("loading quality from file. quality = " + storeadQuality); } else { Device device = sdk.Settings.CurrentDevice; if (device != null) { Log.Debug("getting qaultiy on first run based on device."); storeadQuality = device.Quality; } Log.Debug("saving first time run quality. quality = " + storeadQuality); SaveQuality(storeadQuality); } return (Quality)storeadQuality; }
public static ProgressionData GetProgressionData(PersistentDataStorage data) { ProgressionData progressionData; if (data.FileExists(ProgressionFile)) { progressionData = data.LoadSerialized <ProgressionData>(ProgressionFile); } else { progressionData = new ProgressionData(); } return(progressionData); }
/// <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); } }
private string LoadFromCdnOrSdkResources(string fileName) { string path = System.IO.Path.Combine("Profiles", fileName); // first try the OTA versions if (persistentDataStorage.FileExists(path)) { Log.Debug("load settings from persistent : " + persistentDataStorage.GetPersistentDataPath(path)); string text = persistentDataStorage.LoadText(path); if (text != null) { return(text); } } // fallback to load from Resources path = path.Replace(".json", "").Replace(".txt", ""); //Log.Debug("attempt to load Resource from " + path); TextAsset textAsset = Resources.Load <TextAsset>(path); return(textAsset != null ? textAsset.text : null); }
/// <summary> /// Plays the trailer /// </summary> /// <param name="showVideoControls">If set to <c>true</c> show video controls.</param> public IEnumerator PlayTrailer(bool showVideoControls = false) { StreamingAssetsStorage storage = new StreamingAssetsStorage(Game.ForceVision, null); string introVideoPath = ""; //copying to persistent data may work, you can also try prefixing the path with "jar://" #if UNITY_ANDROID PersistentDataStorage persistentStorage = new PersistentDataStorage(Game.ForceVision); if (persistentStorage.FileExists(StarWarsIntroVideo) == false) { storage.LoadStreamingAssetsFile(StarWarsIntroVideo, (string error, byte[] bytes) => { if (string.IsNullOrEmpty(error)) { //save file in persistentdata bool writeSuccess = persistentStorage.SaveBytes(StarWarsIntroVideo, bytes); if (writeSuccess) { introVideoPath = persistentStorage.GetPersistentDataPath(StarWarsIntroVideo); } else { //handle error Log.Error("Error! Unable to save the video file to persistent data."); } } else { //handle error Log.Error("Error! Unable to load from streaming assets."); } }, true); } else { introVideoPath = persistentStorage.GetPersistentDataPath(StarWarsIntroVideo); } #else introVideoPath = storage.GetStreamingAssetPath(StarWarsIntroVideo); #endif // checking that path is valid string if (!string.IsNullOrEmpty(introVideoPath)) { if (PlayCount > 0) { // setting button state if (TrailerPlayButton) { TrailerPlayButton.interactable = false; } // stopping background music AudioEvent.Play(AudioEventName.Ftue.Stereo.BackgroundMusicPause, gameObject); } if (Application.isEditor) { Debug.Log("Playing Trailer (Trailer cannot play in Editor)"); } else { // playing intro video Handheld.PlayFullScreenMovie(introVideoPath, Color.black, showVideoControls ? FullScreenMovieControlMode.CancelOnInput : FullScreenMovieControlMode.Hidden); } // adding pause yield return(new WaitForSeconds(1.5f)); if (PlayCount > 0) { // setting button state if (TrailerPlayButton) { TrailerPlayButton.interactable = true; } // starting background music AudioEvent.Play(AudioEventName.Ftue.Stereo.BackgroundMusicResume, gameObject); } // setting new play count StereoStorage.SetPrefInt(IntroPlayedCountKey, PlayCount + 1); } }
/// <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); }