private bool OverrideLocalSave(SaveData cloudSave, SaveData localSave) { bool successful = false; //Try save the cloud save SaveState state = cloudSave.Save(false); if (state == SaveState.OK) { if (cloudSave.Load() == LoadState.OK) { successful = true; } } //If cloud save failed save the local again if (!successful) { localSave.Save(); } return(successful); }
private LoadState LoadSave(User user, out SaveData loadedData) { m_savingEnabled = false; string saveID = !string.IsNullOrEmpty(user.saveID) ? user.saveID : LocalSaveID; SaveData save = new SaveData(saveID); Func <LoadState> loadSave = null; loadSave = delegate() { LoadState loadResult = save.Load(); switch (loadResult) { case LoadState.NotFound: if (save.Key != LocalSaveID) { Debug.Log("SaveGameManager (LoadSave) :: Haven't found save for saveID - " + saveID + " attempting to load local.sav instead!"); //If the save isn't found and we aren't trying to load a local save already then try to load a local save instead save = new SaveData(LocalSaveID); loadResult = loadSave(); if (loadResult == LoadState.OK) { Debug.Log("SaveGameManager (LoadSave) :: Found local.sav! Converting to user save"); save.UpdateSavePathAndKey(SaveUtilities.GetSavePath(saveID), saveID); SaveState state = save.Save(); //Note: possible save duplication exploit if (state == SaveState.OK) { //Delete old local.sav when done! string localSavePath = SaveUtilities.GetSavePath(LocalSaveID); try { if (File.Exists(localSavePath)) { File.Delete(localSavePath); } // Fix for HSW-5647 - delete the backup file as well as otherwise in some cases user can get a corrupted popup string backupPath = localSavePath + ".backup"; if (File.Exists(backupPath)) { File.Delete(backupPath); } } catch (Exception e) { Debug.LogWarning("SaveGameManager (LoadSave) :: Unable to delete " + localSavePath + " - " + e.Message); } } } } break; } return(loadResult); }; LoadState result = loadSave(); Action loadSystems = delegate() { if (result == LoadState.OK) { result = LoadSystems(save); if (result == LoadState.OK) { m_savingEnabled = true; } } }; //Check for valid results and enable saving if we are in a valid state! switch (result) { case LoadState.OK: //Now need to check game systems can load it! bool upgraded = false; result = UpgradeSystems(save, out upgraded); save.Version = m_version; //TODO only save on upgrade if (result == LoadState.OK && upgraded) { SaveToDisk(); } loadSystems(); break; case LoadState.NotFound: Debug.Log("SaveGameManager (LoadSave) :: No save found! Creating new save!"); //Create a new save result = LoadState.OK; loadSystems(); save.Version = m_version; if (result == LoadState.OK) { save.Save(); } break; default: loadSystems(); m_savingEnabled = false; break; } loadedData = save; return(result); }