public bool Load(string path)
{
if(path == null) {
throw new ArgumentNullException("path");
}
// check if the file exists
if(File.Exists(path) == false) {
return false;
}
FileStream reader = null;
try {
reader = new FileStream(path, FileMode.Open);
if(reader.CanRead) {
BinaryFormatter formatter = new BinaryFormatter();
StoreData data = (StoreData)formatter.Deserialize(reader);
files = data.Files;
_encrypt = data.Encrypted;
_useDPAPI = data.UseDPAPI;
DeserializeFolders(data.RootFolder);
return true;
}
}
catch(Exception e) {
Debug.ReportError("Failed to deserialize store. Path: {0}, Exception: {1}", path, e.Message);
return false;
}
finally {
if(reader != null) {
reader.Close();
}
}
return true;
}
private void LoadStore(string file) { store = new FileStore(); store.Load(file); storePath = file; if(store.Encrypt) { // show password window Password dialog = new Password(); if(dialog.ShowDialog() == DialogResult.OK) { SHA256Managed passwordHash = new SHA256Managed(); store.EncryptionKey = passwordHash.ComputeHash(Encoding.ASCII.GetBytes(dialog.textBox1.Text)); store.Load(file); } } treeView1.Nodes.Clear(); BuildTreeList(null, null); }