mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 22:25:38 +00:00
Moved all Platform functions to the utility namespace.
This commit is contained in:
parent
5a085c585e
commit
2d149c5161
|
@ -1107,10 +1107,10 @@ void FileData::launchGame(Window* window)
|
||||||
// Possibly keep ES-DE running in the background while the game is launched.
|
// Possibly keep ES-DE running in the background while the game is launched.
|
||||||
|
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
returnValue =
|
returnValue = Utils::Platform::launchGameWindows(Utils::String::stringToWideString(command),
|
||||||
launchGameWindows(Utils::String::stringToWideString(command), runInBackground, hideWindow);
|
runInBackground, hideWindow);
|
||||||
#else
|
#else
|
||||||
returnValue = launchGameUnix(command, runInBackground);
|
returnValue = Utils::Platform::launchGameUnix(command, runInBackground);
|
||||||
#endif
|
#endif
|
||||||
// Notify the user in case of a failed game launch using a popup window.
|
// Notify the user in case of a failed game launch using a popup window.
|
||||||
if (returnValue != 0) {
|
if (returnValue != 0) {
|
||||||
|
|
|
@ -1135,7 +1135,7 @@ void GuiMenu::openQuitMenu()
|
||||||
[this] {
|
[this] {
|
||||||
Scripting::fireEvent("quit");
|
Scripting::fireEvent("quit");
|
||||||
close(true);
|
close(true);
|
||||||
quitES();
|
Utils::Platform::quitES();
|
||||||
},
|
},
|
||||||
"NO", nullptr));
|
"NO", nullptr));
|
||||||
}
|
}
|
||||||
|
@ -1153,7 +1153,7 @@ void GuiMenu::openQuitMenu()
|
||||||
[this] {
|
[this] {
|
||||||
Scripting::fireEvent("quit");
|
Scripting::fireEvent("quit");
|
||||||
close(true);
|
close(true);
|
||||||
quitES();
|
Utils::Platform::quitES();
|
||||||
},
|
},
|
||||||
"NO", nullptr));
|
"NO", nullptr));
|
||||||
});
|
});
|
||||||
|
@ -1170,7 +1170,7 @@ void GuiMenu::openQuitMenu()
|
||||||
[] {
|
[] {
|
||||||
Scripting::fireEvent("quit", "reboot");
|
Scripting::fireEvent("quit", "reboot");
|
||||||
Scripting::fireEvent("reboot");
|
Scripting::fireEvent("reboot");
|
||||||
if (quitES(QuitMode::REBOOT) != 0) {
|
if (Utils::Platform::quitES(Utils::Platform::QuitMode::REBOOT) != 0) {
|
||||||
LOG(LogWarning) << "Reboot terminated with non-zero result!";
|
LOG(LogWarning) << "Reboot terminated with non-zero result!";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1189,7 +1189,7 @@ void GuiMenu::openQuitMenu()
|
||||||
[] {
|
[] {
|
||||||
Scripting::fireEvent("quit", "poweroff");
|
Scripting::fireEvent("quit", "poweroff");
|
||||||
Scripting::fireEvent("poweroff");
|
Scripting::fireEvent("poweroff");
|
||||||
if (quitES(QuitMode::POWEROFF) != 0) {
|
if (Utils::Platform::quitES(Utils::Platform::QuitMode::POWEROFF) != 0) {
|
||||||
LOG(LogWarning) << "Power off terminated with non-zero result!";
|
LOG(LogWarning) << "Power off terminated with non-zero result!";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -563,8 +563,8 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
if (Settings::getInstance()->getBool("HideTaskbar")) {
|
if (Settings::getInstance()->getBool("HideTaskbar")) {
|
||||||
taskbarStateChanged = true;
|
taskbarStateChanged = true;
|
||||||
taskbarState = getTaskbarState();
|
taskbarState = Utils::Platform::getTaskbarState();
|
||||||
hideTaskbar();
|
Utils::Platform::hideTaskbar();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -692,10 +692,10 @@ int main(int argc, char* argv[])
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
// If the taskbar state was changed (taskbar was hidden), then revert it.
|
// If the taskbar state was changed (taskbar was hidden), then revert it.
|
||||||
if (taskbarStateChanged)
|
if (taskbarStateChanged)
|
||||||
revertTaskbarState(taskbarState);
|
Utils::Platform::revertTaskbarState(taskbarState);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
processQuitMode();
|
Utils::Platform::processQuitMode();
|
||||||
|
|
||||||
LOG(LogInfo) << "EmulationStation cleanly shutting down";
|
LOG(LogInfo) << "EmulationStation cleanly shutting down";
|
||||||
|
|
||||||
|
|
|
@ -239,7 +239,7 @@ void InputManager::doOnFinish()
|
||||||
LOG(LogInfo) << " " << tocall;
|
LOG(LogInfo) << " " << tocall;
|
||||||
std::cout << "==============================================\n"
|
std::cout << "==============================================\n"
|
||||||
"input config finish command:\n";
|
"input config finish command:\n";
|
||||||
int exitCode = runSystemCommand(tocall);
|
int exitCode = Utils::Platform::runSystemCommand(tocall);
|
||||||
std::cout << "==============================================\n";
|
std::cout << "==============================================\n";
|
||||||
|
|
||||||
if (exitCode != 0) {
|
if (exitCode != 0) {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// EmulationStation Desktop Edition
|
// EmulationStation Desktop Edition
|
||||||
// Platform.cpp
|
// Platform.cpp
|
||||||
//
|
//
|
||||||
// Platform-specific functions.
|
// Platform utility functions.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
|
@ -25,6 +25,10 @@
|
||||||
#endif
|
#endif
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
namespace Platform
|
||||||
|
{
|
||||||
int runRebootCommand()
|
int runRebootCommand()
|
||||||
{
|
{
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
|
@ -79,7 +83,8 @@ int launchGameUnix(const std::string& cmd_utf8, bool runInBackground)
|
||||||
// instance no output from the command is captured and no real error handling is
|
// instance no output from the command is captured and no real error handling is
|
||||||
// implemented. It should therefore only be used when absolutely necessary.
|
// implemented. It should therefore only be used when absolutely necessary.
|
||||||
if (runInBackground) {
|
if (runInBackground) {
|
||||||
LOG(LogDebug) << "Platform::launchGameUnix(): Launching game while keeping ES-DE running "
|
LOG(LogDebug)
|
||||||
|
<< "Platform::launchGameUnix(): Launching game while keeping ES-DE running "
|
||||||
"in the background, no command output will be written to the log file";
|
"in the background, no command output will be written to the log file";
|
||||||
return system(command.c_str());
|
return system(command.c_str());
|
||||||
}
|
}
|
||||||
|
@ -101,8 +106,8 @@ int launchGameUnix(const std::string& cmd_utf8, bool runInBackground)
|
||||||
returnValue = pclose(commandPipe);
|
returnValue = pclose(commandPipe);
|
||||||
|
|
||||||
#if defined(_RPI_)
|
#if defined(_RPI_)
|
||||||
// Hack to avoid that the application window occasionally loses focus when returning from
|
// Hack to avoid that the application window occasionally loses focus when returning
|
||||||
// a game, which only seems to happen on Raspberry Pi OS 10.
|
// from a game, which only seems to happen on Raspberry Pi OS 10.
|
||||||
SDL_Delay(50);
|
SDL_Delay(50);
|
||||||
SDL_SetWindowInputFocus(Renderer::getSDLWindow());
|
SDL_SetWindowInputFocus(Renderer::getSDLWindow());
|
||||||
#endif
|
#endif
|
||||||
|
@ -117,7 +122,8 @@ int launchGameUnix(const std::string& cmd_utf8, bool runInBackground)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (returnValue) {
|
if (returnValue) {
|
||||||
LOG(LogError) << "launchGameUnix - return value " << std::to_string(returnValue) + ":";
|
LOG(LogError) << "launchGameUnix - return value "
|
||||||
|
<< std::to_string(returnValue) + ":";
|
||||||
if (commandOutput.size())
|
if (commandOutput.size())
|
||||||
LOG(LogError) << commandOutput;
|
LOG(LogError) << commandOutput;
|
||||||
else
|
else
|
||||||
|
@ -143,8 +149,8 @@ int launchGameWindows(const std::wstring& cmd_utf16, bool runInBackground, bool
|
||||||
|
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
if (hideWindow) {
|
if (hideWindow) {
|
||||||
// Optionally hide the window. This is intended primarily for hiding console windows when
|
// Optionally hide the window. This is intended primarily for hiding console windows
|
||||||
// launching scripts (used for example by Steam games and source ports).
|
// when launching scripts (used for example by Steam games and source ports).
|
||||||
si.dwFlags = STARTF_USESHOWWINDOW;
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
||||||
si.wShowWindow = SW_HIDE;
|
si.wShowWindow = SW_HIDE;
|
||||||
}
|
}
|
||||||
|
@ -169,12 +175,12 @@ int launchGameWindows(const std::wstring& cmd_utf16, bool runInBackground, bool
|
||||||
int width{};
|
int width{};
|
||||||
int height{};
|
int height{};
|
||||||
|
|
||||||
// Hack to make the emulator window render correctly when launching games while running in
|
// Hack to make the emulator window render correctly when launching games while
|
||||||
// full screen mode. If not done, the emulator window will simply be black although the
|
// running in full screen mode. If not done, the emulator window will simply be
|
||||||
// game actually works and outputs sounds, accepts input etc. There is sometimes a white
|
// black although the game actually works and outputs sounds, accepts input etc.
|
||||||
// flash the first time an emulator is started during the program session and a white
|
// There is sometimes a white flash the first time an emulator is started during the
|
||||||
// single-pixel line will be visible at the bottom of the screen while the game is loading.
|
// program session and a white single-pixel line will be visible at the bottom of
|
||||||
// But it's at least a tolerable workaround.
|
// the screen while the game is loading. But it's at least a tolerable workaround.
|
||||||
SDL_GetWindowSize(Renderer::getSDLWindow(), &width, &height);
|
SDL_GetWindowSize(Renderer::getSDLWindow(), &width, &height);
|
||||||
SDL_SetWindowSize(Renderer::getSDLWindow(), width, height - 1);
|
SDL_SetWindowSize(Renderer::getSDLWindow(), width, height - 1);
|
||||||
SDL_Delay(100);
|
SDL_Delay(100);
|
||||||
|
@ -254,8 +260,6 @@ void revertTaskbarState(unsigned int& state)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QuitMode quitMode = QuitMode::QUIT;
|
|
||||||
|
|
||||||
int quitES(QuitMode mode)
|
int quitES(QuitMode mode)
|
||||||
{
|
{
|
||||||
quitMode = mode;
|
quitMode = mode;
|
||||||
|
@ -276,20 +280,6 @@ void emergencyShutdown()
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void touch(const std::string& filename)
|
|
||||||
{
|
|
||||||
#if defined(_WIN64)
|
|
||||||
FILE* fp;
|
|
||||||
fopen_s(&fp, filename.c_str(), "ab+");
|
|
||||||
if (fp != nullptr)
|
|
||||||
fclose(fp);
|
|
||||||
#else
|
|
||||||
int fd = open(filename.c_str(), O_CREAT | O_WRONLY, 0644);
|
|
||||||
if (fd >= 0)
|
|
||||||
close(fd);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void processQuitMode()
|
void processQuitMode()
|
||||||
{
|
{
|
||||||
switch (quitMode) {
|
switch (quitMode) {
|
||||||
|
@ -308,3 +298,7 @@ void processQuitMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Platform
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// EmulationStation Desktop Edition
|
// EmulationStation Desktop Edition
|
||||||
// Platform.h
|
// Platform.h
|
||||||
//
|
//
|
||||||
// Platform-specific functions.
|
// Platform utility functions.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef ES_CORE_PLATFORM_H
|
#ifndef ES_CORE_PLATFORM_H
|
||||||
|
@ -17,12 +17,19 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
namespace Platform
|
||||||
|
{
|
||||||
enum QuitMode {
|
enum QuitMode {
|
||||||
QUIT = 0, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
QUIT = 0, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
||||||
REBOOT = 1,
|
REBOOT = 1,
|
||||||
POWEROFF = 2
|
POWEROFF = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int runRebootCommand();
|
||||||
|
int runPoweroffCommand();
|
||||||
|
|
||||||
// Uses UTF-8 for Unix and does a UTF-16/wstring conversion for Windows.
|
// Uses UTF-8 for Unix and does a UTF-16/wstring conversion for Windows.
|
||||||
int runSystemCommand(const std::string& cmd_utf8);
|
int runSystemCommand(const std::string& cmd_utf8);
|
||||||
// Windows specific UTF-16/wstring function. (FOR FUTURE USE)
|
// Windows specific UTF-16/wstring function. (FOR FUTURE USE)
|
||||||
|
@ -42,4 +49,10 @@ int quitES(QuitMode mode = QuitMode::QUIT);
|
||||||
void emergencyShutdown();
|
void emergencyShutdown();
|
||||||
void processQuitMode();
|
void processQuitMode();
|
||||||
|
|
||||||
|
inline static QuitMode quitMode = QuitMode::QUIT;
|
||||||
|
|
||||||
|
} // namespace Platform
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
|
|
||||||
#endif // ES_CORE_PLATFORM_H
|
#endif // ES_CORE_PLATFORM_H
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace Scripting
|
||||||
.append(arg4)
|
.append(arg4)
|
||||||
.append(arg4Quotation);
|
.append(arg4Quotation);
|
||||||
LOG(LogDebug) << "Executing: " << script;
|
LOG(LogDebug) << "Executing: " << script;
|
||||||
runSystemCommand(script);
|
Utils::Platform::runSystemCommand(script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ std::string ResourceManager::getResourcePath(const std::string& path, bool termi
|
||||||
LOG(LogError) << testExePath;
|
LOG(LogError) << testExePath;
|
||||||
LOG(LogError) << "Has EmulationStation been properly installed?";
|
LOG(LogError) << "Has EmulationStation been properly installed?";
|
||||||
Scripting::fireEvent("quit");
|
Scripting::fireEvent("quit");
|
||||||
emergencyShutdown();
|
Utils::Platform::emergencyShutdown();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "";
|
return "";
|
||||||
|
|
Loading…
Reference in a new issue