Merge branch 'paxed-lua-merged3' into paxed-lua-v2-merged
This commit is contained in:
@@ -104,7 +104,8 @@ OPTIONS=suppress_alert:3.3.1
|
||||
# Map window settings
|
||||
# possible map_mode options include: tiles|ascii4x6|ascii6x8|ascii8x8|ascii16x8|
|
||||
# ascii7x12|ascii8x12|ascii16x12|ascii12x16|
|
||||
# ascii10x18|fit_to_screen
|
||||
# ascii10x18|fit_to_screen|ascii_fit_to_screen|
|
||||
# tiles_fit_to_screen
|
||||
OPTIONS=map_mode:tiles,scroll_margin:10
|
||||
|
||||
# Message window settings
|
||||
@@ -3,7 +3,7 @@
|
||||
==============================================================
|
||||
Instructions for compiling and installing
|
||||
NetHack 3.6 on a Windows system
|
||||
(Windows 7/8.x/10 or later only. XP may work but is untested)
|
||||
(Windows 7/8.x/10 or later only)
|
||||
==============================================================
|
||||
Last revision: $NHDT-Date: 1554784481 2019/04/09 04:34:41 $
|
||||
|
||||
|
||||
@@ -99,8 +99,8 @@ TARGET_CPU=x86
|
||||
# of your PDCurses C files which must already be resident on
|
||||
# your machine.
|
||||
#
|
||||
#ADD_CURSES=Y
|
||||
#PDCURSES_TOP=../../pdcurses
|
||||
# ADD_CURSES=Y
|
||||
# PDCURSES_TOP=../../pdcurses
|
||||
|
||||
#4b Qt
|
||||
#
|
||||
@@ -209,7 +209,7 @@ RANDOM = $(OBJ)/random.o
|
||||
#RANDOM =
|
||||
BCRYPT=-lbcrypt
|
||||
|
||||
WINPFLAG = -DTILES -DMSWIN_GRAPHICS -DWIN32CON -D_WIN32_IE=0x0400 -D_WIN32_WINNT=0x0501
|
||||
WINPFLAG = -DTILES -DMSWIN_GRAPHICS -DWIN32CON -D_WIN32_IE=0x0400 -D_WIN32_WINNT=0x0601 -DWINVER=0x0601
|
||||
ifeq "$(WANT_WIN_QT4)" "Y"
|
||||
WINPFLAG += -DQT_GRAPHICS -DPIXMAPDIR='"."'
|
||||
endif
|
||||
@@ -454,12 +454,11 @@ PDCSRC = $(PDCURSES_TOP)/pdcurses
|
||||
PDCWINCON = $(PDCURSES_TOP)/wincon
|
||||
PDCLIBOBJS = $(O)addch.o $(O)addchstr.o $(O)addstr.o $(O)attr.o $(O)beep.o \
|
||||
$(O)bkgd.o $(O)border.o $(O)clear.o $(O)color.o $(O)delch.o $(O)deleteln.o \
|
||||
$(O)deprec.o $(O)getch.o $(O)getstr.o $(O)getyx.o $(O)inch.o $(O)inchstr.o \
|
||||
$(O)getch.o $(O)getstr.o $(O)getyx.o $(O)inch.o $(O)inchstr.o \
|
||||
$(O)initscr.o $(O)inopts.o $(O)insch.o $(O)insstr.o $(O)instr.o $(O)kernel.o \
|
||||
$(O)keyname.o $(O)mouse.o $(O)move.o $(O)outopts.o $(O)overlay.o $(O)pad.o \
|
||||
$(O)panel.o $(O)printw.o $(O)refresh.o $(O)scanw.o $(O)scr_dump.o $(O)scroll.o \
|
||||
$(O)slk.o $(O)termattr.o $(O)terminfo.o $(O)touch.o $(O)util.o $(O)window.o \
|
||||
$(O)debug.o
|
||||
$(O)slk.o $(O)termattr.o $(O)touch.o $(O)util.o $(O)window.o $(O)debug.o
|
||||
|
||||
PDCOBJS = $(O)pdcclip.o $(O)pdcdisp.o $(O)pdcgetsc.o $(O)pdckbd.o $(O)pdcscrn.o \
|
||||
$(O)pdcsetsc.o $(O)pdcutil.o
|
||||
@@ -556,9 +555,9 @@ endif
|
||||
CFLAGSBASE = -c $(cflags) $(WINPINC) $(cdebug) $(CURSESDEF)
|
||||
#LFLAGSBASEC = $(linkdebug)
|
||||
#LFLAGSBASEG = $(linkdebug) -mwindows
|
||||
|
||||
conlibs = -lgdi32 -lwinmm $(BCRYPT)
|
||||
guilibs = -lcomctl32 -lwinmm
|
||||
baselibs = -lwinmm -lshell32 -lole32 -luuid
|
||||
conlibs = -lgdi32 $(baselibs) $(BCRYPT)
|
||||
guilibs = -lcomctl32 $(baselibs)
|
||||
ifeq "$(WANT_WIN_QT4)" "Y"
|
||||
# Might be either Qt 4 or Qt 5
|
||||
ifeq "$(HAVE_QT5)" "Y"
|
||||
@@ -772,11 +771,11 @@ else
|
||||
# $(subst /,\,copy $(DAT)/*.lua $(GAMEDIR))
|
||||
$(subst /,\,if exist $(GAMEDIR)/makefile del $(GAMEDIR)/makefile)
|
||||
endif
|
||||
$(subst /,\,if not exist $(GAMEDIR)/sysconf copy $(MSWSYS)/sysconf $(GAMEDIR))
|
||||
$(subst /,\,if exist $(DAT)/symbols copy $(DAT)/symbols $(GAMEDIR))
|
||||
$(subst /,\,if exist $(MSWSYS)/sysconf.template copy $(MSWSYS)/sysconf.template $(GAMEDIR))
|
||||
$(subst /,\,if exist $(DAT)/symbols copy $(DAT)/symbols $(GAMEDIR)/symbols.template)
|
||||
$(subst /,\,if exist $(DOC)/guidebook.txt copy $(DOC)/guidebook.txt $(GAMEDIR)/Guidebook.txt)
|
||||
$(subst /,\,if exist $(DOC)/nethack.txt copy $(DOC)/nethack.txt $(GAMEDIR)/NetHack.txt)
|
||||
$(subst /,\,if not exist $(GAMEDIR)/defaults.nh copy $(MSWSYS)/defaults.nh $(GAMEDIR)/defaults.nh)
|
||||
$(subst /,\,if exist $(MSWSYS)/.nethackrc.template copy $(MSWSYS)/.nethackrc.template $(GAMEDIR))
|
||||
$(subst /,\,-if not exist $(GAMEDIR)/record. echo.>$(GAMEDIR)/record.)
|
||||
#
|
||||
#
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NetHack 3.7 Makefile.msc $NHDT-Date: 1554784482 2019/04/09 04:34:42 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.153 $ */
|
||||
# NetHack 3.6 Makefile.msc $NHDT-Date: 1572748386 2019/11/03 02:33:06 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.167 $ */
|
||||
# Copyright (c) NetHack PC Development Team 1993-2019
|
||||
#
|
||||
#==============================================================================
|
||||
@@ -593,7 +593,8 @@ guilflags = $(lflags) -subsystem:windows,$(EXEVER)
|
||||
dlllflags = $(lflags) -entry:_DllMainCRTStartup$(DLLENTRY) -dll
|
||||
|
||||
# basic subsystem specific libraries, less the C Run-Time
|
||||
baselibs = kernel32.lib $(optlibs) $(winsocklibs) advapi32.lib gdi32.lib
|
||||
baselibs = kernel32.lib $(optlibs) $(winsocklibs) advapi32.lib gdi32.lib \
|
||||
ole32.lib Shell32.lib
|
||||
winlibs = $(baselibs) user32.lib comdlg32.lib winspool.lib
|
||||
|
||||
# for Windows applications that use the C Run-Time libraries
|
||||
@@ -902,13 +903,13 @@ $(O)install.tag: $(DAT)\data $(DAT)\rumors $(DAT)\dungeon \
|
||||
copy $(DAT)\*.dat $(GAMEDIR)
|
||||
if exist $(GAMEDIR)\makefile del $(GAMEDIR)\makefile
|
||||
! ENDIF
|
||||
if not exist $(GAMEDIR)\sysconf copy $(MSWSYS)\sysconf $(GAMEDIR)
|
||||
if exist $(DAT)\symbols copy $(DAT)\symbols $(GAMEDIR)
|
||||
if exist $(MSWSYS)\sysconf.template copy $(MSWSYS)\sysconf.temnplate $(GAMEDIR)
|
||||
if exist $(DAT)\symbols copy $(DAT)\symbols $(GAMEDIR)\symbols.template
|
||||
if exist $(DOC)\guidebook.txt copy $(DOC)\guidebook.txt $(GAMEDIR)\Guidebook.txt
|
||||
if exist $(DOC)\nethack.txt copy $(DOC)\nethack.txt $(GAMEDIR)\NetHack.txt
|
||||
@if exist $(GAMEDIR)\NetHack.PDB echo NOTE: You may want to remove $(GAMEDIR:\=/)/NetHack.PDB to conserve space
|
||||
@if exist $(GAMEDIR)\NetHackW.PDB echo NOTE: You may want to remove $(GAMEDIR:\=/)/NetHackW.PDB to conserve space
|
||||
-if not exist $(GAMEDIR)\defaults.nh copy $(MSWSYS)\defaults.nh $(GAMEDIR)\defaults.nh
|
||||
-if exist $(MSWSYS)\.nethackrc.template copy $(MSWSYS)\.nethackrc.template $(GAMEDIR)
|
||||
-if not exist $(GAMEDIR)\record. goto>$(GAMEDIR)\record.
|
||||
echo install done > $@
|
||||
|
||||
|
||||
@@ -465,8 +465,15 @@ int *x, *y, *mod;
|
||||
coord cc;
|
||||
DWORD count;
|
||||
really_move_cursor();
|
||||
if (iflags.debug_fuzzer)
|
||||
return randomkey();
|
||||
if (iflags.debug_fuzzer) {
|
||||
int poskey = randomkey();
|
||||
|
||||
if (poskey == 0) {
|
||||
*x = rn2(console.width);
|
||||
*y = rn2(console.height);
|
||||
}
|
||||
return poskey;
|
||||
}
|
||||
ch = (g.program_state.done_hup)
|
||||
? '\033'
|
||||
: keyboard_handler.pCheckInput(
|
||||
@@ -530,12 +537,14 @@ int x, y;
|
||||
set_console_cursor(x, y);
|
||||
}
|
||||
|
||||
void
|
||||
/* same signature as 'putchar()' with potential failure result ignored */
|
||||
int
|
||||
xputc(ch)
|
||||
char ch;
|
||||
int ch;
|
||||
{
|
||||
set_console_cursor(ttyDisplay->curx, ttyDisplay->cury);
|
||||
xputc_core(ch);
|
||||
xputc_core((char) ch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -543,7 +552,7 @@ xputs(s)
|
||||
const char *s;
|
||||
{
|
||||
int k;
|
||||
int slen = strlen(s);
|
||||
int slen = (int) strlen(s);
|
||||
|
||||
if (ttyDisplay)
|
||||
set_console_cursor(ttyDisplay->curx, ttyDisplay->cury);
|
||||
@@ -1597,8 +1606,8 @@ check_font_widths()
|
||||
boolean used[256];
|
||||
memset(used, 0, sizeof(used));
|
||||
for (int i = 0; i < SYM_MAX; i++) {
|
||||
used[g.l_syms[i]] = TRUE;
|
||||
used[g.r_syms[i]] = TRUE;
|
||||
used[g.primary_syms[i]] = TRUE;
|
||||
used[g.rogue_syms[i]] = TRUE;
|
||||
}
|
||||
|
||||
int wcUsedCount = 0;
|
||||
|
||||
@@ -82,11 +82,11 @@ int mode;
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
xputc(ch)
|
||||
char ch;
|
||||
int ch;
|
||||
{
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -52,6 +52,11 @@ WIZARDS=*
|
||||
# Uncomment the next line to disable the SEDUCE option.
|
||||
#SEDUCE=0
|
||||
|
||||
# Uncomment the next line to enable some accessibility features such
|
||||
# as S_player_override and S_pet_override symbols for screen readers
|
||||
# in the user config file.
|
||||
#ACCESSIBILITY=1
|
||||
|
||||
# Record (high score) file options.
|
||||
# CAUTION: changing these after people have started playing games can
|
||||
# lead to lost high scores!
|
||||
@@ -9,6 +9,21 @@
|
||||
|
||||
#include "hack.h"
|
||||
|
||||
typedef DPI_AWARENESS_CONTEXT(WINAPI *GetThreadDpiAwarenessContextProc)(VOID);
|
||||
typedef BOOL(WINAPI *AreDpiAwarenessContextsEqualProc)(
|
||||
DPI_AWARENESS_CONTEXT dpiContextA, DPI_AWARENESS_CONTEXT dpiContextB);
|
||||
typedef UINT(WINAPI *GetDpiForWindowProc)(HWND hwnd);
|
||||
typedef LONG (WINAPI *GetCurrentPackageFullNameProc)(UINT32 *packageFullNameLength,
|
||||
PWSTR packageFullName);
|
||||
|
||||
typedef struct {
|
||||
BOOL Valid;
|
||||
GetThreadDpiAwarenessContextProc GetThreadDpiAwarenessContext;
|
||||
AreDpiAwarenessContextsEqualProc AreDpiAwarenessContextsEqual;
|
||||
GetDpiForWindowProc GetDpiForWindow;
|
||||
GetCurrentPackageFullNameProc GetCurrentPackageFullName;
|
||||
} Win10;
|
||||
|
||||
Win10 gWin10 = { 0 };
|
||||
|
||||
void win10_init()
|
||||
@@ -34,6 +49,17 @@ void win10_init()
|
||||
|
||||
FreeLibrary(hUser32);
|
||||
|
||||
HINSTANCE hKernel32 = LoadLibraryA("kernel32.dll");
|
||||
|
||||
if (hKernel32 == NULL)
|
||||
panic("Unable to load kernel32.dll");
|
||||
|
||||
gWin10.GetCurrentPackageFullName = (GetCurrentPackageFullNameProc) GetProcAddress(hKernel32, "GetCurrentPackageFullName");
|
||||
if (gWin10.GetCurrentPackageFullName == NULL)
|
||||
panic("Unable to get address of GetCurrentPackageFullName");
|
||||
|
||||
FreeLibrary(hKernel32);
|
||||
|
||||
gWin10.Valid = TRUE;
|
||||
}
|
||||
|
||||
@@ -80,4 +106,19 @@ void win10_monitor_info(HWND hWnd, MonitorInfo * monitorInfo)
|
||||
monitorInfo->left = info.rcMonitor.left;
|
||||
monitorInfo->top = info.rcMonitor.top;
|
||||
}
|
||||
|
||||
BOOL
|
||||
win10_is_desktop_bridge_application()
|
||||
{
|
||||
if (gWin10.Valid) {
|
||||
UINT32 length = 0;
|
||||
LONG rc = gWin10.GetCurrentPackageFullName(&length, NULL);
|
||||
|
||||
return (rc == ERROR_INSUFFICIENT_BUFFER);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
@@ -7,18 +7,6 @@
|
||||
|
||||
#include "win32api.h"
|
||||
|
||||
typedef DPI_AWARENESS_CONTEXT(WINAPI *GetThreadDpiAwarenessContextProc)(VOID);
|
||||
typedef BOOL(WINAPI *AreDpiAwarenessContextsEqualProc)(
|
||||
DPI_AWARENESS_CONTEXT dpiContextA, DPI_AWARENESS_CONTEXT dpiContextB);
|
||||
typedef UINT(WINAPI *GetDpiForWindowProc)(HWND hwnd);
|
||||
|
||||
typedef struct {
|
||||
BOOL Valid;
|
||||
GetThreadDpiAwarenessContextProc GetThreadDpiAwarenessContext;
|
||||
AreDpiAwarenessContextsEqualProc AreDpiAwarenessContextsEqual;
|
||||
GetDpiForWindowProc GetDpiForWindow;
|
||||
} Win10;
|
||||
|
||||
typedef struct {
|
||||
double scale; // dpi of monitor / 96
|
||||
int width; // in pixels
|
||||
@@ -27,13 +15,10 @@ typedef struct {
|
||||
int left; // in desktop coordinate pixel space
|
||||
} MonitorInfo;
|
||||
|
||||
extern Win10 gWin10;
|
||||
|
||||
void win10_init();
|
||||
int win10_monitor_dpi(HWND hWnd);
|
||||
double win10_monitor_scale(HWND hWnd);
|
||||
void win10_monitor_size(HWND hWnd, int * width, int * height);
|
||||
void win10_monitor_info(HWND hWnd, MonitorInfo * monitorInfo);
|
||||
|
||||
BOOL win10_is_desktop_bridge_application(void);
|
||||
|
||||
#endif // WIN10_H
|
||||
|
||||
@@ -8,12 +8,10 @@
|
||||
#include "hack.h"
|
||||
#include "dlb.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys\stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if 0
|
||||
#include "wintty.h"
|
||||
#endif
|
||||
#include <ShlObj.h>
|
||||
|
||||
#if !defined(SAFEPROCS)
|
||||
#error You must #define SAFEPROCS to build windmain.c
|
||||
@@ -22,7 +20,7 @@
|
||||
#define E extern
|
||||
static void FDECL(process_options, (int argc, char **argv));
|
||||
static void NDECL(nhusage);
|
||||
static char *FDECL(exepath, (char *));
|
||||
static char *NDECL(get_executable_path);
|
||||
char *NDECL(exename);
|
||||
boolean NDECL(fakeconsole);
|
||||
void NDECL(freefakeconsole);
|
||||
@@ -49,7 +47,6 @@ extern int NDECL(windows_console_custom_nhgetch);
|
||||
void NDECL(safe_routines);
|
||||
|
||||
char orgdir[PATHLEN];
|
||||
char *dir;
|
||||
boolean getreturn_enabled;
|
||||
extern int redirect_stdout; /* from sys/share/pcsys.c */
|
||||
extern int GUILaunched;
|
||||
@@ -66,6 +63,281 @@ static struct stat hbuf;
|
||||
|
||||
extern char orgdir[];
|
||||
|
||||
void
|
||||
get_known_folder_path(
|
||||
const KNOWNFOLDERID * folder_id,
|
||||
char * path
|
||||
, size_t path_size)
|
||||
{
|
||||
PWSTR wide_path;
|
||||
if (FAILED(SHGetKnownFolderPath(folder_id, 0, NULL, &wide_path)))
|
||||
error("Unable to get known folder path");
|
||||
|
||||
size_t converted;
|
||||
errno_t err;
|
||||
|
||||
err = wcstombs_s(&converted, path, path_size, wide_path, path_size - 1);
|
||||
|
||||
CoTaskMemFree(wide_path);
|
||||
|
||||
if (err != 0) error("Failed folder path string conversion");
|
||||
}
|
||||
|
||||
void
|
||||
create_directory(const char * path)
|
||||
{
|
||||
HRESULT hr = CreateDirectoryA(path, NULL);
|
||||
|
||||
if (FAILED(hr) && hr != ERROR_ALREADY_EXISTS)
|
||||
error("Unable to create directory '%s'", path);
|
||||
}
|
||||
|
||||
void
|
||||
build_known_folder_path(
|
||||
const KNOWNFOLDERID * folder_id,
|
||||
char * path,
|
||||
size_t path_size)
|
||||
{
|
||||
get_known_folder_path(folder_id, path, path_size);
|
||||
strcat(path, "\\NetHack\\");
|
||||
create_directory(path);
|
||||
strcat(path, "3.6\\");
|
||||
create_directory(path);
|
||||
}
|
||||
|
||||
void
|
||||
build_environment_path(
|
||||
const char * env_str,
|
||||
const char * folder,
|
||||
char * path,
|
||||
size_t path_size)
|
||||
{
|
||||
path[0] = '\0';
|
||||
|
||||
const char * root_path = nh_getenv(env_str);
|
||||
|
||||
if (root_path == NULL) return;
|
||||
|
||||
strcpy_s(path, path_size, root_path);
|
||||
|
||||
char * colon = index(path, ';');
|
||||
if (colon != NULL) path[0] = '\0';
|
||||
|
||||
if (strlen(path) == 0) return;
|
||||
|
||||
append_slash(path);
|
||||
|
||||
if (folder != NULL) {
|
||||
strcat_s(path, path_size, folder);
|
||||
strcat_s(path, path_size, "\\");
|
||||
}
|
||||
}
|
||||
|
||||
boolean
|
||||
folder_file_exists(const char * folder, const char * file_name)
|
||||
{
|
||||
char path[MAX_PATH];
|
||||
|
||||
if (folder[0] == '\0') return FALSE;
|
||||
|
||||
strcpy(path, folder);
|
||||
strcat(path, file_name);
|
||||
return file_exists(path);
|
||||
}
|
||||
|
||||
/*
|
||||
* Rules for setting prefix locations
|
||||
*
|
||||
* COMMON_NETHACK_PATH = %COMMONPROGRAMFILES%\NetHack\3.6\
|
||||
* PROFILE_PATH = %SystemDrive%\Users\%USERNAME%\
|
||||
*
|
||||
* NETHACK_PROFILE_PATH = PROFILE_PATH\NetHack\3.6\
|
||||
* NETHACK_PER_USER_DATA_PATH = PROFILE_PATH\AppData\Local\NetHack\3.6\
|
||||
* NETHACK_GLOBAL_DATA_PATH = %SystemDrive%\ProgramData\NetHack\3.6\
|
||||
* EXECUTABLE_PATH = path to where .exe lives
|
||||
*
|
||||
* HACKPREFIX:
|
||||
* - use environment variable NETHACKDIR if variable is defined
|
||||
* - otherwise use environment variable HACKDIR if variable is defined
|
||||
* - otherwise if store install use NETHACK_PROFILE_PATH
|
||||
* - otherwise if manual install use EXECUTABLE_PATH
|
||||
*
|
||||
* LEVELPREFIX, SAVEPREFIX:
|
||||
* - if store install use NETHACK_PER_USER_DATA_PATH
|
||||
* - if manual install use HACKPREFIX
|
||||
*
|
||||
* BONESPREFIX, SCOREPREFIX, LOCKPREFIX:
|
||||
* - if store install use NETHACK_GLOBAL_DATA_PATH
|
||||
* - if manual install use HACKPREFIX
|
||||
*
|
||||
* DATAPREFIX
|
||||
* - if store install use EXECUTABLE_PATH
|
||||
* - if manual install use HACKPREFIX
|
||||
*
|
||||
* SYSCONFPREFIX
|
||||
* - use COMMON_NETHACK_PATH if sysconf present
|
||||
* - otherwise use HACKPREFIX
|
||||
*
|
||||
* CONFIGPREFIX
|
||||
* - if manual install use PROFILE_PATH
|
||||
* - if store install use NETHACK_PROFILE_PATH
|
||||
*/
|
||||
|
||||
void
|
||||
set_default_prefix_locations(const char *programPath)
|
||||
{
|
||||
char *envp = NULL;
|
||||
char *sptr = NULL;
|
||||
|
||||
static char hack_path[MAX_PATH];
|
||||
static char executable_path[MAX_PATH];
|
||||
static char nethack_profile_path[MAX_PATH];
|
||||
static char nethack_per_user_data_path[MAX_PATH];
|
||||
static char nethack_global_data_path[MAX_PATH];
|
||||
static char sysconf_path[MAX_PATH];
|
||||
|
||||
strcpy(executable_path, get_executable_path());
|
||||
append_slash(executable_path);
|
||||
|
||||
build_environment_path("NETHACKDIR", NULL, hack_path, sizeof(hack_path));
|
||||
|
||||
if (hack_path[0] == '\0')
|
||||
build_environment_path("HACKDIR", NULL, hack_path, sizeof(hack_path));
|
||||
|
||||
build_known_folder_path(&FOLDERID_Profile, nethack_profile_path,
|
||||
sizeof(nethack_profile_path));
|
||||
|
||||
build_known_folder_path(&FOLDERID_LocalAppData,
|
||||
nethack_per_user_data_path, sizeof(nethack_per_user_data_path));
|
||||
|
||||
build_known_folder_path(&FOLDERID_ProgramData,
|
||||
nethack_global_data_path, sizeof(nethack_global_data_path));
|
||||
|
||||
if (hack_path[0] == '\0')
|
||||
strcpy(hack_path, nethack_profile_path);
|
||||
|
||||
g.fqn_prefix[LEVELPREFIX] = nethack_per_user_data_path;
|
||||
g.fqn_prefix[SAVEPREFIX] = nethack_per_user_data_path;
|
||||
g.fqn_prefix[BONESPREFIX] = nethack_global_data_path;
|
||||
g.fqn_prefix[DATAPREFIX] = executable_path;
|
||||
g.fqn_prefix[SCOREPREFIX] = nethack_global_data_path;
|
||||
g.fqn_prefix[LOCKPREFIX] = nethack_global_data_path;
|
||||
g.fqn_prefix[CONFIGPREFIX] = nethack_profile_path;
|
||||
|
||||
g.fqn_prefix[HACKPREFIX] = hack_path;
|
||||
g.fqn_prefix[TROUBLEPREFIX] = hack_path;
|
||||
|
||||
build_environment_path("COMMONPROGRAMFILES", "NetHack\\3.6", sysconf_path,
|
||||
sizeof(sysconf_path));
|
||||
|
||||
if(!folder_file_exists(sysconf_path, SYSCF_FILE))
|
||||
strcpy(sysconf_path, hack_path);
|
||||
|
||||
g.fqn_prefix[SYSCONFPREFIX] = sysconf_path;
|
||||
|
||||
}
|
||||
|
||||
/* copy file if destination does not exist */
|
||||
void
|
||||
copy_file(
|
||||
const char * dst_folder,
|
||||
const char * dst_name,
|
||||
const char * src_folder,
|
||||
const char * src_name)
|
||||
{
|
||||
char dst_path[MAX_PATH];
|
||||
strcpy(dst_path, dst_folder);
|
||||
strcat(dst_path, dst_name);
|
||||
|
||||
char src_path[MAX_PATH];
|
||||
strcpy(src_path, src_folder);
|
||||
strcat(src_path, src_name);
|
||||
|
||||
if(!file_exists(src_path))
|
||||
error("Unable to copy file '%s' as it does not exist", src_path);
|
||||
|
||||
if(file_exists(dst_path))
|
||||
return;
|
||||
|
||||
BOOL success = CopyFileA(src_path, dst_path, TRUE);
|
||||
if(!success) error("Failed to copy '%s' to '%s'", src_path, dst_path);
|
||||
}
|
||||
|
||||
/* update file copying if it does not exist or src is newer then dst */
|
||||
void
|
||||
update_file(
|
||||
const char * dst_folder,
|
||||
const char * dst_name,
|
||||
const char * src_folder,
|
||||
const char * src_name,
|
||||
BOOL save_copy)
|
||||
{
|
||||
char dst_path[MAX_PATH];
|
||||
strcpy(dst_path, dst_folder);
|
||||
strcat(dst_path, dst_name);
|
||||
|
||||
char src_path[MAX_PATH];
|
||||
strcpy(src_path, src_folder);
|
||||
strcat(src_path, src_name);
|
||||
|
||||
char save_path[MAX_PATH];
|
||||
strcpy(save_path, dst_folder);
|
||||
strcat(save_path, dst_name);
|
||||
strcat(save_path, ".save");
|
||||
|
||||
if(!file_exists(src_path))
|
||||
error("Unable to copy file '%s' as it does not exist", src_path);
|
||||
|
||||
if (!file_newer(src_path, dst_path))
|
||||
return;
|
||||
|
||||
if (file_exists(dst_path) && save_copy)
|
||||
CopyFileA(dst_path, save_path, FALSE);
|
||||
|
||||
BOOL success = CopyFileA(src_path, dst_path, FALSE);
|
||||
if(!success) error("Failed to update '%s' to '%s'", src_path, dst_path);
|
||||
|
||||
}
|
||||
|
||||
void copy_config_content()
|
||||
{
|
||||
/* Keep templates up to date */
|
||||
/* TODO: Update the package to store config file as .nethackrc */
|
||||
update_file(g.fqn_prefix[CONFIGPREFIX], CONFIG_TEMPLATE,
|
||||
g.fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE, FALSE);
|
||||
update_file(g.fqn_prefix[SYSCONFPREFIX], SYSCF_TEMPLATE,
|
||||
g.fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE, FALSE);
|
||||
|
||||
/* If the required early game file does not exist, copy it */
|
||||
/* NOTE: We never replace .nethackrc or sysconf */
|
||||
copy_file(g.fqn_prefix[CONFIGPREFIX], CONFIG_FILE,
|
||||
g.fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE);
|
||||
copy_file(g.fqn_prefix[SYSCONFPREFIX], SYSCF_FILE,
|
||||
g.fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE);
|
||||
|
||||
/* Update symbols and save a copy if we are replacing */
|
||||
/* TODO: Can't HACKDIR be changed during option parsing
|
||||
causing us to perhaps be checking options against the wrong
|
||||
symbols file? */
|
||||
update_file(g.fqn_prefix[HACKPREFIX], SYMBOLS,
|
||||
g.fqn_prefix[DATAPREFIX], SYMBOLS_TEMPLATE, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
copy_hack_content()
|
||||
{
|
||||
/* Keep Guidebook and opthelp up to date */
|
||||
update_file(g.fqn_prefix[HACKPREFIX], GUIDEBOOK_FILE,
|
||||
g.fqn_prefix[DATAPREFIX], GUIDEBOOK_FILE, FALSE);
|
||||
update_file(g.fqn_prefix[HACKPREFIX], OPTIONFILE,
|
||||
g.fqn_prefix[DATAPREFIX], OPTIONFILE, FALSE);
|
||||
|
||||
/* Keep templates up to date */
|
||||
update_file(g.fqn_prefix[HACKPREFIX], SYMBOLS_TEMPLATE,
|
||||
g.fqn_prefix[DATAPREFIX], SYMBOLS_TEMPLATE, FALSE);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* __MINGW32__ Note
|
||||
* If the graphics version is built, we don't need a main; it is skipped
|
||||
@@ -119,110 +391,25 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
#endif
|
||||
|
||||
g.hname = "NetHack"; /* used for syntax messages */
|
||||
|
||||
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
|
||||
/* Save current directory and make sure it gets restored when
|
||||
* the game is exited.
|
||||
*/
|
||||
if (getcwd(orgdir, sizeof orgdir) == (char *) 0)
|
||||
error("NetHack: current directory path too long");
|
||||
dir = nh_getenv("NETHACKDIR");
|
||||
if (dir == (char *) 0)
|
||||
dir = nh_getenv("HACKDIR");
|
||||
if (dir == (char *) 0)
|
||||
dir = exepath(argv[0]);
|
||||
#ifdef _MSC_VER
|
||||
if (IsDebuggerPresent()) {
|
||||
static char exepath[_MAX_PATH];
|
||||
/* check if we're running under the debugger so we can get to the right folder anyway */
|
||||
if (dir != (char *)0) {
|
||||
char *top = (char *)0;
|
||||
|
||||
if (strlen(dir) < (_MAX_PATH - 1))
|
||||
strcpy(exepath, dir);
|
||||
top = strstr(exepath, "\\build\\.\\Debug");
|
||||
if (!top) top = strstr(exepath, "\\build\\.\\Release");
|
||||
if (top) {
|
||||
*top = '\0';
|
||||
if (strlen(exepath) < (_MAX_PATH - (strlen("\\binary\\") + 1))) {
|
||||
Strcat(exepath, "\\binary\\");
|
||||
if (strlen(exepath) < (PATHLEN - 1)) {
|
||||
dir = exepath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (dir != (char *)0) {
|
||||
int prefcnt;
|
||||
int fd;
|
||||
boolean have_syscf = FALSE;
|
||||
|
||||
(void) strncpy(g.hackdir, dir, PATHLEN - 1);
|
||||
g.hackdir[PATHLEN - 1] = '\0';
|
||||
g.fqn_prefix[0] = (char *) alloc(strlen(g.hackdir) + 2);
|
||||
Strcpy(g.fqn_prefix[0], g.hackdir);
|
||||
append_slash(g.fqn_prefix[0]);
|
||||
for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++)
|
||||
g.fqn_prefix[prefcnt] = g.fqn_prefix[0];
|
||||
/* sysconf should be searched for in this location */
|
||||
envp = nh_getenv("COMMONPROGRAMFILES");
|
||||
if (envp) {
|
||||
if ((sptr = index(envp, ';')) != 0)
|
||||
*sptr = '\0';
|
||||
if (strlen(envp) > 0) {
|
||||
g.fqn_prefix[SYSCONFPREFIX] =
|
||||
(char *) alloc(strlen(envp) + 10);
|
||||
Strcpy(g.fqn_prefix[SYSCONFPREFIX], envp);
|
||||
append_slash(g.fqn_prefix[SYSCONFPREFIX]);
|
||||
Strcat(g.fqn_prefix[SYSCONFPREFIX], "NetHack\\");
|
||||
}
|
||||
}
|
||||
set_default_prefix_locations(argv[0]);
|
||||
|
||||
/* okay so we have the overriding and definitive locaton
|
||||
for sysconf, but only in the event that there is not a
|
||||
sysconf file there (for whatever reason), check a secondary
|
||||
location rather than abort. */
|
||||
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
|
||||
chdir(fqn_prefix[HACKPREFIX]);
|
||||
#endif
|
||||
|
||||
/* Is there a SYSCF_FILE there? */
|
||||
fd = open(fqname(SYSCF_FILE, SYSCONFPREFIX, 0), O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
/* readable */
|
||||
close(fd);
|
||||
have_syscf = TRUE;
|
||||
}
|
||||
copy_config_content();
|
||||
|
||||
if (!have_syscf) {
|
||||
/* No SYSCF_FILE where there should be one, and
|
||||
without an installer, a user may not be able
|
||||
to place one there. So, let's try somewhere else... */
|
||||
g.fqn_prefix[SYSCONFPREFIX] = g.fqn_prefix[0];
|
||||
|
||||
/* Is there a SYSCF_FILE there? */
|
||||
fd = open(fqname(SYSCF_FILE, SYSCONFPREFIX, 0), O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
/* readable */
|
||||
close(fd);
|
||||
have_syscf = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* user's home directory should default to this - unless
|
||||
* overridden */
|
||||
envp = nh_getenv("USERPROFILE");
|
||||
if (envp) {
|
||||
if ((sptr = index(envp, ';')) != 0)
|
||||
*sptr = '\0';
|
||||
if (strlen(envp) > 0) {
|
||||
g.fqn_prefix[CONFIGPREFIX] =
|
||||
(char *) alloc(strlen(envp) + 2);
|
||||
Strcpy(g.fqn_prefix[CONFIGPREFIX], envp);
|
||||
append_slash(g.fqn_prefix[CONFIGPREFIX]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (GUILaunched || IsDebuggerPresent()) {
|
||||
if (GUILaunched || IsDebuggerPresent())
|
||||
getreturn_enabled = TRUE;
|
||||
}
|
||||
|
||||
check_recordfile((char *) 0);
|
||||
iflags.windowtype_deferred = TRUE;
|
||||
@@ -232,10 +419,11 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
failbuf);
|
||||
nethack_exit(EXIT_FAILURE);
|
||||
}
|
||||
if (!g.hackdir[0])
|
||||
Strcpy(g.hackdir, orgdir);
|
||||
|
||||
process_options(argc, argv);
|
||||
|
||||
|
||||
copy_hack_content();
|
||||
|
||||
/*
|
||||
* It seems you really want to play.
|
||||
*/
|
||||
@@ -291,10 +479,8 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
setting of renameallowed; when False, player_selection()
|
||||
won't resent renaming as an option */
|
||||
iflags.renameallowed = FALSE;
|
||||
#if 0
|
||||
/* Obtain the name of the logged on user and incorporate
|
||||
* it into the name. */
|
||||
#endif
|
||||
Sprintf(fnamebuf, "%s", g.plname);
|
||||
(void) fname_encode(
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.", '%',
|
||||
@@ -374,7 +560,7 @@ attempt_restore:
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
static void
|
||||
process_options(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
@@ -402,7 +588,7 @@ char *argv[];
|
||||
*/
|
||||
argc--;
|
||||
argv++;
|
||||
dir = argv[0] + 2;
|
||||
const char * dir = argv[0] + 2;
|
||||
if (*dir == '=' || *dir == ':')
|
||||
dir++;
|
||||
if (!*dir && argc > 1) {
|
||||
@@ -533,7 +719,7 @@ char *argv[];
|
||||
}
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
static void
|
||||
nhusage()
|
||||
{
|
||||
char buf1[BUFSZ], buf2[BUFSZ], *bufptr;
|
||||
@@ -665,33 +851,28 @@ void freefakeconsole()
|
||||
}
|
||||
#endif
|
||||
|
||||
#define EXEPATHBUFSZ 256
|
||||
char exepathbuf[EXEPATHBUFSZ];
|
||||
|
||||
char *
|
||||
exepath(str)
|
||||
char *str;
|
||||
get_executable_path()
|
||||
{
|
||||
char *tmp, *tmp2;
|
||||
int bsize;
|
||||
static char path_buffer[MAX_PATH];
|
||||
|
||||
if (!str)
|
||||
return (char *) 0;
|
||||
bsize = EXEPATHBUFSZ;
|
||||
tmp = exepathbuf;
|
||||
#ifdef UNICODE
|
||||
{
|
||||
TCHAR wbuf[BUFSZ];
|
||||
GetModuleFileName((HANDLE) 0, wbuf, BUFSZ);
|
||||
WideCharToMultiByte(CP_ACP, 0, wbuf, -1, tmp, bsize, NULL, NULL);
|
||||
WideCharToMultiByte(CP_ACP, 0, wbuf, -1, path_buffer, sizeof(path_buffer), NULL, NULL);
|
||||
}
|
||||
#else
|
||||
*(tmp + GetModuleFileName((HANDLE) 0, tmp, bsize)) = '\0';
|
||||
DWORD length = GetModuleFileName((HANDLE) 0, path_buffer, MAX_PATH);
|
||||
if (length == ERROR_INSUFFICIENT_BUFFER) error("Unable to get module name");
|
||||
path_buffer[length] = '\0';
|
||||
#endif
|
||||
tmp2 = strrchr(tmp, PATH_SEPARATOR);
|
||||
if (tmp2)
|
||||
*tmp2 = '\0';
|
||||
return tmp;
|
||||
|
||||
char * seperator = strrchr(path_buffer, PATH_SEPARATOR);
|
||||
if (seperator)
|
||||
*seperator = '\0';
|
||||
|
||||
return path_buffer;
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
@@ -783,7 +964,9 @@ getlock()
|
||||
{
|
||||
register int fd, c, ci, ct, ern;
|
||||
int fcmask = FCMASK;
|
||||
#ifndef SELF_RECOVER
|
||||
char tbuf[BUFSZ];
|
||||
#endif
|
||||
const char *fq_lock;
|
||||
#define OOPS_BUFSZ 512
|
||||
char oops[OOPS_BUFSZ];
|
||||
@@ -930,4 +1113,28 @@ const char *path;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
file_newer returns TRUE if the file at a_path is newer then the file
|
||||
at b_path. If a_path does not exist, it returns FALSE. If b_path
|
||||
does not exist, it returns TRUE.
|
||||
*/
|
||||
boolean
|
||||
file_newer(a_path, b_path)
|
||||
const char * a_path;
|
||||
const char * b_path;
|
||||
{
|
||||
struct stat a_sb;
|
||||
struct stat b_sb;
|
||||
|
||||
if (stat(a_path, &a_sb))
|
||||
return FALSE;
|
||||
|
||||
if (stat(b_path, &b_sb))
|
||||
return TRUE;
|
||||
|
||||
if(difftime(a_sb.st_mtime, b_sb.st_mtime) < 0)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*windmain.c*/
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "win10.h"
|
||||
#include "winos.h"
|
||||
|
||||
#define NEED_VARARGS
|
||||
@@ -188,15 +189,26 @@ get_username(lan_username_size)
|
||||
int *lan_username_size;
|
||||
{
|
||||
static TCHAR username_buffer[BUFSZ];
|
||||
unsigned int status;
|
||||
DWORD i = BUFSZ - 1;
|
||||
BOOL allowUserName = TRUE;
|
||||
|
||||
Strcpy(username_buffer, "NetHack");
|
||||
|
||||
#ifndef WIN32CON
|
||||
/* Our privacy policy for the windows store version of nethack makes
|
||||
* a promise about not collecting any personally identifiable information.
|
||||
* Do not allow getting user name if we being run from windows store
|
||||
* version of nethack. In 3.7, we should remove use of username.
|
||||
*/
|
||||
allowUserName = !win10_is_desktop_bridge_application();
|
||||
#endif
|
||||
|
||||
if (allowUserName) {
|
||||
/* i gets updated with actual size */
|
||||
if (GetUserName(username_buffer, &i))
|
||||
username_buffer[i] = '\0';
|
||||
}
|
||||
|
||||
/* i gets updated with actual size */
|
||||
status = GetUserName(username_buffer, &i);
|
||||
if (status)
|
||||
username_buffer[i] = '\0';
|
||||
else
|
||||
Strcpy(username_buffer, "NetHack");
|
||||
if (lan_username_size)
|
||||
*lan_username_size = strlen(username_buffer);
|
||||
return username_buffer;
|
||||
|
||||
Reference in New Issue
Block a user