1 /* NetHack 3.6 winnt.c $NHDT-Date: 1431737068 2015/05/16 00:44:28 $ $NHDT-Branch: master $:$NHDT-Revision: 1.26 $ */
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
24 * The following WIN32 API routines are used in this file.
27 * GetVolumeInformation
35 /* globals required within here */
36 HANDLE ffhandle = (HANDLE) 0;
39 /* The function pointer nt_kbhit contains a kbhit() equivalent
40 * which varies depending on which window port is active.
41 * For the tty port it is tty_kbhit() [from nttty.c]
42 * For the win32 port it is win32_kbhit() [from winmain.c]
43 * It is initialized to point to def_kbhit [in here] for safety.
47 int (*nt_kbhit)() = def_kbhit;
52 /* Could not locate a WIN32 API call for this- MJA */
61 DWORD SectorsPerCluster = 0;
62 DWORD BytesPerSector = 0;
63 DWORD FreeClusters = 0;
64 DWORD TotalClusters = 0;
70 GetDiskFreeSpace(tmppath, &SectorsPerCluster, &BytesPerSector,
71 &FreeClusters, &TotalClusters);
72 return (long) (SectorsPerCluster * BytesPerSector * FreeClusters);
76 * Functions to get filenames using wildcards
84 ffhandle = (HANDLE) 0;
86 ffhandle = FindFirstFile(path, &ffd);
87 return (ffhandle == INVALID_HANDLE_VALUE) ? 0 : 1;
93 return FindNextFile(ffhandle, &ffd) ? 1 : 0;
99 return &ffd.cFileName[0];
106 if (findfirst(file)) {
107 return ((long) ffd.nFileSizeLow);
113 * Chdrive() changes the default drive.
121 if ((ptr = index(str, ':')) != (char *) 0) {
122 drive = toupper(*(ptr - 1));
123 _chdrive((drive - 'A') + 1);
133 status = GetVolumeInformation((LPTSTR) 0, (LPTSTR) 0, 0, (LPDWORD) 0,
134 &maxflen, (LPDWORD) 0, (LPTSTR) 0, 0);
148 * Strip out troublesome file system characters.
151 void nt_regularize(s) /* normalize file name */
154 register unsigned char *lp;
156 for (lp = s; *lp; lp++)
157 if (*lp == '?' || *lp == '"' || *lp == '\\' || *lp == '/'
158 || *lp == '>' || *lp == '<' || *lp == '*' || *lp == '|'
160 || *lp == ':' || (*lp > 127))
167 * This is used in nhlan.c to implement some of the LAN_FEATURES.
170 get_username(lan_username_size)
171 int *lan_username_size;
173 static TCHAR username_buffer[BUFSZ];
177 /* i gets updated with actual size */
178 status = GetUserName(username_buffer, &i);
180 username_buffer[i] = '\0';
182 Strcpy(username_buffer, "NetHack");
183 if (lan_username_size)
184 *lan_username_size = strlen(username_buffer);
185 return username_buffer;
191 char szFullPath[MAX_PATH] = "";
192 HMODULE hInst = NULL; /* NULL gets the filename of this module */
194 GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
195 return &szFullPath[0];
202 VA_DECL(const char *, s)
206 VA_INIT(s, const char *);
207 /* error() may get called before tty is initialized */
208 if (iflags.window_inited)
210 if (!strncmpi(windowprocs.name, "tty", 3)) {
212 (void) vsprintf(&buf[1], s, VA_ARGS);
216 (void) vsprintf(buf, s, VA_ARGS);
230 extern void NDECL(backsp);
238 if (!iflags.window_inited)
241 msmsg("Execute debug breakpoint wizard?");
242 while ((ci = nhgetch()) != '\n') {
244 backsp(); /* \b is visible on NT */
250 if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') {
262 static char interjection_buf[INTERJECTION_TYPES][1024];
263 static int interjection[INTERJECTION_TYPES];
266 interject_assistance(num, interjection_type, ptr1, ptr2)
268 int interjection_type;
274 char *panicmsg = (char *) ptr1;
275 char *datadir = (char *) ptr2;
276 char *tempdir = nh_getenv("TEMP");
277 interjection_type = INTERJECT_PANIC;
278 interjection[INTERJECT_PANIC] = 1;
280 * ptr1 = the panic message about to be delivered.
281 * ptr2 = the directory prefix of the dungeon file
282 * that failed to open.
283 * Check to see if datadir matches tempdir or a
284 * common windows temp location. If it does, inform
285 * the user that they are probably trying to run the
286 * game from within their unzip utility, so the required
287 * files really don't exist at the location. Instruct
288 * them to unpack them first.
290 if (panicmsg && datadir) {
291 if (!strncmpi(datadir, "C:\\WINDOWS\\TEMP", 15)
292 || strstri(datadir, "TEMP")
293 || (tempdir && strstri(datadir, tempdir))) {
295 interjection_buf[INTERJECT_PANIC],
296 "\nOne common cause of this error is attempting to "
298 "the game by double-clicking on it while it is "
300 "inside an unzip utility.\n\n"
301 "You have to unzip the contents of the zip file into a\n"
302 "folder on your system, and then run \"NetHack.exe\" or "
304 "\"NetHackW.exe\" from there.\n\n"
305 "If that is not the situation, you are encouraged to\n"
306 "report the error as shown above.\n\n",
315 interject(interjection_type)
316 int interjection_type;
318 if (interjection_type >= 0 && interjection_type < INTERJECTION_TYPES)
319 msmsg(interjection_buf[interjection_type]);
322 #ifdef RUNTIME_PORT_ID
324 * _M_IX86 is Defined for x86 processors. This is not defined for x64
326 * _M_X64 is Defined for x64 processors.
327 * _M_IA64 is Defined for Itanium Processor Family 64-bit processors.
328 * _WIN64 is Defined for applications for Win64.
332 #define TARGET_PORT "(x64) "
335 #define TARGET_PORT "(IA64) "
340 #define TARGET_PORT "(x86) "
347 char *portstr = TARGET_PORT;
348 Sprintf(eos(buf), " %s", portstr);
350 #endif /* RUNTIME_PORT_ID */