/* * Reads the name of a property, and must be positioned (with or without whitespace) either: * - Before the '"' of a property name. * - Before the ',' separating properties. * - Before the '}' or ']' terminating this list of properties. * Can be used in conjunction with Read(ES3Type) to read a property. */ public override string ReadPropertyName() { char c = PeekCharIgnoreWhitespace(); // Check whether there are any properties left to read. if (IsTerminator(c)) { return(null); } else if (c == ',') { ReadCharIgnoreWhitespace(); } else if (!IsQuotationMark(c)) { throw new FormatException("Expected ',' separating properties or '\"' before property name, found '" + c + "'."); } var propertyName = Read_string(); if (propertyName == null) { throw new FormatException("Stream isn't positioned before a property."); } ES3Debug.Log("<b>" + propertyName + "</b> (reading property)", null, serializationDepth); // Skip the ':' seperating property and value. ReadCharIgnoreWhitespace(':'); return(propertyName); }
/* * Reads the name of a property, and must be positioned immediately before a property name. */ public override string ReadPropertyName() { var propertyName = baseReader.ReadString(); if (propertyName == null) { throw new FormatException("Stream isn't positioned before a property."); } else if (propertyName == ES3Binary.ObjectTerminator) { return(null); } ES3Debug.Log("<b>" + propertyName + "</b> (reading property)", null, serializationDepth); return(propertyName); }
public static void CommitBackup(ES3Settings settings) { ES3Debug.Log("Committing backup for " + settings.path + " to storage location " + settings.location); var temporaryFilePath = settings.FullPath + temporaryFileSuffix; if (settings.location == ES3.Location.File) { var oldFileBackup = settings.FullPath + temporaryFileSuffix + ".bak"; // If there's existing save data to overwrite ... if (FileExists(settings.FullPath)) { // Delete any old backups. DeleteFile(oldFileBackup); // Rename the old file so we can restore it if it fails. MoveFile(settings.FullPath, oldFileBackup); try { // Now rename the temporary file to the name of the save file. MoveFile(temporaryFilePath, settings.FullPath); } catch (Exception e) { // If any exceptions occur, restore the original save file. try { DeleteFile(settings.FullPath); } catch { } MoveFile(oldFileBackup, settings.FullPath); throw e; } DeleteFile(oldFileBackup); } // Else just rename the temporary file to the main file. else { MoveFile(temporaryFilePath, settings.FullPath); } } else if (settings.location == ES3.Location.PlayerPrefs) { PlayerPrefs.SetString(settings.FullPath, PlayerPrefs.GetString(temporaryFilePath)); PlayerPrefs.DeleteKey(temporaryFilePath); PlayerPrefs.Save(); } }
public static void CommitBackup(ES3Settings settings) { ES3Debug.Log("Committing backup for " + settings.path + " to storage location " + settings.location); if (settings.location == ES3.Location.File) { // Delete the old file before overwriting it. DeleteFile(settings.FullPath); // Rename temporary file to new file. MoveFile(settings.FullPath + temporaryFileSuffix, settings.FullPath); } else if (settings.location == ES3.Location.PlayerPrefs) { PlayerPrefs.SetString(settings.FullPath, PlayerPrefs.GetString(settings.FullPath + temporaryFileSuffix)); PlayerPrefs.DeleteKey(settings.FullPath + temporaryFileSuffix); PlayerPrefs.Save(); } }