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