From de9ece5139ca4823cad7397cb9f88907bb882bed Mon Sep 17 00:00:00 2001 From: brindosch Date: Sun, 12 Jul 2020 09:18:40 +0200 Subject: [PATCH] feat: Windows console window (#860) * Add console option for windows * add changelog entry * chnagelog * update changelog * Daran solls nicht fehlen * nsis: Install vcredist * Disable vc_redist detection --- .vscode/tasks.json | 4 ++-- CHANGELOG.md | 2 ++ README.md | 3 +++ cmake/nsis/template/NSIS.template.in | 18 +++++++++++++++ cmake/packages.cmake | 8 ++++--- src/hyperiond/CMakeLists.txt | 1 + src/hyperiond/console.h | 34 ++++++++++++++++++++++++++++ src/hyperiond/main.cpp | 20 ++++++++++------ 8 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 src/hyperiond/console.h diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 6bd2346e..f0d5e0ae 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -106,7 +106,7 @@ "type": "shell", "command": "${workspaceFolder}/build/bin/hyperiond -d", "windows": { - "command": "${workspaceFolder}/build/bin/Debug/hyperiond" + "command": "${workspaceFolder}/build/bin/Debug/hyperiond -d -c" }, "group": "build" }, @@ -115,7 +115,7 @@ "type": "shell", "command": "${workspaceFolder}/build/bin/hyperiond -d", "windows": { - "command": "${workspaceFolder}/build/bin/Release/hyperiond" + "command": "${workspaceFolder}/build/bin/Release/hyperiond -d -c" }, "group": "build" } diff --git a/CHANGELOG.md b/CHANGELOG.md index eb1b5fda..569a6a83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - An option to reset (delete) the database for the commandline has been added (#820) - Improve language selection usability (#812) - readded V4L2 Input method from old Hyperion (#825) +- Windows: Start Hyperion with a console window `hyperiond -c` (Or new start menu entry) (#860) + ### Changed - Updated dependency rpi_ws281x to latest upstream (#820) - Updated websocket-extensions (#826) diff --git a/README.md b/README.md index 8d2749e6..e5065dad 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,9 @@ Covers these topics (WorkInProgress) [![Visit Documentation](https://img.shields.io/website?down_message=offline&label=Documentation%20%20&up_message=online&url=https%3A%2F%2Fdocs.hyperion-project.org)](https://docs.hyperion-project.org) +## Changelog +Released and unreleased changes at [Changelog.md](CHANGELOG.md) + ## Building See [CompileHowto](CompileHowto.md) and [CrossCompileHowto](CrossCompileHowto.md). diff --git a/cmake/nsis/template/NSIS.template.in b/cmake/nsis/template/NSIS.template.in index 660bfa3f..b014a44d 100644 --- a/cmake/nsis/template/NSIS.template.in +++ b/cmake/nsis/template/NSIS.template.in @@ -724,6 +724,24 @@ Section "-Core installation" @CPACK_NSIS_EXTRA_INSTALL_COMMANDS@ +; Custom vcredist install script, detection is not reliable +;ReadRegStr $1 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64" "Bld" +;DetailPrint "VCREDIS KEY: $1" +; +;IntCmp $1 28508 Equal Val1Less Val1More +;Equal: +; DetailPrint "$1 = 28508 " +; Goto End +;Val1Less: +; DetailPrint "$1 < 28508 " +; Goto End +;Val1More: +; DetailPrint "$1 > 28508 " +; Goto End +;End: + +ExecWait '"$INSTDIR\bin\vc_redist.x64.exe" /install /quiet' + SectionEnd Section "-Add to path" diff --git a/cmake/packages.cmake b/cmake/packages.cmake index 9c5fdaa4..687c6ed9 100644 --- a/cmake/packages.cmake +++ b/cmake/packages.cmake @@ -101,14 +101,16 @@ SET ( CPACK_NSIS_PACKAGE_NAME "Hyperion" ) SET ( CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\hyperiond.exe") SET ( CPACK_NSIS_HELP_LINK "https://www.hyperion-project.org") SET ( CPACK_NSIS_URL_INFO_ABOUT "https://www.hyperion-project.org") -# hyperiond startmenu link +# additional hyperiond startmenu link, won't be created if the user disables startmenu links +SET ( CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Hyperion (Console).lnk' '$INSTDIR\\\\bin\\\\hyperiond.exe' '-d -c'") +SET ( CPACK_NSIS_DELETE_ICONS_EXTRA "Delete '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Hyperion (Console).lnk'") + + #SET ( CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Hyperion.lnk' '$INSTDIR\\\\bin\\\\hyperiond.exe'") #SET ( CPACK_NSIS_DELETE_ICONS_EXTRA "Delete '$SMPROGRAMS\\\\$START_MENU\\\\Hyperion.lnk'") # hyperiond desktop link #SET ( CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$DESKTOP\\\\Hyperion.lnk' '$INSTDIR\\\\bin\\\\hyperiond.exe' ") #SET ( CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "Delete '$DESKTOP\\\\Hyperion.lnk' ") - -# With cli args: SET ( CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Hyperion (Debug).lnk' '$INSTDIR\\\\bin\\\\hyperiond.exe' '-d'") #SET ( CPACK_NSIS_EXTRA_INSTALL_COMMANDS "CreateShortCut \\\"$DESKTOP\\\\Hyperion.lnk\\\" \\\"$INSTDIR\\\\bin\\\\hyperiond.exe\\\" ") #SET ( CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "Delete \\\"$DESKTOP\\\\Hyperion.lnk\\\" ") diff --git a/src/hyperiond/CMakeLists.txt b/src/hyperiond/CMakeLists.txt index 5ec69820..e68995f7 100644 --- a/src/hyperiond/CMakeLists.txt +++ b/src/hyperiond/CMakeLists.txt @@ -9,6 +9,7 @@ endif() find_package(Qt5Widgets REQUIRED) add_executable(hyperiond + console.h hyperiond.h systray.h hyperiond.cpp diff --git a/src/hyperiond/console.h b/src/hyperiond/console.h new file mode 100644 index 00000000..52a76687 --- /dev/null +++ b/src/hyperiond/console.h @@ -0,0 +1,34 @@ +#include + +// https://stackoverflow.com/a/57241985 +void CreateConsole() +{ + if (!AllocConsole()) { + // Add some error handling here. + // You can call GetLastError() to get more info about the error. + return; + } + + // std::cout, std::clog, std::cerr, std::cin + 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(); + + + /*// std::wcout, std::wclog, std::wcerr, std::wcin + 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(); + */ +} diff --git a/src/hyperiond/main.cpp b/src/hyperiond/main.cpp index 99c099e6..80b40af8 100644 --- a/src/hyperiond/main.cpp +++ b/src/hyperiond/main.cpp @@ -9,8 +9,8 @@ #endif // getpid() #ifdef _WIN32 +#include "console.h" #include -//#include #else #include #endif @@ -143,10 +143,6 @@ int main(int argc, char** argv) { #ifndef _WIN32 setenv("AVAHI_COMPAT_NOWARN", "1", 1); -#endif -#ifdef _WIN32 - // We can get a console window also in app gui mode conditional - //AllocConsole(); #endif // initialize main logger and set global log level Logger *log = Logger::getInstance("MAIN"); @@ -195,12 +191,22 @@ int main(int argc, char** argv) BooleanOption & silentOption = parser.add ('s', "silent", "do not print any outputs"); BooleanOption & verboseOption = parser.add ('v', "verbose", "Increase verbosity"); BooleanOption & debugOption = parser.add ('d', "debug", "Show debug messages"); - parser.add (0x0, "desktop", "show systray on desktop"); - parser.add (0x0, "service", "force hyperion to start as console service"); +#ifdef WIN32 + BooleanOption & consoleOption = parser.add ('c', "console", "Open a console window to view log output"); +#endif + parser.add (0x0, "desktop", "show systray on desktop"); + parser.add (0x0, "service", "force hyperion to start as console service"); Option & exportEfxOption = parser.add