void HandleAMPSListenerInstanceFileDownloaded(object sender, AMPListenerEventArgs e) { eventsListener.FileDownloaded -= HandleAMPSListenerInstanceFileDownloaded; Debug.Log("Asset downloaded " + e.Result); TweaksSystemEventArgs res = new TweaksSystemEventArgs(); if (e.Result == true) { PlayerPrefs.SetString(LAST_UPDATE, System.DateTime.UtcNow.ToBinary().ToString()); PlayerPrefs.SetString(FILE_VERSION_KEY, AMPSBinding.GetVersionOfFile(GetPath(), e.FilenameDownloaded)); this.LoadFromDisk(); res.Error = null; res.Message = "Tweaks System Downloaded and setted as new values"; res.SaveIn = TweaksResultSave.Disk; res.Result = true; PlayerPrefs.Save(); } else { res.Error = e.Error; res.Message = "Error downloading " + e.FilenameDownloaded; res.SaveIn = TweaksResultSave.NotSave; res.Result = false; this.LoadFromDisk(); } if (_onResult != null) { _onResult(res); } }
void HandleAMPSListenerInstanceAMPSManagerInit(object sender, AMPListenerEventArgs e) { eventsListener.AMPSManagerInit -= HandleAMPSListenerInstanceAMPSManagerInit; if (e.Result) { string serverFileVersion = AMPSBinding.GetVersionOfFile(DataPath, FILE_NAME); Debug.Log("Version local: " + PlayerPrefs.GetString(FILE_VERSION_KEY)); Debug.Log("Version server: " + serverFileVersion); int versionLocal = string.IsNullOrEmpty(PlayerPrefs.GetString(FILE_VERSION_KEY)) ? 0 : Convert.ToInt32(PlayerPrefs.GetString(FILE_VERSION_KEY)); int versionServer = string.IsNullOrEmpty(serverFileVersion) ? 0 : Convert.ToInt32(serverFileVersion); if (!PlayerPrefs.HasKey(FILE_VERSION_KEY)) { eventsListener.FileDownloaded += HandleAMPSListenerInstanceFileDownloaded; AMPSBinding.DownloadAsset(DataPath, FILE_NAME); } else if (versionServer > versionLocal) { eventsListener.FileDownloaded += HandleAMPSListenerInstanceFileDownloaded; AMPSBinding.DownloadAsset(DataPath, FILE_NAME); } else { Debug.Log("Update is not neccessary"); RaiseLocalizationCallback(true, false, "it is not neccessary update the currents files", string.Empty, _onResult); } } else { RaiseLocalizationCallback(false, false, "Error downloading " + e.FilenameDownloaded, e.Error, _onResult); } }
void HandleAMPSListenerInstanceAMPSManagerInit(object sender, AMPListenerEventArgs e) { eventsListener.AMPSManagerInit -= HandleAMPSListenerInstanceAMPSManagerInit; string serverFileVersion = AMPSBinding.GetVersionOfFile(GetPath(), FILE_NAME); Debug.Log("TWEAKS Version " + serverFileVersion); if (e.Result) { if (!PlayerPrefs.HasKey(FILE_VERSION_KEY)) { eventsListener.FileDownloaded += HandleAMPSListenerInstanceFileDownloaded; AMPSBinding.DownloadAsset(GetPath(), FILE_NAME); } else if (Convert.ToSingle(serverFileVersion) > Convert.ToSingle(PlayerPrefs.GetString(FILE_VERSION_KEY))) { eventsListener.FileDownloaded += HandleAMPSListenerInstanceFileDownloaded; AMPSBinding.DownloadAsset(GetPath(), FILE_NAME); } else { Debug.Log("Update is not neccessary"); TweaksSystemEventArgs args = new TweaksSystemEventArgs(); args.Result = true; args.Message = "Update is not neccessary, loaded default values"; args.SaveIn = TweaksResultSave.NotSave; this.LoadFromDisk(); } } else { TweaksSystemEventArgs res = new TweaksSystemEventArgs(); res.Error = e.Error; res.Message = "Error downloading " + e.FilenameDownloaded; res.SaveIn = TweaksResultSave.NotSave; res.Result = false; if (_onResult != null) { _onResult(res); } this.LoadFromDisk(); } }
void HandleAMPSListenerInstanceFileDownloaded(object sender, AMPListenerEventArgs e) { eventsListener.FileDownloaded -= HandleAMPSListenerInstanceFileDownloaded; Debug.Log("Asset downloaded " + e.Result); if (e.Result == true) { //Unzip the file bool succesfullUnzip = this.ExtractZipFile(this.GetPath(FILE_NAME)); if (succesfullUnzip) { PlayerPrefs.SetString(LAST_UPDATE, System.DateTime.UtcNow.ToBinary().ToString()); PlayerPrefs.SetString(FILE_VERSION_KEY, AMPSBinding.GetVersionOfFile(DataPath, e.FilenameDownloaded)); Language.SwitchLanguage(Language.CurrentLanguage()); //Delete downloaded file File.Delete(this.GetPath(FILE_NAME)); RaiseLocalizationCallback(true, true, e.Message, string.Empty, _onResult); } else { //Delete downloaded file File.Delete(this.GetPath(FILE_NAME)); RaiseLocalizationCallback(false, false, "Error unzipping " + e.FilenameDownloaded, e.Error, _onResult); } } else { RaiseLocalizationCallback(false, false, "Error downloading " + e.FilenameDownloaded, e.Error, _onResult); } }