diff --git a/Source/build.cpp b/Source/build.cpp index 9c282057..ebb1f018 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -475,25 +475,6 @@ definedlist.add("NSIS_SUPPORT_LANG_IN_STRINGS"); m_ShellConstants.add("CDBURN_AREA", CSIDL_CDBURN_AREA, CSIDL_CDBURN_AREA); } -namespace { -string get_executable_path(const char* argv0) { -#ifdef _WIN32 - char temp_buf[1024]; - temp_buf[0] = '\0'; - int rc = GetModuleFileName(NULL,temp_buf,1024); - assert(rc != 0); - return string(temp_buf); -#else - return get_full_path(argv0); -#endif -} - -string get_executable_dir(const char *argv0) { - return get_dir_name(get_executable_path(argv0)); -} - -} // end anonymous namespace - void CEXEBuild::setdirs(const char *argv0) { string nsis_dir = get_executable_dir(argv0); diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp index 318e15fb..cd7fce70 100644 --- a/Source/makenssi.cpp +++ b/Source/makenssi.cpp @@ -41,11 +41,13 @@ const char *NSIS_VERSION="v2.03"; #else # include #endif +#include #include "build.h" #include "util.h" #include "exedata.h" +using namespace std; int g_noconfig=0; int g_display_errors=1; @@ -278,15 +280,8 @@ int main(int argc, char **argv) if (!g_noconfig) { g_noconfig=1; - char exepath[1024]; - strncpy(exepath,argv[0],sizeof(exepath)-1); - exepath[1023]=0; - char *p=exepath; - while (*p) p++; - while (p > exepath && *p != PLATFORM_PATH_SEPARATOR_C) p=CharPrev(exepath,p); - if (p>exepath) p++; - strcpy(p,"nsisconf.nsh"); - FILE *cfg=fopen(exepath,"rt"); + string nsisconf=get_executable_dir(argv[0])+PLATFORM_PATH_SEPARATOR_STR+"nsisconf.nsh"; + FILE *cfg=fopen(nsisconf.c_str(),"rt"); if (cfg) { if (build.display_script) @@ -294,7 +289,7 @@ int main(int argc, char **argv) fprintf(g_output,"Processing config: \n"); fflush(g_output); } - int ret=build.process_script(cfg,exepath); + int ret=build.process_script(cfg,(char*)nsisconf.c_str()); fclose(cfg); if (ret != PS_OK && ret != PS_EOF) { diff --git a/Source/util.cpp b/Source/util.cpp index e912a85a..643c9e12 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -536,3 +536,19 @@ string get_file_name(const string& path) { return path; return path.substr(last_separator_pos + 1, string::npos); } + +string get_executable_path(const char* argv0) { +#ifdef _WIN32 + char temp_buf[1024]; + temp_buf[0] = '\0'; + int rc = GetModuleFileName(NULL,temp_buf,1024); + assert(rc != 0); + return string(temp_buf); +#else + return get_full_path(argv0); +#endif +} + +string get_executable_dir(const char *argv0) { + return get_dir_name(get_executable_path(argv0)); +} diff --git a/Source/util.h b/Source/util.h index 0fe8464b..d0b513a7 100644 --- a/Source/util.h +++ b/Source/util.h @@ -49,6 +49,7 @@ size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm); std::string get_full_path(const std::string &path); std::string get_dir_name(const std::string& path); std::string get_file_name(const std::string& path); +std::string get_executable_dir(const char *argv0); #ifndef _WIN32 char *CharPrev(const char *s, const char *p);