Skip to content

Commit

Permalink
- Setup tool for the Windows driver now works properly when invoked f…
Browse files Browse the repository at this point in the history
…rom command line
  • Loading branch information
sergm committed Aug 8, 2013
1 parent 36d706c commit 55f9d1d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mt32emu_win32drv_setup/mt32emu_win32drv_setup.cpp
Expand Up @@ -188,8 +188,9 @@ int main(int argc, char *argv[]) {
unregisterDriver();
return 0;
}
int setupPathLen = strrchr(argv[0], '\\') - argv[0];
if (setupPathLen > MAX_PATH - sizeof(MT32EMU_DRIVER_NAME) - 2) {
const char *pathDelimPosition = strrchr(argv[0], '\\');
int setupPathLen = pathDelimPosition - argv[0];
if (pathDelimPosition != NULL && setupPathLen > MAX_PATH - sizeof(MT32EMU_DRIVER_NAME) - 2) {
MessageBoxA(NULL, CANNOT_INSTALL_PATH_TOO_LONG_ERR, ERROR_TITLE, MB_OK | MB_ICONEXCLAMATION);
return 2;
}
Expand All @@ -201,8 +202,12 @@ int main(int argc, char *argv[]) {
constructDriverPathName(driverPathName);
deleteFileReliably(driverPathName);
char setupPathName[MAX_PATH + 1];
strncpy(setupPathName, argv[0], setupPathLen);
setupPathName[setupPathLen] = 0;
if (pathDelimPosition == NULL) {
GetCurrentDirectoryA(sizeof(setupPathName), setupPathName);
} else {
strncpy(setupPathName, argv[0], setupPathLen);
setupPathName[setupPathLen] = 0;
}
strncat(setupPathName, PATH_SEPARATOR, MAX_PATH - strlen(setupPathName));
strncat(setupPathName, MT32EMU_DRIVER_NAME, MAX_PATH - strlen(setupPathName));
if (!CopyFileA(setupPathName, driverPathName, FALSE)) {
Expand Down

0 comments on commit 55f9d1d

Please sign in to comment.