1 /* SCCS Id: @(#)winnt.c 3.4 $Date: 2003/10/26 15:58:22 $ */
2 /* Copyright (c) NetHack PC Development Team 1993, 1994 */
3 /* NetHack may be freely redistributed. See license for details. */
6 * WIN32 system functions.
8 * Initial Creation: Michael Allison - January 31/93
27 * The following WIN32 API routines are used in this file.
30 * GetVolumeInformation
39 /* globals required within here */
40 HANDLE ffhandle = (HANDLE)0;
43 /* The function pointer nt_kbhit contains a kbhit() equivalent
44 * which varies depending on which window port is active.
45 * For the tty port it is tty_kbhit() [from nttty.c]
46 * For the win32 port it is win32_kbhit() [from winmain.c]
47 * It is initialized to point to def_kbhit [in here] for safety.
51 int (*nt_kbhit)() = def_kbhit;
56 /* Could not locate a WIN32 API call for this- MJA */
65 DWORD SectorsPerCluster = 0;
66 DWORD BytesPerSector = 0;
67 DWORD FreeClusters = 0;
68 DWORD TotalClusters = 0;
74 GetDiskFreeSpace(tmppath, &SectorsPerCluster,
78 return (long)(SectorsPerCluster * BytesPerSector *
83 * Functions to get filenames using wildcards
93 ffhandle = FindFirstFile(path,&ffd);
95 (ffhandle == INVALID_HANDLE_VALUE) ? 0 : 1;
101 return FindNextFile(ffhandle,&ffd) ? 1 : 0;
107 return &ffd.cFileName[0];
114 if (findfirst(file)) {
115 return ((long)ffd.nFileSizeLow);
121 * Chdrive() changes the default drive.
129 if ((ptr = index(str, ':')) != (char *)0)
131 drive = toupper(*(ptr - 1));
132 _chdrive((drive - 'A') + 1);
142 status = GetVolumeInformation((LPTSTR)0,(LPTSTR)0, 0
143 ,(LPDWORD)0,&maxflen,(LPDWORD)0,(LPTSTR)0,0);
144 if (status) return maxflen;
155 * Strip out troublesome file system characters.
159 nt_regularize(s) /* normalize file name */
162 register unsigned char *lp;
164 for (lp = s; *lp; lp++)
165 if ( *lp == '?' || *lp == '"' || *lp == '\\' ||
166 *lp == '/' || *lp == '>' || *lp == '<' ||
167 *lp == '*' || *lp == '|' || *lp == ':' || (*lp > 127))
172 * This is used in nhlan.c to implement some of the LAN_FEATURES.
174 char *get_username(lan_username_size)
175 int *lan_username_size;
177 static TCHAR username_buffer[BUFSZ];
181 /* i gets updated with actual size */
182 status = GetUserName(username_buffer, &i);
183 if (status) username_buffer[i] = '\0';
184 else Strcpy(username_buffer, "NetHack");
185 if (lan_username_size) *lan_username_size = strlen(username_buffer);
186 return username_buffer;
192 char szFullPath[MAX_PATH] = "";
193 HMODULE hInst = NULL; /* NULL gets the filename of this module */
195 GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
196 return &szFullPath[0];
204 error VA_DECL(const char *,s)
207 VA_INIT(s, const char *);
208 /* error() may get called before tty is initialized */
209 if (iflags.window_inited) end_screen();
210 if (!strncmpi(windowprocs.name, "tty", 3)) {
212 (void) vsprintf(&buf[1], s, VA_ARGS);
216 (void) vsprintf(buf, s, VA_ARGS);
231 extern void NDECL(backsp);
241 if (!iflags.window_inited)
244 msmsg("Execute debug breakpoint wizard?");
245 while ((ci=nhgetch()) != '\n') {
247 backsp(); /* \b is visible on NT */
253 if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') {
267 static char interjection_buf[INTERJECTION_TYPES][1024];
268 static int interjection[INTERJECTION_TYPES];
271 interject_assistance(num, interjection_type, ptr1, ptr2)
273 int interjection_type;
279 char *panicmsg = (char *)ptr1;
280 char *datadir = (char *)ptr2;
281 char *tempdir = nh_getenv("TEMP");
282 interjection_type = INTERJECT_PANIC;
283 interjection[INTERJECT_PANIC] = 1;
285 * ptr1 = the panic message about to be delivered.
286 * ptr2 = the directory prefix of the dungeon file
287 * that failed to open.
288 * Check to see if datadir matches tempdir or a
289 * common windows temp location. If it does, inform
290 * the user that they are probably trying to run the
291 * game from within their unzip utility, so the required
292 * files really don't exist at the location. Instruct
293 * them to unpack them first.
295 if (panicmsg && datadir) {
296 if (!strncmpi(datadir, "C:\\WINDOWS\\TEMP", 15) ||
297 strstri(datadir, "TEMP") ||
298 (tempdir && strstri(datadir, tempdir))) {
299 (void)strncpy(interjection_buf[INTERJECT_PANIC],
300 "\nOne common cause of this error is attempting to execute\n"
301 "the game by double-clicking on it while it is displayed\n"
302 "inside an unzip utility.\n\n"
303 "You have to unzip the contents of the zip file into a\n"
304 "folder on your system, and then run \"NetHack.exe\" or \n"
305 "\"NetHackW.exe\" from there.\n\n"
306 "If that is not the situation, you are encouraged to\n"
307 "report the error as shown above.\n\n", 1023);
316 interject(interjection_type)
317 int interjection_type;
319 if (interjection_type >= 0 && interjection_type < INTERJECTION_TYPES)
320 msmsg(interjection_buf[interjection_type]);