void LaunchPasswordActivityForIoc(IOConnectionInfo ioc) { IFileStorage fileStorage = App.Kp2a.GetFileStorage(ioc); if (fileStorage.RequiresCredentials(ioc)) { Util.QueryCredentials(ioc, AfterQueryCredentials, this); } else { try { PasswordActivity.Launch(this, ioc, new ActivityLaunchModeForward(), Intent.GetBooleanExtra("MakeCurrent", true)); Finish(); } catch (Java.IO.FileNotFoundException) { Toast.MakeText(this, Resource.String.FileNotFound, ToastLength.Long).Show(); } } }
private bool OnOpenButton(string filename, Dialog dialog) { IOConnectionInfo ioc = new IOConnectionInfo { Path = filename }; // Make sure file name exists if (filename.Length == 0) { Toast.MakeText(_activity, Resource.String.error_filename_required, ToastLength.Long).Show(); return(false); } int lastSlashPos = filename.LastIndexOf('/'); int lastDotPos = filename.LastIndexOf('.'); if (lastSlashPos >= lastDotPos) //no dot after last slash or == in case neither / nor . { ShowFilenameWarning(filename, () => { IocSelected(ioc); dialog.Dismiss(); }, () => { /* don't do anything, leave dialog open, let user try again*/ }); //signal that the dialog should be kept open return(false); } IFileStorage fileStorage; try { fileStorage = App.Kp2a.GetFileStorage(ioc); } catch (NoFileStorageFoundException) { Toast.MakeText(_activity, "Unexpected scheme in " + filename, ToastLength.Long).Show(); return(false); } if (_isForSave && ioc.IsLocalFile()) { // Try to create the file File file = new File(filename); try { File parent = file.ParentFile; if (parent == null || (parent.Exists() && !parent.IsDirectory)) { Toast.MakeText(_activity, Resource.String.error_invalid_path, ToastLength.Long).Show(); return(false); } if (!parent.Exists()) { // Create parent dircetory if (!parent.Mkdirs()) { Toast.MakeText(_activity, Resource.String.error_could_not_create_parent, ToastLength.Long).Show(); return(false); } } System.IO.File.Create(filename); } catch (IOException ex) { Toast.MakeText( _activity, _activity.GetText(Resource.String.error_file_not_create) + " " + ex.LocalizedMessage, ToastLength.Long).Show(); return(false); } } if (fileStorage.RequiresCredentials(ioc)) { Util.QueryCredentials(ioc, IocSelected, _activity); } else { IocSelected(ioc); } return(true); }