From 90bddb8566eed2a2b16de533a655d1c04d9a584f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 25 Jul 2004 12:54:15 +0000 Subject: [PATCH] check better before overwriting files (patch 951868) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28465 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/filedlg.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index de26b29ef6..1e3eba9bf2 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -264,6 +264,30 @@ int wxFileDialog::ShowModal() of.lpstrFile = fileNameBuffer; // holds returned filename of.nMaxFile = wxMAXPATH; + // we must set the default extension because otherwise Windows would check + // for the existing of a wrong file with wxOVERWRITE_PROMPT (i.e. if the + // user types "foo" and the default extension is ".bar" we should force it + // to check for "foo.bar" existence and not "foo") + wxString defextBuffer; // we need it to be alive until GetSaveFileName()! + if (m_dialogStyle & wxSAVE) + { + const wxChar* extension = filterBuffer; + int maxFilter = (int)(of.nFilterIndex*2L) - 1; + + for( int i = 0; i < maxFilter; i++ ) // get extension + extension = extension + wxStrlen( extension ) + 1; + + // use dummy name a to avoid assert in AppendExtension + defextBuffer = AppendExtension(wxT("a"), extension); + if (defextBuffer.StartsWith(wxT("a."))) + { + defextBuffer.Mid(2); + of.lpstrDefExt = defextBuffer.c_str(); + } + } + + //== Execute FileDialog >>================================================= + //== Execute FileDialog >>================================================= bool success = (m_dialogStyle & wxSAVE ? GetSaveFileName(&of) -- 2.45.2