From: John L. <jr...@us...> - 2010-11-09 06:05:51
|
Update of /cvsroot/wxlua/wxLua/apps/wxluafreeze/src In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv31642/src Modified Files: wxluafreeze.cpp Log Message: Added Julian Smart's function to get full app path in any os when trying to run a frozen in script. Index: wxluafreeze.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxluafreeze/src/wxluafreeze.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** wxluafreeze.cpp 23 Jan 2008 06:43:34 -0000 1.17 --- wxluafreeze.cpp 9 Nov 2010 06:05:43 -0000 1.18 *************** *** 34,37 **** --- 34,40 ---- #include "wxlua/include/wxlstate.h" + // implemented below + wxFileName wxFindAppFullName(const wxString& argv0, const wxString& cwd, const wxString& appVariableName); + // Declare the binding initialization functions // Note : We could also do this "extern bool wxLuaBinding_XXX_init();" and *************** *** 96,100 **** // you want to use decimal points in. That's because the file has been lexed // and compiler before the locale has changed, so the lexer - the part that ! // recognises numbers - will use the old locale. setlocale(LC_NUMERIC, "C"); #endif --- 99,103 ---- // you want to use decimal points in. That's because the file has been lexed // and compiler before the locale has changed, so the lexer - the part that ! // recognizes numbers - will use the old locale. setlocale(LC_NUMERIC, "C"); #endif *************** *** 107,111 **** WXLUA_IMPLEMENT_BIND_ALL ! m_fileName = argv[0]; // the filename of 'this' program // When this function returns wxApp:MainLoop() will be called by wxWidgets --- 110,124 ---- WXLUA_IMPLEMENT_BIND_ALL ! // Find the full path this this executable ! wxFileName appFile = wxFindAppFullName(argv[0], wxGetCwd(), wxEmptyString); ! ! if (appFile.FileExists() == false) ! { ! m_fileName = argv[0]; // the filename of 'this' program ! //OutputPrint(wxString::Format(wxT("Unable to find the path for '%s'\n"), argv[0])); ! } ! else ! m_fileName = appFile.GetFullPath(); ! // When this function returns wxApp:MainLoop() will be called by wxWidgets *************** *** 118,122 **** return false; ! // if no script attached try to run a the program on the command line if (LoadScript(m_fileName, true) == LOADSCRIPT_MISSING) { --- 131,135 ---- return false; ! // if no script attached try to run the program on the command line if (LoadScript(m_fileName, true) == LOADSCRIPT_MISSING) { *************** *** 249,250 **** --- 262,320 ---- #endif // __WXMSW__ } + + // -------------------------------------------------------------------------- + // Find the absolute path where this application has been run from. (Julian Smart) + // argv0 is wxTheApp->argv[0] + // cwd is the current working directory (at startup) + // appVariableName is the name of a variable containing the directory for this app, e.g. + // MYAPPDIR. This is checked first. + // -------------------------------------------------------------------------- + + wxFileName wxFindAppFullName(const wxString& argv0, const wxString& cwd, const wxString& appVariableName) + { + wxFileName fileName(argv0); + wxString str; + wxString path; + + #if defined(__WXMSW__) + if (!fileName.HasExt()) + fileName.SetExt("exe"); + #endif + + // Try appVariableName + if (!appVariableName.IsEmpty()) + path = wxGetenv(appVariableName); + + #if defined(__WXMAC__) && !defined(__DARWIN__) + // On Mac, the current directory is the relevant one when + // the application starts. + if (path.IsEmpty()) + path = cwd; + #endif + + if (path.IsEmpty()) + { + if (wxIsAbsolutePath(fileName.GetFullPath())) + path = fileName.GetFullPath(); + else + { + // Is it a relative path? + wxString currentDir(cwd); + if (currentDir.Last() != wxFILE_SEP_PATH) + currentDir += wxFILE_SEP_PATH; + if (wxFileExists(currentDir + fileName.GetFullName())) + path = currentDir; + } + } + + if (path.IsEmpty()) + { + // OK, it's neither an absolute path nor a relative path. + // Search PATH. + wxPathList pathList; + pathList.AddEnvList(wxT("PATH")); + path = wxFileName(pathList.FindAbsoluteValidPath(fileName.GetFullName())).GetPath(); + } + fileName.SetPath(path); + return fileName; + } |