win32: hold .0 file open exclusively

-prevents problems with internal recover
if second copy of game is started up with
the same player name.
This commit is contained in:
nethack.allison
2002-08-21 15:21:56 +00:00
parent e86d1a4436
commit 2697615bd3
6 changed files with 107 additions and 59 deletions

View File

@@ -88,6 +88,9 @@ eraseoldlocks()
(void) unlink(fqname(lock, LEVELPREFIX, 0));
}
set_levelfile_name(lock, 0);
#ifdef HOLD_LOCKFILE_OPEN
really_close();
#endif
if(unlink(fqname(lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return(1); /* success! */
@@ -122,6 +125,15 @@ getlock()
chdirx(orgdir, 0);
# endif
# if defined(WIN32)
# if defined(HOLD_LOCKFILE_OPEN)
if(errno == EACCES) {
msmsg("\nThere are files from a game in progress under your name.");
msmsg(
"\nThe files are locked or inaccessible. Is the other game still running?");
unlock_file(HLOCK);
error("Cannot open %s", fq_lock);
} else
# endif
error("Bad directory or name: %s\n%s\n",
fq_lock, strerror(errno));
# else

View File

@@ -233,53 +233,6 @@ void win32_abort()
#endif
abort();
}
#if !defined(WIN_CE)
#include <tlhelp32.h>
boolean
is_NetHack_process(pid)
int pid;
{
HANDLE hProcessSnap = NULL;
PROCESSENTRY32 pe32 = {0};
boolean bRet = FALSE;
HINSTANCE hinstLib;
genericptr_t ProcTest;
BOOL fFreeResult;
hinstLib = LoadLibrary("KERNEL32");
if (hinstLib != NULL) {
ProcTest = (genericptr_t) GetProcAddress(hinstLib, "Process32Next");
if (!ProcTest) {
fFreeResult = FreeLibrary(hinstLib);
return FALSE;
}
fFreeResult = FreeLibrary(hinstLib);
}
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
return FALSE;
/* Set size of the processentry32 structure before using it. */
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hProcessSnap, &pe32)) {
do {
if (pe32.th32ProcessID == (unsigned)pid && pe32.szExeFile &&
((strlen(pe32.szExeFile) >= 12 &&
!strcmpi(&pe32.szExeFile[strlen(pe32.szExeFile) - 12], "nethackw.exe")) ||
(strlen(pe32.szExeFile) >= 11 &&
!strcmpi(&pe32.szExeFile[strlen(pe32.szExeFile) - 11], "nethack.exe"))))
bRet = TRUE;
}
while (Process32Next(hProcessSnap, &pe32));
}
else
bRet = FALSE;
CloseHandle(hProcessSnap);
return bRet;
}
#endif /* WIN_CE*/
#endif /* WIN32 */
/*winnt.c*/