Removes console from Windows release builds. (#1536)

This commit is contained in:
Kenix3 2022-09-20 23:23:47 -04:00 committed by GitHub
parent d83c6f1753
commit d628bafe29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 10 deletions

View File

@ -31,6 +31,8 @@ cd Shipwright
# Setup cmake project # Setup cmake project
& 'C:\Program Files\CMake\bin\cmake' -S . -B "build/x64" -G "Visual Studio 17 2022" -T v142 -A x64 # -DCMAKE_BUILD_TYPE:STRING=Release (if you're packaging) & 'C:\Program Files\CMake\bin\cmake' -S . -B "build/x64" -G "Visual Studio 17 2022" -T v142 -A x64 # -DCMAKE_BUILD_TYPE:STRING=Release (if you're packaging)
# or for VS2019
& 'C:\Program Files\CMake\bin\cmake' -S . -B "build/x64" -G "Visual Studio 16 2019" -T v142 -A x64
# Extract assets & generate OTR (run this anytime you need to regenerate OTR) # Extract assets & generate OTR (run this anytime you need to regenerate OTR)
& 'C:\Program Files\CMake\bin\cmake.exe' --build .\build\x64 --target ExtractAssets # --config Release (if you're packaging) & 'C:\Program Files\CMake\bin\cmake.exe' --build .\build\x64 --target ExtractAssets # --config Release (if you're packaging)
# Compile project # Compile project

View File

@ -13,6 +13,7 @@
#include "Blob.h" #include "Blob.h"
#include "Matrix.h" #include "Matrix.h"
#include "Hooks.h" #include "Hooks.h"
#include <string>
#include "Lib/Fast3D/gfx_pc.h" #include "Lib/Fast3D/gfx_pc.h"
#include "Lib/Fast3D/gfx_sdl.h" #include "Lib/Fast3D/gfx_sdl.h"
#include "Lib/Fast3D/gfx_dxgi.h" #include "Lib/Fast3D/gfx_dxgi.h"
@ -500,12 +501,38 @@ namespace Ship {
std::vector<spdlog::sink_ptr> Sinks; std::vector<spdlog::sink_ptr> Sinks;
auto SohConsoleSink = std::make_shared<spdlog::sinks::soh_sink_mt>(); auto SohConsoleSink = std::make_shared<spdlog::sinks::soh_sink_mt>();
SohConsoleSink->set_level(spdlog::level::trace); //SohConsoleSink->set_level(spdlog::level::trace);
Sinks.push_back(SohConsoleSink); Sinks.push_back(SohConsoleSink);
#if (!defined(_WIN32) && !defined(__WIIU__)) || defined(_DEBUG) #if (!defined(_WIN32) && !defined(__WIIU__)) || defined(_DEBUG)
#if defined(_DEBUG) && defined(_WIN32)
if (AllocConsole() == 0) {
throw std::system_error(GetLastError(), std::generic_category(), "Failed to create debug console");
}
SetConsoleOutputCP(CP_UTF8);
FILE* fDummy;
freopen_s(&fDummy, "CONOUT$", "w", stdout);
freopen_s(&fDummy, "CONOUT$", "w", stderr);
freopen_s(&fDummy, "CONIN$", "r", stdin);
std::cout.clear();
std::clog.clear();
std::cerr.clear();
std::cin.clear();
HANDLE hConOut = CreateFile(_T("CONOUT$"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hConIn = CreateFile(_T("CONIN$"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
SetStdHandle(STD_OUTPUT_HANDLE, hConOut);
SetStdHandle(STD_ERROR_HANDLE, hConOut);
SetStdHandle(STD_INPUT_HANDLE, hConIn);
std::wcout.clear();
std::wclog.clear();
std::wcerr.clear();
std::wcin.clear();
#endif
auto ConsoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>(); auto ConsoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
ConsoleSink->set_level(spdlog::level::trace); //ConsoleSink->set_level(spdlog::level::trace);
Sinks.push_back(ConsoleSink); Sinks.push_back(ConsoleSink);
#endif #endif

View File

@ -1695,7 +1695,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
"NDEBUG" "NDEBUG"
">" ">"
"INCLUDE_GAME_PRINTF;" "INCLUDE_GAME_PRINTF;"
"_CONSOLE;"
"UNICODE;" "UNICODE;"
"_UNICODE" "_UNICODE"
STORMLIB_NO_AUTO_LINK STORMLIB_NO_AUTO_LINK
@ -1710,11 +1709,10 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
"ENABLE_OPENGL" "ENABLE_OPENGL"
">" ">"
"$<$<CONFIG:Release>:" "$<$<CONFIG:Release>:"
"INCLUDE_GAME_PRINTF;"
"NDEBUG;" "NDEBUG;"
">" ">"
"INCLUDE_GAME_PRINTF;"
"WIN32;" "WIN32;"
"_CONSOLE;"
"UNICODE;" "UNICODE;"
"_UNICODE" "_UNICODE"
STORMLIB_NO_AUTO_LINK STORMLIB_NO_AUTO_LINK
@ -1723,7 +1721,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
target_compile_definitions(${PROJECT_NAME} PRIVATE target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:" "$<$<CONFIG:Debug>:"
"_DEBUG" "_DEBUG"
">" ">"
"$<$<CONFIG:Release>:" "$<$<CONFIG:Release>:"
"NDEBUG" "NDEBUG"
@ -1736,7 +1734,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
target_compile_definitions(${PROJECT_NAME} PRIVATE target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:" "$<$<CONFIG:Debug>:"
"_DEBUG" "_DEBUG"
">" ">"
"$<$<CONFIG:Release>:" "$<$<CONFIG:Release>:"
"NDEBUG" "NDEBUG"
@ -1799,7 +1797,7 @@ if(MSVC)
/INCREMENTAL:NO /INCREMENTAL:NO
> >
/DEBUG; /DEBUG;
/SUBSYSTEM:CONSOLE; /SUBSYSTEM:WINDOWS;
/FORCE:MULTIPLE /FORCE:MULTIPLE
) )
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
@ -1814,7 +1812,7 @@ if(MSVC)
/FORCE:MULTIPLE /FORCE:MULTIPLE
> >
/DEBUG; /DEBUG;
/SUBSYSTEM:CONSOLE /SUBSYSTEM:WINDOWS
) )
endif() endif()
endif() endif()

View File

@ -12,7 +12,7 @@ extern "C"
#include "../../libultraship/libultraship/luslog.h" #include "../../libultraship/libultraship/luslog.h"
#include <soh/Enhancements/item-tables/ItemTableTypes.h> #include <soh/Enhancements/item-tables/ItemTableTypes.h>
#if defined(INCLUDE_GAME_PRINTF) && !defined(NDEBUG) #if defined(INCLUDE_GAME_PRINTF) && defined(_DEBUG)
#define osSyncPrintf(fmt, ...) lusprintf(__FILE__, __LINE__, 0, fmt, __VA_ARGS__) #define osSyncPrintf(fmt, ...) lusprintf(__FILE__, __LINE__, 0, fmt, __VA_ARGS__)
#else #else
#define osSyncPrintf(fmt, ...) osSyncPrintfUnused(fmt, ##__VA_ARGS__) #define osSyncPrintf(fmt, ...) osSyncPrintfUnused(fmt, ##__VA_ARGS__)

View File

@ -38,7 +38,11 @@ void Main_LogSystemHeap(void) {
osSyncPrintf(VT_RST); osSyncPrintf(VT_RST);
} }
#ifdef _WIN32
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow)
#else
int main(int argc, char** argv) int main(int argc, char** argv)
#endif
{ {
#ifdef __linux__ #ifdef __linux__
SetupHandlerLinux(); SetupHandlerLinux();
@ -49,6 +53,7 @@ int main(int argc, char** argv)
GameConsole_Init(); GameConsole_Init();
InitOTR(); InitOTR();
BootCommands_Init(); BootCommands_Init();
Main(0); Main(0);
DeinitOTR(); DeinitOTR();
return 0; return 0;