public FlxSave(StorageDevice Device) : base(FlxG.Game) { FlxG.Game.Components.Add(this); _device = Device; name = null; _so = null; _savedata = new FlxSaveData(); }
/// <summary> /// Erases everything stored in the local shared object. /// </summary> /// <param name="MinFileSize">If you need X amount of space for your save, specify it here.</param> /// <returns>Whether or not the clear and flush was successful.</returns> public bool erase(uint MinFileSize) { if (_so == null) { FlxG.log("WARNING: You must call FlxSave.bind()\nbefore calling FlxSave.erase()."); return(false); } _savedata = null; forceSave(MinFileSize); _savedata = new FlxSaveData(); return(true); }
/// <summary> /// Automatically creates or reconnects to locally saved data. /// </summary> /// <param name="Name">The name of the object (should be the same each time to access old data).</param> /// <returns>Whether or not you successfully connected to the save data.</returns> public bool bind(string Name) { _so = null; name = Name; try { _savedata = new FlxSaveData(); // Open a storage container. IAsyncResult result = _device.BeginOpenContainer(Name, null, null); // Wait for the WaitHandle to become signaled. result.AsyncWaitHandle.WaitOne(); _so = _device.EndOpenContainer(result); // Close the wait handle. result.AsyncWaitHandle.Close(); // Check to see whether the save exists. if (!_so.FileExists(_savefile)) { // If not, dispose of the container and return new blank data. _so.Dispose(); _savedata = new FlxSaveData(); return(true); } // Open the file. Stream stream = _so.OpenFile(_savefile, FileMode.Open); _savedata.deserialize(stream); // Close the file. stream.Close(); // Dispose the container. _so.Dispose(); } catch { FlxG.log("WARNING: There was a problem binding to\nthe shared object data from FlxSave."); name = null; _so = null; _savedata = null; return(false); } return(true); }