// Load a data pool public FileActionResult LoadDataPool(int id, bool ignoreEmpty = false) { // Get pool to load if (id == -1) { id = GetDefaultPoolId(); } if (id == -1) { return(FileActionResult.NotFound); } // Load the pool try { _dataPool = new SmoothSaveDataPool(id, ignoreEmpty); } catch (FileNotFoundException) { return(FileActionResult.NotFound); } catch (Exception) { return(FileActionResult.AccessError); } return(FileActionResult.Success); }
// Deletes a data pool file and, if loaded, removes it from memory protected FileActionResult DeleteDataPool(int id = -1) { // Get pool to delete if (id == -1) { id = GetDefaultPoolId(); } if (id == -1) { return(FileActionResult.NotFound); } var filePath = SmoothSaveDataPool.GetFilePath(id); // If current, unload if (_dataPool != null) { if (id == _dataPool.Id) { UnloadDataPool(); } } // Delete data pool // From file if (!UsePlayerPrefs) { if (!File.Exists(filePath)) { return(FileActionResult.NotFound); } try { File.Delete(filePath); } catch (Exception exception) { Debug.LogWarning(exception); return(FileActionResult.AccessError); } } // From PlayerPrefs else { if (PlayerPrefs.HasKey(filePath)) { PlayerPrefs.DeleteKey(filePath); } else { return(FileActionResult.NotFound); } } return(FileActionResult.Success); }
// Get default pool ID int GetDefaultPoolId() { if (_dataPool != null) { return(_dataPool.Id); } else { return(SmoothSaveDataPool.FindFirstFileId()); } }
// Removes the data pool from memory protected bool UnloadDataPool() { if (_dataPool != null) { _dataPool = null; return(true); } else { return(false); } }
// Create a new data pool protected int MakeDataPool(string name = null) { try { _dataPool = new SmoothSaveDataPool(name); } catch (Exception exception) { Debug.LogError("Error creating data pool", Owner); Debug.LogError(exception); return(-1); } return(_dataPool.Id); }
// Load or create default data pool void DefaultDataPool() { var id = SmoothSaveDataPool.FindFirstFileId(); if (id != -1) { LoadDataPool(id, true); } else { MakeDataPool(); } if (_dataPool == null) { throw new InvalidOperationException("Cannot create default data pool."); } }