From 6ac4ef292b0b2fca15c183d0d97fc1ae04fd8d58 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 7 Apr 2022 15:32:47 +0800 Subject: [PATCH] add basis mount/unmount to pddb shell commands, fix some UX formatting --- services/pddb/locales/i18n.json | 8 +++- services/pddb/src/main.rs | 36 +++++++++------- services/pddb/src/ux.rs | 2 +- services/shellchat/src/cmds/pddb_cmd.rs | 57 ++++++++++++++++++++++++- 4 files changed, 83 insertions(+), 20 deletions(-) diff --git a/services/pddb/locales/i18n.json b/services/pddb/locales/i18n.json index 6484fcc0a..62d347fa5 100644 --- a/services/pddb/locales/i18n.json +++ b/services/pddb/locales/i18n.json @@ -108,11 +108,17 @@ "en-tts": "Enter name of Basis" }, "pddb.password": { - "en": "Basis Password:", + "en": "Enter Basis password", "ja": "Basis パスワード", "zh": "基础密码", "en-tts": "Enter password for Basis" }, + "pddb.password_for": { + "en": "For basis: ", + "ja": "Basis 名前: ", + "zh": "基础姓名: ", + "en-tts": "For basis: " + }, "pddb.menu.listbasis": { "en": "List unlocked bases", "ja": "ロック解除されたベースをー覧表します", diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index bc9eeea69..c9f7b6a2d 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -649,24 +649,28 @@ fn xmain() -> ! { basis_cache.basis_add(basis); finished = true; mgmt.code = PddbRequestCode::NoErr; + } else { + modals.add_list_item(t!("pddb.yes", xous::LANG)).expect("couldn't build radio item list"); + modals.add_list_item(t!("pddb.no", xous::LANG)).expect("couldn't build radio item list"); + match modals.get_radiobutton(t!("pddb.badpass", xous::LANG)) { + Ok(response) => { + if response.as_str() == t!("pddb.yes", xous::LANG) { + finished = false; + // this will cause just another go-around + } else if response.as_str() == t!("pddb.no", xous::LANG) { + finished = true; + mgmt.code = PddbRequestCode::AccessDenied; // this will cause a return of AccessDenied + } else { + panic!("Got unexpected return from radiobutton"); + } + } + _ => panic!("get_radiobutton failed"), + } + xous::yield_slice(); // allow a redraw to happen before repeating the request } } else { - modals.add_list_item(t!("pddb.yes", xous::LANG)).expect("couldn't build radio item list"); - modals.add_list_item(t!("pddb.no", xous::LANG)).expect("couldn't build radio item list"); - match modals.get_radiobutton(t!("pddb.badpass", xous::LANG)) { - Ok(response) => { - if response.as_str() == t!("pddb.yes", xous::LANG) { - finished = false; - // this will cause just another go-around - } else if response.as_str() == t!("pddb.no", xous::LANG) { - finished = true; - mgmt.code = PddbRequestCode::AccessDenied; // this will cause a return of AccessDenied - } else { - panic!("Got unexpected return from radiobutton"); - } - } - _ => panic!("get_radiobutton failed"), - } + finished = true; + log::error!("internal error in basis unlock, aborting!"); } } } diff --git a/services/pddb/src/ux.rs b/services/pddb/src/ux.rs index 7ab29987a..164a47901 100644 --- a/services/pddb/src/ux.rs +++ b/services/pddb/src/ux.rs @@ -104,7 +104,7 @@ pub(crate) fn password_ux_manager( pddb_modal.modify( Some(ActionType::TextEntry(password_action)), Some(t!("pddb.password", xous::LANG)), false, - Some(db_name.as_str().unwrap()), false, None + Some(format!("{}'{}'", t!("pddb.password_for", xous::LANG), db_name.as_str().unwrap()).as_str()), false, None ); pddb_modal.activate(); dr = Some(msg); diff --git a/services/shellchat/src/cmds/pddb_cmd.rs b/services/shellchat/src/cmds/pddb_cmd.rs index 918037dbe..9c49f5f85 100644 --- a/services/shellchat/src/cmds/pddb_cmd.rs +++ b/services/shellchat/src/cmds/pddb_cmd.rs @@ -21,9 +21,9 @@ impl<'a> ShellCmdApi<'a> for PddbCmd { use core::fmt::Write; let mut ret = String::<1024>::new(); #[cfg(not(feature="pddbtest"))] - let helpstring = "pddb [basislist] [dictlist] [keylist] [query] [dictdelete] [keydelete]"; + let helpstring = "pddb [basislist] [basiscreate] [basisunlock] [basislock] [basisdelete] [default]\n[dictlist] [keylist] [query] [dictdelete] [keydelete]"; #[cfg(feature="pddbtest")] - let helpstring = "pddb [basislist] [dictlist] [keylist] [query] [dictdelete] [keydelete] [test]"; + let helpstring = "pddb [basislist] [basiscreate] [basisunlock] [basislock] [basisdelete] [default]\n[dictlist] [keylist] [query] [dictdelete] [keydelete]\n[test]"; let mut tokens = args.as_str().unwrap().split(' '); if let Some(sub_cmd) = tokens.next() { @@ -43,6 +43,52 @@ impl<'a> ShellCmdApi<'a> for PddbCmd { }}) ).unwrap();*/ } + "default" => { + match self.pddb.latest_basis() { + Some(latest) => write!(ret, "The current default basis is: {}", latest).unwrap(), + None => write!(ret, "No open basis detected").unwrap(), + } + } + "basiscreate" => { + if let Some(bname) = tokens.next() { + match self.pddb.create_basis(bname) { + Ok(_) => write!(ret, "basis {} created successfully", bname).unwrap(), + Err(e) => write!(ret, "basis {} could not be created: {:?}", bname, e).unwrap(), + } + } else { + write!(ret, "usage: pddb basiscreate [basis name]").unwrap() + } + } + "basisunlock" => { + if let Some(bname) = tokens.next() { + match self.pddb.unlock_basis(bname, None) { + Ok(_) => write!(ret, "basis {} unlocked successfully", bname).unwrap(), + Err(e) => write!(ret, "basis {} could not be unlocked: {:?}", bname, e).unwrap(), + } + } else { + write!(ret, "usage: pddb basisunlock [basis name]").unwrap() + } + } + "basislock" => { + if let Some(bname) = tokens.next() { + match self.pddb.lock_basis(bname) { + Ok(_) => write!(ret, "basis {} locked successfully", bname).unwrap(), + Err(e) => write!(ret, "basis {} could not be locked: {:?}", bname, e).unwrap(), + } + } else { + write!(ret, "usage: pddb basisunlock [basis name]").unwrap() + } + } + "basisdelete" => { + if let Some(bname) = tokens.next() { + match self.pddb.delete_basis(bname) { + Ok(_) => write!(ret, "basis {} deleted successfully", bname).unwrap(), + Err(e) => write!(ret, "basis {} could not be deleted: {:?}", bname, e).unwrap(), + } + } else { + write!(ret, "usage: pddb basisdelete [basis name]").unwrap() + } + } "query" => { if let Some(descriptor) = tokens.next() { if let Some((dict, keyname)) = descriptor.split_once(':') { @@ -171,6 +217,7 @@ impl<'a> ShellCmdApi<'a> for PddbCmd { // note that this feature only works in hosted mode #[cfg(feature="pddbtest")] "test" => { + let bname = tokens.next(); // zero-length key test let mut test_handle = pddb::Pddb::new(); // build a key, but don't write to it. @@ -183,6 +230,12 @@ impl<'a> ShellCmdApi<'a> for PddbCmd { ).expect("couldn't build empty key"); self.pddb.sync().unwrap(); self.pddb.dbg_remount().unwrap(); + if let Some(name) = bname { + match self.pddb.unlock_basis(name, None) { + Ok(_) => log::info!("basis {} unlocked successfully", name), + Err(e) => log::info!("basis {} could not be unlocked: {:?}", name, e), + } + } self.pddb.dbg_dump("std_test1").unwrap(); write!(ret, "dumped std_test1\n").unwrap(); log::info!("finished zero-length alloc");