mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
Revert "[Backport release-10.x] refactor(console): attach console early" (#5013)
This commit is contained in:
commit
4898f25e5f
10 changed files with 84 additions and 79 deletions
|
|
@ -158,6 +158,7 @@
|
|||
#endif
|
||||
#include <windows.h>
|
||||
#include <QStyleHints>
|
||||
#include "console/WindowsConsole.h"
|
||||
#endif
|
||||
|
||||
#include "console/Console.h"
|
||||
|
|
@ -291,9 +292,21 @@ std::tuple<QDateTime, QString, QString, QString, QString> read_lock_File(const Q
|
|||
|
||||
Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
||||
{
|
||||
#if defined Q_OS_WIN32
|
||||
// attach the parent console if stdout not already captured
|
||||
if (AttachWindowsConsole()) {
|
||||
consoleAttached = true;
|
||||
if (auto err = EnableAnsiSupport(); !err) {
|
||||
isANSIColorConsole = true;
|
||||
} else {
|
||||
std::cout << "Error setting up ansi console" << err.message() << std::endl;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (console::isConsole()) {
|
||||
isANSIColorConsole = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
setOrganizationName(BuildConfig.LAUNCHER_NAME);
|
||||
setOrganizationDomain(BuildConfig.LAUNCHER_DOMAIN);
|
||||
|
|
@ -1405,6 +1418,16 @@ Application::~Application()
|
|||
{
|
||||
// Shut down logger by setting the logger function to nothing
|
||||
qInstallMessageHandler(nullptr);
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
// Detach from Windows console
|
||||
if (consoleAttached) {
|
||||
fclose(stdout);
|
||||
fclose(stdin);
|
||||
fclose(stderr);
|
||||
FreeConsole();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Application::messageReceived(const QByteArray& message)
|
||||
|
|
|
|||
|
|
@ -271,6 +271,11 @@ class Application : public QApplication {
|
|||
Qt::ApplicationState m_prevAppState = Qt::ApplicationInactive;
|
||||
#endif
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
// used on Windows to attach the standard IO streams
|
||||
bool consoleAttached = false;
|
||||
#endif
|
||||
|
||||
// FIXME: attach to instances instead.
|
||||
struct InstanceXtras {
|
||||
InstanceWindow* window = nullptr;
|
||||
|
|
|
|||
|
|
@ -24,16 +24,12 @@
|
|||
#endif
|
||||
#include <windows.h>
|
||||
|
||||
#include <consoleapi.h>
|
||||
#include <fcntl.h>
|
||||
#include <fileapi.h>
|
||||
#include <io.h>
|
||||
#include <stdio.h>
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
|
||||
namespace console {
|
||||
|
||||
void RedirectHandle(DWORD handle, FILE* stream, const char* mode)
|
||||
{
|
||||
HANDLE stdHandle = GetStdHandle(handle);
|
||||
|
|
@ -161,31 +157,3 @@ std::error_code EnableAnsiSupport()
|
|||
|
||||
return {};
|
||||
}
|
||||
|
||||
void FreeWindowsConsole()
|
||||
{
|
||||
fclose(stdout);
|
||||
fclose(stdin);
|
||||
fclose(stderr);
|
||||
FreeConsole();
|
||||
}
|
||||
|
||||
WindowsConsoleGuard::WindowsConsoleGuard() : m_consoleAttached(false)
|
||||
{
|
||||
if (console::AttachWindowsConsole()) {
|
||||
m_consoleAttached = true;
|
||||
if (auto err = console::EnableAnsiSupport(); err) {
|
||||
std::cout << "Error setting up ansi console" << err.message() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WindowsConsoleGuard::~WindowsConsoleGuard()
|
||||
{
|
||||
// Detach from Windows console
|
||||
if (m_consoleAttached) {
|
||||
console::FreeWindowsConsole();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace console
|
||||
|
|
|
|||
|
|
@ -21,24 +21,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#include <system_error>
|
||||
namespace console {
|
||||
|
||||
void BindCrtHandlesToStdHandles(bool bindStdIn, bool bindStdOut, bool bindStdErr);
|
||||
bool AttachWindowsConsole();
|
||||
std::error_code EnableAnsiSupport();
|
||||
void FreeWindowsConsole();
|
||||
|
||||
class WindowsConsoleGuard {
|
||||
public:
|
||||
WindowsConsoleGuard();
|
||||
~WindowsConsoleGuard();
|
||||
|
||||
private:
|
||||
bool m_consoleAttached;
|
||||
};
|
||||
|
||||
} // namespace console
|
||||
|
|
|
|||
|
|
@ -34,11 +34,26 @@
|
|||
|
||||
#include <DesktopServices.h>
|
||||
|
||||
#include <sys.h>
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include "console/WindowsConsole.h"
|
||||
#endif
|
||||
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
FileLinkApp::FileLinkApp(int& argc, char** argv) : QCoreApplication(argc, argv), socket(new QLocalSocket(this))
|
||||
{
|
||||
#if defined Q_OS_WIN32
|
||||
// attach the parent console
|
||||
if (AttachWindowsConsole()) {
|
||||
consoleAttached = true;
|
||||
}
|
||||
#endif
|
||||
setOrganizationName(BuildConfig.LAUNCHER_NAME);
|
||||
setOrganizationDomain(BuildConfig.LAUNCHER_DOMAIN);
|
||||
setApplicationName(BuildConfig.LAUNCHER_NAME + "FileLink");
|
||||
|
|
@ -221,4 +236,13 @@ FileLinkApp::~FileLinkApp()
|
|||
qDebug() << "link program shutting down";
|
||||
// Shut down logger by setting the logger function to nothing
|
||||
qInstallMessageHandler(nullptr);
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
// Detach from Windows console
|
||||
if (consoleAttached) {
|
||||
fclose(stdout);
|
||||
fclose(stdin);
|
||||
fclose(stderr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,4 +64,8 @@ class FileLinkApp : public QCoreApplication {
|
|||
QList<FS::LinkPair> m_links_to_make;
|
||||
QList<FS::LinkResult> m_path_results;
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
// used on Windows to attach the standard IO streams
|
||||
bool consoleAttached = false;
|
||||
#endif
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,17 +22,8 @@
|
|||
|
||||
#include "FileLink.h"
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
#include "console/WindowsConsole.h"
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#if defined Q_OS_WIN32
|
||||
// attach the parent console
|
||||
console::WindowsConsoleGuard _consoleGuard;
|
||||
#endif
|
||||
|
||||
FileLinkApp ldh(argc, argv);
|
||||
|
||||
switch (ldh.status()) {
|
||||
|
|
|
|||
|
|
@ -33,23 +33,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
#include "console/WindowsConsole.h"
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#if defined Q_OS_WIN32
|
||||
// used on Windows to attach the standard IO streams
|
||||
console::WindowsConsoleGuard _consoleGuard;
|
||||
#endif
|
||||
|
||||
// initialize Qt
|
||||
Application app(argc, argv);
|
||||
|
||||
switch (app.status()) {
|
||||
case Application::StartingUp:
|
||||
case Application::Initialized: {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,16 @@
|
|||
#include <QProgressDialog>
|
||||
#include <memory>
|
||||
|
||||
#include <sys.h>
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include "console/WindowsConsole.h"
|
||||
#endif
|
||||
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
|
@ -76,6 +86,12 @@ void appDebugOutput(QtMsgType type, const QMessageLogContext& context, const QSt
|
|||
|
||||
PrismUpdaterApp::PrismUpdaterApp(int& argc, char** argv) : QApplication(argc, argv)
|
||||
{
|
||||
#if defined Q_OS_WIN32
|
||||
// attach the parent console if stdout not already captured
|
||||
if (AttachWindowsConsole()) {
|
||||
consoleAttached = true;
|
||||
}
|
||||
#endif
|
||||
setOrganizationName(BuildConfig.LAUNCHER_NAME);
|
||||
setOrganizationDomain(BuildConfig.LAUNCHER_DOMAIN);
|
||||
setApplicationName(BuildConfig.LAUNCHER_NAME + "Updater");
|
||||
|
|
@ -366,6 +382,16 @@ PrismUpdaterApp::~PrismUpdaterApp()
|
|||
qDebug() << "updater shutting down";
|
||||
// Shut down logger by setting the logger function to nothing
|
||||
qInstallMessageHandler(nullptr);
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
// Detach from Windows console
|
||||
if (consoleAttached) {
|
||||
fclose(stdout);
|
||||
fclose(stdin);
|
||||
fclose(stderr);
|
||||
FreeConsole();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PrismUpdaterApp::fail(const QString& reason)
|
||||
|
|
|
|||
|
|
@ -21,18 +21,8 @@
|
|||
*/
|
||||
|
||||
#include "PrismUpdater.h"
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
#include "console/WindowsConsole.h"
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#if defined Q_OS_WIN32
|
||||
// attach the parent console if stdout not already captured
|
||||
console::WindowsConsoleGuard _consoleGuard;
|
||||
#endif
|
||||
|
||||
PrismUpdaterApp wUpApp(argc, argv);
|
||||
|
||||
switch (wUpApp.status()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue