diff options
Diffstat (limited to 'src/sdk')
-rw-r--r-- | src/sdk/console.h | 66 | ||||
-rw-r--r-- | src/sdk/console_win.cpp | 139 | ||||
-rw-r--r-- | src/sdk/main.cpp | 25 | ||||
-rw-r--r-- | src/sdk/sdk.pro | 3 | ||||
-rw-r--r-- | src/sdk/sdkapp.h | 4 |
5 files changed, 19 insertions, 218 deletions
diff --git a/src/sdk/console.h b/src/sdk/console.h deleted file mode 100644 index 378a37e60..000000000 --- a/src/sdk/console.h +++ /dev/null @@ -1,66 +0,0 @@ -/************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Installer Framework. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -**************************************************************************/ - -#ifndef CONSOLE_H -#define CONSOLE_H - -#include <QtGlobal> - -#ifdef Q_OS_WIN - -#include <fstream> -#include <iostream> - -class Console -{ -public: - Console(); - ~Console(); - -private: - bool parentConsole; - bool newConsoleCreated; - - std::ofstream m_newCout; - std::ofstream m_newCerr; - - std::streambuf* m_oldCout; - std::streambuf* m_oldCerr; -}; - -#else // Q_OS_WIN - -class Console -{ -public: - Console() {} -}; - -#endif // Q_OS_WIN - -#endif // CONSOLE_H diff --git a/src/sdk/console_win.cpp b/src/sdk/console_win.cpp deleted file mode 100644 index 978159612..000000000 --- a/src/sdk/console_win.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Installer Framework. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -**************************************************************************/ - -#include "console.h" - -# include <qt_windows.h> -# include <wincon.h> - - -# ifndef ENABLE_INSERT_MODE -# define ENABLE_INSERT_MODE 0x0020 -# endif - -# ifndef ENABLE_QUICK_EDIT_MODE -# define ENABLE_QUICK_EDIT_MODE 0x0040 -# endif - -# ifndef ENABLE_EXTENDED_FLAGS -# define ENABLE_EXTENDED_FLAGS 0x0080 -# endif - -static bool isRedirected(HANDLE stdHandle) -{ - if (stdHandle == nullptr) // launched from GUI - return false; - DWORD fileType = GetFileType(stdHandle); - if (fileType == FILE_TYPE_UNKNOWN) { - // launched from console, but no redirection - return false; - } - // redirected into file, pipe ... - return true; -} - -/** - * Redirects stdout, stderr output to console - * - * Console is a RAII class that ensures stdout, stderr output is visible - * for GUI applications on Windows. - * - * If the application is launched from the explorer, startup menu etc - * a new console window is created. - * - * If the application is launched from the console (cmd.exe), output is - * printed there. - * - * If the application is launched from the console, but stdout is redirected - * (e.g. into a file), Console does not interfere. - */ -Console::Console() : - m_oldCout(nullptr), - m_oldCerr(nullptr), - parentConsole(false), - newConsoleCreated(false) -{ - bool isCoutRedirected = isRedirected(GetStdHandle(STD_OUTPUT_HANDLE)); - bool isCerrRedirected = isRedirected(GetStdHandle(STD_ERROR_HANDLE)); - - if (!isCoutRedirected) { // verbose output only ends up in cout - // try to use parent console. else launch & set up new console - parentConsole = AttachConsole(ATTACH_PARENT_PROCESS); - if (!parentConsole) { - newConsoleCreated = true; - AllocConsole(); - HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); - if (handle != INVALID_HANDLE_VALUE) { - COORD largestConsoleWindowSize = GetLargestConsoleWindowSize(handle); - largestConsoleWindowSize.X -= 3; - largestConsoleWindowSize.Y = 5000; - SetConsoleScreenBufferSize(handle, largestConsoleWindowSize); - } - handle = GetStdHandle(STD_INPUT_HANDLE); - if (handle != INVALID_HANDLE_VALUE) - SetConsoleMode(handle, ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE - | ENABLE_EXTENDED_FLAGS); -# ifndef Q_CC_MINGW - HMENU systemMenu = GetSystemMenu(GetConsoleWindow(), FALSE); - if (systemMenu != nullptr) - RemoveMenu(systemMenu, SC_CLOSE, MF_BYCOMMAND); - DrawMenuBar(GetConsoleWindow()); -# endif - } - } - - if (!isCoutRedirected) { - m_oldCout = std::cout.rdbuf(); - m_newCout.open("CONOUT$"); - std::cout.rdbuf(m_newCout.rdbuf()); - } - - if (!isCerrRedirected) { - m_oldCerr = std::cerr.rdbuf(); - m_newCerr.open("CONOUT$"); - std::cerr.rdbuf(m_newCerr.rdbuf()); - } -} - -Console::~Console() -{ - if (parentConsole) { - // simulate enter key to switch to boot prompt - PostMessage(GetConsoleWindow(), WM_KEYDOWN, 0x0D, 0); - } else if (newConsoleCreated) { - system("PAUSE"); - } - - if (m_oldCerr) - std::cerr.rdbuf(m_oldCerr); - if (m_oldCout) - std::cout.rdbuf(m_oldCout); - - if (m_oldCout) - FreeConsole(); -} diff --git a/src/sdk/main.cpp b/src/sdk/main.cpp index 70214a9c5..8745541d7 100644 --- a/src/sdk/main.cpp +++ b/src/sdk/main.cpp @@ -26,7 +26,6 @@ ** **************************************************************************/ -#include "console.h" #include "constants.h" #include "commandlineparser.h" #include "installerbase.h" @@ -112,7 +111,6 @@ int main(int argc, char *argv[]) } const bool help = parser.isSet(CommandLineOptions::scHelpLong); if (help || parser.isSet(CommandLineOptions::scVersionLong) || !sanityCheck) { - Console c; QCoreApplication app(argc, argv); if (parser.isSet(CommandLineOptions::scVersionLong)) { @@ -170,7 +168,6 @@ int main(int argc, char *argv[]) SDKApp<QCoreApplication> app(argc, argv); if (!argumentsValid) { - Console c; std::cout << qPrintable(parser.helpText()) << std::endl; QString startServerStr = CommandLineOptions::scStartServerLong; std::cerr << "Wrong argument(s) for option --" << startServerStr.toStdString() << std::endl; @@ -195,8 +192,6 @@ int main(int argc, char *argv[]) } try { - QScopedPointer<Console> console; - // Check if any options requiring verbose output is set bool setVerbose = parser.isSet(CommandLineOptions::scVerboseLong); @@ -205,11 +200,9 @@ int main(int argc, char *argv[]) setVerbose = parser.positionalArguments().contains(option); } if (setVerbose) { - console.reset(new Console); QInstaller::setVerbose(true); } - // On Windows we need the console window from above, we are a GUI application. const QStringList unknownOptionNames = parser.unknownOptionNames(); if (!unknownOptionNames.isEmpty()) { const QString options = unknownOptionNames.join(QLatin1String(", ")); @@ -225,7 +218,6 @@ int main(int argc, char *argv[]) QNetworkProxyFactory::setUseSystemConfiguration(false); const SelfRestarter restarter(argc, argv); - if (parser.positionalArguments().contains(CommandLineOptions::scCheckUpdatesShort) || parser.positionalArguments().contains(CommandLineOptions::scCheckUpdatesLong)) { return CommandLineInterface(argc, argv).checkUpdates(); @@ -248,9 +240,22 @@ int main(int argc, char *argv[]) || parser.positionalArguments().contains(CommandLineOptions::scPurgeLong)){ return CommandLineInterface(argc, argv).removeInstallation(); } - if (QInstaller::isVerbose()) + if (QInstaller::isVerbose()) { std::cout << VERSION << std::endl << BUILDDATE << std::endl << SHA << std::endl; - + } else { +#ifdef Q_OS_WIN + // Check if installer is started from console. If so, restart the installer so it + // won't reserve the console handles. + DWORD procIDs[2]; + DWORD maxCount = 2; + DWORD result = GetConsoleProcessList((LPDWORD)procIDs, maxCount); + FreeConsole(); // Closes console in GUI version + if (result > 1) { + restarter.setRestartOnQuit(true); + return EXIT_FAILURE; + } +#endif + } return InstallerBase(argc, argv).run(); } catch (const QInstaller::Error &e) { diff --git a/src/sdk/sdk.pro b/src/sdk/sdk.pro index 426802892..d952d3462 100644 --- a/src/sdk/sdk.pro +++ b/src/sdk/sdk.pro @@ -98,7 +98,6 @@ HEADERS += \ tabcontroller.h \ installerbasecommons.h \ settingsdialog.h \ - console.h \ sdkapp.h \ commandlineinterface.h \ installerbase.h @@ -115,8 +114,6 @@ win32 { # Use our own manifest file CONFIG -= embed_manifest_exe RC_FILE = installerbase.rc - - SOURCES += console_win.cpp } macx:include(../../no_app_bundle.pri) diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h index c72ec60bb..145f4e7ea 100644 --- a/src/sdk/sdkapp.h +++ b/src/sdk/sdkapp.h @@ -291,6 +291,10 @@ public: return false; } } + + if (m_parser.isSet(CommandLineOptions::scMessageDefaultAnswer)) { + m_core->acceptMessageBoxDefaultButton(); + } return true; } |