diff --git a/Source/Platform.h b/Source/Platform.h index 783b38ed..486b2044 100644 --- a/Source/Platform.h +++ b/Source/Platform.h @@ -49,14 +49,20 @@ typedef unsigned long HBRUSH; typedef WORD LANGID; #endif -// system specific -#ifdef _WIN32 +// script path separator + # define PATH_SEPARATOR_STR "\\" # define PATH_SEPARATOR_C '\\' + +// system specific separator + +#ifdef _WIN32 +# define PLATFORM_PATH_SEPARATOR_STR "\\" +# define PLATFORM_PATH_SEPARATOR_C '\\' #else -# define PATH_SEPARATOR_STR "/" -# define PATH_SEPARATOR_C '/' +# define PLATFORM_PATH_SEPARATOR_STR "/" +# define PLATFORM_PATH_SEPARATOR_C '/' #endif // attributes diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp index a5df537a..10646e18 100644 --- a/Source/Plugins.cpp +++ b/Source/Plugins.cpp @@ -34,7 +34,7 @@ void Plugins::FindCommands(char* path, bool displayInfo) char* pathAndWildcard = new char [length+7]; strcpy(pathAndWildcard,basePath); - strcat(pathAndWildcard,PATH_SEPARATOR_STR "*.dll"); + strcat(pathAndWildcard,PLATFORM_PATH_SEPARATOR_STR "*.dll"); #ifdef _WIN32 WIN32_FIND_DATA data; @@ -59,7 +59,7 @@ void Plugins::FindCommands(char* path, bool displayInfo) #ifdef _WIN32 { char* dllPath = new char [length+strlen(data.cFileName)+2]; - wsprintf(dllPath,"%s" PATH_SEPARATOR_STR "%s",basePath,data.cFileName); + wsprintf(dllPath,"%s" PLATFORM_PATH_SEPARATOR_STR "%s",basePath,data.cFileName); #else char *dllPath = new char [strlen(globbuf.gl_pathv[i])+1]; strcpy(dllPath,globbuf.gl_pathv[i]); @@ -93,7 +93,7 @@ void Plugins::GetExports(char* pathToDll, bool displayInfo) char signature[1024]; dllName[0] = 0; - char* ptr = strrchr(pathToDll,PATH_SEPARATOR_C); + char* ptr = strrchr(pathToDll,PLATFORM_PATH_SEPARATOR_C); if (ptr && *ptr && *(ptr+1)) strcpy(dllName,ptr+1); // find .dll diff --git a/Source/build.cpp b/Source/build.cpp index 75621a5d..217d0195 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -478,7 +478,7 @@ definedlist.add("NSIS_SUPPORT_LANG_IN_STRINGS"); void CEXEBuild::setdirs(char *argv0) { char szNSISDir[NSIS_MAX_STRLEN*2],*fn2; - int len = sizeof(szNSISDir) - sizeof(PATH_SEPARATOR_STR "Include") - 1; + int len = sizeof(szNSISDir) - sizeof(PLATFORM_PATH_SEPARATOR_STR "Include") - 1; #ifdef _WIN32 GetModuleFileName(NULL,szNSISDir,len); #else @@ -487,10 +487,10 @@ void CEXEBuild::setdirs(char *argv0) szNSISDir[sizeof(szNSISDir)-1] = 0; my_free_realpath(argv0, buffer); #endif - fn2=strrchr(szNSISDir,PATH_SEPARATOR_C); + fn2=strrchr(szNSISDir,PLATFORM_PATH_SEPARATOR_C); if(fn2!=NULL) *fn2=0; definedlist.add("NSISDIR",(char*)szNSISDir); - strcat(szNSISDir, PATH_SEPARATOR_STR "Include"); + strcat(szNSISDir, PLATFORM_PATH_SEPARATOR_STR "Include"); include_dirs.add(szNSISDir,0); } @@ -2322,7 +2322,7 @@ int CEXEBuild::write_output(void) // Pack exe header if asked for if (build_packname[0] && build_packcmd[0]) { - FILE *tmpfile=fopen(build_packname,"wb"); + FILE *tmpfile=FOPEN(build_packname,"wb"); if (!tmpfile) { ERROR_MSG("Error: writing temporary file \"%s\" for pack\n",build_packname); @@ -2336,7 +2336,7 @@ int CEXEBuild::write_output(void) ERROR_MSG("Error: calling packer on \"%s\"\n",build_packname); return PS_ERROR; } - tmpfile=fopen(build_packname,"rb"); + tmpfile=FOPEN(build_packname,"rb"); if (!tmpfile) { remove(build_packname); @@ -2389,7 +2389,7 @@ int CEXEBuild::write_output(void) my_free_realpath(build_output_filename, buffer); #endif } - FILE *fp = fopen(build_output_filename,"w+b"); + FILE *fp = FOPEN(build_output_filename,"w+b"); if (!fp) { ERROR_MSG("Can't open output file\n"); @@ -2451,7 +2451,7 @@ int CEXEBuild::write_output(void) #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT if (build_compress_whole) { - int n; + int n; if (compressor == &lzma_compressor) n = ((CLZMA *) compressor)->Init(build_compress_level, build_compress_dict_size); else @@ -3176,8 +3176,8 @@ void CEXEBuild::build_plugin_table(void) char* searchPath = new char [strlen(nsisdir)+9]; if (searchPath) { - sprintf(searchPath,"%s" PATH_SEPARATOR_STR "Plugins",nsisdir); - INFO_MSG("Processing plugin dlls: \"%s" PATH_SEPARATOR_STR "*.dll\"\n",searchPath); + sprintf(searchPath,"%s" PLATFORM_PATH_SEPARATOR_STR "Plugins",nsisdir); + INFO_MSG("Processing plugin dlls: \"%s" PLATFORM_PATH_SEPARATOR_STR "*.dll\"\n",searchPath); m_plugins.FindCommands(searchPath,display_info?true:false); INFO_MSG("\n"); delete[] searchPath; diff --git a/Source/lang.cpp b/Source/lang.cpp index 2c87910b..39e60bbe 100644 --- a/Source/lang.cpp +++ b/Source/lang.cpp @@ -2,6 +2,7 @@ #include #include #include "build.h" +#include "util.h" #include "DialogTemplate.h" #include "exehead/resource.h" @@ -730,9 +731,9 @@ BOOL IsValidCodePage(UINT CodePage) // NSIS Language File parser LanguageTable * CEXEBuild::LoadLangFile(char *filename) { - FILE *f = fopen(filename, "r"); + FILE *f = FOPEN(filename, "r"); if (!f) { - ERROR_MSG("Error: Can't open language file!\n"); + ERROR_MSG("Error: Can't open language file - \"%s\"!\n",filename); return 0; } diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp index 207a6300..a24249dc 100644 --- a/Source/makenssi.cpp +++ b/Source/makenssi.cpp @@ -271,7 +271,7 @@ int main(int argc, char **argv) exepath[1023]=0; char *p=exepath; while (*p) p++; - while (p > exepath && *p != PATH_SEPARATOR_C) p=CharPrev(exepath,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"); @@ -336,10 +336,10 @@ int main(int argc, char **argv) p=CharPrev(dirbuf,p); #else getcwd(dirbuf,sizeof(dirbuf)-strlen(sfile)-2); - if (dirbuf[strlen(dirbuf)-1]!=PATH_SEPARATOR_C) - strcat(dirbuf,PATH_SEPARATOR_STR); + if (dirbuf[strlen(dirbuf)-1]!=PLATFORM_PATH_SEPARATOR_C) + strcat(dirbuf,PLATFORM_PATH_SEPARATOR_STR); strcat(dirbuf,sfile); - p=strrchr(dirbuf,PATH_SEPARATOR_C); + p=strrchr(dirbuf,PLATFORM_PATH_SEPARATOR_C); #endif if (!p) p=dirbuf; *p=0; diff --git a/Source/script.cpp b/Source/script.cpp index d216b575..a8b485c4 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -634,7 +634,7 @@ int CEXEBuild::parseScript() int CEXEBuild::includeScript(char *f) { SCRIPT_MSG("!include: \"%s\"\n",f); - FILE *incfp=fopen(f,"rt"); + FILE *incfp=FOPEN(f,"rt"); if (!incfp) { ERROR_MSG("!include: could not open file: \"%s\"\n",f); @@ -1335,7 +1335,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) FILE *fp; unsigned int datalen; - fp=fopen(file,"rb"); + fp=FOPEN(file,"rb"); if (!fp) { ERROR_MSG("LicenseLangString: open failed \"%s\"\n",file); @@ -1643,7 +1643,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!idx) { unsigned int datalen; - FILE *fp=fopen(file,"rb"); + FILE *fp=FOPEN(file,"rb"); if (!fp) { ERROR_MSG("LicenseData: open failed \"%s\"\n",file); @@ -2196,7 +2196,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int k=line.gettoken_enum(1, "all\0IDD_LICENSE\0IDD_DIR\0IDD_SELCOM\0IDD_INST\0IDD_INSTFILES\0IDD_UNINST\0IDD_VERIFY\0IDD_LICENSE_FSRB\0IDD_LICENSE_FSCB\0"); if (k<0) PRINTHELP(); - FILE *fui = fopen(line.gettoken_str(2), "rb"); + FILE *fui = FOPEN(line.gettoken_str(2), "rb"); if (!fui) { ERROR_MSG("Error: Can't open \"%s\"!\n", line.gettoken_str(2)); return PS_ERROR; @@ -2589,7 +2589,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int cmpv=line.gettoken_int(3,&success); if (!success && comp != 4) PRINTHELP() SCRIPT_MSG("!system: \"%s\"\n",exec); +#ifdef _WIN32 int ret=system(exec); +#else + char *execfixed = my_convert(exec); + int ret=system(execfixed); + my_convert_free(execfixed); +#endif if (comp == 0 && ret < cmpv); else if (comp == 1 && ret > cmpv); else if (comp == 2 && ret != cmpv); @@ -2616,7 +2622,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) CloseHandle(pi.hProcess); } #else - system(exec); + char *execfixed = my_convert(exec); + system(execfixed); + my_convert_free(execfixed); #endif SCRIPT_MSG("!execute: \"%s\"\n",exec); } @@ -2652,7 +2660,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) char *incfile = (char *) malloc(malloced); strcpy(incfile, f); glob_t globbuf; - if (!glob(incfile, GLOB_NOSORT, NULL, &globbuf)) + if (!GLOB(incfile, GLOB_NOSORT, NULL, &globbuf)) { for (unsigned int i = 0; i < globbuf.gl_pathc; i++) { @@ -2700,7 +2708,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (includeScript(incfile) != PS_OK) #else - if (!glob(incfile, GLOB_NOSORT, NULL, &globbuf)) + if (!GLOB(incfile, GLOB_NOSORT, NULL, &globbuf)) { for (unsigned int i = 0; i < globbuf.gl_pathc; i++) { @@ -4021,7 +4029,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!*on||line.getnumtokens()!=a+1||strstr(on,"*") || strstr(on,"?")) PRINTHELP() int tf=0; +#ifdef _WIN32 int v=do_add_file(line.gettoken_str(a), attrib, 0, linecnt,&tf,on); +#else + char *fn = my_convert(line.gettoken_str(a)); + int v=do_add_file(fn, attrib, 0, linecnt,&tf,on); + my_convert_free(fn); +#endif if (v != PS_OK) return v; if (tf > 1) PRINTHELP() if (!tf) @@ -4039,11 +4053,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_OK; } +#ifdef _WIN32 else if (line.gettoken_str(a)[0] == '/') PRINTHELP() +#endif if (line.getnumtokens() dir && *s != PATH_SEPARATOR_C) s=CharPrev(dir,s); + while (s > dir && *s != PLATFORM_PATH_SEPARATOR_C) s=CharPrev(dir,s); if (s == dir) { - if (*s == PATH_SEPARATOR_C) - sprintf(dir,"%c.",PATH_SEPARATOR_C); + if (*s == PLATFORM_PATH_SEPARATOR_C) + sprintf(dir,"%c.",PLATFORM_PATH_SEPARATOR_C); else strcpy(dir,"."); } @@ -5512,14 +5545,14 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn if ((d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { #else - glob(lgss, GLOB_NOSORT, NULL, &globbuf); + GLOB(lgss, GLOB_NOSORT, NULL, &globbuf); { for (unsigned int i = 0; i < globbuf.gl_pathc; i++) { struct stat s; if (!stat(globbuf.gl_pathv[i], &s) && S_ISREG(s.st_mode)) { - char *filename = strrchr(globbuf.gl_pathv[i], PATH_SEPARATOR_C); + char *filename = strrchr(globbuf.gl_pathv[i], PLATFORM_PATH_SEPARATOR_C); if (filename) filename++; else @@ -5532,7 +5565,7 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn #ifdef _WIN32 HANDLE hFile; - sprintf(newfn,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",d.cFileName); + sprintf(newfn,"%s%s%s",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:"",d.cFileName); hFile = CreateFile( newfn, GENERIC_READ, @@ -5559,10 +5592,10 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn #else int fd; - sprintf(newfn,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",filename); + sprintf(newfn,"%s%s%s",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:"",filename); len = (DWORD) s.st_size; - fd = open(newfn, O_RDONLY); + fd = OPEN(newfn, O_RDONLY); if (fd == -1) { globfree(&globbuf); @@ -5792,7 +5825,7 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn if (a==INVALID_FILE_ATTRIBUTES) { a=GetFileAttributes(dir); - sprintf(newfn,"%s%s*.*",dir,dir[0]?PATH_SEPARATOR_STR:""); + sprintf(newfn,"%s%s*.*",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:""); } #else int a; @@ -5800,7 +5833,7 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn if (stat(lgss, &st)) { stat(dir, &st); - sprintf(newfn,"%s%s*",dir,dir[0]?PATH_SEPARATOR_STR:""); + sprintf(newfn,"%s%s*",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:""); } #endif else @@ -5828,14 +5861,14 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn #else if (S_ISDIR(st.st_mode)) { - if (!glob(newfn, GLOB_NOSORT, NULL, &globbuf)) + if (!GLOB(newfn, GLOB_NOSORT, NULL, &globbuf)) { for (unsigned int i = 0; i < globbuf.gl_pathc; i++) { struct stat s; if (!stat(globbuf.gl_pathv[i], &s) && S_ISDIR(s.st_mode)) { - char *dirname = strrchr(globbuf.gl_pathv[i], PATH_SEPARATOR_C); + char *dirname = strrchr(globbuf.gl_pathv[i], PLATFORM_PATH_SEPARATOR_C); if (dirname) dirname++; else @@ -5876,12 +5909,12 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn char spec[1024]; #ifdef _WIN32 - wsprintf(spec,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",d.cFileName); + wsprintf(spec,"%s%s%s",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:"",d.cFileName); #else - wsprintf(spec,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",dirname); + wsprintf(spec,"%s%s%s",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:"",dirname); #endif SCRIPT_MSG("%sFile: Descending to: \"%s\"\n",generatecode?"":"Reserve",spec); - strcat(spec,PATH_SEPARATOR_STR); + strcat(spec,PLATFORM_PATH_SEPARATOR_STR); strcat(spec,fspec); if (generatecode) { @@ -5914,7 +5947,7 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn FindClose(htemp); #else glob_t globbuf2; - glob(spec, GLOB_NOSORT, NULL, &globbuf2); + GLOB(spec, GLOB_NOSORT, NULL, &globbuf2); if (globbuf2.gl_pathc) { #endif diff --git a/Source/util.cpp b/Source/util.cpp index 46dae61e..d8fbee46 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -2,11 +2,16 @@ #include #include #include +#include #include "exedata.h" #include "exehead/fileform.h" #include "util.h" #include "strlist.h" +#ifndef _WIN32 +# include +#endif + int g_dopause=0; extern int g_display_errors; extern FILE *g_output; @@ -28,7 +33,7 @@ void dopause(void) // Returns -3 if the size doesn't match // Returns -4 if the bpp doesn't match int update_bitmap(CResourceEditor* re, WORD id, char* filename, int width/*=0*/, int height/*=0*/, int maxbpp/*=0*/) { - FILE *f = fopen(filename, "rb"); + FILE *f = FOPEN(filename, "rb"); if (!f) return -1; if (fgetc(f) != 'B' || fgetc(f) != 'M') { @@ -128,7 +133,7 @@ typedef struct { // -1 - Bad icon file int replace_icon(CResourceEditor* re, WORD wIconId, char* filename) { - FILE* f = fopen(filename, "rb"); + FILE* f = FOPEN(filename, "rb"); if (!f) return -1; IconGroupHeader igh; @@ -204,7 +209,7 @@ unsigned char* generate_uninstall_icon_data(char* filename) { int i; - FILE* f = fopen(filename, "rb"); + FILE* f = FOPEN(filename, "rb"); if (!f) return 0; IconGroupHeader igh; @@ -379,7 +384,7 @@ char *CharPrev(const char *s, const char *p) { char *CharNext(const char *s) { int l = 0; if (s && *s) - l = max(1, mblen(s, strlen(s))); + l = max(1, mblen(s, MB_CUR_MAX)); return (char *) s + l; } @@ -416,7 +421,76 @@ void my_free_realpath(char *path, char *buffer) #endif } +#define MY_ERROR_MSG(x) {if (g_display_errors) {fprintf(g_output,"%s", x);}} +char *my_convert(const char *path) +{ + char *converted_path = strdup(path); + size_t len = strlen(path); + + if(!converted_path) + { + MY_ERROR_MSG("Error: could not allocate memory in my_convert()\n"); + return (char*) path; /* dirty */ + } + + /* Replace drive letter X: by /X */ + if(len >= 2) + { + if (path[1] == ':') + { + converted_path[0] = '/'; + converted_path[1] = (char) tolower((int) path[0]); + } + } + + char *p = converted_path; + + do + { + if (*p == '\\') + { + *p = '/'; + } + p = CharNext(p); + } + while (*p); + + return converted_path; +} + +void my_convert_free(char *converted_path) +{ + free(converted_path); +} + +int my_open(const char *pathname, int flags) +{ + char *converted_pathname = my_convert(pathname); + + int result = open(converted_pathname, flags); + my_convert_free(converted_pathname); + return result; +} + +FILE *my_fopen(const char *path, const char *mode) +{ + char *converted_path = my_convert(path); + + FILE *result = fopen(converted_path, mode); + my_convert_free(converted_path); + return result; +} + +int my_glob(const char *pattern, int flags, + int errfunc(const char * epath, int eerrno), glob_t *pglob) +{ + char *converted_pattern = my_convert(pattern); + + int result = glob(converted_pattern, flags, errfunc, pglob); + my_convert_free(converted_pattern); + return result; +} #endif void *operator new(size_t size) { diff --git a/Source/util.h b/Source/util.h index 6cc136a6..970345c3 100644 --- a/Source/util.h +++ b/Source/util.h @@ -3,6 +3,8 @@ #ifndef _WIN32 # include +# include +# include #endif #include "ResourceEditor.h" @@ -44,6 +46,23 @@ inline size_t __iconv_adaptor { return iconv_func (cd, (T)inbuf, inbytesleft, outbuf, outbytesleft); } + +char *my_convert(const char *path); +void my_convert_free(char *converted_path); +int my_open(const char *pathname, int flags); +FILE *my_fopen(const char *path, const char *mode); +int my_glob(const char *pattern, int flags, + int errfunc(const char * epath, int eerrno), glob_t *pglob); + +#define FOPEN(a, b) my_fopen(a, b) +#define GLOB(a, b, c, d) my_glob(a, b, c, d) +#define OPEN(a, b) my_open(a, b) + +#else + +#define FOPEN(a, b) fopen(a, b) +#define GLOB(a, b, c, d) glob(a, b, c, d) +#define OPEN(a, b) open(a, b) #endif #endif //_UTIL_H_