From 0f936f39d8a10779d1220dc54ddc13549da8b45d Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 29 May 2017 12:20:30 +0300 Subject: [PATCH 1/3] Rewrote directory creation function for Windows Previous implementation had several security issues https://forum.zdoom.org/viewtopic.php?t=56622 --- src/cmdlib.cpp | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/src/cmdlib.cpp b/src/cmdlib.cpp index 7013c6a60b..f667610c0b 100644 --- a/src/cmdlib.cpp +++ b/src/cmdlib.cpp @@ -477,16 +477,45 @@ const char *myasctime () void DoCreatePath(const char *fn) { char drive[_MAX_DRIVE]; - char path[PATH_MAX]; - char p[PATH_MAX]; - int i; + char dir[_MAX_DIR]; + _splitpath_s(fn, drive, sizeof drive, dir, sizeof dir, nullptr, 0, nullptr, 0); - _splitpath(fn,drive,path,NULL,NULL); - _makepath(p,drive,path,NULL,NULL); - i=(int)strlen(p); - if (p[i-1]=='/' || p[i-1]=='\\') p[i-1]=0; - if (*path) DoCreatePath(p); - _mkdir(p); + if ('\0' == *dir) + { + // Root/current/parent directory always exists + return; + } + + char path[PATH_MAX]; + _makepath_s(path, sizeof path, drive, dir, nullptr, nullptr); + + if ('\0' == *path) + { + // No need to process empty relative path + return; + } + + // Remove trailing path separator(s) + for (size_t i = strlen(path); 0 != i; --i) + { + char& lastchar = path[i - 1]; + + if ('/' == lastchar || '\\' == lastchar) + { + lastchar = '\0'; + } + else + { + break; + } + } + + // Create all directories for given path + if ('\0' != *path) + { + DoCreatePath(path); + _mkdir(path); + } } void CreatePath(const char *fn) From 3b61be3145c3d7196c10fe1f8eb89cff32234ef5 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 29 May 2017 14:46:56 +0300 Subject: [PATCH 2/3] Removed dependency on dxguid library It's impossible to use VS2017 with XP compatible toolset otherwise --- src/CMakeLists.txt | 12 ------------ src/win32/win32video.cpp | 4 +++- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 387d6855f0..8a9b2aa87d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,7 +60,6 @@ if( WIN32 ) ( MSVC15 AND NOT CMAKE_GENERATOR_TOOLSET STREQUAL "v141_xp" ) ) # For VS 2017. # for modern Windows SDKs the DirectX headers should be available by default. set( DX_dinput8_LIBRARY dinput8 ) - set( DX_dxguid_LIBRARY dxguid ) else() find_path( D3D_INCLUDE_DIR d3d9.h @@ -97,9 +96,6 @@ if( WIN32 ) find_library( DX_dinput8_LIBRARY dinput8 PATHS ENV DXSDK_DIR PATH_SUFFIXES Lib Lib/${XBITS} ) - find_library( DX_dxguid_LIBRARY dxguid - PATHS ENV DXSDK_DIR - PATH_SUFFIXES Lib Lib/${XBITS} ) # Modern versions of the Windows SDK include dinput8.lib. Unfortunately, # CMake cannot find these libraries via find_library. @@ -108,11 +104,6 @@ if( WIN32 ) set( DX_dinput8_LIBRARY dinput8 ) endif() - # Modern versions of the Windows SDK do NOT include dxguid.lib. Its contents - # were moved to dinput8.lib. - if( NOT DX_dxguid_LIBRARY ) - message( STATUS "Could not find dxguid.lib. Build may fail on old Windows SDKs.") - endif() endif() set( ZDOOM_LIBS @@ -133,9 +124,6 @@ if( WIN32 ) set( ZDOOM_LIBS ${ZDOOM_LIBS} DelayImp ) endif() - if( DX_dxguid_LIBRARY ) - list( APPEND ZDOOM_LIBS "${DX_dxguid_LIBRARY}" ) - endif() else() if( APPLE ) set( NO_GTK ON ) diff --git a/src/win32/win32video.cpp b/src/win32/win32video.cpp index 93da57c69f..0546863cb6 100644 --- a/src/win32/win32video.cpp +++ b/src/win32/win32video.cpp @@ -284,7 +284,9 @@ void Win32Video::InitDDraw () if (FAILED(dderr)) I_FatalError ("Could not create DirectDraw object: %08lx", dderr); - dderr = ddraw1->QueryInterface (IID_IDirectDraw2, (LPVOID*)&DDraw); + static const GUID IDIRECTDRAW2_GUID = { 0xB3A6F3E0, 0x2B43, 0x11CF, 0xA2, 0xDE, 0x00, 0xAA, 0x00, 0xB9, 0x33, 0x56 }; + + dderr = ddraw1->QueryInterface (IDIRECTDRAW2_GUID, (LPVOID*)&DDraw); if (FAILED(dderr)) { ddraw1->Release (); From 7e7e1ff12e22921549fe8b479ad5c76132e83e12 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 29 May 2017 14:50:39 +0300 Subject: [PATCH 3/3] Added VS2017 Release targets to AppVeyor configuration Removed VS2015 Win32 Debug target to speedup build process --- .appveyor.yml | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 48b51af0b1..457f0883c8 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -6,29 +6,34 @@ branches: clone_depth: 10 -os: Visual Studio 2015 +environment: + matrix: + - GENERATOR: "Visual Studio 14 2015" + CONFIGURATION: Release + TOOLSET: v140_xp + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + - GENERATOR: "Visual Studio 14 2015 Win64" + CONFIGURATION: Release + TOOLSET: v140_xp + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + - GENERATOR: "Visual Studio 15 2017" + CONFIGURATION: Release + TOOLSET: v141_xp + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2017" + - GENERATOR: "Visual Studio 15 2017 Win64" + CONFIGURATION: Release + TOOLSET: v141_xp + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2017" + - GENERATOR: "Visual Studio 14 2015 Win64" + CONFIGURATION: Debug + TOOLSET: v140 + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" -platform: - - Win32 - - x64 - -configuration: - - Debug - - Release - -before_build: +build_script: - md build - cd build - - if "%PLATFORM%"=="Win32" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015 - - if "%PLATFORM%"=="x64" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015 Win64 - - cmake -G "%CMAKE_GENERATOR_NAME%" -T "v140_xp" - -DCMAKE_BUILD_TYPE="%CONFIGURATION%" - .. - -build: - project: build\GZDoom.sln - parallel: true - verbosity: minimal + - cmake -G "%GENERATOR%" -T "%TOOLSET%" .. + - cmake --build . --config "%CONFIGURATION%" after_build: - set OUTPUT_DIR=%APPVEYOR_BUILD_FOLDER%\build\%CONFIGURATION%\