FileStore.FileStore.Save C# (CSharp) Method

Save() public method

Saves the store to the specified path.
public Save ( string path ) : bool
path string The path.
return bool
        public bool Save(string path)
        {
            if(path == null) {
                throw new ArgumentNullException("path");
            }

            FileStream writer = null;

            try {
                writer = new FileStream(path, FileMode.OpenOrCreate);

                if(writer.CanWrite) {
                    BinaryFormatter formatter = new BinaryFormatter();
                    StoreData data = new StoreData();

                    data.Files = files;
                    data.Encrypted = _encrypt;
                    data.UseDPAPI = _useDPAPI;
                    MemoryStream folderStream = SerializeFolders();

                    if(_encrypt) {
                        data.RootFolder = EncryptData(folderStream.ToArray());
                    }
                    else {
                        data.RootFolder = folderStream.ToArray();
                    }

                    formatter.Serialize(writer, data);
                    return true;
                }
            }
            catch(Exception e) {
                return false;
            }
            finally {
                if(writer != null) {
                    writer.Close();
                }
            }

            return true;
        }