public string UnlockFile(ulong dht, uint project, string path, StorageFile file, bool history, List <LockError> errors) { // path needs to include name, because for things like history files name is diff than file.Info string finalpath = GetRootPath(dht, project) + path; finalpath += history ? Path.DirectorySeparatorChar + ".history" + Path.DirectorySeparatorChar : Path.DirectorySeparatorChar.ToString(); if (!CreateFolder(finalpath, errors, false)) { return(null); } finalpath += history ? GetHistoryName(file) : file.Name; // file not in storage if (!FileMap.SafeContainsKey(file.HashID) || !File.Exists(GetFilePath(file.HashID))) { errors.Add(new LockError(finalpath, "", true, LockErrorType.Missing)); return(null); } // check if already unlocked if (File.Exists(finalpath) && file.IsFlagged(StorageFlags.Unlocked)) { return(finalpath); } // file already exists if (File.Exists(finalpath)) { // ask user about local if (dht == Core.UserID) { errors.Add(new LockError(finalpath, "", true, LockErrorType.Existing, file, history)); return(null); } // overwrite remote else { try { File.Delete(finalpath); } catch { // not an existing error, dont want to give user option to 'use' the old remote file errors.Add(new LockError(finalpath, "", true, LockErrorType.Unexpected, file, history)); return(null); } } } // extract file try { Utilities.DecryptTagFile(GetFilePath(file.HashID), finalpath, file.FileKey, Core); } catch (Exception ex) { Core.Network.UpdateLog("Storage", "UnlockFile: " + ex.Message); errors.Add(new LockError(finalpath, "", true, LockErrorType.Unexpected, file, history)); return(null); } file.SetFlag(StorageFlags.Unlocked); if (dht != Core.UserID) { //FileInfo info = new FileInfo(finalpath); //info.IsReadOnly = true; } // local else if (Working.ContainsKey(project)) { // let caller trigger event because certain ops unlock multiple files // set watch on root path Working[project].StartWatchers(); } return(finalpath); }
public string UnlockFile(ulong dht, uint project, string path, StorageFile file, bool history, List<LockError> errors) { // path needs to include name, because for things like history files name is diff than file.Info string finalpath = GetRootPath(dht, project) + path; finalpath += history ? Path.DirectorySeparatorChar + ".history" + Path.DirectorySeparatorChar : Path.DirectorySeparatorChar.ToString(); if (!CreateFolder(finalpath, errors, false)) return null; finalpath += history ? GetHistoryName(file) : file.Name; // file not in storage if(!FileMap.SafeContainsKey(file.HashID) || !File.Exists(GetFilePath(file.HashID))) { errors.Add(new LockError(finalpath, "", true, LockErrorType.Missing)); return null; } // check if already unlocked if (File.Exists(finalpath) && file.IsFlagged(StorageFlags.Unlocked)) return finalpath; // file already exists if(File.Exists(finalpath)) { // ask user about local if (dht == Core.UserID) { errors.Add(new LockError(finalpath, "", true, LockErrorType.Existing, file, history)); return null; } // overwrite remote else { try { File.Delete(finalpath); } catch { // not an existing error, dont want to give user option to 'use' the old remote file errors.Add(new LockError(finalpath, "", true, LockErrorType.Unexpected, file, history)); return null; } } } // extract file try { Utilities.DecryptTagFile(GetFilePath(file.HashID), finalpath, file.FileKey, Core); } catch (Exception ex) { Core.Network.UpdateLog("Storage", "UnlockFile: " + ex.Message); errors.Add(new LockError(finalpath, "", true, LockErrorType.Unexpected, file, history)); return null; } file.SetFlag(StorageFlags.Unlocked); if (dht != Core.UserID) { //FileInfo info = new FileInfo(finalpath); //info.IsReadOnly = true; } // local else if (Working.ContainsKey(project) ) { // let caller trigger event because certain ops unlock multiple files // set watch on root path Working[project].StartWatchers(); } return finalpath; }