1
0
forked from cheng/wallet

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