From 3d805aa7c5057e0d5b0551a33a4f1cee4baecae4 Mon Sep 17 00:00:00 2001 From: Cheng Date: Sun, 29 Oct 2023 05:37:33 +0000 Subject: [PATCH] Fixed wallet to use the default wallet location if available, rather than asking for a location --- src/frame.cpp | 78 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/src/frame.cpp b/src/frame.cpp index fe9ea89..a712e29 100644 --- a/src/frame.cpp +++ b/src/frame.cpp @@ -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. } }