Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

174 linhas
5.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using CIGEnums;
  5. using SUISS.Core;
  6. using SUISS.Storage;
  7. using SUISSEngine;
  8. public static class StorageController
  9. {
  10. public static bool Initialized { get; private set; }
  11. public static CloudStorage CloudStorage { get; private set; }
  12. public static bool HasLoadedCloudSave
  13. {
  14. get
  15. {
  16. return Storage.Get(StorageLifecycle.Forever).Root.GetBoolean("HasLoadedCloudSave", false);
  17. }
  18. }
  19. public static void Initialize()
  20. {
  21. if (StorageController._initializing || StorageController.Initialized)
  22. {
  23. return;
  24. }
  25. StorageController.CloudStorage = new CloudStorage();
  26. if (Singleton<CIGSettings>.Instance.CloudStorageState == CloudStorageState.Activated)
  27. {
  28. StorageController._initializing = true;
  29. CloudStorage cloudStorage = StorageController.CloudStorage;
  30. if (StorageController._003C_003Ef__mg_0024cache0 == null)
  31. {
  32. StorageController._003C_003Ef__mg_0024cache0 = new Action<bool>(StorageController.OnCloudStorageAuthenticated);
  33. }
  34. cloudStorage.Authenticate(StorageController._003C_003Ef__mg_0024cache0);
  35. }
  36. else
  37. {
  38. StorageController.Initialized = true;
  39. }
  40. CIGSettings instance = Singleton<CIGSettings>.Instance;
  41. if (StorageController._003C_003Ef__mg_0024cache1 == null)
  42. {
  43. StorageController._003C_003Ef__mg_0024cache1 = new CIGSettings.CloudStorageStateChanged(StorageController.OnCloudStorageStateChanged);
  44. }
  45. instance.CloudStorageStateChangedEvent += StorageController._003C_003Ef__mg_0024cache1;
  46. }
  47. public static void SaveAll()
  48. {
  49. StorageController.CloudStorage.Push();
  50. Storage.SaveAll(false);
  51. }
  52. public static void ReplaceGameDictionary(Dictionary<string, object> replacement)
  53. {
  54. Storage storage = Storage.Get(StorageLifecycle.Game);
  55. storage.Root.Clear();
  56. foreach (KeyValuePair<string, object> keyValuePair in replacement)
  57. {
  58. storage.Root.Add(keyValuePair.Key, keyValuePair.Value);
  59. }
  60. }
  61. private static void OnCloudStorageStateChanged(CloudStorageState state)
  62. {
  63. if (state == CloudStorageState.Activated)
  64. {
  65. StorageController.Initialized = false;
  66. StorageController._initializing = true;
  67. if (!StorageController.HasLoadedCloudSave && SingletonMonobehaviour<CIGSessionRestarter>.IsAvailable)
  68. {
  69. SingletonMonobehaviour<CIGSessionRestarter>.Instance.RestartNow();
  70. StorageController.CloudStorage.Authenticate(delegate(bool success)
  71. {
  72. if (success)
  73. {
  74. StorageController.StartFirstPull();
  75. }
  76. else
  77. {
  78. StorageController._initializing = false;
  79. StorageController.Initialized = true;
  80. }
  81. });
  82. }
  83. else
  84. {
  85. CloudStorage cloudStorage = StorageController.CloudStorage;
  86. if (StorageController._003C_003Ef__mg_0024cache2 == null)
  87. {
  88. StorageController._003C_003Ef__mg_0024cache2 = new Action<bool>(StorageController.OnFinishedInitialization);
  89. }
  90. cloudStorage.Authenticate(StorageController._003C_003Ef__mg_0024cache2);
  91. }
  92. }
  93. else if (state == CloudStorageState.Deactivated)
  94. {
  95. StorageController.CloudStorage.Deauthenticate();
  96. }
  97. }
  98. private static void OnCloudStorageAuthenticated(bool success)
  99. {
  100. if (success && !StorageController.HasLoadedCloudSave)
  101. {
  102. StorageController.StartFirstPull();
  103. }
  104. else
  105. {
  106. StorageController._initializing = false;
  107. StorageController.Initialized = true;
  108. }
  109. }
  110. private static void StartFirstPull()
  111. {
  112. CloudStorage cloudStorage = StorageController.CloudStorage;
  113. if (StorageController._003C_003Ef__mg_0024cache3 == null)
  114. {
  115. StorageController._003C_003Ef__mg_0024cache3 = new CloudStorage.ConflictResolvedEventHandler(StorageController.OnConflictResolved);
  116. }
  117. cloudStorage.ConflictResolved += StorageController._003C_003Ef__mg_0024cache3;
  118. CloudStorage cloudStorage2 = StorageController.CloudStorage;
  119. if (StorageController._003C_003Ef__mg_0024cache4 == null)
  120. {
  121. StorageController._003C_003Ef__mg_0024cache4 = new Action<bool>(StorageController.OnFinishedInitialization);
  122. }
  123. cloudStorage2.Pull(StorageController._003C_003Ef__mg_0024cache4);
  124. }
  125. private static void OnFinishedInitialization(bool success)
  126. {
  127. StorageController._initializing = false;
  128. StorageController.Initialized = true;
  129. }
  130. private static void OnConflictResolved()
  131. {
  132. CloudStorage cloudStorage = StorageController.CloudStorage;
  133. if (StorageController._003C_003Ef__mg_0024cache5 == null)
  134. {
  135. StorageController._003C_003Ef__mg_0024cache5 = new CloudStorage.ConflictResolvedEventHandler(StorageController.OnConflictResolved);
  136. }
  137. cloudStorage.ConflictResolved -= StorageController._003C_003Ef__mg_0024cache5;
  138. Storage.Get(StorageLifecycle.Forever).Root["HasLoadedCloudSave"] = true;
  139. }
  140. private const string HasLoadedCloudSaveKey = "HasLoadedCloudSave";
  141. private static bool _initializing;
  142. [CompilerGenerated]
  143. private static Action<bool> _003C_003Ef__mg_0024cache0;
  144. [CompilerGenerated]
  145. private static CIGSettings.CloudStorageStateChanged _003C_003Ef__mg_0024cache1;
  146. [CompilerGenerated]
  147. private static Action<bool> _003C_003Ef__mg_0024cache2;
  148. [CompilerGenerated]
  149. private static CloudStorage.ConflictResolvedEventHandler _003C_003Ef__mg_0024cache3;
  150. [CompilerGenerated]
  151. private static Action<bool> _003C_003Ef__mg_0024cache4;
  152. [CompilerGenerated]
  153. private static CloudStorage.ConflictResolvedEventHandler _003C_003Ef__mg_0024cache5;
  154. }