Ejemplo n.º 1
0
        ///<summary>
        /// Encrypt and save the current engine state to file, so it can be loaded later.
        /// If file with the same name exists it won't be replaced,
        /// but to the current filename will be added a number, 'filename(1).acc' e.g.
        ///</summary>
        ///<param name="password">
        /// The password to encrypt the file.
        ///</param>
        ///<param name="savePath">
        /// The folder to save in.
        /// If not setted, the file will be saved in "pSavepath".
        ///</param>
        public string FileSaveSafe(string password, string savePath = "")
        {
            if (!Initial("FileSaveSafe()"))
            {
                return(null);
            }
            try
            {
                if (savePath == "")
                {
                    savePath = pSavepath + FileName;
                }
                else
                {
                    if (savePath[savePath.Length - 1] != '\\')
                    {
                        savePath += '\\';
                    }
                    savePath += FileName;
                }
                if (Validators.ValidateWriteAccess(savePath) == false)
                {
                    Fault("You don't have write access!");
                    return(savePath);
                }

                byte[] buff    = IO.Serialize(Memory);
                byte[] crypted = IO.EncryptBytes(buff, password);
                IO.SaveSafe(savePath, crypted);
                Success(FileName + " Saved!");
                return(savePath);
            }
            catch (Exception ex)
            {
                Exceptional(ex);
                return(null);
            }
        }
Ejemplo n.º 2
0
        ///<summary>
        /// Save the current engine state to file, so it can be loaded later.
        /// If FileName property is not set, the FileName is a string, representing a timestamp.
        ///</summary>
        ///<param name="savePath">
        /// The folder to save in.
        /// If not setted, the file will be saved in "pSavepath".
        ///</param>
        public string FileSave(string savePath = "")
        {
            if (!Initial("FileSave()"))
            {
                return(null);
            }
            try
            {
                if (savePath == "")
                {
                    savePath = pSavepath + FileName;
                }
                else
                {
                    if (savePath[savePath.Length - 1] != '\\')
                    {
                        savePath += '\\';
                    }
                    savePath += FileName;
                }
                if (Validators.ValidateWriteAccess(savePath) == false)
                {
                    Fault("You don't have write access!");
                    return(savePath);
                }

                IO.Serialize(savePath, Memory);
                Success(FileName + " Saved!");
                return(savePath);
            }
            catch (Exception ex)
            {
                Exceptional(ex);
                return(null);
            }
        }