int ReadCore(PWScore& othercore, const wxString& file, const StringX& combination, bool showMsgbox /*= true*/, wxWindow* msgboxParent /*= NULL*/) { othercore.ClearData(); // Reading a new file changes the preferences! const StringX sxSavePrefString(PWSprefs::GetInstance()->Store()); const bool bDBPrefsChanged = PWSprefs::GetInstance()->IsDBprefsChanged(); StringX dbpath(tostringx(file)); int rc = othercore.ReadFile(dbpath, combination); // Reset database preferences - first to defaults then add saved changes! PWSprefs::GetInstance()->Load(sxSavePrefString); PWSprefs::GetInstance()->SetDBprefsChanged(bDBPrefsChanged); switch (rc) { case PWScore::SUCCESS: othercore.SetCurFile(tostringx(file)); break; case PWScore::CANT_OPEN_FILE: if (showMsgbox) wxMessageBox(wxString(file) << _("\n\nCould not open file for reading!"), _("File Read Error"), wxOK | wxICON_ERROR, msgboxParent ); break; case PWScore::BAD_DIGEST: if (showMsgbox && wxMessageBox(wxString(file) << _("\n\nFile corrupt or truncated!\nData may have been lost or modified.\nContinue anyway?"), _("File Read Error"), wxYES_NO | wxICON_QUESTION, msgboxParent) == wxYES) { rc = PWScore::SUCCESS; } break; #ifdef DEMO case PWScore::LIMIT_REACHED: if( showMsgbox) wxMessageBox(wxString::Format(_("This version of PasswordSafe does not support more than %d entries in a database.\nTo get an unlimited version for the U3 platform, please visit http://software.u3.com\nNote: Saving this database will result in the removal of unread entries!"), MAXDEMO), _("Trial Version Limitation"), wxOK | wxICON_WARNING, msgboxParent); break; #endif default: if (showMsgbox) wxMessageBox( wxString(file) << _("\n\nUnknown error"), _("File Read Error"), wxOK | wxICON_ERROR, msgboxParent); break; } return rc; }
int ReadCore(PWScore& othercore, const wxString& file, const StringX& combination, bool showMsgbox /*= true*/, wxWindow* msgboxParent /*= NULL*/, bool setupCopy /*= false*/) { othercore.ClearData(); StringX dbpath(tostringx(file)); int rc = othercore.ReadFile(dbpath, combination); if (setupCopy) PWSprefs::GetInstance()->SetupCopyPrefs(); switch (rc) { case PWScore::SUCCESS: othercore.SetCurFile(tostringx(file)); break; case PWScore::CANT_OPEN_FILE: if (showMsgbox) wxMessageBox(wxString(file) << wxT("\n\n") << _("Could not open file for reading!"), _("File Read Error"), wxOK | wxICON_ERROR, msgboxParent ); break; case PWScore::BAD_DIGEST: if (showMsgbox && wxMessageBox(wxString(file) << wxT("\n\n") << _("File corrupt or truncated!\nData may have been lost or modified.\nContinue anyway?"), _("File Read Error"), wxYES_NO | wxICON_QUESTION, msgboxParent) == wxYES) { rc = PWScore::SUCCESS; } break; default: if (showMsgbox) wxMessageBox( wxString(file) << wxT("\n\n") << _("Unknown error"), _("File Read Error"), wxOK | wxICON_ERROR, msgboxParent); break; } return rc; }
int main(int argc, char *argv[]) { UserArgs ua; if (!parseArgs(argc, argv, ua)) { usage(argv[0]); return 1; } PWScore core; if (!pws_os::FileExists(ua.safe.c_str())) { cerr << argv[1] << " - file not found" << endl; return 2; } wstring wpk; cout << "Enter Password: "******"CheckPasskey returned: " << status_text(status) << endl; goto done; } { CUTF8Conv conv; const char *user = getlogin() != NULL ? getlogin() : "unknown"; StringX locker; if (!conv.FromUTF8((const unsigned char *)user, strlen(user), locker)) { cerr << "Could not convert user " << user << " to StringX" << endl; return 2; } stringT lk(locker.c_str()); if (!core.LockFile(ua.safe.c_str(), lk)) { wcout << L"Couldn't lock file " << ua.safe << L": locked by " << locker << endl; status = -1; goto done; } } // Since we may be writing the same file we're reading, // it behooves us to set the Current File and use its' related // functions core.SetCurFile(ua.safe); status = core.ReadCurFile(pk); if (status != PWScore::SUCCESS) { cout << "ReadFile returned: " << status_text(status) << endl; goto done; } if (ua.ImpExp == UserArgs::Export) { CItemData::FieldBits all(~0L); int N; if (ua.Format == UserArgs::XML) { status = core.WriteXMLFile(ua.fname, all, L"", 0, 0, L' ', N); } else { // export text status = core.WritePlaintextFile(ua.fname, all, L"", 0, 0, L' ', N); } } else { // Import if (ua.Format == UserArgs::XML) { status = ImportXML(core, ua.fname); } else { // import text status = ImportText(core, ua.fname); } if (status == PWScore::SUCCESS) status = core.WriteCurFile(); } if (status != PWScore::SUCCESS) { cout << "Operation returned status: " << status_text(status) << endl; goto done; } done: core.UnlockFile(ua.safe.c_str()); return status; }