Backups
You can create a backup using ES3.CreateBackup, and restore it using ES3.RestoreBackup.
Creating a backup
Creating a backup will overwriting any existing backup. The backup will have the same name as the file we’re backing up, but have the extension .bak appended.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// Save some data. try { ES3.Save("myKey", 123, "myFile.es3"); ES3.Save("myKey2", 456, "myFile.es3"); ES3.Save("myKey3", 789, "myFile.es3"); } catch { // See the 'Restoring a backup' section below for an example of what goes here. } // Now we've finished saving our data, we now make a backup. ES3.CreateBackup("myFile.es3"); |
Restoring a backup
Restoring a backup will overwrite the original file. Generally you should restore the backup if an exception occurs while saving or loading. See the Error Handling guide for information on what exceptions you might want to catch.
1 2 3 4 5 6 7 8 9 10 11 |
try { myInt = ES3.Load<int>("myInt", "myFile.es3"); } catch { if(ES3.RestoreBackup("myFile.es3")) Debug.Log("Backup restored."); else Debug.Log("Backup could not be restored as no backup exists."); } |
You can also manage backups when saving in a similar way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Save some data. try { ES3.Save("myKey", 123, "myFile.es3"); ES3.Save("myKey2", 456, "myFile.es3"); ES3.Save("myKey3", 789, "myFile.es3"); } catch { if(ES3.RestoreBackup("myFile.es3")) Debug.Log("Backup restored."); else Debug.Log("Backup could not be restored as no backup exists."); } // Now we've finished saving our data, we now make a backup. ES3.CreateBackup("myFile.es3"); |