Пример #1
0
        /*
         *  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);
        }
Пример #2
0
        internal UnityEngine.Object Get(long id, Type type)
        {
            if (id == -1)
            {
                return(null);
            }
            UnityEngine.Object obj;
            if (!idRef.TryGetValue(id, out obj))
            {
                if (GlobalReferences != null)
                {
                    var globalRef = GlobalReferences.Get(id);
                    if (globalRef != null)
                    {
                        return(globalRef);
                    }
                }

                ES3Debug.LogWarning("Reference for " + type + " with ID " + id + " could not be found in Easy Save's reference manager. Try pressing the Refresh References button on the ES3ReferenceMgr Component of the Easy Save 3 Manager in your scene. If you are loading objects dynamically, this warning is expected and can be ignored.", this);
                return(null);
            }
            if (obj == null) // If obj has been marked as destroyed but not yet destroyed, don't return it.
            {
                return(null);
            }
            return(obj);
        }
Пример #3
0
        /*
         *  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);
        }
Пример #4
0
        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();
            }
        }
Пример #5
0
        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();
            }
        }
Пример #6
0
        internal UnityEngine.Object Get(long id, Type type, bool suppressWarnings = false)
        {
            foreach (var mgr in mgrs)
            {
                if (mgr == null)
                {
                    continue;
                }

                if (id == -1)
                {
                    return(null);
                }
                UnityEngine.Object obj;
                if (!mgr.idRef.TryGetValue(id, out obj))
                {
                    if (GlobalReferences != null)
                    {
                        var globalRef = GlobalReferences.Get(id);
                        if (globalRef != null)
                        {
                            return(globalRef);
                        }
                    }

                    if (type != null)
                    {
                        ES3Debug.LogWarning("Reference for " + type + " with ID " + id + " could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored.", this);
                    }
                    else
                    {
                        ES3Debug.LogWarning("Reference with ID " + id + " could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored.", this);
                    }
                    return(null);
                }
                if (obj == null) // If obj has been marked as destroyed but not yet destroyed, don't return it.
                {
                    return(null);
                }
                return(obj);
            }
            return(null);
        }
Пример #7
0
        /*
         *  Given a path, it returns the directory that path points to.
         *  eg. "C:/myFolder/thisFolder/myFile.txt" will return "C:/myFolder/thisFolder".
         */
        public static string GetDirectoryPath(string path, char seperator = '/')
        {
            //return Path.GetDirectoryName(path);
            // Path.GetDirectoryName turns forward slashes to backslashes in some cases on Windows, which is why
            // Substring is used instead.
            char slashChar = UsesForwardSlash(path) ? '/' : '\\';

            int slash = path.LastIndexOf(slashChar);

            // Ignore trailing slash if necessary.
            if (slash == (path.Length - 1))
            {
                slash = path.Substring(0, slash).LastIndexOf(slashChar);
            }
            if (slash == -1)
            {
                ES3Debug.LogError("Path provided is not a directory path as it contains no slashes.");
            }
            return(path.Substring(0, slash));
        }
Пример #8
0
        public long GetOrAdd(UnityEngine.Object obj)
        {
            if (Application.isPlaying)
            {
                ES3Debug.LogError("GetOrAdd can only be called in the Editor, not during runtime");
                return(-1);
            }

            var id = Get(obj);

            if (id == -1 && UnityEditor.AssetDatabase.Contains(obj) && ES3ReferenceMgr.CanBeSaved(obj))
            {
                id = ES3ReferenceMgrBase.GetNewRefID();
                refId.Add(obj, id);

                UnityEditor.EditorUtility.SetDirty(this);
            }

            return(id);
        }
Пример #9
0
        public long GetPrefab(ES3Prefab prefabToFind, bool suppressWarnings = false)
        {
            foreach (var mgr in mgrs)
            {
                if (mgr == null)
                {
                    continue;
                }

                foreach (var prefab in prefabs)
                {
                    if (prefab == prefabToFind)
                    {
                        return(prefab.prefabId);
                    }
                }
            }
            if (!suppressWarnings)
            {
                ES3Debug.LogWarning("Prefab with name " + prefabToFind.name + " could not be found in Easy Save's reference manager. Try pressing the Refresh References button on the ES3ReferenceMgr Component of the Easy Save 3 Manager in your scene.", prefabToFind);
            }
            return(-1);
        }
Пример #10
0
        public ES3Prefab GetPrefab(long id, bool suppressWarnings = false)
        {
            foreach (var mgr in mgrs)
            {
                if (mgr == null)
                {
                    continue;
                }

                foreach (var prefab in mgr.prefabs)
                {
                    if (prefabs != null && prefab.prefabId == id)
                    {
                        return(prefab);
                    }
                }
            }
            if (!suppressWarnings)
            {
                ES3Debug.LogWarning("Prefab with ID " + id + " could not be found in Easy Save's reference manager. Try pressing the Refresh References button on the ES3ReferenceMgr Component of the Easy Save 3 Manager in your scene.", this);
            }
            return(null);
        }
Пример #11
0
 internal override void Write(string key, Type type, byte[] value)
 {
     ES3Debug.LogError("Not implemented");
 }