Look in multiple paths when searching for resource files of samples

When using an out of source build, the files are not in the default wxWidgets directories.
Also search in the current directory, parent directory and sample sub-directories.

Closes https://trac.wxwidgets.org/ticket/18118
This commit is contained in:
Maarten Bent
2018-05-17 19:42:43 +02:00
parent de4e20ee93
commit e581b72955
5 changed files with 27 additions and 7 deletions

View File

@@ -413,7 +413,8 @@ bool MyApp::LoadImages()
pathList.Add(wxFileName(argv[0]).GetPath());
pathList.Add(wxT("."));
pathList.Add(wxT(".."));
pathList.Add(wxT("../.."));
pathList.Add(wxT("../drawing"));
pathList.Add(wxT("../../../samples/drawing"));
wxString path = pathList.FindValidPath(wxT("pat4.bmp"));
if ( !path )

View File

@@ -163,10 +163,16 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
help.UseConfig(wxConfig::Get());
bool ret;
help.SetTempDir(wxT("."));
ret = help.AddBook(wxFileName(wxT("helpfiles/testing.hhp"), wxPATH_UNIX));
wxPathList pathlist;
pathlist.Add(wxT("./helpfiles"));
pathlist.Add(wxT("../helpfiles"));
pathlist.Add(wxT("../../html/help/helpfiles"));
ret = help.AddBook(wxFileName(pathlist.FindValidPath(wxT("testing.hhp")), wxPATH_UNIX));
if (! ret)
wxMessageBox(wxT("Failed adding book helpfiles/testing.hhp"));
ret = help.AddBook(wxFileName(wxT("helpfiles/another.hhp"), wxPATH_UNIX));
ret = help.AddBook(wxFileName(pathlist.FindValidPath(wxT("another.hhp")), wxPATH_UNIX));
if (! ret)
wxMessageBox(_("Failed adding book helpfiles/another.hhp"));
}

View File

@@ -741,7 +741,13 @@ void WebFrame::OnMode(wxCommandEvent& WXUNUSED(evt))
void WebFrame::OnLoadScheme(wxCommandEvent& WXUNUSED(evt))
{
wxFileName helpfile("../help/doc.zip");
wxPathList pathlist;
pathlist.Add(wxT("."));
pathlist.Add(wxT(".."));
pathlist.Add(wxT("../help"));
pathlist.Add(wxT("../../../samples/help"));
wxFileName helpfile(pathlist.FindValidPath(wxT("doc.zip")));
helpfile.MakeAbsolute();
wxString path = helpfile.GetFullPath();
//Under MSW we need to flip the slashes

View File

@@ -90,7 +90,13 @@ void StatBmpWidgetsPage::CreateContent()
wxString testImage;
#if wxUSE_LIBPNG
wxFileName fn("../image/toucan.png");
wxPathList pathlist;
pathlist.Add(wxT("."));
pathlist.Add(wxT(".."));
pathlist.Add(wxT("../image"));
pathlist.Add(wxT("../../../samples/image"));
wxFileName fn(pathlist.FindValidPath(wxT("toucan.png")));
if ( fn.FileExists() )
testImage = fn.GetFullPath();
#endif // wxUSE_LIBPNG

View File

@@ -913,6 +913,7 @@ void TextWidgetsPage::OnButtonLoad(wxCommandEvent& WXUNUSED(event))
wxPathList pathlist;
pathlist.Add(wxT("."));
pathlist.Add(wxT(".."));
pathlist.Add(wxT("../widgets"));
pathlist.Add(wxT("../../../samples/widgets"));
wxString filename = pathlist.FindValidPath(wxT("textctrl.cpp"));