Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Windows console window #860

Merged
merged 7 commits into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
}
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
18 changes: 18 additions & 0 deletions cmake/nsis/template/NSIS.template.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions cmake/packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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\\\" ")

Expand Down
1 change: 1 addition & 0 deletions src/hyperiond/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ endif()
find_package(Qt5Widgets REQUIRED)

add_executable(hyperiond
console.h
hyperiond.h
systray.h
hyperiond.cpp
Expand Down
34 changes: 34 additions & 0 deletions src/hyperiond/console.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <Windows.h>

// 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();
*/
}
20 changes: 13 additions & 7 deletions src/hyperiond/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#endif
// getpid()
#ifdef _WIN32
#include "console.h"
#include <process.h>
//#include <Windows.h>
#else
#include <unistd.h>
#endif
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -195,12 +191,22 @@ int main(int argc, char** argv)
BooleanOption & silentOption = parser.add<BooleanOption> ('s', "silent", "do not print any outputs");
BooleanOption & verboseOption = parser.add<BooleanOption> ('v', "verbose", "Increase verbosity");
BooleanOption & debugOption = parser.add<BooleanOption> ('d', "debug", "Show debug messages");
parser.add<BooleanOption> (0x0, "desktop", "show systray on desktop");
parser.add<BooleanOption> (0x0, "service", "force hyperion to start as console service");
#ifdef WIN32
BooleanOption & consoleOption = parser.add<BooleanOption> ('c', "console", "Open a console window to view log output");
#endif
parser.add<BooleanOption> (0x0, "desktop", "show systray on desktop");
parser.add<BooleanOption> (0x0, "service", "force hyperion to start as console service");
Option & exportEfxOption = parser.add<Option> (0x0, "export-effects", "export effects to given path");

parser.process(*qApp);

#ifdef WIN32
if (parser.isSet(consoleOption))
{
CreateConsole();
}
#endif

int logLevelCheck = 0;
if (parser.isSet(silentOption))
{
Expand Down