1 /* aNetHack 0.0.1 winnt.c $ANH-Date: 1431737068 2015/05/16 00:44:28 $ $ANH-Branch: master $:$ANH-Revision: 1.26 $ */
2 /* Copyright (c) aNetHack PC Development Team 1993, 1994 */
3 /* aNetHack 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((uchar
) *(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
== '|'
159 || *lp
== ':' || (*lp
> 127))
164 * This is used in nhlan.c to implement some of the LAN_FEATURES.
167 get_username(lan_username_size
)
168 int *lan_username_size
;
170 static TCHAR username_buffer
[BUFSZ
];
174 /* i gets updated with actual size */
175 status
= GetUserName(username_buffer
, &i
);
177 username_buffer
[i
] = '\0';
179 Strcpy(username_buffer
, "aNetHack");
180 if (lan_username_size
)
181 *lan_username_size
= strlen(username_buffer
);
182 return username_buffer
;
188 char szFullPath
[MAX_PATH
] = "";
189 HMODULE hInst
= NULL
; /* NULL gets the filename of this module */
191 GetModuleFileName(hInst
, szFullPath
, sizeof(szFullPath
));
192 return &szFullPath
[0];
199 VA_DECL(const char *, s
)
203 VA_INIT(s
, const char *);
204 /* error() may get called before tty is initialized */
205 if (iflags
.window_inited
)
207 if (!strncmpi(windowprocs
.name
, "tty", 3)) {
209 (void) vsprintf(&buf
[1], s
, VA_ARGS
);
213 (void) vsprintf(buf
, s
, VA_ARGS
);
227 extern void NDECL(backsp
);
235 if (!iflags
.window_inited
)
238 msmsg("Execute debug breakpoint wizard?");
239 while ((ci
= nhgetch()) != '\n') {
241 backsp(); /* \b is visible on NT */
247 if (ci
== 'y' || ci
== 'n' || ci
== 'Y' || ci
== 'N') {
259 static char interjection_buf
[INTERJECTION_TYPES
][1024];
260 static int interjection
[INTERJECTION_TYPES
];
263 interject_assistance(num
, interjection_type
, ptr1
, ptr2
)
265 int interjection_type
;
271 char *panicmsg
= (char *) ptr1
;
272 char *datadir
= (char *) ptr2
;
273 char *tempdir
= nh_getenv("TEMP");
274 interjection_type
= INTERJECT_PANIC
;
275 interjection
[INTERJECT_PANIC
] = 1;
277 * ptr1 = the panic message about to be delivered.
278 * ptr2 = the directory prefix of the dungeon file
279 * that failed to open.
280 * Check to see if datadir matches tempdir or a
281 * common windows temp location. If it does, inform
282 * the user that they are probably trying to run the
283 * game from within their unzip utility, so the required
284 * files really don't exist at the location. Instruct
285 * them to unpack them first.
287 if (panicmsg
&& datadir
) {
288 if (!strncmpi(datadir
, "C:\\WINDOWS\\TEMP", 15)
289 || strstri(datadir
, "TEMP")
290 || (tempdir
&& strstri(datadir
, tempdir
))) {
292 interjection_buf
[INTERJECT_PANIC
],
293 "\nOne common cause of this error is attempting to "
295 "the game by double-clicking on it while it is "
297 "inside an unzip utility.\n\n"
298 "You have to unzip the contents of the zip file into a\n"
299 "folder on your system, and then run \"aNetHack.exe\" or "
301 "\"aNetHackW.exe\" from there.\n\n"
302 "If that is not the situation, you are encouraged to\n"
303 "report the error as shown above.\n\n",
312 interject(interjection_type
)
313 int interjection_type
;
315 if (interjection_type
>= 0 && interjection_type
< INTERJECTION_TYPES
)
316 msmsg(interjection_buf
[interjection_type
]);
319 #ifdef RUNTIME_PORT_ID
321 * _M_IX86 is Defined for x86 processors. This is not defined for x64
323 * _M_X64 is Defined for x64 processors.
324 * _M_IA64 is Defined for Itanium Processor Family 64-bit processors.
325 * _WIN64 is Defined for applications for Win64.
329 #define TARGET_PORT "(x64) "
332 #define TARGET_PORT "(IA64) "
337 #define TARGET_PORT "(x86) "
344 char *portstr
= TARGET_PORT
;
345 Sprintf(eos(buf
), " %s", portstr
);
347 #endif /* RUNTIME_PORT_ID */