From fa2c13bc8c4629cf84af4ec7f057ef4237477822 Mon Sep 17 00:00:00 2001 From: roblabla Date: Fri, 29 Sep 2023 01:01:52 +0200 Subject: [PATCH 1/2] Use utf8 in the repository Using shift-jis in the repository was too problematic, it caused various issues with git as it stores everything in utf8 internally, and the conversion from shift-jis to utf8 and back would sometimes fail with cryptic and unhelpful errors. So instead of this, we now store the repository in utf8, and handle converting from utf8 to shift-jis ourselves, using python. This is done automatically in the makefile. The devenv is adjusted to automatically install Python 3.4 (the last version of python that supports Windows XP). --- .gitattributes | 2 -- Makefile | 14 +++++++++++--- scripts/create_devenv.py | 12 ++++++++++++ scripts/download_requirements | 7 +++++++ scripts/download_requirements.ps1 | 7 +++++++ scripts/th06vars.bat | 3 ++- src/{i18n.hpp => i18n.tpl} | 24 ++++++++++++------------ 7 files changed, 51 insertions(+), 18 deletions(-) delete mode 100644 .gitattributes rename src/{i18n.hpp => i18n.tpl} (79%) diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 898141fb..00000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -*.cpp text working-tree-encoding=SHIFT-JIS -*.hpp text working-tree-encoding=SHIFT-JIS \ No newline at end of file diff --git a/Makefile b/Makefile index 7ee7b5b2..90fb59bd 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,8 @@ CPP=cl.exe LINK32=link.exe RSC=rc.exe +PYTHON=python.exe -CFLAGS=/nologo /MT /EHsc /G5 /GS /Od /Oi /Ob1 /DNDEBUG /Zi LINK32_BASE_LIBS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib LINK32_LIBS=dxguid.lib d3dx8.lib d3d8.lib winmm.lib $(LINK32_BASE_LIBS) LINK32_FLAGS=/nologo /subsystem:windows /machine:X86 /filealign:4096 /incremental:no @@ -15,6 +15,8 @@ OBJ_DIR=build RES_DIR=resources SRC_DIR=src +CFLAGS=/nologo /MT /EHsc /G5 /GS /Od /Oi /Ob1 /DNDEBUG /Zi /I $(OBJ_DIR)\autogenerated + .SUFFIXES : .cpp .obj TH06E_OBJS= $(OBJ_DIR)\main.obj \ @@ -30,6 +32,11 @@ TH06E_OBJS= $(OBJ_DIR)\main.obj \ all: $(OBJ_DIR)\th06e.exe +$(OBJ_DIR)\autogenerated\i18n.hpp: "$(SRC_DIR)\i18n.tpl" + -@if not exist "$(OBJ_DIR)\autogenerated" mkdir "$(OBJ_DIR)\autogenerated" + -@echo $(SRC_DIR)\i18n.tpl + -@$(PYTHON) -c "import sys; open(sys.argv[2], 'wb').write(open(sys.argv[1], 'rb').read().decode('utf8').encode('shift_jis'))" "$(SRC_DIR)\i18n.tpl" $@ + $(OBJ_DIR)\th06.res: "$(OBJ_DIR)\icon.ico" "$(OBJ_DIR)": @@ -39,7 +46,7 @@ $(OBJ_DIR)\th06.res: "$(OBJ_DIR)\icon.ico" -@if exist "$(RES_DIR)\icon.ico" copy "$(RES_DIR)\icon.ico" "$(OBJ_DIR)\icon.ico" -@if not exist "$(RES_DIR)\icon.ico" copy "$(RES_DIR)\placeholder.ico" "$(OBJ_DIR)\icon.ico" -"$(OBJ_DIR)\th06e.exe": $(OBJ_DIR) $(TH06E_OBJS) +"$(OBJ_DIR)\th06e.exe": $(OBJ_DIR)\autogenerated\i18n.hpp $(OBJ_DIR) $(TH06E_OBJS) -@$(LINK32) /out:$@ $(LINK32_FLAGS) /debug /pdb:"$(OBJ_DIR)\th06e.pdb" $(LINK32_LIBS) $(TH06E_OBJS) {$(SRC_DIR)}.cpp{$(OBJ_DIR)}.obj: @@ -50,7 +57,8 @@ $(OBJ_DIR)\th06.res: "$(OBJ_DIR)\icon.ico" -@$(RSC) /fo $@ $< clean: - -@erase $(TH06E_OBJS) "$(OBJ_DIR)\th06e.exe" "$(OBJ_DIR)\th06e.pdb" "$(OBJ_DIR)\icon.ico" + -@erase $(TH06E_OBJS) "$(OBJ_DIR)\th06e.exe" "$(OBJ_DIR)\th06e.pdb" "$(OBJ_DIR)\icon.ico" "$(OBJ_DIR)\autogenerated\i18n.hpp" + -@rmdir $(OBJ_DIR)\autogenerated -@rmdir $(OBJ_DIR) diff --git a/scripts/create_devenv.py b/scripts/create_devenv.py index 0005d213..50e3625f 100644 --- a/scripts/create_devenv.py +++ b/scripts/create_devenv.py @@ -98,6 +98,10 @@ def main(args: Namespace) -> int: input_path / "en_vs.net_pro_full.exe", "Missing installer for Visual Studio .NET 2002 Professional Edition", ) + python_installer_path = check_file( + input_path / "python-3.4.4.msi", + "Missing installer for Python 3.4.4", + ) program_files = output_path / "PROGRAM FILES" program_files.mkdir(parents=True, exist_ok=True) @@ -176,6 +180,14 @@ def main(args: Namespace) -> int: shutil.move(tmp_dir, dx8sdk_dst_dir) shutil.rmtree(tmp_dir, ignore_errors=True) + print("Installing Python") + shutil.rmtree(tmp_dir, ignore_errors=True) + tmp_dir.mkdir(parents=True, exist_ok=True) + msiextract(python_installer_path, tmp_dir) + python_dst_dir = output_path / "python" + shutil.move(tmp_dir, python_dst_dir) + shutil.rmtree(tmp_dir, ignore_errors=True) + return 0 diff --git a/scripts/download_requirements b/scripts/download_requirements index 4f5c8612..3f48bee7 100755 --- a/scripts/download_requirements +++ b/scripts/download_requirements @@ -12,6 +12,9 @@ DX8_URL="$ARCHIVE_DOWNLOAD_BASE_URL/dx8sdk/$DX8_FILE_NAME" VS_02_FILE_NAME="en_vs.net_pro_full.exe" VS_02_URL="$ARCHIVE_DOWNLOAD_BASE_URL/en_vs.net_pro_full/$VS_02_FILE_NAME" +PYTHON_FILE_NAME="python-3.4.4.msi" +PYTHON_URL="https://www.python.org/ftp/python/3.4.4/$PYTHON_FILE_NAME" + mkdir -p $DL_PATH pushd $DL_PATH if [[ ! -e $DX8_FILE_NAME ]]; then @@ -23,4 +26,8 @@ if [[ ! -e $VS_02_FILE_NAME ]]; then echo "Downloading Visual Studio .NET 2002 Professional Edition" curl -L -O $VS_02_URL fi +if [[ ! -e $PYTHON_FILE_NAME ]]; then + echo "Downloading Python 3.4.4" + curl -L -O $PYTHON_URL +fi popd diff --git a/scripts/download_requirements.ps1 b/scripts/download_requirements.ps1 index 8db40f29..f646f06c 100644 --- a/scripts/download_requirements.ps1 +++ b/scripts/download_requirements.ps1 @@ -7,6 +7,9 @@ $DX8_URL="$ARCHIVE_DOWNLOAD_BASE_URL/dx8sdk/$DX8_FILE_NAME" $VS_02_FILE_NAME="en_vs.net_pro_full.exe" $VS_02_URL="$ARCHIVE_DOWNLOAD_BASE_URL/en_vs.net_pro_full/$VS_02_FILE_NAME" +$PYTHON_FILE_NAME="python-3.4.4.msi" +$PYTHON_URL="https://www.python.org/ftp/python/3.4.4/$PYTHON_FILE_NAME" + $SCRIPT_DIR=$PSScriptRoot $DL_PATH="$SCRIPT_DIR/dls" @@ -21,3 +24,7 @@ if (!(Test-Path "$DL_PATH/$VS_02_FILE_NAME")) { Write-Host "Downloading Visual Studio 2002" $client.DownloadFile($VS_02_URL, "$DL_PATH/$VS_02_FILE_NAME") } +if (!(Test-Path "$DL_PATH/$PYTHON_FILE_NAME")) { + Write-Host "Downloading Python 3.4.4" + $client.DownloadFile($PYTHON_URL, "$DL_PATH/$PYTHON_FILE_NAME") +} diff --git a/scripts/th06vars.bat b/scripts/th06vars.bat index 33b37d17..c040dc23 100644 --- a/scripts/th06vars.bat +++ b/scripts/th06vars.bat @@ -2,8 +2,9 @@ @SET VS_BASE_PATH=%DEVENV_PREFIX%\Program Files\MICROSOFT VISUAL STUDIO .NET @SET MS_VC_PATH=%VS_BASE_PATH%\VC7 @SET DXSDK_DIR=%DEVENV_PREFIX%\mssdk +@SET PY_PATH=%DEVENV_PREFIX%\python -@SET PATH=%MS_VC_PATH%\Bin;%VS_BASE_PATH%\FrameworkSDK\Bin;%VS_BASE_PATH%\Common7\IDE;%PATH% +@SET PATH=%PY_PATH%;%MS_VC_PATH%\Bin;%VS_BASE_PATH%\FrameworkSDK\Bin;%VS_BASE_PATH%\Common7\IDE;%PATH% @SET INCLUDE=%DXSDK_DIR%\include;%MS_VC_PATH%\INCLUDE;%MS_VC_PATH%\PlatformSDK\include\prerelease;%MS_VC_PATH%\PlatformSDK\include;%MS_VC_PATH%\PlatformSDK\common\include\prerelease;%MS_VC_PATH%\PlatformSDK\common\include @SET LIB=%DXSDK_DIR%\lib;%MS_VC_PATH%\LIB;%MS_VC_PATH%\PlatformSDK\lib\prerelease;%MS_VC_PATH%\PlatformSDK\lib;%MS_VC_PATH%\PlatformSDK\common\lib\prerelease;%MS_VC_PATH%\PlatformSDK\common\lib;%MS_VC_PATH%\PlatformSDK\x86\lib diff --git a/src/i18n.hpp b/src/i18n.tpl similarity index 79% rename from src/i18n.hpp rename to src/i18n.tpl index 2a7fac61..96ae9097 100644 --- a/src/i18n.hpp +++ b/src/i18n.tpl @@ -6,22 +6,22 @@ // JP #define TH_JP_CONFIG_FILE "東方紅魔郷.cfg" #define TH_JP_WINDOW_TITLE "東方紅魔郷 〜 the Embodiment of Scarlet Devil" -#define TH_JP_ERR_ALREADY_RUNNING "二つは起動できません¥n" -#define TH_JP_ERR_D3D_ERR_COULD_NOT_CREATE_OBJ "Direct3D オブジェクトは何故か作成出来なかった¥n" -#define TH_JP_ERR_LOGGER_START "東方動作記録 --------------------------------------------- ¥n" -#define TH_JP_ERR_LOGGER_END "---------------------------------------------------------- ¥n" -#define TH_JP_ERR_NO_PAD_FOUND "使えるパッドが存在しないようです、残念¥n" -#define TH_JP_ERR_OPTION_CHANGED_RESTART "再起動を要するオプションが変更されたので再起動します¥n" +#define TH_JP_ERR_ALREADY_RUNNING "二つは起動できません\n" +#define TH_JP_ERR_D3D_ERR_COULD_NOT_CREATE_OBJ "Direct3D オブジェクトは何故か作成出来なかった\n" +#define TH_JP_ERR_LOGGER_START "東方動作記録 --------------------------------------------- \n" +#define TH_JP_ERR_LOGGER_END "---------------------------------------------------------- \n" +#define TH_JP_ERR_NO_PAD_FOUND "使えるパッドが存在しないようです、残念\n" +#define TH_JP_ERR_OPTION_CHANGED_RESTART "再起動を要するオプションが変更されたので再起動します\n" // EN #define TH_EN_CONFIG_FILE "th06.cfg" #define TH_EN_WINDOW_TITLE "Touhou Koumakyou 〜 the Embodiment of Scarlet Devil" -#define TH_EN_ERR_ALREADY_RUNNING "Touhou cannot be started¥n" -#define TH_EN_ERR_D3D_COULD_NOT_CREATE_OBJ "Direct3D object could not be created for some reason¥n" -#define TH_EN_ERR_LOGGER_START "Logger started --------------------------------------------- ¥n" -#define TH_EN_ERR_LOGGER_END "---------------------------------------------------------- ¥n" -#define TH_EN_ERR_NO_PAD_FOUND "Unfortunately, there doesn't seem to be a pad that can be used.¥n" -#define TH_EN_ERR_OPTION_CHANGED_RESTART "An option that requires a restart has been changed¥n" +#define TH_EN_ERR_ALREADY_RUNNING "Touhou cannot be started\n" +#define TH_EN_ERR_D3D_COULD_NOT_CREATE_OBJ "Direct3D object could not be created for some reason\n" +#define TH_EN_ERR_LOGGER_START "Logger started --------------------------------------------- \n" +#define TH_EN_ERR_LOGGER_END "---------------------------------------------------------- \n" +#define TH_EN_ERR_NO_PAD_FOUND "Unfortunately, there doesn't seem to be a pad that can be used.\n" +#define TH_EN_ERR_OPTION_CHANGED_RESTART "An option that requires a restart has been changed.\n" #define TH_CONCAT_HELPER(x, y) x##y From 411e6792d3911fb0a23b152fc4ac9e1afa6a372d Mon Sep 17 00:00:00 2001 From: roblabla Date: Fri, 29 Sep 2023 01:07:53 +0200 Subject: [PATCH 2/2] Fix typo in jp constant name --- src/i18n.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n.tpl b/src/i18n.tpl index 96ae9097..d89b4703 100644 --- a/src/i18n.tpl +++ b/src/i18n.tpl @@ -7,7 +7,7 @@ #define TH_JP_CONFIG_FILE "東方紅魔郷.cfg" #define TH_JP_WINDOW_TITLE "東方紅魔郷 〜 the Embodiment of Scarlet Devil" #define TH_JP_ERR_ALREADY_RUNNING "二つは起動できません\n" -#define TH_JP_ERR_D3D_ERR_COULD_NOT_CREATE_OBJ "Direct3D オブジェクトは何故か作成出来なかった\n" +#define TH_JP_ERR_D3D_COULD_NOT_CREATE_OBJ "Direct3D オブジェクトは何故か作成出来なかった\n" #define TH_JP_ERR_LOGGER_START "東方動作記録 --------------------------------------------- \n" #define TH_JP_ERR_LOGGER_END "---------------------------------------------------------- \n" #define TH_JP_ERR_NO_PAD_FOUND "使えるパッドが存在しないようです、残念\n"