Beispiel #1
0
        /// <summary>
        ///     Allows to initialize the object from the gived path
        /// </summary>
        /// <param name="path">The file's path</param>
        /// <author>Quijada Romero Luis Gonzalo</author>
        ///
        public DataFileManager(String path, String password = null)
        {
            this.fileSource = path;
            this.password   = password;

            try
            {
                String encrypted = System.IO.File.ReadAllText(path);
                if (password == null)
                {
                    this.dataString = encrypted;
                }
                else
                {
                    this.dataString = BiEncrypt.Decrypt(encrypted, password);
                }
            }
            catch (Exception e) {
                this.dataString = null;
            }

            try
            {
                this.dataObject = new DataJson(dataString);
            }
            catch (Exception e) {
                this.dataObject = null;
            }
        }
Beispiel #2
0
        public void Save()
        {
            dataString = dataObject.ToString();
            String encrypted;

            if (password == null)
            {
                encrypted = dataString;
            }
            else
            {
                encrypted = BiEncrypt.Encrypt(dataString, password);
            }
            String directory = fileSource.Substring(0, fileSource.LastIndexOf("/"));
            bool   exists    = System.IO.Directory.Exists(directory);

            if (!exists)
            {
                System.IO.Directory.CreateDirectory(directory);// .Directory.CreateDirectory(fileSource);
            }
            System.IO.File.WriteAllText(fileSource, encrypted);
        }