using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using CIGEnums; using SUISS.Core; using SUISS.Storage; using SUISSEngine; public static class StorageController { public static bool Initialized { get; private set; } public static CloudStorage CloudStorage { get; private set; } public static bool HasLoadedCloudSave { get { return Storage.Get(StorageLifecycle.Forever).Root.GetBoolean("HasLoadedCloudSave", false); } } public static void Initialize() { if (StorageController._initializing || StorageController.Initialized) { return; } StorageController.CloudStorage = new CloudStorage(); if (Singleton.Instance.CloudStorageState == CloudStorageState.Activated) { StorageController._initializing = true; CloudStorage cloudStorage = StorageController.CloudStorage; if (StorageController._003C_003Ef__mg_0024cache0 == null) { StorageController._003C_003Ef__mg_0024cache0 = new Action(StorageController.OnCloudStorageAuthenticated); } cloudStorage.Authenticate(StorageController._003C_003Ef__mg_0024cache0); } else { StorageController.Initialized = true; } CIGSettings instance = Singleton.Instance; if (StorageController._003C_003Ef__mg_0024cache1 == null) { StorageController._003C_003Ef__mg_0024cache1 = new CIGSettings.CloudStorageStateChanged(StorageController.OnCloudStorageStateChanged); } instance.CloudStorageStateChangedEvent += StorageController._003C_003Ef__mg_0024cache1; } public static void SaveAll() { StorageController.CloudStorage.Push(); Storage.SaveAll(false); } public static void ReplaceGameDictionary(Dictionary replacement) { Storage storage = Storage.Get(StorageLifecycle.Game); storage.Root.Clear(); foreach (KeyValuePair keyValuePair in replacement) { storage.Root.Add(keyValuePair.Key, keyValuePair.Value); } } private static void OnCloudStorageStateChanged(CloudStorageState state) { if (state == CloudStorageState.Activated) { StorageController.Initialized = false; StorageController._initializing = true; if (!StorageController.HasLoadedCloudSave && SingletonMonobehaviour.IsAvailable) { SingletonMonobehaviour.Instance.RestartNow(); StorageController.CloudStorage.Authenticate(delegate(bool success) { if (success) { StorageController.StartFirstPull(); } else { StorageController._initializing = false; StorageController.Initialized = true; } }); } else { CloudStorage cloudStorage = StorageController.CloudStorage; if (StorageController._003C_003Ef__mg_0024cache2 == null) { StorageController._003C_003Ef__mg_0024cache2 = new Action(StorageController.OnFinishedInitialization); } cloudStorage.Authenticate(StorageController._003C_003Ef__mg_0024cache2); } } else if (state == CloudStorageState.Deactivated) { StorageController.CloudStorage.Deauthenticate(); } } private static void OnCloudStorageAuthenticated(bool success) { if (success && !StorageController.HasLoadedCloudSave) { StorageController.StartFirstPull(); } else { StorageController._initializing = false; StorageController.Initialized = true; } } private static void StartFirstPull() { CloudStorage cloudStorage = StorageController.CloudStorage; if (StorageController._003C_003Ef__mg_0024cache3 == null) { StorageController._003C_003Ef__mg_0024cache3 = new CloudStorage.ConflictResolvedEventHandler(StorageController.OnConflictResolved); } cloudStorage.ConflictResolved += StorageController._003C_003Ef__mg_0024cache3; CloudStorage cloudStorage2 = StorageController.CloudStorage; if (StorageController._003C_003Ef__mg_0024cache4 == null) { StorageController._003C_003Ef__mg_0024cache4 = new Action(StorageController.OnFinishedInitialization); } cloudStorage2.Pull(StorageController._003C_003Ef__mg_0024cache4); } private static void OnFinishedInitialization(bool success) { StorageController._initializing = false; StorageController.Initialized = true; } private static void OnConflictResolved() { CloudStorage cloudStorage = StorageController.CloudStorage; if (StorageController._003C_003Ef__mg_0024cache5 == null) { StorageController._003C_003Ef__mg_0024cache5 = new CloudStorage.ConflictResolvedEventHandler(StorageController.OnConflictResolved); } cloudStorage.ConflictResolved -= StorageController._003C_003Ef__mg_0024cache5; Storage.Get(StorageLifecycle.Forever).Root["HasLoadedCloudSave"] = true; } private const string HasLoadedCloudSaveKey = "HasLoadedCloudSave"; private static bool _initializing; [CompilerGenerated] private static Action _003C_003Ef__mg_0024cache0; [CompilerGenerated] private static CIGSettings.CloudStorageStateChanged _003C_003Ef__mg_0024cache1; [CompilerGenerated] private static Action _003C_003Ef__mg_0024cache2; [CompilerGenerated] private static CloudStorage.ConflictResolvedEventHandler _003C_003Ef__mg_0024cache3; [CompilerGenerated] private static Action _003C_003Ef__mg_0024cache4; [CompilerGenerated] private static CloudStorage.ConflictResolvedEventHandler _003C_003Ef__mg_0024cache5; }