mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-06 06:51:26 +12:00
Move freopen to console.h
This commit is contained in:
parent
dfec577417
commit
16f006362e
7 changed files with 88 additions and 62 deletions
|
@ -42,6 +42,7 @@ target_include_directories(rpcs3_emu
|
|||
# Utilities
|
||||
target_sources(rpcs3_emu PRIVATE
|
||||
../util/atomic.cpp
|
||||
../util/console.cpp
|
||||
../util/media_utils.cpp
|
||||
../util/video_provider.cpp
|
||||
../util/logs.cpp
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "headless_application.h"
|
||||
#include "Utilities/sema.h"
|
||||
#include "Utilities/date_time.h"
|
||||
#include "util/console.h"
|
||||
#include "Crypto/decrypt_binaries.h"
|
||||
#ifdef _WIN32
|
||||
#include "module_verifier.hpp"
|
||||
|
@ -151,10 +152,8 @@ LOG_CHANNEL(q_debug, "QDEBUG");
|
|||
|
||||
if (s_headless)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
|
||||
[[maybe_unused]] const auto con_out = freopen("conout$", "w", stderr);
|
||||
#endif
|
||||
utils::attach_console(utils::console_stream::std_err, true);
|
||||
|
||||
std::cerr << fmt::format("RPCS3: %s\n", text);
|
||||
#ifdef __linux__
|
||||
jit_announce(0, 0, "");
|
||||
|
@ -274,11 +273,9 @@ struct fatal_error_listener final : logs::listener
|
|||
_msg += text;
|
||||
_msg += '\n';
|
||||
|
||||
#ifdef _WIN32
|
||||
// If launched from CMD
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
||||
[[maybe_unused]] const auto con_out = freopen("CONOUT$", "w", stderr);
|
||||
#endif
|
||||
utils::attach_console(utils::console_stream::std_err, false);
|
||||
|
||||
// Output to error stream as is
|
||||
std::cerr << _msg;
|
||||
|
||||
|
@ -727,13 +724,8 @@ int main(int argc, char** argv)
|
|||
|
||||
if (parser.isSet(codec_option))
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
|
||||
{
|
||||
[[maybe_unused]] const auto con_out = freopen("CONOUT$", "w", stdout);
|
||||
[[maybe_unused]] const auto con_err = freopen("CONOUT$", "w", stderr);
|
||||
}
|
||||
#endif
|
||||
utils::attach_console(utils::console_stream::std_out | utils::console_stream::std_err, true);
|
||||
|
||||
for (const utils::ffmpeg_codec& codec : utils::list_ffmpeg_decoders())
|
||||
{
|
||||
fprintf(stdout, "Found ffmpeg decoder: %s (%d, %s)\n", codec.name.c_str(), codec.codec_id, codec.long_name.c_str());
|
||||
|
@ -750,18 +742,16 @@ int main(int argc, char** argv)
|
|||
#ifdef _WIN32
|
||||
if (parser.isSet(arg_stdout) || parser.isSet(arg_stderr))
|
||||
{
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
|
||||
{
|
||||
int stream = 0;
|
||||
if (parser.isSet(arg_stdout))
|
||||
{
|
||||
[[maybe_unused]] const auto con_out = freopen("CONOUT$", "w", stdout);
|
||||
stream |= utils::console_stream::std_out;
|
||||
}
|
||||
|
||||
if (parser.isSet(arg_stderr))
|
||||
{
|
||||
[[maybe_unused]] const auto con_err = freopen("CONOUT$", "w", stderr);
|
||||
}
|
||||
stream |= utils::console_stream::std_err;
|
||||
}
|
||||
utils::attach_console(stream, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -770,13 +760,7 @@ int main(int argc, char** argv)
|
|||
|
||||
if (rpcs3::curl::g_curl_verbose)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
|
||||
{
|
||||
[[maybe_unused]] const auto con_out = freopen("CONOUT$", "w", stdout);
|
||||
[[maybe_unused]] const auto con_err = freopen("CONOUT$", "w", stderr);
|
||||
}
|
||||
#endif
|
||||
utils::attach_console(utils::console_stream::std_out | utils::console_stream::std_err, true);
|
||||
fprintf(stdout, "Enabled Curl verbose logging.\n");
|
||||
sys_log.always()("Enabled Curl verbose logging. Please look at your console output.");
|
||||
}
|
||||
|
@ -784,13 +768,8 @@ int main(int argc, char** argv)
|
|||
// Handle update of commit database
|
||||
if (parser.isSet(arg_commit_db))
|
||||
{
|
||||
utils::attach_console(utils::console_stream::std_out | utils::console_stream::std_err, true);
|
||||
#ifdef _WIN32
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
|
||||
{
|
||||
[[maybe_unused]] const auto con_out = freopen("CONOUT$", "w", stdout);
|
||||
[[maybe_unused]] const auto con_err = freopen("CONOUT$", "w", stderr);
|
||||
}
|
||||
|
||||
std::string path;
|
||||
#else
|
||||
std::string path = "bin/git/commits.lst";
|
||||
|
@ -1010,10 +989,8 @@ int main(int argc, char** argv)
|
|||
|
||||
if (parser.isSet(arg_styles))
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
|
||||
[[maybe_unused]] const auto con_out = freopen("CONOUT$", "w", stdout);
|
||||
#endif
|
||||
utils::attach_console(utils::console_stream::std_out, true);
|
||||
|
||||
for (const auto& style : QStyleFactory::keys())
|
||||
std::cout << "\n" << style.toStdString();
|
||||
|
||||
|
@ -1166,13 +1143,7 @@ int main(int argc, char** argv)
|
|||
|
||||
if (parser.isSet(arg_decrypt))
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
|
||||
{
|
||||
[[maybe_unused]] const auto con_out = freopen("CONOUT$", "w", stdout);
|
||||
[[maybe_unused]] const auto con_in = freopen("CONIN$", "r", stdin);
|
||||
}
|
||||
#endif
|
||||
utils::attach_console(utils::console_stream::std_out | utils::console_stream::std_in, true);
|
||||
|
||||
std::vector<std::string> vec_modules;
|
||||
for (const QString& mod : parser.values(decrypt_option))
|
||||
|
@ -1400,11 +1371,9 @@ int main(int argc, char** argv)
|
|||
}
|
||||
else if (s_headless || s_no_gui)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// If launched from CMD
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
||||
[[maybe_unused]] const auto con_out = freopen("CONOUT$", "w", stderr);
|
||||
#endif
|
||||
utils::attach_console(utils::console_stream::std_out | utils::console_stream::std_err, false);
|
||||
|
||||
sys_log.error("Cannot run %s mode without boot target. Terminating...", s_headless ? "headless" : "no-gui");
|
||||
fprintf(stderr, "Cannot run %s mode without boot target. Terminating...\n", s_headless ? "headless" : "no-gui");
|
||||
|
||||
|
|
|
@ -817,6 +817,7 @@
|
|||
<ClCompile Include="rpcs3qt\save_data_list_dialog.cpp" />
|
||||
<ClCompile Include="rpcs3qt\settings_dialog.cpp" />
|
||||
<ClCompile Include="Input\xinput_pad_handler.cpp" />
|
||||
<ClCompile Include="util\console.cpp" />
|
||||
<ClCompile Include="\rpcs3qt\*.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -1736,6 +1737,7 @@
|
|||
<ClInclude Include="rpcs3qt\trophy_notification_helper.h" />
|
||||
<ClInclude Include="rpcs3qt\user_account.h" />
|
||||
<ClInclude Include="Input\xinput_pad_handler.h" />
|
||||
<ClInclude Include="util\console.h" />
|
||||
<ClInclude Include="\rpcs3qt\*.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1065,6 +1065,9 @@
|
|||
<ClCompile Include="Input\gui_pad_thread.cpp">
|
||||
<Filter>Io</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="util\console.cpp">
|
||||
<Filter>rpcs3</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Input\ds4_pad_handler.h">
|
||||
|
@ -1241,9 +1244,6 @@
|
|||
<ClInclude Include="rpcs3qt\movie_item_base.h">
|
||||
<Filter>Gui\custom items</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="rpcs3qt\midi_creator.h">
|
||||
<Filter>Gui\settings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Input\skateboard_pad_handler.h">
|
||||
<Filter>Io\Skateboard</Filter>
|
||||
</ClInclude>
|
||||
|
@ -1253,6 +1253,9 @@
|
|||
<ClInclude Include="Input\gui_pad_thread.h">
|
||||
<Filter>Io</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="util\console.h">
|
||||
<Filter>rpcs3</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="debug\moc_predefs.h.cbt">
|
||||
|
@ -1555,6 +1558,9 @@
|
|||
<CustomBuild Include="rpcs3qt\emulated_pad_settings_dialog.h">
|
||||
<Filter>Gui\settings</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="rpcs3qt\midi_creator.h">
|
||||
<Filter>Gui\settings</Filter>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="rpcs3.ico" />
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "Emu/Io/Null/null_music_handler.h"
|
||||
#include "Emu/vfs_config.h"
|
||||
#include "util/init_mutex.hpp"
|
||||
#include "util/console.h"
|
||||
#include "Input/raw_mouse_handler.h"
|
||||
#include "trophy_notification_helper.h"
|
||||
#include "save_data_dialog.h"
|
||||
|
@ -116,16 +117,11 @@ bool gui_application::Init()
|
|||
return false;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (m_gui_settings->GetValue(gui::m_attachCommandLine).toBool())
|
||||
{
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
|
||||
{
|
||||
[[maybe_unused]] const auto con_out = freopen("CONOUT$", "w", stderr);
|
||||
}
|
||||
utils::attach_console(utils::console_stream::std_err, true);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
m_gui_settings->SetValue(gui::m_attachCommandLine, false);
|
||||
}
|
||||
|
|
39
rpcs3/util/console.cpp
Normal file
39
rpcs3/util/console.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "console.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Windows.h"
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
namespace utils
|
||||
{
|
||||
void attach_console([[maybe_unused]] int stream, [[maybe_unused]] bool open_console)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!stream)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(AttachConsole(ATTACH_PARENT_PROCESS) || (open_console && AllocConsole())))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (stream & console_stream::std_out)
|
||||
{
|
||||
[[maybe_unused]] const auto con_out = freopen("CONOUT$", "w", stdout);
|
||||
}
|
||||
|
||||
if (stream & console_stream::std_err)
|
||||
{
|
||||
[[maybe_unused]] const auto con_err = freopen("CONOUT$", "w", stderr);
|
||||
}
|
||||
|
||||
if (stream & console_stream::std_in)
|
||||
{
|
||||
[[maybe_unused]] const auto con_in = freopen("CONIN$", "r", stdin);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
13
rpcs3/util/console.h
Normal file
13
rpcs3/util/console.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
namespace utils
|
||||
{
|
||||
enum console_stream
|
||||
{
|
||||
std_out = 0x01,
|
||||
std_err = 0x02,
|
||||
std_in = 0x04,
|
||||
};
|
||||
|
||||
void attach_console(int stream, bool open_console);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue