Fixed wallet to use the default wallet location

if available, rather than asking for a location
This commit is contained in:
Cheng 2023-10-29 05:37:33 +00:00
parent 1d7ce60cf7
commit 3d805aa7c5
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA

View File

@ -374,45 +374,59 @@ COMMIT;
void Frame::OnSaveNew(wxCommandEvent& WXUNUSED(event)) void Frame::OnSaveNew(wxCommandEvent& WXUNUSED(event))
{ {
wxString wxstrWalletPath; wxFileName wxFileWallet;
wxString wxstrWalletName(wxEmptyString); if (m_DefaultWalletLocation.FileExists()) {
if (!m_LastUsedWallet.IsOk() || !m_LastUsedWallet.DirExists()) { // OK, the default wallet exists, so we need a new
m_LastUsedWallet = m_DefaultWalletLocation; // name and wallet location
RecursiveCreateDirectory(m_LastUsedWallet); wxString wxstrWalletPath;
} wxString wxstrWalletName(wxEmptyString);
wxstrWalletPath = m_LastUsedWallet.GetPath(); //Directory guaranteed to exist, so we will not get idiot default if (!m_LastUsedWallet.IsOk() || !m_LastUsedWallet.DirExists()) {
// It took me a ridiculous amount of time to fix that all paths to this file dialog m_LastUsedWallet = m_DefaultWalletLocation;
// are either terminated by an exception, or the directory exists, or is created. RecursiveCreateDirectory(m_LastUsedWallet);
// Any time the program has to deal with something external to itself, anything that can go wrong }
// will go wrong. wxstrWalletPath = m_LastUsedWallet.GetPath(); //Directory guaranteed to exist, so we will not get idiot default
if (!m_LastUsedWallet.FileExists()) wxstrWalletName = m_LastUsedWallet.GetFullName(); // It took me a ridiculous amount of time to fix that all paths to this file dialog
wxFileDialog dialog(this, // are either terminated by an exception, or the directory exists, or is created.
sz_new_wallet_new_secret, // Any time the program has to deal with something external to itself, anything that can go wrong
wxstrWalletPath, // will go wrong.
wxstrWalletName, if (!m_LastUsedWallet.FileExists()) wxstrWalletName = m_LastUsedWallet.GetFullName();
wxString::Format wxFileDialog dialog(this,
("wallet (*.wallet)|*.wallet|All (%s)|%s", sz_new_wallet_new_secret,
wxFileSelectorDefaultWildcardStr, wxstrWalletPath,
wxFileSelectorDefaultWildcardStr wxstrWalletName,
), wxString::Format
wxFD_SAVE | wxFD_OVERWRITE_PROMPT ("wallet (*.wallet)|*.wallet|All (%s)|%s",
); wxFileSelectorDefaultWildcardStr,
dialog.SetFilterIndex(m_FileDialogFilterIndex); wxFileSelectorDefaultWildcardStr
if (dialog.ShowModal() == wxID_OK) ),
{ wxFD_SAVE | wxFD_OVERWRITE_PROMPT
wxLogMessage("%s, filter %d",
dialog.GetPath(),
dialog.GetFilterIndex()
); );
wxFileName wxFileWallet(dialog.GetPath()); dialog.SetFilterIndex(m_FileDialogFilterIndex);
ristretto255::hash<256> WalletSecret( wxFileWallet.GetFullPath().ToUTF8()); if (dialog.ShowModal() == wxID_OK)
{
wxLogMessage("%s, filter %d",
dialog.GetPath(),
dialog.GetFilterIndex()
);
wxFileWallet.Assign(dialog.GetPath());
m_FileDialogFilterIndex = dialog.GetFilterIndex();
}
}
else {
// Default does not exist, so we go right
// ahead without asking the user to invent
// a name and select a directory
RecursiveCreateDirectory(m_DefaultWalletLocation);
wxFileWallet = m_DefaultWalletLocation;
}
if (wxFileWallet.IsOk()) {
ristretto255::hash<256> WalletSecret(wxFileWallet.GetFullPath().ToUTF8());
NewWallet(wxFileWallet, WalletSecret); NewWallet(wxFileWallet, WalletSecret);
wxLogMessage("new wallet created: %s", wxFileWallet.GetFullPath()); wxLogMessage("new wallet created: %s", wxFileWallet.GetFullPath());
if (m_panel)m_panel->Close(true); if (m_panel)m_panel->Close(true);
m_panel = nullptr; m_panel = nullptr;
auto panel = new display_wallet(this, wxFileWallet); auto panel = new display_wallet(this, wxFileWallet);
m_panel = panel; m_panel = panel;
m_FileDialogFilterIndex = dialog.GetFilterIndex();
m_LastUsedWallet = wxFileWallet; //We do this last, so that if an exception occurs the filename is forgotten. m_LastUsedWallet = wxFileWallet; //We do this last, so that if an exception occurs the filename is forgotten.
} }
} }