/// <summary> /// Creates and returns a file from the given serialized data. /// </summary> public static HashFile GetFileFromSerializedData(SerializedHashFile serializedFile) { var file = new HashFile(); file.FileId = serializedFile.FileId; file.Name = serializedFile.Name; file.ParentDirId = serializedFile.ParentDirId; file.Status = serializedFile.Status; file.Password = serializedFile.Password; file.Condition = serializedFile.Condition; file.UserPermission = SList.Create <ClassPair <string, AccessPermission> >(serializedFile.UserPermission.Length); for (int i = 0; i < serializedFile.UserPermission.Length; i++) { var permission = serializedFile.UserPermission[i]; var user = permission.Key; var pair = new ClassPair <string, AccessPermission>(); pair.Key = user.UserName; pair.Value = permission.Value; SList.Add(file.UserPermission, pair); } return(file); }
/// <summary> /// Returns the file that has the given id. /// </summary> public static HashFile FindFileById(int fileId) { var data = DataHolder.DeviceData.CurrentDevice.FileSystem; HashFile file = STable.Find(data.AllFiles, fileId); return(file); }
public static void OpenImageFile(HashFile file, ImageFile imageFile, bool openOnTerminal) { var imageContent = imageFile.ImageContent; if (file.Status == FileStatus.Encrypted) { ShowEncryptedFileMessage(); } if (openOnTerminal) { TerminalUtil.ShowImage(imageContent); } else { string title = FileSystem.GetWindowTitleForFile(file); ImageWindowComponent imageWindow = WindowUtil.CreateImageWindow(imageContent, title); if (file.Status == FileStatus.Encrypted) { var materialPrefab = DataHolder.GUIReferences.EncryptedImageMaterial; var material = new Material(materialPrefab); material.CopyPropertiesFromMaterial(materialPrefab); imageWindow.ImageHolder.material = material; imageWindow.UpdateImageBlendFactor = true; imageWindow.EncryptedImageBlendFactor = 1f; } } }
public static void OpenTextFile(HashFile file, TextFile textFile, bool openOnTerminal) { string textContent; if (file.Status == FileStatus.Encrypted) { ShowEncryptedFileMessage(); textContent = textFile.EncryptedTextContent; } else { textContent = FileSystem.GetTextFileContent(textFile); } if (openOnTerminal) { TerminalUtil.ShowText(textContent); } else { string title = FileSystem.GetWindowTitleForFile(file); WindowUtil.CreateTextWindow(textContent, title); } }
public static void ExecuteOnFile(Pair <string, string> fileArg, Pair <string, string> hintArg) { var filePath = fileArg.Value; HashFile file = FileSystem.FindFileByPath(filePath); if (file == null) { var msg = string.Format("No file found at '{0}'.", filePath); msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } else { var password = file.Password; LoopUtil.RunCoroutine(ExecuteOnPassword(password, hintArg.Value, (success) => { if (success) { var msg = string.Format("Password found!\nThe password of '{0}' is: {1}", filePath, file.Password); msg = TextUtil.Success(msg); TerminalUtil.ShowText(msg); } else { var msg = "Unable to find the password of '{0}' with the given arguments. Please try another set of hints."; msg = string.Format(msg, filePath); msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } })); } }
/// <summary> /// Returns true if the given file is avaiable for use. /// </summary> public static bool IsFileAvaibale(HashFile file) { var result = StoryUtil.EvaluateCondition(file.Condition); var permission = GetAccessPermission(file); result = result && permission > AccessPermission.Hidden; return(result); }
/// <summary> /// Calculates and returns the file full path. /// </summary> public static string GetFileFullPath(HashFile file) { var parentDirFullPath = GetDirFullPath(file.ParentDir); var fullName = GetFileFullName(file); var path = string.Format("{0}{1}", parentDirFullPath, fullName); // parentDirFullPath already has a trailling slash return(path); }
public static void AddFileToDir(HashDir dir, HashFile file) { file.ParentDir = dir; file.ParentDirId = dir.DirId; SList.Add(dir.Files, file); SList.Add(dir.FilesId, file.FileId); CacheFile(file); }
public static string GetWindowTitleForFile(HashFile file) { string format = "{0}{1}"; string status = string.Empty; if (file.Status != FileStatus.Normal) { status = string.Format(" - {0}", GetStatusString(file.Status)); } return(string.Format(format, file.FullName, status)); }
public static AccessPermission GetAccessPermissionForUser(HashFile file, string username) { var permissionPair = SList.Find(file.UserPermission, p => string.Equals(p.Key, username)); if (permissionPair != null) { return(permissionPair.Value); } else { return(AccessPermission.Editable); } }
private static HashFile CreateBaseFile(HashDir parent, string name) { var hashFile = new HashFile(); hashFile.Name = GetValidFileName(parent, name); hashFile.FileId = MathUtil.GetStringHash(name); hashFile.UserPermission = SList.Create <ClassPair <string, AccessPermission> >(1); hashFile.Condition = new HashStory.Condition(); hashFile.Condition.MinimalDays = HashStory.MainState.CurrentDay; AddFileToDir(parent, hashFile); return(hashFile); }
/// <summary> /// Adds the given file to the list of files. /// </summary> public static void AddAsFile(HashDir dir, HashFile file) { SList.Add(dir.FilesId, file.FileId); SList.Add(dir.Files, file); file.ParentDir = dir; }
/// <summary> /// Returns true if there's a file at path and this file is available for use. Stores the found file at the given parameter. /// Returns null if there's no file at the path. /// </summary> public static bool FileExistsAndIsAvailable(string path, out HashFile file) { file = FindFileByPath(path); return(file != null && IsFileAvaibale(file)); }
public static AccessPermission GetAccessPermission(HashFile file) { var user = DataHolder.DeviceData.CurrentUser.Username; return(GetAccessPermissionForUser(file, user)); }
/// <summary> /// Cache files path, folder and load its contents. /// </summary> public static void CacheFileContents(HashFile file) { CacheFile(file); }
/// <summary> /// Caches the file full path and full name. /// </summary> public static void CacheFile(HashFile file) { file.FullPath = GetFileFullPath(file); file.FullName = GetFileFullName(file); }
/// <summary> /// Returns true there's a file at path. Stores the found file on out file parameter. /// </summary> public static bool FileExists(string path, out HashFile file) { file = FindFileByPath(path); return(file != null); }
/// <summary> /// Caches the file parent dir. /// </summary> public static void CacheFileDir(HashFile file) { var parent = FindDirById(file.ParentDirId); AddAsFile(parent, file); }
public static void ChangeFileStatus(HashFile file, FileStatus newStatus) { file.Status = newStatus; }
/// <summary> /// Returns the file name + extension. /// </summary> public static string GetFileFullName(HashFile file) { return(string.Format("{0}.{1}", file.Name, GetFileExtension(file.FileType))); }
public static void Execute(ProgramExecutionOptions options) { if (ProgramUtil.ShowHelpIfNeeded(options)) { return; } if (CommandLineUtil.ValidateArguments(options.ParsedArguments, Validations)) { Pair <string, string> pathArg = CommandLineUtil.FindArgumentByName(options.ParsedArguments, PathArgName); Pair <string, string> passwordArg = CommandLineUtil.FindArgumentByName(options.ParsedArguments, PasswordArgName); var path = pathArg.Value; var password = passwordArg.Value; HashFile file = FileSystem.FindFileByPath(path); if (file == null) { var msg = string.Format("The path '{0}' is not a valid file path.", path); ShowErrorMessage(msg); } else { if (file.Status != FileStatus.Encrypted) { var msg = string.Format("The file '{0}' is not encrypt. You can open it using 'open {0}'", path); msg = TextUtil.ApplyNGUIColor(msg, Constants.Colors.Success); TerminalUtil.ShowText(msg); } else { var filePassword = file.Password; if (string.Equals(password, filePassword)) { var msg = string.Format("File '{0}' decrypted successfully. Use 'open {0}' to open the file.", path); msg = TextUtil.ApplyNGUIColor(msg, Constants.Colors.Success); TerminalUtil.ShowText(msg); FileSystem.ChangeFileStatus(file, FileStatus.Normal); } else { var msg = "Invalid password."; ShowErrorMessage(msg); } } } } else { var pathResult = (int)PathValidation.ValidationResult; var passwordResult = (int)PasswordValidation.ValidationResult; if (MathUtil.ContainsFlag(pathResult, (int)ArgValidationResult.NotFound) || MathUtil.ContainsFlag(pathResult, (int)ArgValidationResult.EmptyValue)) { var msg = "You need to supply a path. Please use 'help cracker' for more info."; ShowErrorMessage(msg); } else if (MathUtil.ContainsFlag(passwordResult, (int)ArgValidationResult.NotFound) || MathUtil.ContainsFlag(passwordResult, (int)ArgValidationResult.EmptyValue)) { var msg = "You need to supply a password. Please use 'help cracker' for more info."; ShowErrorMessage(msg); } } }