private static void GetSourceFile(Action <IRuntimeFileInfo, Passphrase> fileSelected) { NSOpenPanel panel = NSOpenPanel.OpenPanel; PasswordViewController passwordController = new PasswordViewController(); panel.AccessoryView = passwordController.View; panel.Begin(result => { if (result == 0 || panel.Urls.Length == 0) { return; } if (!panel.Urls[0].IsFileUrl) { return; } string filePath = panel.Urls[0].Path; Passphrase generatedPassphrase = passwordController.Passphrase; panel.Close(); ThreadPool.QueueUserWorkItem(delegate { using (new NSAutoreleasePool()) { fileSelected(OS.Current.FileInfo(filePath), generatedPassphrase); }; }); }); }
public static void EncryptFile(ProgressContext progress, Action <string, ProgressContext> failure) { CreatePassphraseViewController passphraseController = new CreatePassphraseViewController { EncryptedFileName = DateTime.Now.ToString("yyyyMMddHHmmss") }; NSOpenPanel open = new NSOpenPanel { AccessoryView = passphraseController.View, AllowsMultipleSelection = false, CanChooseDirectories = false, CanChooseFiles = true, CanSelectHiddenExtension = true, CollectionBehavior = NSWindowCollectionBehavior.Transient, ExtensionHidden = true, Message = "Please select the file you would like to encrypt", Prompt = "Encrypt file", Title = "Encrypt", TreatsFilePackagesAsDirectories = false, }; open.Begin(result => { if (result == 0 || open.Urls.Length == 0) { return; } if (!open.Urls[0].IsFileUrl) { return; } string sourceFilePath = open.Urls[0].Path; open.Close(); IRuntimeFileInfo sourceFile = OS.Current.FileInfo(sourceFilePath); Passphrase passphrase = passphraseController.VerifiedPassphrase; if (passphrase == null) { return; } IRuntimeFileInfo targetFile = GetTargetFileName(sourceFilePath, passphraseController.EncryptedFileName); ThreadPool.QueueUserWorkItem(delegate { using (new NSAutoreleasePool()) { AxCryptFile.EncryptFileWithBackupAndWipe(sourceFile, targetFile, passphrase.DerivedPassphrase, progress); }; }); }); }
static void GetTargetPath(Action <string> directorySelected) { NSOpenPanel panel = NSOpenPanel.OpenPanel; panel.CanChooseFiles = false; panel.CanChooseDirectories = true; panel.Begin(result => { if (result == 0 || panel.Urls.Length == 0) { return; } if (!panel.Urls[0].IsFileUrl) { return; } string filePath = panel.Urls[0].Path; panel.Close(); directorySelected(filePath); }); }
/// <inheritdoc /> public override FileBrowserDialogResult ShowDialog() { _fileDialog.Title = Title; _fileDialog.CanChooseDirectories = IsFolderBrowser; _fileDialog.CanChooseFiles = !IsFolderBrowser; _fileDialog.AllowsMultipleSelection = Multiselect; var dialogResult = FileBrowserDialogResult.None; var result = (NSPanelButtonType)(int)_fileDialog.RunModal(); if (result == NSPanelButtonType.Cancel) { dialogResult = FileBrowserDialogResult.Cancel; _files = new List <string>(); } else if (result == NSPanelButtonType.Ok) { dialogResult = FileBrowserDialogResult.Ok; _files = _fileDialog.Urls.Select(f => f.Path).ToList(); } _fileDialog.Close(); _fileDialog.Dispose(); _fileDialog = null; return(dialogResult); }
public void Destroy() { open_panel.Close(); }