/// <summary> /// Unshares a file with all shared users on EnigmaEfs. /// </summary> /// <param name="pathOnEfs"></param> public void Unshare(string pathOnEfs) { var encryptedFile = new EncryptedFile(pathOnEfs.Substring(pathOnEfs.LastIndexOf('\\') + 1).Split('.')[0]); var updatedEncryptedFileRaw = encryptedFile.Unshare(File.ReadAllBytes(pathOnEfs), currentUser.Id); if (CanItBeStored(updatedEncryptedFileRaw.Length)) { CreateFile(updatedEncryptedFileRaw, RootDir + "\\" + UserDir + "\\" + encryptedFile.GetEncryptedFileFullName()); DeleteFile(pathOnEfs); } else { throw new Exception("Insufficient storage available. File can't be updated."); } }
/// <summary> /// Unshares a file with specific user on EnigmaEfs. /// </summary> /// <param name="pathOnEfs">The name of the shared file.</param> /// <param name="userId">Unique user identifier from the database.</param> public void Unshare(string pathOnEfs, int userId) { var encryptedFile = new EncryptedFile(pathOnEfs.Substring(pathOnEfs.LastIndexOf('\\') + 1).Split('.')[0]); var updatedEncryptedFileRaw = encryptedFile.Unshare(File.ReadAllBytes(pathOnEfs), currentUser.Id, userId, out var numberOfSharedUsers); if (CanItBeStored(updatedEncryptedFileRaw.Length)) { // File is moved from shared folder to user's folder. if (numberOfSharedUsers != 1) { CreateFile(updatedEncryptedFileRaw, SharedDir + "\\" + encryptedFile.GetEncryptedFileFullName()); } // If no other user other than file owner can access a file, it's moved from shared folder to file owner's folder. else { CreateFile(updatedEncryptedFileRaw, RootDir + "\\" + UserDir + "\\" + encryptedFile.GetEncryptedFileFullName()); DeleteFile(pathOnEfs); } } else { throw new Exception("Insufficient storage available. File can't be updated."); } }