From: <ma...@us...> - 2003-11-21 10:26:11
|
Update of /cvsroot/sharedaemon/ui-wx/src In directory sc8-pr-cvs1:/tmp/cvs-serv27352 Modified Files: Images.cpp wxInterface.cpp Log Message: Fixes resources dir access if CurrentPath != ApplicationPath Index: Images.cpp =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/Images.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- Images.cpp 20 Nov 2003 01:27:26 -0000 1.12 +++ Images.cpp 21 Nov 2003 10:26:08 -0000 1.13 @@ -35,38 +35,34 @@ } /** - * This method converts the paths we need to platform-dependant version. - * Under wxMac, the separator is :, and relative paths must be prepended - * by :. Also, for release builds, we add ::Resources, as it is standard - * under wxMac to have resources there - packager must compile with - * -D__RELEASE__ and ensure the images are there. - */ -wxString CImages::MakePath(wxString path) { - #if defined(__WXMAC__) && !defined(__MACH__) - path.Replace(wxT("/"), wxT(":")); - path.Prepend(wxT(":")); - path.Prepend(wxT("::Resources")); - #endif - return path; -} - -/** * This method loads all images into the global variables. */ void CImages::LoadImages() { - wxString path; + wxString path, apppath; + + /** + * We get the application binary path from argv[0], remove the binary + * name from it, and use it as base for our resources. Needed if + * application startup path != application binary path, which would + * prevent us from accessing resources. + */ + apppath = wxTheApp->argv[0]; + while (apppath.Last() != *wxT("/")) { + apppath.RemoveLast(); + } m_config->Read( wxT("/General/IconSets/CurIconSet"), &path, wxT("Default") ); path.MakeLower(); - path = wxString::Format(wxT("images/%s/"), path.c_str()); + path = wxString::Format( + wxT("%s/images/%s/"), apppath.c_str(), path.c_str() + ); /* * Under wxMac, the separator is :, and relative paths must be prepended - * by :. Also, for release builds, we add ::Resources, as it is standard - * under wxMac to have resources there - packager must compile with - * -D__RELEASE__ and ensure the images are there. + * by :. We also prepend the path by ::Resources, as it is standard + * under wxMac to have resources there. */ #if defined(__WXMAC__) && !defined(__MACH__) path.Replace(wxT("/"), wxT(":")); Index: wxInterface.cpp =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/wxInterface.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- wxInterface.cpp 20 Nov 2003 01:27:26 -0000 1.1 +++ wxInterface.cpp 21 Nov 2003 10:26:08 -0000 1.2 @@ -50,7 +50,7 @@ SetVendorName(wxT("ShareDaemon")); SetAppName(wxT("wxInterface")); - + ::wxInitAllImageHandlers(); m_config = wxConfigBase::Get(); @@ -87,16 +87,16 @@ } /* - * Main program shutdown function. If anything needs to be cleaned up, do it + * Main program shutdown function. If anything needs to be cleaned up, do it * here. */ int wxInterface::OnExit() { /* Save configuration object to disk */ delete m_config->Set(NULL); - + /* Delete images class (it doesn't get automatically deleted by wx */ delete img; - + /* Return true :) */ return 0; } @@ -108,12 +108,23 @@ * language from config object, and add the catalog. */ void wxInterface::Localize() { - wxString curlang; + wxString curlang, path; + + /** + * Get application binary path from argv[0] and remove the binary file- + * name from it, leaving only the actual path to us. Needed if current + * path differs from application path, thus preventing us from accessing + * resources. + */ + path = wxTheApp->argv[0]; + while (path.Last() != *wxT("/")) { + path.RemoveLast(); + } CheckAndAddSupportedLangs(); /* Set localization files directories */ - m_locale.AddCatalogLookupPathPrefix(wxT("lang/")); + m_locale.AddCatalogLookupPathPrefix(path+wxT("/lang/")); #if defined(__WXMAC__) && !defined(__MACH__) m_locale.AddCatalogLookupPathPrefix(wxT("::Resources:lang")); #endif |