Last active
October 5, 2020 17:30
-
-
Save toger5/993114395ade31d5edfd67272718fd2f to your computer and use it in GitHub Desktop.
rust user not updating issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
let user: Rc<RefCell<Option<mpw::User>>> = Rc::new(RefCell::new(None)); | |
... | |
// PASSWORD UI connections | |
{ | |
let pwd_win = pwd_window.clone(); | |
let m_k = master_key.clone(); | |
let usr = user.clone(); | |
pwd_entry_big.connect_activate(move |entry| { | |
// log_win.hide(); | |
pwd_win.hide(); | |
let m_k = m_k.borrow().expect("NO MASTER KEY GOT DAMMIT"); | |
let site_name = entry.get_text().expect("No site name"); | |
let pwd = mpw::site_result( | |
site_name.as_str(), | |
m_k, | |
password_type, | |
mpw::AlgorithmVersionDefault, | |
); | |
let mut exists = false; | |
for s in usr.borrow().unwrap().get_sites() { | |
unsafe { | |
if (*s).get_name() == site_name.as_str().to_owned() { | |
exists = true; | |
} | |
} | |
} | |
if !exists { | |
print!("The site does not exist!!!"); | |
//show popup | |
// HERE: the usr object is empty as expected | |
usr.borrow_mut().unwrap().add_site( | |
site_name.as_str(), | |
mpw::ResultType::TemplateLong, | |
1, | |
mpw::AlgorithmVersionDefault, | |
); | |
// HERE: the usr object is still empty. which is not what i want | |
let mut path = dirs::home_dir().unwrap(); | |
path.push("mpsites"); | |
path.set_extension("txt"); | |
match mpw::marshal_write_to_file(path, mpw::MarshalFormat::flat, usr.borrow().unwrap()) { | |
Ok(a) => println!("succsesfully wrote to file"), | |
Err(r) => println!("err {}", r), | |
} | |
} | |
println!("{:?}", pwd); | |
println!("{:}", mpw::c_char_to_string(usr.borrow().unwrap().fullName)); | |
gtk::Clipboard::get_default( | |
&entry | |
.get_display() | |
.expect("cannot get display on pwd_enty_big"), | |
) | |
.expect("There is no default Clipboard") | |
.set_text(&pwd); | |
}); | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub type User = mpwbind::MPMarshalledUser; | |
impl User { | |
pub fn create( | |
full_name: &str, | |
master_password: &str, | |
algorithm_version: AlgorithmVersion, | |
) -> User { | |
unsafe { | |
*mpwbind::mpw_marshal_user( | |
CString::new(full_name).unwrap().as_ptr(), | |
CString::new(master_password).unwrap().as_ptr(), | |
algorithm_version as u32, | |
) | |
} | |
} | |
pub fn get_sites(&self) -> Vec<*mut Site> { | |
let mut sites: Vec<*mut Site> = Vec::new(); | |
for i in 0..self.sites_count { | |
unsafe { | |
sites.push(self.sites.wrapping_add(i)); | |
} | |
} | |
sites | |
} | |
pub fn add_site( | |
&mut self, | |
site_name: &str, | |
result_type: ResultType, | |
site_counter: u32, | |
algorithm_version: AlgorithmVersion, | |
) { | |
let s : Site; | |
let site_name_ptr = CString::new(site_name).unwrap(); | |
unsafe { | |
mpwbind::mpw_marshal_site( | |
self, | |
site_name_ptr.as_ptr(), | |
result_type as u32, | |
site_counter, | |
algorithm_version as u32, | |
); | |
} | |
unsafe{ | |
println!("\n site name: {}", (*self.sites).get_name()); | |
} | |
// HERE: the self object is fine and contains the sites | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment