From: <tm...@us...> - 2010-03-01 06:17:32
|
Revision: 5037 http://hugin.svn.sourceforge.net/hugin/?rev=5037&view=rev Author: tmodes Date: 2010-03-01 06:17:23 +0000 (Mon, 01 Mar 2010) Log Message: ----------- Warn user about invalid characters in filenames Modified Paths: -------------- hugin/trunk/src/hugin1/base_wx/platform.cpp hugin/trunk/src/hugin1/base_wx/platform.h hugin/trunk/src/hugin1/hugin/MainFrame.cpp hugin/trunk/src/hugin1/ptbatcher/BatchFrame.cpp hugin/trunk/src/hugin1/stitch_project/hugin_stitch_project.cpp Modified: hugin/trunk/src/hugin1/base_wx/platform.cpp =================================================================== --- hugin/trunk/src/hugin1/base_wx/platform.cpp 2010-03-01 06:15:14 UTC (rev 5036) +++ hugin/trunk/src/hugin1/base_wx/platform.cpp 2010-03-01 06:17:23 UTC (rev 5037) @@ -287,3 +287,27 @@ #endif // MAC_SELF_CONTAINED_BUNDLE #endif // __WXMAC__ + +const wxString getInvalidCharacters() +{ +#if defined __WXMSW__ + // the characters :"*?<>| are not allowed in filenames, these are handled well by the file dialog + // we need only to check for characters, which does not work with the makefiles + return wxT("=;%"); +#else + return wxT("=;:%"); +#endif +}; + +bool containsInvalidCharacters(const wxString stringToTest) +{ + if(stringToTest.IsEmpty()) + return false; + wxString forbiddenChars=getInvalidCharacters(); + for(unsigned int j=0;j<forbiddenChars.size();j++) + { + if(stringToTest.Find(forbiddenChars[j])!=wxNOT_FOUND) + return true; + }; + return false; +}; Modified: hugin/trunk/src/hugin1/base_wx/platform.h =================================================================== --- hugin/trunk/src/hugin1/base_wx/platform.h 2010-03-01 06:15:14 UTC (rev 5036) +++ hugin/trunk/src/hugin1/base_wx/platform.h 2010-03-01 06:17:23 UTC (rev 5037) @@ -59,4 +59,9 @@ #endif //__WXMAC__ +/** returns all invalid characters for the filename (mainly characters, which does not work with gnu make) */ +const wxString getInvalidCharacters(); +/** returns true, if the given strings contains invalid characters */ +bool containsInvalidCharacters(const wxString stringToTest); + #endif Modified: hugin/trunk/src/hugin1/hugin/MainFrame.cpp =================================================================== --- hugin/trunk/src/hugin1/hugin/MainFrame.cpp 2010-03-01 06:15:14 UTC (rev 5036) +++ hugin/trunk/src/hugin1/hugin/MainFrame.cpp 2010-03-01 06:17:23 UTC (rev 5037) @@ -824,20 +824,31 @@ // e safe the current path to config config->Write(wxT("/actualPath"), dlg.GetDirectory()); // remember for later - std::vector<std::string> filesv; - for (unsigned int i=0; i< Pathnames.GetCount(); i++) { - filesv.push_back((const char *)Pathnames[i].mb_str(HUGIN_CONV_FILENAME)); + bool foundForbiddenChars=false; + for(unsigned int i=0;i<Pathnames.GetCount(); i++) + foundForbiddenChars=foundForbiddenChars || containsInvalidCharacters(Pathnames[i]); + if(foundForbiddenChars) + { + wxMessageBox(wxString::Format(_("The filename(s) contains one of the following invalid characters: %s\nHugin can not work with these filenames. Please rename your file(s) and try again."),getInvalidCharacters().c_str()), + _("Error"),wxOK | wxICON_EXCLAMATION,this); } + else + { + std::vector<std::string> filesv; + for (unsigned int i=0; i< Pathnames.GetCount(); i++) { + filesv.push_back((const char *)Pathnames[i].mb_str(HUGIN_CONV_FILENAME)); + } - // we got some images to add. - if (filesv.size() > 0) { - // use a Command to ensure proper undo and updating of GUI - // parts - wxBusyCursor(); - GlobalCmdHist::getInstance().addCommand( - new wxAddImagesCmd(pano,filesv) - ); - } + // we got some images to add. + if (filesv.size() > 0) { + // use a Command to ensure proper undo and updating of GUI + // parts + wxBusyCursor(); + GlobalCmdHist::getInstance().addCommand( + new wxAddImagesCmd(pano,filesv) + ); + }; + }; DEBUG_INFO ( wxString::Format(wxT("img_ext: %d"), dlg.GetFilterIndex()).mb_str(wxConvLocal) ) // save the image extension switch ( dlg.GetFilterIndex() ) { Modified: hugin/trunk/src/hugin1/ptbatcher/BatchFrame.cpp =================================================================== --- hugin/trunk/src/hugin1/ptbatcher/BatchFrame.cpp 2010-03-01 06:15:14 UTC (rev 5036) +++ hugin/trunk/src/hugin1/ptbatcher/BatchFrame.cpp 2010-03-01 06:17:23 UTC (rev 5037) @@ -413,6 +413,13 @@ wxSAVE, wxDefaultPosition); if (dlg.ShowModal() == wxID_OK) { + while(containsInvalidCharacters(dlg.GetPath())) + { + wxMessageBox(wxString::Format(_("The given filename contains one of the following invalid characters: %s\nHugin can not work with this filename. Please enter a valid filename."),getInvalidCharacters().c_str()), + _("Error"),wxOK | wxICON_EXCLAMATION,this); + if(dlg.ShowModal()!=wxID_OK) + return; + }; wxString outname(dlg.GetPath()); ChangePrefix(selIndex,outname); //SetStatusText(_T("Changed prefix for "+projListBox->GetSelectedProject())); Modified: hugin/trunk/src/hugin1/stitch_project/hugin_stitch_project.cpp =================================================================== --- hugin/trunk/src/hugin1/stitch_project/hugin_stitch_project.cpp 2010-03-01 06:15:14 UTC (rev 5036) +++ hugin/trunk/src/hugin1/stitch_project/hugin_stitch_project.cpp 2010-03-01 06:17:23 UTC (rev 5037) @@ -374,6 +374,13 @@ wxSAVE, wxDefaultPosition); dlg.SetDirectory(wxConfigBase::Get()->Read(wxT("/actualPath"),wxT(""))); if (dlg.ShowModal() == wxID_OK) { + while(containsInvalidCharacters(dlg.GetPath())) + { + wxMessageBox(wxString::Format(_("The given filename contains one of the following invalid characters: %s\nHugin can not work with this filename. Please enter a valid filename."),getInvalidCharacters().c_str()), + _("Error"),wxOK | wxICON_EXCLAMATION); + if(dlg.ShowModal()!=wxID_OK) + return false; + }; wxConfig::Get()->Write(wxT("/actualPath"), dlg.GetDirectory()); // remember for later outname = dlg.GetPath(); } else { // bail This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |