Ejemplo n.º 1
0
 /// <summary>Synchronises a local file with a file on the server. If the file on the server is newer than the local copy, the local file will be overwritten by the file on the server. Otherwise, the file on the server will be overwritten.</summary>
 /// <param name="filePath">The relative or absolute path of the file we want to use.</param>
 /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public IEnumerator Sync(string filePath, string user, ES3Settings settings)
 {
     return(Sync(new ES3Settings(filePath, settings), user, ""));
 }
Ejemplo n.º 2
0
 /// <summary>Creates a new ES3File and loads the specified file into the ES3File if there is data to load.</summary>
 /// <param name="bytes">The bytes representing our file.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public ES3File(byte[] bytes, ES3Settings settings) : this(bytes, settings, true)
 {
 }
Ejemplo n.º 3
0
        private void Generate()
        {
            var type = types[selectedType].type;

            if (type == null)
            {
                EditorUtility.DisplayDialog("Type not selected", "Type not selected. Please ensure you select a type", "Ok");
                return;
            }

            unsavedChanges = false;

            // Get the serializable fields of this class.
            //var fields = ES3Reflection.GetSerializableES3Fields(type);

            // The string that we suffix to the class name. i.e. UnityEngine_UnityEngine_Transform.
            string es3TypeSuffix = type.Name;
            // The string for the full C#-safe type name. This name must be suitable for going inside typeof().
            string fullType = GetFullTypeName(type);
            // The list of WriteProperty calls to write the properties of this type.
            string writes = GenerateWrites();
            // The list of case statements and Read calls to read the properties of this type.
            string reads = GenerateReads();
            // A comma-seperated string of fields we've supported in this type.
            string propertyNames = "";

            bool first = true;

            for (int i = 0; i < fields.Length; i++)
            {
                if (!fieldSelected[i])
                {
                    continue;
                }

                if (first)
                {
                    first = false;
                }
                else
                {
                    propertyNames += ", ";
                }
                propertyNames += "\"" + fields[i].Name + "\"";
            }

            var easySaveEditorPath = ES3Settings.PathToEasySaveFolder() + "Editor/";

            // Insert the relevant strings into the template.
            string template;

            if (typeof(Component).IsAssignableFrom(type))
            {
                template = File.ReadAllText(easySaveEditorPath + componentTemplateFile);
            }
            else if (ES3Reflection.IsValueType(type))
            {
                template = File.ReadAllText(easySaveEditorPath + valueTemplateFile);
            }
            else if (typeof(ScriptableObject).IsAssignableFrom(type))
            {
                template = File.ReadAllText(easySaveEditorPath + scriptableObjectTemplateFile);
            }
            else
            {
                template = File.ReadAllText(easySaveEditorPath + classTemplateFile);
            }
            template = template.Replace("[es3TypeSuffix]", es3TypeSuffix);
            template = template.Replace("[fullType]", fullType);
            template = template.Replace("[writes]", writes);
            template = template.Replace("[reads]", reads);
            template = template.Replace("[propertyNames]", propertyNames);

            // Create the output file.


            string outputFilePath = GetOutputPath(type);
            var    fileInfo       = new FileInfo(outputFilePath);

            fileInfo.Directory.Create();
            File.WriteAllText(outputFilePath, template);
            AssetDatabase.Refresh();
        }
Ejemplo n.º 4
0
 /// <summary>Synchronises this ES3File with a file in storage.</summary>
 /// <param name="filepath">The relative or absolute path of the file in storage we want to synchronise with.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public void Sync(string filePath, ES3Settings settings)
 {
     Sync(new ES3Settings(filePath, settings));
 }
Ejemplo n.º 5
0
 /// <summary>Creates a new ES3File and loads the specified file into the ES3File if there is data to load.</summary>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public ES3File(ES3Settings settings) : this(settings, true)
 {
 }
Ejemplo n.º 6
0
 public ES3XMLWriter(Stream stream, ES3Settings settings) : this(stream, settings, true, true)
 {
 }
Ejemplo n.º 7
0
 /// <summary>Creates a new ES3Writer.</summary>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public static ES3Writer Create(ES3Settings settings)
 {
     return(Create(settings, true, true, false));
 }
Ejemplo n.º 8
0
 /// <summary>Deletes a file from the server. An error is *not* returned if the file does not exist.</summary>
 /// <param name="filePath">The relative or absolute path of the file we want to delete.</param>
 /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param>
 /// <param name="password">The password of the user this file belongs to.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public IEnumerator DeleteFile(string filePath, string user, string password, ES3Settings settings)
 {
     return(DeleteFile(new ES3Settings(filePath, settings), user, password));
 }
Ejemplo n.º 9
0
 /// <summary>Renames a file from the server. An error is *not* returned if the file does not exist.</summary>
 /// <param name="filePath">The relative or absolute path of the file we want to delete.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public IEnumerator RenameFile(string filePath, string newFilePath, ES3Settings settings)
 {
     return(RenameFile(new ES3Settings(filePath, settings), new ES3Settings(newFilePath, settings), "", ""));
 }
Ejemplo n.º 10
0
 /// <summary>Downloads a file from the server and saves it locally, overwriting any existing local file. An error is returned if the file does not exist.</summary>
 /// <param name="filePath">The relative or absolute path of the file we want to download.</param>
 /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public IEnumerator DownloadFile(string filePath, string user, ES3Settings settings)
 {
     return(DownloadFile(new ES3Settings(filePath, settings), user, "", 0));
 }
Ejemplo n.º 11
0
 /// <summary>Deletes a file from the server. An error is *not* returned if the file does not exist.</summary>
 /// <param name="filePath">The relative or absolute path of the file we want to delete.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public IEnumerator DeleteFile(string filePath, ES3Settings settings)
 {
     return(DeleteFile(new ES3Settings(filePath, settings), "", ""));
 }
Ejemplo n.º 12
0
 /// <summary>Uploads a local file to the server, overwriting any existing file.</summary>
 /// <param name="es3File">An ES3File containing the data we want to upload.</param>
 /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param>
 /// <param name="password">The password of the user this file belongs to.</param>
 public IEnumerator UploadFile(ES3Settings settings, string user, string password)
 {
     return(UploadFile(ES3.LoadRawBytes(settings), settings, user, password));
 }
Ejemplo n.º 13
0
 /// <summary>Uploads a local file to the server, overwriting any existing file.</summary>
 /// <param name="filePath">The relative or absolute path of the file we want to use.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public IEnumerator UploadFile(string filePath, ES3Settings settings)
 {
     return(UploadFile(new ES3Settings(filePath, settings), "", ""));
 }
Ejemplo n.º 14
0
 /// <summary>Synchronises a local file with a file on the server. If the file on the server is newer than the local copy, the local file will be overwritten by the file on the server. Otherwise, the file on the server will be overwritten.</summary>
 /// <param name="filePath">The relative or absolute path of the local file we want to synchronise.</param>
 /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param>
 /// <param name="password">The password of the user this file belongs to.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public IEnumerator Sync(string filePath, string user, string password, ES3Settings settings)
 {
     return(Sync(new ES3Settings(filePath, settings), user, password));
 }
Ejemplo n.º 15
0
 /// <summary>Creates a new ES3Settings object with the given path and encryption settings.</summary>
 /// <param name="path">The path associated with this ES3Settings object.</param>
 /// <param name="encryptionType">The type of encryption to use, if any.</param>
 /// <param name="encryptionPassword">The password to use when encrypting data.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public ES3Settings(string path, ES3.EncryptionType encryptionType, string encryptionPassword, ES3Settings settings) : this(path, settings)
 {
     this.encryptionType     = encryptionType;
     this.encryptionPassword = encryptionPassword;
 }
Ejemplo n.º 16
0
 /// <summary>Renames a file from the server. An error is *not* returned if the file does not exist.</summary>
 /// <param name="filePath">The relative or absolute path of the file we want to delete.</param>
 /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param>
 /// <param name="password">The password of the user this file belongs to.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public IEnumerator RenameFile(string filePath, string newFilePath, string user, string password, ES3Settings settings)
 {
     return(RenameFile(new ES3Settings(filePath, settings), new ES3Settings(newFilePath, settings), user, password));
 }
Ejemplo n.º 17
0
 public void Init()
 {
     editorSettings = ES3EditorUtility.GetDefaultSettings();
     settings       = editorSettings.settings;
 }
Ejemplo n.º 18
0
 /// <summary>Downloads the timestamp representing when the server file was last updated. The downloaded timestamp is stored in the 'timestamp' variable of the ES3Cloud object.</summary>
 /// <param name="filePath">The relative or absolute path of the file we want to get the timestamp of.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public IEnumerator DownloadTimestamp(string filePath, ES3Settings settings)
 {
     return(DownloadTimestamp(new ES3Settings(filePath, settings), "", ""));
 }
Ejemplo n.º 19
0
 internal ES3XMLWriter(Stream stream, ES3Settings settings, bool writeHeaderAndFooter, bool overwriteKeys) : base(settings, writeHeaderAndFooter, overwriteKeys)
 {
     baseWriter = new StreamWriter(stream);
     StartWriteFile();
 }
Ejemplo n.º 20
0
 /// <summary>Downloads the timestamp representing when the server file was last updated. The downloaded timestamp is stored in the 'timestamp' variable of the ES3Cloud object.</summary>
 /// <param name="filePath">The relative or absolute path of the file we want to get the timestamp of.</param>
 /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param>
 /// <param name="password">The password of the user this file belongs to.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public IEnumerator DownloadTimestamp(string filePath, string user, string password, ES3Settings settings)
 {
     return(DownloadTimestamp(new ES3Settings(filePath, settings), user, password));
 }
Ejemplo n.º 21
0
 protected ES3Writer(ES3Settings settings, bool writeHeaderAndFooter, bool overwriteKeys)
 {
     this.settings             = settings;
     this.writeHeaderAndFooter = writeHeaderAndFooter;
     this.overwriteKeys        = overwriteKeys;
 }
Ejemplo n.º 22
0
 private long GetFileTimestamp(ES3Settings settings)
 {
     return(DateTimeToUnixTimestamp(ES3.GetTimestamp(settings)));
 }
Ejemplo n.º 23
0
 /// <summary>Creates a new ES3File and loads the specified file into the ES3File if there is data to load.</summary>
 /// <param name="filepath">The relative or absolute path of the file in storage our ES3File is associated with.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public ES3File(string filePath, ES3Settings settings) : this(new ES3Settings(filePath, settings), true)
 {
 }
Ejemplo n.º 24
0
 /// <summary>Creates a new ES3File and loads the bytes into the ES3File. Note the bytes must represent that of a file.</summary>
 /// <param name="bytes">The bytes representing our file.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 /// <param name="syncWithFile">Whether we should sync this ES3File with the one in storage immediately after creating it.</param>
 public ES3File(byte[] bytes, ES3Settings settings)
 {
     this.settings = settings;
     SaveRaw(bytes, settings);
 }
Ejemplo n.º 25
0
 /// <summary>Creates a new ES3File and only loads the specified file into it if syncWithFile is set to true.</summary>
 /// <param name="filepath">The relative or absolute path of the file in storage our ES3File is associated with.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 /// <param name="syncWithFile">Whether we should sync this ES3File with the one in storage immediately after creating it.</param>
 public ES3File(string filePath, ES3Settings settings, bool syncWithFile) : this(new ES3Settings(filePath, settings), syncWithFile)
 {
 }
Ejemplo n.º 26
0
 internal static void RemoveCachedFile(ES3Settings settings)
 {
     cachedFiles.Remove(settings.path);
 }
Ejemplo n.º 27
0
        private void Init()
        {
            componentTemplateFile        = "ES3ComponentTypeTemplate.txt";
            classTemplateFile            = "ES3ClassTypeTemplate.txt";
            valueTemplateFile            = "ES3ValueTypeTemplate.txt";
            scriptableObjectTemplateFile = "ES3ScriptableObjectTypeTemplate.txt";

            // Init Type List
            var tempTypes = new List <TypeListItem> ();

            var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => !assembly.FullName.Contains("Editor") && assembly.FullName != "ES3" && !assembly.FullName.Contains("ES3")).OrderBy(assembly => assembly.GetName().Name).ToArray();

            foreach (var assembly in assemblies)
            {
                var assemblyTypes = assembly.GetTypes();

                for (int i = 0; i < assemblyTypes.Length; i++)
                {
                    var type = assemblyTypes [i];
                    if (type.IsGenericType || type.IsEnum || type.IsNotPublic || type.IsAbstract || type.IsInterface)
                    {
                        continue;
                    }

                    var typeName = type.Name;
                    if (typeName [0] == '$' || typeName [0] == '_' || typeName [0] == '<')
                    {
                        continue;
                    }

                    var typeNamespace = type.Namespace;
                    var namespaceName = typeNamespace == null ? "" : typeNamespace.ToString();

                    tempTypes.Add(new TypeListItem(type.Name, namespaceName, type, true, HasExplicitES3Type(type)));
                }
            }
            types = tempTypes.OrderBy(type => type.name).ToArray();

            // Load types and recent types.
            if (Event.current.type == EventType.Layout)
            {
                recentTypes = new List <int>();
                for (int i = 0; i < recentTypeCount; i++)
                {
                    int typeIndex = LoadTypeIndex("TypesWindowRecentType" + i);
                    if (typeIndex != -1)
                    {
                        recentTypes.Add(typeIndex);
                    }
                }
                SelectType(LoadTypeIndex("TypesWindowSelectedType"));
            }

            PerformSearch(searchFieldValue);

            // Init Assets.
            string es3FolderPath = ES3Settings.PathToEasySaveFolder();

            checkmark = AssetDatabase.LoadAssetAtPath <Texture2D>(es3FolderPath + "Editor/checkmark.png");
            //checkmarkSmall = AssetDatabase.LoadAssetAtPath<Texture2D>(es3FolderPath + "Editor/checkmarkSmall.png");

            // Init Styles.
            searchBarCancelButtonStyle = new GUIStyle(EditorStyles.miniButton);
            var cancelButtonSize = EditorStyles.miniTextField.CalcHeight(new GUIContent(""), 20);

            searchBarCancelButtonStyle.fixedWidth  = cancelButtonSize;
            searchBarCancelButtonStyle.fixedHeight = cancelButtonSize;
            searchBarCancelButtonStyle.fontSize    = 8;
            searchBarCancelButtonStyle.padding     = new RectOffset();
            searchBarStyle = new GUIStyle(EditorStyles.toolbarTextField);
            searchBarStyle.stretchWidth = true;

            typeButtonStyle                   = new GUIStyle(EditorStyles.largeLabel);
            typeButtonStyle.alignment         = TextAnchor.MiddleLeft;
            typeButtonStyle.stretchWidth      = false;
            selectedTypeButtonStyle           = new GUIStyle(typeButtonStyle);
            selectedTypeButtonStyle.fontStyle = FontStyle.Bold;

            leftPaneStyle            = new GUIStyle();
            leftPaneStyle.fixedWidth = leftPaneWidth;
            leftPaneStyle.clipping   = TextClipping.Clip;
            leftPaneStyle.padding    = new RectOffset(10, 10, 10, 10);

            selectAllNoneButtonStyle = new GUIStyle(EditorStyles.miniButton);
            selectAllNoneButtonStyle.stretchWidth = false;
            selectAllNoneButtonStyle.margin       = new RectOffset(0, 0, 0, 10);
        }
Ejemplo n.º 28
0
 internal static bool FileExists(ES3Settings settings)
 {
     return(cachedFiles.ContainsKey(settings.path));
 }
Ejemplo n.º 29
0
 /// <summary>Creates a new ES3Reader and loads a file in storage into it.</summary>
 /// <param name="filePath">The relative or absolute path of the file we want to load into the reader.</param>
 /// <param name="settings">The settings we want to use to override the default settings.</param>
 public static ES3Reader Create(string filePath, ES3Settings settings)
 {
     return(Create(new ES3Settings(filePath, settings)));
 }
Ejemplo n.º 30
0
    /// <summary>Creates a backup of a file.</summary>
    /// <remarks>A backup is created by copying the file and giving it a .bak extension.
    /// If a backup already exists it will be overwritten, so you will need to ensure that the old backup will not be required before calling this method.</remarks>
    /// <param name="settings">The settings we want to use to override the default settings.</param>
    public static void CreateBackup(ES3Settings settings)
    {
        var backupSettings = new ES3Settings(settings.path + backupFileSuffix, settings);

        ES3.CopyFile(backupSettings, settings);
    }