2012-11-01 16:19:01 +01:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 23:01:49 +01:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-11-04 10:56:22 +01:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-11-01 16:19:01 +01:00
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
// NativeApp implementation for platforms that will use that framework, like:
|
|
|
|
// Android, Linux, MacOSX.
|
|
|
|
//
|
|
|
|
// Native is a cross platform framework. It's not very mature and mostly
|
|
|
|
// just built according to the needs of my own apps.
|
|
|
|
//
|
|
|
|
// Windows has its own code that bypasses the framework entirely.
|
|
|
|
|
2017-02-24 20:50:27 +01:00
|
|
|
#include "ppsspp_config.h"
|
2013-04-13 21:24:07 +02:00
|
|
|
|
|
|
|
// Background worker threads should be spawned in NativeInit and joined
|
|
|
|
// in NativeShutdown.
|
|
|
|
|
2013-04-25 10:41:43 +02:00
|
|
|
#include <locale.h>
|
2014-04-26 02:32:43 -04:00
|
|
|
#include <algorithm>
|
2021-01-30 16:08:29 +00:00
|
|
|
#include <cstdlib>
|
2014-11-25 11:58:19 -08:00
|
|
|
#include <memory>
|
2017-02-27 21:57:46 +01:00
|
|
|
#include <mutex>
|
2018-09-01 13:57:20 -07:00
|
|
|
#include <thread>
|
2014-04-26 02:32:43 -04:00
|
|
|
|
2014-06-18 15:36:49 +10:00
|
|
|
#if defined(_WIN32)
|
2017-06-27 11:46:10 +02:00
|
|
|
#include "Windows/WindowsAudio.h"
|
2015-09-19 13:14:05 +02:00
|
|
|
#include "Windows/MainWindow.h"
|
2020-01-14 17:15:11 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
|
2020-01-13 15:06:02 +08:00
|
|
|
#include "Windows/CaptureDevice.h"
|
2013-12-08 03:06:15 +10:00
|
|
|
#endif
|
2013-04-13 21:24:07 +02:00
|
|
|
|
2020-10-04 20:48:47 +02:00
|
|
|
#include "Common/Net/HTTPClient.h"
|
|
|
|
#include "Common/Net/Resolve.h"
|
2021-09-09 00:00:54 +02:00
|
|
|
#include "Common/Net/URL.h"
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/Render/TextureAtlas.h"
|
2020-10-05 00:05:28 +02:00
|
|
|
#include "Common/Render/Text/draw_text.h"
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/GPU/OpenGL/GLFeatures.h"
|
|
|
|
#include "Common/GPU/thin3d.h"
|
2020-10-04 20:48:47 +02:00
|
|
|
#include "Common/UI/UI.h"
|
|
|
|
#include "Common/UI/Screen.h"
|
|
|
|
#include "Common/UI/Context.h"
|
|
|
|
#include "Common/UI/View.h"
|
2023-07-12 20:04:02 +02:00
|
|
|
#include "Common/UI/IconCache.h"
|
2023-06-16 13:04:20 +02:00
|
|
|
|
2020-08-15 19:01:16 +02:00
|
|
|
#include "android/jni/app-android.h"
|
|
|
|
|
2020-10-04 10:30:18 +02:00
|
|
|
#include "Common/System/Display.h"
|
2023-03-22 12:26:14 +01:00
|
|
|
#include "Common/System/Request.h"
|
2020-10-04 10:30:18 +02:00
|
|
|
#include "Common/System/System.h"
|
2023-06-30 17:15:49 +02:00
|
|
|
#include "Common/System/OSD.h"
|
2020-10-04 10:30:18 +02:00
|
|
|
#include "Common/System/NativeApp.h"
|
2023-03-22 12:26:14 +01:00
|
|
|
|
2020-10-04 10:30:18 +02:00
|
|
|
#include "Common/Data/Text/I18n.h"
|
|
|
|
#include "Common/Input/InputState.h"
|
|
|
|
#include "Common/Math/math_util.h"
|
|
|
|
#include "Common/Math/lin/matrix4x4.h"
|
|
|
|
#include "Common/Profiler/Profiler.h"
|
2020-10-04 00:25:21 +02:00
|
|
|
#include "Common/Data/Encoding/Utf8.h"
|
|
|
|
#include "Common/File/VFS/VFS.h"
|
2023-03-06 15:30:39 +01:00
|
|
|
#include "Common/File/VFS/ZipFileReader.h"
|
|
|
|
#include "Common/File/VFS/DirectoryReader.h"
|
2014-03-22 09:26:28 +01:00
|
|
|
#include "Common/CPUDetect.h"
|
2020-10-04 20:48:47 +02:00
|
|
|
#include "Common/File/FileUtil.h"
|
2020-09-29 12:19:22 +02:00
|
|
|
#include "Common/TimeUtil.h"
|
|
|
|
#include "Common/StringUtils.h"
|
2013-06-01 23:34:50 +02:00
|
|
|
#include "Common/LogManager.h"
|
2014-12-20 08:31:56 -08:00
|
|
|
#include "Common/MemArena.h"
|
2015-12-31 17:25:48 +01:00
|
|
|
#include "Common/GraphicsContext.h"
|
2020-01-13 15:06:02 +08:00
|
|
|
#include "Common/OSVersion.h"
|
2021-01-04 23:51:34 +01:00
|
|
|
#include "Common/GPU/ShaderTranslation.h"
|
2022-08-27 17:33:37 +02:00
|
|
|
#include "Common/VR/PPSSPPVR.h"
|
2020-08-15 19:01:16 +02:00
|
|
|
|
2021-07-08 21:30:23 +02:00
|
|
|
#include "Core/ControlMapper.h"
|
2013-06-01 23:34:50 +02:00
|
|
|
#include "Core/Config.h"
|
2018-06-16 18:42:31 -07:00
|
|
|
#include "Core/ConfigValues.h"
|
2014-06-22 14:17:57 +02:00
|
|
|
#include "Core/Core.h"
|
2015-06-27 18:32:21 -07:00
|
|
|
#include "Core/FileLoaders/DiskCachingFileLoader.h"
|
2023-08-07 22:10:38 +02:00
|
|
|
#include "Core/FrameTiming.h"
|
2020-10-04 00:25:21 +02:00
|
|
|
#include "Core/KeyMap.h"
|
2016-09-28 22:35:09 -07:00
|
|
|
#include "Core/Reporting.h"
|
2023-07-02 12:00:13 +02:00
|
|
|
#include "Core/RetroAchievements.h"
|
2013-06-01 23:34:50 +02:00
|
|
|
#include "Core/SaveState.h"
|
2014-12-20 23:14:46 -08:00
|
|
|
#include "Core/Screenshot.h"
|
2013-12-30 00:11:29 +01:00
|
|
|
#include "Core/System.h"
|
2015-01-11 12:02:49 +01:00
|
|
|
#include "Core/HLE/__sceAudio.h"
|
2013-12-30 00:11:29 +01:00
|
|
|
#include "Core/HLE/sceCtrl.h"
|
2017-08-20 21:03:06 +03:00
|
|
|
#include "Core/HLE/sceUsbCam.h"
|
|
|
|
#include "Core/HLE/sceUsbGps.h"
|
2016-10-24 01:49:12 +08:00
|
|
|
#include "Core/HLE/proAdhoc.h"
|
2021-09-11 07:36:02 -07:00
|
|
|
#include "Core/HW/MemoryStick.h"
|
2013-11-20 14:42:48 +01:00
|
|
|
#include "Core/Util/GameManager.h"
|
2023-07-20 23:55:35 +02:00
|
|
|
#include "Core/Util/PortManager.h"
|
2015-01-11 13:50:52 -08:00
|
|
|
#include "Core/Util/AudioFormat.h"
|
2018-04-21 13:51:18 -07:00
|
|
|
#include "Core/WebServer.h"
|
2023-02-01 15:04:32 +01:00
|
|
|
#include "Core/TiltEventProcessor.h"
|
2020-11-28 00:12:06 +01:00
|
|
|
#include "Core/ThreadPools.h"
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2020-08-15 19:01:16 +02:00
|
|
|
#include "GPU/GPUInterface.h"
|
2023-03-24 17:19:57 +01:00
|
|
|
#include "UI/AudioCommon.h"
|
2020-05-09 13:52:04 -07:00
|
|
|
#include "UI/BackgroundAudio.h"
|
|
|
|
#include "UI/ControlMappingScreen.h"
|
2023-12-14 11:10:36 +01:00
|
|
|
#include "UI/DevScreens.h"
|
2020-05-09 13:52:04 -07:00
|
|
|
#include "UI/DiscordIntegration.h"
|
2016-09-28 22:35:09 -07:00
|
|
|
#include "UI/EmuScreen.h"
|
|
|
|
#include "UI/GameInfoCache.h"
|
2020-05-09 13:52:04 -07:00
|
|
|
#include "UI/GPUDriverTestScreen.h"
|
2013-10-17 16:15:04 +02:00
|
|
|
#include "UI/MiscScreens.h"
|
2021-07-25 15:33:11 +02:00
|
|
|
#include "UI/MemStickScreen.h"
|
2020-05-09 13:52:04 -07:00
|
|
|
#include "UI/OnScreenDisplay.h"
|
2017-12-10 18:30:28 -08:00
|
|
|
#include "UI/RemoteISOScreen.h"
|
2022-02-11 12:32:23 +01:00
|
|
|
#include "UI/Theme.h"
|
2013-06-01 23:34:50 +02:00
|
|
|
|
2018-06-09 11:34:12 -07:00
|
|
|
#if defined(USING_QT_UI)
|
|
|
|
#include <QFontDatabase>
|
|
|
|
#endif
|
2019-06-07 05:16:27 +08:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
|
|
|
#include <dwrite_3.h>
|
2023-08-23 21:01:00 +04:00
|
|
|
#include "UWP/UWPHelpers/InputHelpers.h"
|
2019-06-07 05:16:27 +08:00
|
|
|
#endif
|
2021-02-28 13:44:35 +01:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
|
|
|
#include "android/jni/app-android.h"
|
|
|
|
#endif
|
2018-03-03 08:46:12 +01:00
|
|
|
|
2020-08-29 08:45:50 -07:00
|
|
|
#if PPSSPP_ARCH(ARM) && defined(__ANDROID__)
|
2013-03-30 21:14:18 +01:00
|
|
|
#include "../../android/jni/ArmEmitterTest.h"
|
2020-08-29 08:45:50 -07:00
|
|
|
#elif PPSSPP_ARCH(ARM64) && defined(__ANDROID__)
|
2015-03-21 19:22:24 +01:00
|
|
|
#include "../../android/jni/Arm64EmitterTest.h"
|
2013-03-21 20:52:33 +01:00
|
|
|
#endif
|
2012-11-23 19:41:35 +01:00
|
|
|
|
2021-03-02 20:57:25 -08:00
|
|
|
#if PPSSPP_PLATFORM(IOS)
|
2013-06-25 16:18:16 -05:00
|
|
|
#include "ios/iOSCoreAudio.h"
|
2013-12-07 15:06:12 +10:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#include <mach-o/dyld.h>
|
2013-06-25 16:18:16 -05:00
|
|
|
#endif
|
|
|
|
|
2023-01-22 20:32:34 +03:00
|
|
|
#if PPSSPP_PLATFORM(IOS) || PPSSPP_PLATFORM(MAC)
|
2023-01-31 13:36:14 +03:00
|
|
|
#include "UI/DarwinFileSystemServices.h"
|
2023-01-22 20:32:34 +03:00
|
|
|
#endif
|
|
|
|
|
2023-10-22 11:10:42 -06:00
|
|
|
#if !defined(__LIBRETRO__)
|
|
|
|
#include "Core/Util/GameDB.h"
|
|
|
|
#endif
|
|
|
|
|
2022-12-05 14:46:00 +03:00
|
|
|
#include <Core/HLE/Plugins.h>
|
2022-12-04 23:46:01 +03:00
|
|
|
|
2023-09-30 11:21:22 +02:00
|
|
|
bool HandleGlobalMessage(UIMessage message, const std::string &value);
|
2023-12-17 19:40:59 +01:00
|
|
|
static void ProcessWheelRelease(InputKeyCode keyCode, double now, bool keyPress);
|
2023-08-07 22:44:06 +02:00
|
|
|
|
2023-03-22 09:42:31 +01:00
|
|
|
ScreenManager *g_screenManager;
|
2012-11-01 16:19:01 +01:00
|
|
|
std::string config_filename;
|
|
|
|
|
2013-06-22 22:27:59 +02:00
|
|
|
// Really need to clean this mess of globals up... but instead I add more :P
|
|
|
|
bool g_TakeScreenshot;
|
2013-10-31 11:06:54 +01:00
|
|
|
static bool isOuya;
|
2014-12-26 01:41:12 +09:00
|
|
|
static bool resized = false;
|
2017-04-15 16:30:37 -07:00
|
|
|
static bool restarting = false;
|
2014-02-13 17:47:02 +01:00
|
|
|
|
2018-09-06 18:31:09 -07:00
|
|
|
static int renderCounter = 0;
|
2018-03-24 12:51:54 +01:00
|
|
|
|
2014-02-13 17:47:02 +01:00
|
|
|
struct PendingMessage {
|
2023-09-30 11:21:22 +02:00
|
|
|
UIMessage message;
|
2014-02-13 17:47:02 +01:00
|
|
|
std::string value;
|
|
|
|
};
|
|
|
|
|
2017-02-27 21:57:46 +01:00
|
|
|
static std::mutex pendingMutex;
|
2014-02-13 17:47:02 +01:00
|
|
|
static std::vector<PendingMessage> pendingMessages;
|
2017-01-30 14:33:38 +01:00
|
|
|
static Draw::DrawContext *g_draw;
|
2016-12-26 13:42:53 +01:00
|
|
|
static Draw::Pipeline *colorPipeline;
|
|
|
|
static Draw::Pipeline *texColorPipeline;
|
2013-03-30 19:23:20 +01:00
|
|
|
static UIContext *uiContext;
|
2024-01-18 17:57:14 +01:00
|
|
|
static bool g_restartGraphics;
|
2013-03-29 20:51:14 +01:00
|
|
|
|
2015-01-11 21:00:56 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
WindowsAudioBackend *winAudioBackend;
|
|
|
|
#endif
|
|
|
|
|
2013-04-13 21:24:07 +02:00
|
|
|
std::thread *graphicsLoadThread;
|
2013-03-29 20:51:14 +01:00
|
|
|
|
2020-08-15 19:01:16 +02:00
|
|
|
class PrintfLogger : public LogListener {
|
2012-11-01 16:19:01 +01:00
|
|
|
public:
|
2017-03-18 10:47:10 +01:00
|
|
|
void Log(const LogMessage &message) override {
|
|
|
|
// Log with simplified headers as Android already provides timestamp etc.
|
|
|
|
switch (message.level) {
|
2023-08-25 11:33:48 +02:00
|
|
|
case LogLevel::LVERBOSE:
|
|
|
|
case LogLevel::LDEBUG:
|
|
|
|
case LogLevel::LINFO:
|
2020-08-15 19:01:16 +02:00
|
|
|
printf("INFO [%s] %s", message.log, message.msg.c_str());
|
2012-11-04 10:56:22 +01:00
|
|
|
break;
|
2023-08-25 11:33:48 +02:00
|
|
|
case LogLevel::LERROR:
|
2020-08-15 19:01:16 +02:00
|
|
|
printf("ERR [%s] %s", message.log, message.msg.c_str());
|
2012-11-04 10:56:22 +01:00
|
|
|
break;
|
2023-08-25 11:33:48 +02:00
|
|
|
case LogLevel::LWARNING:
|
2020-08-15 19:01:16 +02:00
|
|
|
printf("WARN [%s] %s", message.log, message.msg.c_str());
|
2012-11-04 10:56:22 +01:00
|
|
|
break;
|
2023-08-25 11:33:48 +02:00
|
|
|
case LogLevel::LNOTICE:
|
2012-11-04 10:56:22 +01:00
|
|
|
default:
|
2020-08-15 19:01:16 +02:00
|
|
|
printf("NOTE [%s] !!! %s", message.log, message.msg.c_str());
|
2012-11-04 10:56:22 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-01 16:19:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// globals
|
2020-08-15 19:01:16 +02:00
|
|
|
static LogListener *logger = nullptr;
|
2021-05-09 18:38:48 +02:00
|
|
|
Path boot_filename;
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2023-03-24 13:59:27 +01:00
|
|
|
int NativeMix(short *audio, int numSamples, int sampleRateHz) {
|
|
|
|
return __AudioMix(audio, numSamples, sampleRateHz);
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2014-02-04 12:09:14 +01:00
|
|
|
// This is called before NativeInit so we do a little bit of initialization here.
|
2014-12-18 22:43:54 +01:00
|
|
|
void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, bool *landscape, std::string *version) {
|
2012-11-01 16:19:01 +01:00
|
|
|
*app_nice_name = "PPSSPP";
|
|
|
|
*app_dir_name = "ppsspp";
|
|
|
|
*landscape = true;
|
2014-12-18 22:43:54 +01:00
|
|
|
*version = PPSSPP_GIT_VERSION;
|
2012-11-23 19:41:35 +01:00
|
|
|
|
2020-08-29 08:45:50 -07:00
|
|
|
#if PPSSPP_ARCH(ARM) && defined(__ANDROID__)
|
2013-02-11 23:10:11 +01:00
|
|
|
ArmEmitterTest();
|
2020-08-29 08:45:50 -07:00
|
|
|
#elif PPSSPP_ARCH(ARM64) && defined(__ANDROID__)
|
2015-03-21 19:22:24 +01:00
|
|
|
Arm64EmitterTest();
|
2013-03-01 16:36:18 -08:00
|
|
|
#endif
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2018-06-09 11:34:12 -07:00
|
|
|
#if defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)
|
2018-04-29 11:45:32 -07:00
|
|
|
static bool CheckFontIsUsable(const wchar_t *fontFace) {
|
2015-10-04 15:11:36 -07:00
|
|
|
wchar_t actualFontFace[1024] = { 0 };
|
|
|
|
|
|
|
|
HFONT f = CreateFont(0, 0, 0, 0, FW_LIGHT, 0, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, fontFace);
|
|
|
|
if (f != nullptr) {
|
|
|
|
HDC hdc = CreateCompatibleDC(nullptr);
|
|
|
|
if (hdc != nullptr) {
|
|
|
|
SelectObject(hdc, f);
|
|
|
|
GetTextFace(hdc, 1024, actualFontFace);
|
|
|
|
DeleteDC(hdc);
|
|
|
|
}
|
|
|
|
DeleteObject(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we were able to get the font name, did it load?
|
|
|
|
if (actualFontFace[0] != 0) {
|
|
|
|
return wcsncmp(actualFontFace, fontFace, ARRAY_SIZE(actualFontFace)) == 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-07-25 00:16:30 +02:00
|
|
|
void PostLoadConfig() {
|
2018-04-29 11:45:32 -07:00
|
|
|
if (g_Config.currentDirectory.empty()) {
|
2021-05-30 00:20:41 +02:00
|
|
|
g_Config.currentDirectory = g_Config.defaultCurrentDirectory;
|
2018-04-29 11:45:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allow the lang directory to be overridden for testing purposes (e.g. Android, where it's hard to
|
|
|
|
// test new languages without recompiling the entire app, which is a hassle).
|
2021-05-06 01:31:38 +02:00
|
|
|
const Path langOverridePath = GetSysDirectory(DIRECTORY_SYSTEM) / "lang";
|
2018-04-29 11:45:32 -07:00
|
|
|
|
|
|
|
// If we run into the unlikely case that "lang" is actually a file, just use the built-in translations.
|
|
|
|
if (!File::Exists(langOverridePath) || !File::IsDirectory(langOverridePath))
|
2023-04-07 10:20:00 +02:00
|
|
|
g_i18nrepo.LoadIni(g_Config.sLanguageIni);
|
2018-04-29 11:45:32 -07:00
|
|
|
else
|
2023-04-07 10:20:00 +02:00
|
|
|
g_i18nrepo.LoadIni(g_Config.sLanguageIni, langOverridePath);
|
2021-07-25 00:16:30 +02:00
|
|
|
|
2023-08-23 02:25:57 +04:00
|
|
|
#if !PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(UWP)
|
2023-08-18 12:56:38 +02:00
|
|
|
CreateSysDirectories();
|
2021-07-25 00:16:30 +02:00
|
|
|
#endif
|
2018-04-29 11:45:32 -07:00
|
|
|
}
|
|
|
|
|
2018-09-01 13:57:20 -07:00
|
|
|
static void CheckFailedGPUBackends() {
|
2018-10-08 13:33:21 +02:00
|
|
|
#ifdef _DEBUG
|
|
|
|
// If you're in debug mode, you probably don't want a fallback. If you're in release mode, use IGNORE below.
|
2020-08-16 22:22:58 +02:00
|
|
|
NOTICE_LOG(LOADER, "Not checking for failed graphics backends in debug mode");
|
2018-10-08 13:33:21 +02:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2021-11-09 23:05:23 +01:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
|
|
|
if (System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= 30) {
|
|
|
|
// In Android 11 or later, Vulkan is as stable as OpenGL, so let's not even bother.
|
|
|
|
// Have also seen unexplained issues with random fallbacks to OpenGL for no good reason,
|
|
|
|
// especially when debugging.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-06 07:31:15 -07:00
|
|
|
// We only want to do this once per process run and backend, to detect process crashes.
|
|
|
|
// If NativeShutdown is called before we finish, we might call this multiple times.
|
|
|
|
static int lastBackend = -1;
|
|
|
|
if (lastBackend == g_Config.iGPUBackend) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastBackend = g_Config.iGPUBackend;
|
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
Path cache = GetSysDirectory(DIRECTORY_APP_CACHE) / "FailedGraphicsBackends.txt";
|
2018-09-01 13:57:20 -07:00
|
|
|
|
|
|
|
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
|
|
|
std::string data;
|
2021-05-09 15:02:46 +02:00
|
|
|
if (File::ReadFileToString(true, cache, data))
|
2018-09-01 13:57:20 -07:00
|
|
|
g_Config.sFailedGPUBackends = data;
|
|
|
|
}
|
|
|
|
|
2018-09-01 14:16:39 -07:00
|
|
|
// Use this if you want to debug a graphics crash...
|
|
|
|
if (g_Config.sFailedGPUBackends == "IGNORE")
|
|
|
|
return;
|
2018-09-05 23:13:15 -07:00
|
|
|
else if (!g_Config.sFailedGPUBackends.empty())
|
|
|
|
ERROR_LOG(LOADER, "Failed graphics backends: %s", g_Config.sFailedGPUBackends.c_str());
|
2018-09-01 14:16:39 -07:00
|
|
|
|
2018-09-01 13:57:20 -07:00
|
|
|
// Okay, let's not try a backend in the failed list.
|
2018-09-06 07:31:15 -07:00
|
|
|
g_Config.iGPUBackend = g_Config.NextValidBackend();
|
2020-03-28 06:19:11 -07:00
|
|
|
if (lastBackend != g_Config.iGPUBackend) {
|
|
|
|
std::string param = GPUBackendToString((GPUBackend)lastBackend) + " -> " + GPUBackendToString((GPUBackend)g_Config.iGPUBackend);
|
2023-03-22 22:17:53 +01:00
|
|
|
System_GraphicsBackendFailedAlert(param);
|
2020-03-28 06:19:11 -07:00
|
|
|
WARN_LOG(LOADER, "Failed graphics backend switched from %s (%d to %d)", param.c_str(), lastBackend, g_Config.iGPUBackend);
|
|
|
|
}
|
2018-09-01 13:57:20 -07:00
|
|
|
// And then let's - for now - add the current to the failed list.
|
|
|
|
if (g_Config.sFailedGPUBackends.empty()) {
|
2019-06-22 11:20:01 -07:00
|
|
|
g_Config.sFailedGPUBackends = GPUBackendToString((GPUBackend)g_Config.iGPUBackend);
|
2018-09-01 13:57:20 -07:00
|
|
|
} else if (g_Config.sFailedGPUBackends.find("ALL") == std::string::npos) {
|
2019-06-22 11:20:01 -07:00
|
|
|
g_Config.sFailedGPUBackends += "," + GPUBackendToString((GPUBackend)g_Config.iGPUBackend);
|
2018-09-01 13:57:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
|
|
|
// Let's try to create, in case it doesn't exist.
|
|
|
|
if (!File::Exists(GetSysDirectory(DIRECTORY_APP_CACHE)))
|
|
|
|
File::CreateDir(GetSysDirectory(DIRECTORY_APP_CACHE));
|
2021-05-09 15:02:46 +02:00
|
|
|
File::WriteStringToFile(true, g_Config.sFailedGPUBackends, cache);
|
2018-09-01 13:57:20 -07:00
|
|
|
} else {
|
|
|
|
// Just save immediately, since we have storage.
|
2019-02-23 10:49:49 +01:00
|
|
|
g_Config.Save("got storage permission");
|
2018-09-01 13:57:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ClearFailedGPUBackends() {
|
2018-09-01 14:16:39 -07:00
|
|
|
if (g_Config.sFailedGPUBackends == "IGNORE")
|
|
|
|
return;
|
|
|
|
|
2018-09-01 13:57:20 -07:00
|
|
|
// We've successfully started graphics without crashing, hurray.
|
|
|
|
// In case they update drivers and have totally different problems much later, clear the failed list.
|
|
|
|
g_Config.sFailedGPUBackends.clear();
|
2021-07-25 15:33:11 +02:00
|
|
|
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS) || System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) {
|
2021-05-14 22:48:04 -07:00
|
|
|
File::Delete(GetSysDirectory(DIRECTORY_APP_CACHE) / "FailedGraphicsBackends.txt");
|
2018-09-01 13:57:20 -07:00
|
|
|
} else {
|
2019-02-23 10:49:49 +01:00
|
|
|
g_Config.Save("clearFailedGPUBackends");
|
2018-09-01 13:57:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-09 16:28:15 -07:00
|
|
|
void NativeInit(int argc, const char *argv[], const char *savegame_dir, const char *external_dir, const char *cache_dir) {
|
2017-03-12 17:24:46 +01:00
|
|
|
net::Init(); // This needs to happen before we load the config. So on Windows we also run it in Main. It's fine to call multiple times.
|
2017-03-06 10:51:28 +01:00
|
|
|
|
2021-01-04 23:51:34 +01:00
|
|
|
ShaderTranslationInit();
|
|
|
|
|
2021-07-25 15:33:11 +02:00
|
|
|
g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count);
|
|
|
|
|
2017-08-08 15:58:25 +02:00
|
|
|
// Make sure UI state is MENU.
|
|
|
|
ResetUIState();
|
|
|
|
|
2013-07-27 13:07:34 +02:00
|
|
|
bool skipLogo = false;
|
2013-04-25 10:41:43 +02:00
|
|
|
setlocale( LC_ALL, "C" );
|
2016-01-17 22:11:28 +01:00
|
|
|
std::string user_data_path = savegame_dir;
|
2014-02-13 17:47:02 +01:00
|
|
|
pendingMessages.clear();
|
2023-03-22 12:26:14 +01:00
|
|
|
g_requestManager.Clear();
|
2013-07-10 07:27:25 +10:00
|
|
|
|
2021-05-30 00:20:41 +02:00
|
|
|
// external_dir has all kinds of meanings depending on platform.
|
|
|
|
// on iOS it's even the path to bundled app assets. It's a mess.
|
|
|
|
|
2013-07-10 07:27:25 +10:00
|
|
|
// We want this to be FIRST.
|
2021-11-06 09:22:08 +03:00
|
|
|
#if PPSSPP_PLATFORM(IOS) || PPSSPP_PLATFORM(MAC)
|
2013-07-10 07:27:25 +10:00
|
|
|
// Packed assets are included in app
|
2023-03-06 15:30:39 +01:00
|
|
|
g_VFS.Register("", new DirectoryReader(Path(external_dir)));
|
2017-03-19 08:21:54 -07:00
|
|
|
#endif
|
2020-12-05 17:49:21 -08:00
|
|
|
#if defined(ASSETS_DIR)
|
2023-03-06 15:30:39 +01:00
|
|
|
g_VFS.Register("", new DirectoryReader(Path(ASSETS_DIR)));
|
2020-12-05 17:49:21 -08:00
|
|
|
#endif
|
2019-09-28 09:23:18 -07:00
|
|
|
#if !defined(MOBILE_DEVICE) && !defined(_WIN32) && !PPSSPP_PLATFORM(SWITCH)
|
2023-03-06 15:30:39 +01:00
|
|
|
g_VFS.Register("", new DirectoryReader(File::GetExeDirectory() / "assets"));
|
|
|
|
g_VFS.Register("", new DirectoryReader(File::GetExeDirectory()));
|
|
|
|
g_VFS.Register("", new DirectoryReader(Path("/usr/local/share/ppsspp/assets")));
|
|
|
|
g_VFS.Register("", new DirectoryReader(Path("/usr/local/share/games/ppsspp/assets")));
|
|
|
|
g_VFS.Register("", new DirectoryReader(Path("/usr/share/ppsspp/assets")));
|
|
|
|
g_VFS.Register("", new DirectoryReader(Path("/usr/share/games/ppsspp/assets")));
|
2013-04-11 15:14:44 +10:00
|
|
|
#endif
|
2021-02-28 13:44:35 +01:00
|
|
|
|
2019-09-28 09:23:18 -07:00
|
|
|
#if PPSSPP_PLATFORM(SWITCH)
|
2021-05-15 09:54:28 -07:00
|
|
|
Path assetPath = Path(user_data_path) / "assets";
|
2023-03-06 15:30:39 +01:00
|
|
|
g_VFS.Register("", new DirectoryReader(assetPath));
|
2019-09-28 09:23:18 -07:00
|
|
|
#else
|
2023-03-06 15:30:39 +01:00
|
|
|
g_VFS.Register("", new DirectoryReader(Path("assets")));
|
2019-09-28 09:23:18 -07:00
|
|
|
#endif
|
2023-03-06 15:30:39 +01:00
|
|
|
g_VFS.Register("", new DirectoryReader(Path(savegame_dir)));
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2023-08-18 15:04:20 +02:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(MAC)
|
|
|
|
g_Config.defaultCurrentDirectory = Path(System_GetProperty(SYSPROP_USER_DOCUMENTS_DIR));
|
2023-08-18 14:02:59 +02:00
|
|
|
#else
|
2023-08-18 15:04:20 +02:00
|
|
|
g_Config.defaultCurrentDirectory = Path("/");
|
2023-08-18 14:02:59 +02:00
|
|
|
#endif
|
|
|
|
|
2023-05-02 00:09:22 +04:00
|
|
|
#if !PPSSPP_PLATFORM(UWP)
|
2021-05-15 09:32:41 -07:00
|
|
|
g_Config.internalDataDirectory = Path(savegame_dir);
|
2023-05-02 00:09:22 +04:00
|
|
|
#endif
|
2018-04-29 11:45:32 -07:00
|
|
|
|
2021-04-26 23:34:20 +02:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
2021-05-29 22:55:43 +02:00
|
|
|
// In Android 12 with scoped storage, due to the above, the external directory
|
|
|
|
// is no longer the plain root of external storage, but it's an app specific directory
|
|
|
|
// on external storage (g_extFilesDir).
|
2021-05-16 16:43:14 +02:00
|
|
|
if (System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) {
|
2021-07-25 15:33:11 +02:00
|
|
|
// There's no sensible default directory. Let the user browse for files.
|
|
|
|
g_Config.defaultCurrentDirectory.clear();
|
2021-05-16 16:43:14 +02:00
|
|
|
} else {
|
2021-07-25 15:33:11 +02:00
|
|
|
g_Config.memStickDirectory = Path(external_dir);
|
2021-05-29 22:55:43 +02:00
|
|
|
g_Config.defaultCurrentDirectory = Path(external_dir);
|
2021-05-16 16:43:14 +02:00
|
|
|
}
|
2021-02-28 13:44:35 +01:00
|
|
|
|
2021-05-29 22:55:43 +02:00
|
|
|
// Might also add an option to move it to internal / non-visible storage, but there's
|
|
|
|
// little point, really.
|
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
g_Config.flash0Directory = Path(external_dir) / "flash0";
|
2019-02-18 09:15:15 -08:00
|
|
|
|
2021-05-15 09:32:41 -07:00
|
|
|
Path memstickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt";
|
2019-02-18 09:15:15 -08:00
|
|
|
if (File::Exists(memstickDirFile)) {
|
2021-07-25 15:33:11 +02:00
|
|
|
INFO_LOG(SYSTEM, "Reading '%s' to find memstick dir.", memstickDirFile.c_str());
|
2019-02-18 09:15:15 -08:00
|
|
|
std::string memstickDir;
|
2021-05-16 16:43:14 +02:00
|
|
|
if (File::ReadFileToString(true, memstickDirFile, memstickDir)) {
|
|
|
|
Path memstickPath(memstickDir);
|
|
|
|
if (!memstickPath.empty() && File::Exists(memstickPath)) {
|
|
|
|
g_Config.memStickDirectory = memstickPath;
|
2021-05-29 22:55:43 +02:00
|
|
|
INFO_LOG(SYSTEM, "Memstick Directory from memstick_dir.txt: '%s'", g_Config.memStickDirectory.c_str());
|
2021-05-16 16:43:14 +02:00
|
|
|
} else {
|
|
|
|
ERROR_LOG(SYSTEM, "Couldn't read directory '%s' specified by memstick_dir.txt.", memstickDir.c_str());
|
2021-05-29 22:55:43 +02:00
|
|
|
if (System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) {
|
2021-07-25 00:16:30 +02:00
|
|
|
// Ask the user to configure a memstick directory.
|
|
|
|
INFO_LOG(SYSTEM, "Asking the user.");
|
|
|
|
g_Config.memStickDirectory.clear();
|
2021-05-29 22:55:43 +02:00
|
|
|
}
|
2021-05-16 16:43:14 +02:00
|
|
|
}
|
2019-02-18 09:15:15 -08:00
|
|
|
}
|
2021-04-26 23:34:20 +02:00
|
|
|
} else {
|
2021-07-25 15:33:11 +02:00
|
|
|
INFO_LOG(SYSTEM, "No memstick directory file found (tried to open '%s')", memstickDirFile.c_str());
|
2019-02-18 09:15:15 -08:00
|
|
|
}
|
2021-04-24 22:47:57 +02:00
|
|
|
|
2021-09-25 20:40:34 -07:00
|
|
|
// Attempt to create directories after reading the path.
|
|
|
|
if (!System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) {
|
2023-08-18 15:04:20 +02:00
|
|
|
CreateSysDirectories();
|
2021-09-25 20:40:34 -07:00
|
|
|
}
|
2023-04-28 23:22:17 +04:00
|
|
|
#elif PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__)
|
|
|
|
Path memstickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt";
|
2023-05-02 00:09:22 +04:00
|
|
|
if (File::Exists(memstickDirFile)) {
|
|
|
|
INFO_LOG(SYSTEM, "Reading '%s' to find memstick dir.", memstickDirFile.c_str());
|
2023-04-28 23:22:17 +04:00
|
|
|
std::string memstickDir;
|
2023-05-02 00:09:22 +04:00
|
|
|
if (File::ReadFileToString(true, memstickDirFile, memstickDir)) {
|
2023-04-28 23:22:17 +04:00
|
|
|
Path memstickPath(memstickDir);
|
|
|
|
if (!memstickPath.empty() && File::Exists(memstickPath)) {
|
|
|
|
g_Config.memStickDirectory = memstickPath;
|
|
|
|
g_Config.SetSearchPath(GetSysDirectory(DIRECTORY_SYSTEM));
|
|
|
|
g_Config.Reload();
|
|
|
|
INFO_LOG(SYSTEM, "Memstick Directory from memstick_dir.txt: '%s'", g_Config.memStickDirectory.c_str());
|
2023-05-02 00:09:22 +04:00
|
|
|
} else {
|
2023-04-28 23:22:17 +04:00
|
|
|
ERROR_LOG(SYSTEM, "Couldn't read directory '%s' specified by memstick_dir.txt.", memstickDir.c_str());
|
2023-05-02 00:09:22 +04:00
|
|
|
g_Config.memStickDirectory.clear();
|
2023-04-28 23:22:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2023-05-02 00:09:22 +04:00
|
|
|
INFO_LOG(SYSTEM, "No memstick directory file found (tried to open '%s')", memstickDirFile.c_str());
|
2023-04-28 23:22:17 +04:00
|
|
|
}
|
2021-03-02 20:57:25 -08:00
|
|
|
#elif PPSSPP_PLATFORM(IOS)
|
2021-05-29 17:32:22 -07:00
|
|
|
g_Config.defaultCurrentDirectory = g_Config.internalDataDirectory;
|
2023-01-31 13:36:14 +03:00
|
|
|
g_Config.memStickDirectory = DarwinFileSystemServices::appropriateMemoryStickDirectoryToUse();
|
2021-05-09 15:25:12 +02:00
|
|
|
g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0";
|
2021-11-06 09:22:08 +03:00
|
|
|
#elif PPSSPP_PLATFORM(MAC)
|
2023-01-31 13:36:14 +03:00
|
|
|
g_Config.memStickDirectory = DarwinFileSystemServices::appropriateMemoryStickDirectoryToUse();
|
2021-11-06 09:22:08 +03:00
|
|
|
g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0";
|
2019-09-28 09:23:18 -07:00
|
|
|
#elif PPSSPP_PLATFORM(SWITCH)
|
2021-05-15 09:32:41 -07:00
|
|
|
g_Config.memStickDirectory = g_Config.internalDataDirectory / "config/ppsspp";
|
|
|
|
g_Config.flash0Directory = g_Config.internalDataDirectory / "assets/flash0";
|
2021-05-06 01:31:38 +02:00
|
|
|
#elif !PPSSPP_PLATFORM(WINDOWS)
|
2014-06-25 16:10:00 +10:00
|
|
|
std::string config;
|
|
|
|
if (getenv("XDG_CONFIG_HOME") != NULL)
|
|
|
|
config = getenv("XDG_CONFIG_HOME");
|
|
|
|
else if (getenv("HOME") != NULL)
|
|
|
|
config = getenv("HOME") + std::string("/.config");
|
|
|
|
else // Just in case
|
|
|
|
config = "./config";
|
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
g_Config.memStickDirectory = Path(config) / "ppsspp";
|
2021-05-15 09:59:25 -07:00
|
|
|
g_Config.flash0Directory = File::GetExeDirectory() / "assets/flash0";
|
2021-05-30 00:20:41 +02:00
|
|
|
if (getenv("HOME") != nullptr) {
|
|
|
|
g_Config.defaultCurrentDirectory = Path(getenv("HOME"));
|
|
|
|
} else {
|
|
|
|
// Hm, should probably actually explicitly set the current directory..
|
|
|
|
// Though it's not many platforms that'll land us here.
|
|
|
|
g_Config.currentDirectory = Path(".");
|
|
|
|
}
|
2013-10-12 16:02:03 -07:00
|
|
|
#endif
|
|
|
|
|
2021-11-20 14:47:59 +01:00
|
|
|
if (g_Config.currentDirectory.empty()) {
|
2023-08-18 14:02:59 +02:00
|
|
|
g_Config.currentDirectory = g_Config.defaultCurrentDirectory;
|
2021-11-20 14:47:59 +01:00
|
|
|
}
|
|
|
|
|
2016-02-27 13:10:08 -08:00
|
|
|
if (cache_dir && strlen(cache_dir)) {
|
2021-05-15 09:32:41 -07:00
|
|
|
g_Config.appCacheDirectory = Path(cache_dir);
|
|
|
|
DiskCachingFileLoaderCache::SetCacheDir(g_Config.appCacheDirectory);
|
2016-02-27 13:10:08 -08:00
|
|
|
}
|
|
|
|
|
2021-07-25 15:33:11 +02:00
|
|
|
if (!LogManager::GetInstance()) {
|
2020-08-15 18:40:50 +02:00
|
|
|
LogManager::Init(&g_Config.bEnableLogging);
|
2021-07-25 15:33:11 +02:00
|
|
|
}
|
2017-04-15 16:30:37 -07:00
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
#if !PPSSPP_PLATFORM(WINDOWS)
|
2021-05-30 12:45:12 +02:00
|
|
|
g_Config.SetSearchPath(GetSysDirectory(DIRECTORY_SYSTEM));
|
2018-03-24 12:51:54 +01:00
|
|
|
|
|
|
|
// Note that if we don't have storage permission here, loading the config will
|
|
|
|
// fail and it will be set to the default. Later, we load again when we get permission.
|
2013-10-12 16:02:03 -07:00
|
|
|
g_Config.Load();
|
2013-03-31 18:22:27 -07:00
|
|
|
#endif
|
2021-05-30 12:45:12 +02:00
|
|
|
|
2016-01-10 13:08:19 +01:00
|
|
|
LogManager *logman = LogManager::GetInstance();
|
2012-12-25 08:34:19 +01:00
|
|
|
|
2012-12-27 00:18:45 +01:00
|
|
|
const char *fileToLog = 0;
|
2021-05-06 01:31:38 +02:00
|
|
|
Path stateToLoad;
|
2012-12-27 00:18:45 +01:00
|
|
|
|
2017-11-21 12:22:38 +01:00
|
|
|
bool gotBootFilename = false;
|
2020-05-09 13:52:04 -07:00
|
|
|
bool gotoGameSettings = false;
|
|
|
|
bool gotoTouchScreenTest = false;
|
2021-05-09 18:38:48 +02:00
|
|
|
boot_filename.clear();
|
2017-11-21 12:22:38 +01:00
|
|
|
|
2012-11-04 11:31:06 +01:00
|
|
|
// Parse command line
|
2023-08-25 11:33:48 +02:00
|
|
|
LogLevel logLevel = LogLevel::LINFO;
|
2021-01-30 19:51:35 +00:00
|
|
|
bool forceLogLevel = false;
|
2023-08-25 11:33:48 +02:00
|
|
|
const auto setLogLevel = [&logLevel, &forceLogLevel](LogLevel level) {
|
2021-01-30 19:51:35 +00:00
|
|
|
logLevel = level;
|
|
|
|
forceLogLevel = true;
|
|
|
|
};
|
|
|
|
|
2012-11-04 11:31:06 +01:00
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (argv[i][0] == '-') {
|
2021-09-19 11:54:53 +03:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
// On Apple system debugged executable may get -NSDocumentRevisionsDebugMode YES in argv.
|
|
|
|
if (!strcmp(argv[i], "-NSDocumentRevisionsDebugMode") && argc - 1 > i) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-04 11:31:06 +01:00
|
|
|
switch (argv[i][1]) {
|
|
|
|
case 'd':
|
|
|
|
// Enable debug logging
|
2013-01-09 00:12:02 +01:00
|
|
|
// Note that you must also change the max log level in Log.h.
|
2023-08-25 11:33:48 +02:00
|
|
|
setLogLevel(LogLevel::LDEBUG);
|
2012-11-04 11:31:06 +01:00
|
|
|
break;
|
2016-09-10 17:16:53 +02:00
|
|
|
case 'v':
|
|
|
|
// Enable verbose logging
|
|
|
|
// Note that you must also change the max log level in Log.h.
|
2023-08-25 11:33:48 +02:00
|
|
|
setLogLevel(LogLevel::LVERBOSE);
|
2012-12-01 23:20:08 +01:00
|
|
|
break;
|
2012-12-05 13:55:24 +07:00
|
|
|
case 'j':
|
2017-03-02 12:36:54 +01:00
|
|
|
g_Config.iCpuCore = (int)CPUCore::JIT;
|
2012-12-25 08:34:19 +01:00
|
|
|
g_Config.bSaveSettings = false;
|
2012-12-22 09:49:59 -08:00
|
|
|
break;
|
2012-12-05 13:55:24 +07:00
|
|
|
case 'i':
|
2017-03-02 12:36:54 +01:00
|
|
|
g_Config.iCpuCore = (int)CPUCore::INTERPRETER;
|
2016-05-08 01:43:27 +02:00
|
|
|
g_Config.bSaveSettings = false;
|
|
|
|
break;
|
|
|
|
case 'r':
|
2023-08-20 18:36:06 -07:00
|
|
|
g_Config.iCpuCore = (int)CPUCore::IR_INTERPRETER;
|
|
|
|
g_Config.bSaveSettings = false;
|
|
|
|
break;
|
|
|
|
case 'J':
|
|
|
|
g_Config.iCpuCore = (int)CPUCore::JIT_IR;
|
2012-12-25 08:34:19 +01:00
|
|
|
g_Config.bSaveSettings = false;
|
2012-12-05 13:55:24 +07:00
|
|
|
break;
|
2012-12-27 00:18:45 +01:00
|
|
|
case '-':
|
2021-01-30 16:08:29 +00:00
|
|
|
if (!strncmp(argv[i], "--loglevel=", strlen("--loglevel=")) && strlen(argv[i]) > strlen("--loglevel="))
|
2023-08-25 11:33:48 +02:00
|
|
|
setLogLevel(static_cast<LogLevel>(std::atoi(argv[i] + strlen("--loglevel="))));
|
2012-12-27 00:18:45 +01:00
|
|
|
if (!strncmp(argv[i], "--log=", strlen("--log=")) && strlen(argv[i]) > strlen("--log="))
|
|
|
|
fileToLog = argv[i] + strlen("--log=");
|
2013-04-01 00:28:40 -07:00
|
|
|
if (!strncmp(argv[i], "--state=", strlen("--state=")) && strlen(argv[i]) > strlen("--state="))
|
2021-05-06 01:31:38 +02:00
|
|
|
stateToLoad = Path(std::string(argv[i] + strlen("--state=")));
|
2014-04-26 01:14:08 -04:00
|
|
|
if (!strncmp(argv[i], "--escape-exit", strlen("--escape-exit")))
|
2014-04-26 01:54:32 -04:00
|
|
|
g_Config.bPauseExitsEmulator = true;
|
2018-04-02 16:31:26 +02:00
|
|
|
if (!strncmp(argv[i], "--pause-menu-exit", strlen("--pause-menu-exit")))
|
|
|
|
g_Config.bPauseMenuExitsEmulator = true;
|
2020-10-10 15:22:59 +02:00
|
|
|
if (!strcmp(argv[i], "--fullscreen")) {
|
2022-05-28 15:47:12 -07:00
|
|
|
g_Config.iForceFullScreen = 1;
|
2023-03-22 22:17:53 +01:00
|
|
|
System_ToggleFullscreenState("1");
|
2020-10-10 15:22:59 +02:00
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "--windowed")) {
|
2022-05-28 15:47:12 -07:00
|
|
|
g_Config.iForceFullScreen = 0;
|
2023-03-22 22:17:53 +01:00
|
|
|
System_ToggleFullscreenState("0");
|
2020-10-10 15:22:59 +02:00
|
|
|
}
|
2020-05-09 13:52:04 -07:00
|
|
|
if (!strcmp(argv[i], "--touchscreentest"))
|
|
|
|
gotoTouchScreenTest = true;
|
|
|
|
if (!strcmp(argv[i], "--gamesettings"))
|
|
|
|
gotoGameSettings = true;
|
2022-10-09 15:04:19 +02:00
|
|
|
if (!strncmp(argv[i], "--appendconfig=", strlen("--appendconfig=")) && strlen(argv[i]) > strlen("--appendconfig=")) {
|
|
|
|
g_Config.SetAppendedConfigIni(Path(std::string(argv[i] + strlen("--appendconfig="))));
|
|
|
|
g_Config.LoadAppendedConfig();
|
|
|
|
}
|
2012-12-27 00:18:45 +01:00
|
|
|
break;
|
2012-11-04 11:31:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-11-21 12:22:38 +01:00
|
|
|
// This parameter should be a boot filename. Only accept it if we
|
|
|
|
// don't already have one.
|
|
|
|
if (!gotBootFilename) {
|
|
|
|
gotBootFilename = true;
|
2020-08-15 16:25:50 +02:00
|
|
|
INFO_LOG(SYSTEM, "Boot filename found in args: '%s'", argv[i]);
|
2017-11-21 12:22:38 +01:00
|
|
|
|
|
|
|
bool okToLoad = true;
|
2018-04-01 23:28:36 -07:00
|
|
|
bool okToCheck = true;
|
2017-11-21 12:22:38 +01:00
|
|
|
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
|
|
|
PermissionStatus status = System_GetPermissionStatus(SYSTEM_PERMISSION_STORAGE);
|
2018-04-01 23:28:36 -07:00
|
|
|
if (status == PERMISSION_STATUS_DENIED) {
|
2020-08-15 16:25:50 +02:00
|
|
|
ERROR_LOG(IO, "Storage permission denied. Launching without argument.");
|
2017-11-21 12:22:38 +01:00
|
|
|
okToLoad = false;
|
2018-04-01 23:28:36 -07:00
|
|
|
okToCheck = false;
|
|
|
|
} else if (status != PERMISSION_STATUS_GRANTED) {
|
2020-08-15 16:25:50 +02:00
|
|
|
ERROR_LOG(IO, "Storage permission not granted. Launching without argument check.");
|
2018-04-01 23:28:36 -07:00
|
|
|
okToCheck = false;
|
2017-11-21 12:22:38 +01:00
|
|
|
} else {
|
2020-08-15 16:25:50 +02:00
|
|
|
INFO_LOG(IO, "Storage permission granted.");
|
2017-11-21 12:22:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (okToLoad) {
|
2021-09-09 00:00:54 +02:00
|
|
|
std::string str = std::string(argv[i]);
|
|
|
|
// Handle file:/// URIs, since you get those when creating shortcuts on some Android systems.
|
|
|
|
if (startsWith(str, "file:///")) {
|
|
|
|
str = UriDecode(str.substr(7));
|
|
|
|
INFO_LOG(IO, "Decoding '%s' to '%s'", argv[i], str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
boot_filename = Path(str);
|
2017-11-21 12:22:38 +01:00
|
|
|
skipLogo = true;
|
2018-04-01 23:28:36 -07:00
|
|
|
}
|
|
|
|
if (okToLoad && okToCheck) {
|
2017-11-21 12:22:38 +01:00
|
|
|
std::unique_ptr<FileLoader> fileLoader(ConstructFileLoader(boot_filename));
|
|
|
|
if (!fileLoader->Exists()) {
|
|
|
|
fprintf(stderr, "File not found: %s\n", boot_filename.c_str());
|
2020-05-09 13:52:04 -07:00
|
|
|
#if defined(_WIN32) || defined(__ANDROID__)
|
2018-05-10 00:59:21 +02:00
|
|
|
// Ignore and proceed.
|
|
|
|
#else
|
|
|
|
// Bail.
|
2017-11-21 12:22:38 +01:00
|
|
|
exit(1);
|
2018-05-10 00:59:21 +02:00
|
|
|
#endif
|
2017-11-21 12:22:38 +01:00
|
|
|
}
|
2012-12-01 23:38:18 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Can only boot one file");
|
2020-05-09 13:52:04 -07:00
|
|
|
#if defined(_WIN32) || defined(__ANDROID__)
|
2018-05-10 00:59:21 +02:00
|
|
|
// Ignore and proceed.
|
|
|
|
#else
|
|
|
|
// Bail.
|
2012-11-04 11:31:06 +01:00
|
|
|
exit(1);
|
2018-05-10 00:59:21 +02:00
|
|
|
#endif
|
2012-11-04 11:31:06 +01:00
|
|
|
}
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 14:59:37 +01:00
|
|
|
if (fileToLog)
|
2012-12-27 00:18:45 +01:00
|
|
|
LogManager::GetInstance()->ChangeFileLog(fileToLog);
|
|
|
|
|
2021-01-30 19:51:35 +00:00
|
|
|
if (forceLogLevel)
|
|
|
|
LogManager::GetInstance()->SetAllLogLevels(logLevel);
|
2021-01-30 16:08:29 +00:00
|
|
|
|
2018-04-29 11:45:32 -07:00
|
|
|
PostLoadConfig();
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2020-08-15 19:01:16 +02:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
|
|
|
logger = new AndroidLogger();
|
|
|
|
logman->AddListener(logger);
|
|
|
|
#elif (defined(MOBILE_DEVICE) && !defined(_DEBUG))
|
2017-12-31 00:12:34 -08:00
|
|
|
// Enable basic logging for any kind of mobile device, since LogManager doesn't.
|
|
|
|
// The MOBILE_DEVICE/_DEBUG condition matches LogManager.cpp.
|
2020-08-15 19:01:16 +02:00
|
|
|
logger = new PrintfLogger();
|
2017-12-31 00:12:34 -08:00
|
|
|
logman->AddListener(logger);
|
2016-01-10 13:08:19 +01:00
|
|
|
#endif
|
2016-09-10 17:16:53 +02:00
|
|
|
|
2018-03-24 12:51:54 +01:00
|
|
|
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
|
|
|
if (System_GetPermissionStatus(SYSTEM_PERMISSION_STORAGE) != PERMISSION_STATUS_GRANTED) {
|
|
|
|
System_AskForPermission(SYSTEM_PERMISSION_STORAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-06 00:34:50 +02:00
|
|
|
auto des = GetI18NCategory(I18NCat::DESKTOPUI);
|
2013-11-29 16:33:17 +01:00
|
|
|
// Note to translators: do not translate this/add this to PPSSPP-lang's files.
|
|
|
|
// It's intended to be custom for every user.
|
2013-08-30 13:52:15 -04:00
|
|
|
// Only add it to your own personal copies of PPSSPP.
|
2019-06-07 05:16:27 +08:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
|
|
|
// Roboto font is loaded in TextDrawerUWP.
|
|
|
|
g_Config.sFont = des->T("Font", "Roboto");
|
|
|
|
#elif defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)
|
2013-08-31 01:36:52 -07:00
|
|
|
// TODO: Could allow a setting to specify a font file to load?
|
|
|
|
// TODO: Make this a constant if we can sanely load the font on other systems?
|
|
|
|
AddFontResourceEx(L"assets/Roboto-Condensed.ttf", FR_PRIVATE, NULL);
|
2015-10-04 15:11:36 -07:00
|
|
|
// The font goes by two names, let's allow either one.
|
|
|
|
if (CheckFontIsUsable(L"Roboto Condensed")) {
|
|
|
|
g_Config.sFont = des->T("Font", "Roboto Condensed");
|
|
|
|
} else {
|
|
|
|
g_Config.sFont = des->T("Font", "Roboto");
|
|
|
|
}
|
2018-06-09 11:34:12 -07:00
|
|
|
#elif defined(USING_QT_UI)
|
|
|
|
size_t fontSize = 0;
|
2023-03-06 14:23:56 +01:00
|
|
|
uint8_t *fontData = g_VFS.ReadFile("Roboto-Condensed.ttf", &fontSize);
|
2018-06-09 11:34:12 -07:00
|
|
|
if (fontData) {
|
|
|
|
int fontID = QFontDatabase::addApplicationFontFromData(QByteArray((const char *)fontData, fontSize));
|
|
|
|
delete [] fontData;
|
|
|
|
|
|
|
|
QStringList fontsFound = QFontDatabase::applicationFontFamilies(fontID);
|
|
|
|
if (fontsFound.size() >= 1) {
|
|
|
|
// Might be "Roboto" or "Roboto Condensed".
|
|
|
|
g_Config.sFont = des->T("Font", fontsFound.at(0).toUtf8().constData());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Let's try for it being a system font.
|
|
|
|
g_Config.sFont = des->T("Font", "Roboto Condensed");
|
|
|
|
}
|
2013-08-30 20:19:03 +02:00
|
|
|
#endif
|
2013-04-18 11:58:54 +02:00
|
|
|
|
2020-08-04 23:36:35 +02:00
|
|
|
// TODO: Load these in the background instead of synchronously.
|
2023-07-12 15:37:16 +02:00
|
|
|
g_BackgroundAudio.SFX().LoadSamples();
|
2020-08-04 23:36:35 +02:00
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
if (!boot_filename.empty() && stateToLoad.Valid()) {
|
2020-05-16 15:20:22 +02:00
|
|
|
SaveState::Load(stateToLoad, -1, [](SaveState::Status status, const std::string &message, void *) {
|
2019-06-03 12:21:22 +02:00
|
|
|
if (!message.empty() && (!g_Config.bDumpFrames || !g_Config.bDumpVideoOutput)) {
|
2023-06-20 14:40:46 +02:00
|
|
|
g_OSD.Show(status == SaveState::Status::SUCCESS ? OSDType::MESSAGE_SUCCESS : OSDType::MESSAGE_ERROR,
|
|
|
|
message, status == SaveState::Status::SUCCESS ? 2.0 : 5.0);
|
2016-05-27 21:25:05 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-10-17 16:44:09 +02:00
|
|
|
|
2023-07-12 20:04:02 +02:00
|
|
|
if (g_Config.bAchievementsEnable) {
|
|
|
|
FILE *iconCacheFile = File::OpenCFile(GetSysDirectory(DIRECTORY_CACHE) / "icon.cache", "rb");
|
|
|
|
if (iconCacheFile) {
|
|
|
|
g_iconCache.LoadFromFile(iconCacheFile);
|
|
|
|
fclose(iconCacheFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-28 09:14:53 -07:00
|
|
|
DEBUG_LOG(SYSTEM, "ScreenManager!");
|
2023-03-22 09:42:31 +01:00
|
|
|
g_screenManager = new ScreenManager();
|
2021-07-25 15:33:11 +02:00
|
|
|
if (g_Config.memStickDirectory.empty()) {
|
|
|
|
INFO_LOG(SYSTEM, "No memstick directory! Asking for one to be configured.");
|
2023-03-22 09:42:31 +01:00
|
|
|
g_screenManager->switchScreen(new LogoScreen(AfterLogoScreen::MEMSTICK_SCREEN_INITIAL_SETUP));
|
2021-07-25 15:33:11 +02:00
|
|
|
} else if (gotoGameSettings) {
|
2023-03-22 09:42:31 +01:00
|
|
|
g_screenManager->switchScreen(new LogoScreen(AfterLogoScreen::TO_GAME_SETTINGS));
|
2020-05-09 13:52:04 -07:00
|
|
|
} else if (gotoTouchScreenTest) {
|
2023-03-22 09:42:31 +01:00
|
|
|
g_screenManager->switchScreen(new MainScreen());
|
|
|
|
g_screenManager->push(new TouchTestScreen(Path()));
|
2020-05-09 13:52:04 -07:00
|
|
|
} else if (skipLogo) {
|
2023-03-22 09:42:31 +01:00
|
|
|
g_screenManager->switchScreen(new EmuScreen(boot_filename));
|
2013-07-27 13:07:34 +02:00
|
|
|
} else {
|
2023-03-22 09:42:31 +01:00
|
|
|
g_screenManager->switchScreen(new LogoScreen(AfterLogoScreen::DEFAULT));
|
2013-07-27 13:07:34 +02:00
|
|
|
}
|
2013-10-31 11:06:54 +01:00
|
|
|
|
2023-12-10 21:57:05 +01:00
|
|
|
g_screenManager->SetBackgroundOverlayScreens(new BackgroundScreen(), new OSDOverlayScreen());
|
2023-06-19 15:50:36 +02:00
|
|
|
|
2018-12-18 23:56:36 +01:00
|
|
|
// Easy testing
|
|
|
|
// screenManager->push(new GPUDriverTestScreen());
|
2018-12-18 09:35:53 +01:00
|
|
|
|
2018-04-21 13:54:44 -07:00
|
|
|
if (g_Config.bRemoteShareOnStartup && g_Config.bRemoteDebuggerOnStartup)
|
2018-04-21 13:51:18 -07:00
|
|
|
StartWebServer(WebServerFlags::ALL);
|
2018-04-21 13:54:44 -07:00
|
|
|
else if (g_Config.bRemoteShareOnStartup)
|
|
|
|
StartWebServer(WebServerFlags::DISCS);
|
|
|
|
else if (g_Config.bRemoteDebuggerOnStartup)
|
|
|
|
StartWebServer(WebServerFlags::DEBUGGER);
|
2017-12-10 18:30:28 -08:00
|
|
|
|
2013-10-31 11:06:54 +01:00
|
|
|
std::string sysName = System_GetProperty(SYSPROP_NAME);
|
|
|
|
isOuya = KeyMap::IsOuya(sysName);
|
2014-03-02 01:09:16 +10:00
|
|
|
|
2014-06-29 01:09:15 -07:00
|
|
|
// We do this here, instead of in NativeInitGraphics, because the display may be reset.
|
|
|
|
// When it's reset we don't want to forget all our managed things.
|
2018-09-01 13:57:20 -07:00
|
|
|
CheckFailedGPUBackends();
|
2023-08-18 15:04:44 +02:00
|
|
|
SetGPUBackend((GPUBackend)g_Config.iGPUBackend);
|
2018-09-06 18:31:09 -07:00
|
|
|
renderCounter = 0;
|
2017-04-15 16:30:37 -07:00
|
|
|
|
2023-06-16 13:04:20 +02:00
|
|
|
// Initialize retro achievements runtime.
|
|
|
|
Achievements::Initialize();
|
|
|
|
|
2017-04-15 16:30:37 -07:00
|
|
|
// Must be done restarting by now.
|
|
|
|
restarting = false;
|
2013-07-16 22:50:53 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 19:03:33 +02:00
|
|
|
void CallbackPostRender(UIContext *dc, void *userdata);
|
2020-07-28 19:06:29 +02:00
|
|
|
bool CreateGlobalPipelines();
|
2017-05-16 14:09:15 +02:00
|
|
|
|
2017-11-29 18:53:52 +01:00
|
|
|
bool NativeInitGraphics(GraphicsContext *graphicsContext) {
|
2020-08-15 16:25:50 +02:00
|
|
|
INFO_LOG(SYSTEM, "NativeInitGraphics");
|
2017-03-26 09:51:33 -07:00
|
|
|
|
2023-09-24 12:33:01 +02:00
|
|
|
_assert_msg_(g_screenManager, "No screenmanager, bad init order. Backend = %d", g_Config.iGPUBackend);
|
2023-01-02 17:38:38 +01:00
|
|
|
|
2020-02-29 19:31:58 -08:00
|
|
|
// We set this now so any resize during init is processed later.
|
|
|
|
resized = false;
|
|
|
|
|
2017-03-26 09:51:33 -07:00
|
|
|
Core_SetGraphicsContext(graphicsContext);
|
|
|
|
g_draw = graphicsContext->GetDrawContext();
|
|
|
|
|
2022-12-18 21:58:20 +01:00
|
|
|
_assert_(g_draw);
|
|
|
|
|
2020-07-28 19:06:29 +02:00
|
|
|
if (!CreateGlobalPipelines()) {
|
|
|
|
ERROR_LOG(G3D, "Failed to create global pipelines");
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-29 21:51:14 +01:00
|
|
|
|
2022-03-31 17:03:34 +02:00
|
|
|
ui_draw2d.SetAtlas(GetUIAtlas());
|
|
|
|
ui_draw2d.SetFontAtlas(GetFontAtlas());
|
2017-03-26 09:51:33 -07:00
|
|
|
|
2013-03-30 19:23:20 +01:00
|
|
|
uiContext = new UIContext();
|
2022-02-11 12:32:23 +01:00
|
|
|
uiContext->theme = GetTheme();
|
2022-03-31 17:03:34 +02:00
|
|
|
UpdateTheme(uiContext);
|
2014-08-17 12:19:04 +02:00
|
|
|
|
2017-01-30 14:33:38 +01:00
|
|
|
ui_draw2d.Init(g_draw, texColorPipeline);
|
2016-12-26 17:03:01 +01:00
|
|
|
|
2023-12-08 12:29:24 +01:00
|
|
|
uiContext->Init(g_draw, texColorPipeline, colorPipeline, &ui_draw2d);
|
2013-08-30 18:15:45 +02:00
|
|
|
if (uiContext->Text())
|
|
|
|
uiContext->Text()->SetFont("Tahoma", 20, 0);
|
2014-02-10 15:14:45 +01:00
|
|
|
|
2023-03-22 09:42:31 +01:00
|
|
|
g_screenManager->setUIContext(uiContext);
|
|
|
|
g_screenManager->setDrawContext(g_draw);
|
2023-08-23 19:03:33 +02:00
|
|
|
g_screenManager->setPostRenderCallback(&CallbackPostRender, nullptr);
|
2023-03-22 09:42:31 +01:00
|
|
|
g_screenManager->deviceRestored();
|
2013-03-30 19:23:20 +01:00
|
|
|
|
2014-06-22 14:23:06 +02:00
|
|
|
#ifdef _WIN32
|
2015-01-24 13:50:27 +01:00
|
|
|
winAudioBackend = CreateAudioBackend((AudioBackendType)g_Config.iAudioBackend);
|
2017-02-25 00:25:46 +01:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
2023-03-24 15:32:48 +01:00
|
|
|
winAudioBackend->Init(0, &NativeMix, 44100);
|
2017-02-25 00:25:46 +01:00
|
|
|
#else
|
2023-03-24 13:59:27 +01:00
|
|
|
winAudioBackend->Init(MainWindow::GetHWND(), &NativeMix, 44100);
|
2017-02-25 00:25:46 +01:00
|
|
|
#endif
|
2014-06-22 14:23:06 +02:00
|
|
|
#endif
|
2016-02-14 22:07:10 +01:00
|
|
|
|
2020-01-14 17:15:11 +08:00
|
|
|
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
|
|
|
|
if (IsWin7OrHigher()) {
|
2020-01-13 15:06:02 +08:00
|
|
|
winCamera = new WindowsCaptureDevice(CAPTUREDEVIDE_TYPE::VIDEO);
|
|
|
|
winCamera->sendMessage({ CAPTUREDEVIDE_COMMAND::INITIALIZE, nullptr });
|
2020-07-31 10:24:17 +08:00
|
|
|
winMic = new WindowsCaptureDevice(CAPTUREDEVIDE_TYPE::AUDIO);
|
|
|
|
winMic->sendMessage({ CAPTUREDEVIDE_COMMAND::INITIALIZE, nullptr });
|
2020-01-13 15:06:02 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-14 22:07:10 +01:00
|
|
|
g_gameInfoCache = new GameInfoCache();
|
2017-11-10 13:13:56 +01:00
|
|
|
|
2020-07-28 19:06:29 +02:00
|
|
|
if (gpu) {
|
2023-08-30 23:42:00 +02:00
|
|
|
PSP_CoreParameter().pixelWidth = g_display.pixel_xres;
|
|
|
|
PSP_CoreParameter().pixelHeight = g_display.pixel_yres;
|
2023-02-25 23:04:27 +01:00
|
|
|
gpu->DeviceRestore(g_draw);
|
2020-07-28 19:06:29 +02:00
|
|
|
}
|
2017-12-07 14:56:19 +01:00
|
|
|
|
2020-08-15 16:25:50 +02:00
|
|
|
INFO_LOG(SYSTEM, "NativeInitGraphics completed");
|
2023-03-21 12:08:03 +01:00
|
|
|
|
2017-11-29 18:53:52 +01:00
|
|
|
return true;
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2020-07-28 19:06:29 +02:00
|
|
|
bool CreateGlobalPipelines() {
|
|
|
|
using namespace Draw;
|
|
|
|
|
2022-07-25 12:22:50 +02:00
|
|
|
ShaderModule *vs_color_2d = g_draw->GetVshaderPreset(VS_COLOR_2D);
|
|
|
|
ShaderModule *fs_color_2d = g_draw->GetFshaderPreset(FS_COLOR_2D);
|
|
|
|
ShaderModule *vs_texture_color_2d = g_draw->GetVshaderPreset(VS_TEXTURE_COLOR_2D);
|
|
|
|
ShaderModule *fs_texture_color_2d = g_draw->GetFshaderPreset(FS_TEXTURE_COLOR_2D);
|
|
|
|
|
|
|
|
if (!vs_color_2d || !fs_color_2d || !vs_texture_color_2d || !fs_texture_color_2d) {
|
|
|
|
ERROR_LOG(G3D, "Failed to get shader preset");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-28 19:06:29 +02:00
|
|
|
InputLayout *inputLayout = ui_draw2d.CreateInputLayout(g_draw);
|
|
|
|
BlendState *blendNormal = g_draw->CreateBlendState({ true, 0xF, BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA });
|
|
|
|
DepthStencilState *depth = g_draw->CreateDepthStencilState({ false, false, Comparison::LESS });
|
|
|
|
RasterState *rasterNoCull = g_draw->CreateRasterState({});
|
|
|
|
|
|
|
|
PipelineDesc colorDesc{
|
|
|
|
Primitive::TRIANGLE_LIST,
|
2022-07-25 12:22:50 +02:00
|
|
|
{ vs_color_2d, fs_color_2d },
|
2020-07-28 19:06:29 +02:00
|
|
|
inputLayout, depth, blendNormal, rasterNoCull, &vsColBufDesc,
|
|
|
|
};
|
|
|
|
PipelineDesc texColorDesc{
|
|
|
|
Primitive::TRIANGLE_LIST,
|
2022-07-25 12:22:50 +02:00
|
|
|
{ vs_texture_color_2d, fs_texture_color_2d },
|
2020-07-28 19:06:29 +02:00
|
|
|
inputLayout, depth, blendNormal, rasterNoCull, &vsTexColBufDesc,
|
|
|
|
};
|
|
|
|
|
2022-09-07 23:55:33 +02:00
|
|
|
colorPipeline = g_draw->CreateGraphicsPipeline(colorDesc, "global_color");
|
2020-07-28 19:06:29 +02:00
|
|
|
if (!colorPipeline) {
|
|
|
|
// Something really critical is wrong, don't care much about correct releasing of the states.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-07 23:55:33 +02:00
|
|
|
texColorPipeline = g_draw->CreateGraphicsPipeline(texColorDesc, "global_texcolor");
|
2020-07-28 19:06:29 +02:00
|
|
|
if (!texColorPipeline) {
|
|
|
|
// Something really critical is wrong, don't care much about correct releasing of the states.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release these now, reference counting should ensure that they get completely released
|
|
|
|
// once we delete both pipelines.
|
|
|
|
inputLayout->Release();
|
|
|
|
rasterNoCull->Release();
|
|
|
|
blendNormal->Release();
|
|
|
|
depth->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-16 22:50:53 +02:00
|
|
|
void NativeShutdownGraphics() {
|
2022-02-06 23:34:44 -08:00
|
|
|
INFO_LOG(SYSTEM, "NativeShutdownGraphics");
|
|
|
|
|
2023-03-22 09:42:31 +01:00
|
|
|
if (g_screenManager) {
|
|
|
|
g_screenManager->deviceLost();
|
2022-12-30 22:59:44 +01:00
|
|
|
}
|
2023-12-10 12:37:35 +01:00
|
|
|
g_iconCache.ClearTextures();
|
2018-03-27 23:10:33 +02:00
|
|
|
|
2017-12-07 14:56:19 +01:00
|
|
|
if (gpu)
|
|
|
|
gpu->DeviceLost();
|
|
|
|
|
2020-07-28 19:06:29 +02:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS)
|
2015-01-11 21:00:56 +01:00
|
|
|
delete winAudioBackend;
|
2017-03-25 15:01:33 -07:00
|
|
|
winAudioBackend = nullptr;
|
2014-06-22 14:23:06 +02:00
|
|
|
#endif
|
2014-06-22 14:17:57 +02:00
|
|
|
|
2020-07-28 19:06:29 +02:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
|
2020-01-14 08:19:44 +08:00
|
|
|
if (winCamera) {
|
2021-01-02 22:49:06 -08:00
|
|
|
winCamera->waitShutDown();
|
2020-01-14 08:19:44 +08:00
|
|
|
delete winCamera;
|
|
|
|
winCamera = nullptr;
|
|
|
|
}
|
2020-07-31 10:24:17 +08:00
|
|
|
if (winMic) {
|
2021-01-02 22:49:06 -08:00
|
|
|
winMic->waitShutDown();
|
2020-07-31 10:24:17 +08:00
|
|
|
delete winMic;
|
|
|
|
winMic = nullptr;
|
|
|
|
}
|
2020-01-13 15:06:02 +08:00
|
|
|
#endif
|
|
|
|
|
2019-09-28 11:12:12 -07:00
|
|
|
UIBackgroundShutdown();
|
|
|
|
|
2016-02-14 22:07:10 +01:00
|
|
|
delete g_gameInfoCache;
|
|
|
|
g_gameInfoCache = nullptr;
|
2013-07-16 22:50:53 +02:00
|
|
|
|
|
|
|
delete uiContext;
|
2017-03-25 15:01:33 -07:00
|
|
|
uiContext = nullptr;
|
2013-07-16 22:50:53 +02:00
|
|
|
|
|
|
|
ui_draw2d.Shutdown();
|
|
|
|
|
2018-01-20 21:47:16 +01:00
|
|
|
if (colorPipeline) {
|
|
|
|
colorPipeline->Release();
|
|
|
|
colorPipeline = nullptr;
|
|
|
|
}
|
|
|
|
if (texColorPipeline) {
|
|
|
|
texColorPipeline->Release();
|
|
|
|
texColorPipeline = nullptr;
|
|
|
|
}
|
2017-03-18 15:20:36 +01:00
|
|
|
|
2020-08-15 16:25:50 +02:00
|
|
|
INFO_LOG(SYSTEM, "NativeShutdownGraphics done");
|
2013-07-16 22:50:53 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 19:03:33 +02:00
|
|
|
static void TakeScreenshot() {
|
2021-05-14 22:48:04 -07:00
|
|
|
Path path = GetSysDirectory(DIRECTORY_SCREENSHOT);
|
2014-12-28 20:52:44 -08:00
|
|
|
if (!File::Exists(path)) {
|
|
|
|
File::CreateDir(path);
|
|
|
|
}
|
2013-06-22 22:27:59 +02:00
|
|
|
|
|
|
|
// First, find a free filename.
|
|
|
|
int i = 0;
|
|
|
|
|
2017-06-02 20:54:28 -07:00
|
|
|
std::string gameId = g_paramSFO.GetDiscID();
|
2014-02-17 23:43:58 +01:00
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
Path filename;
|
2013-07-07 14:56:18 -04:00
|
|
|
while (i < 10000){
|
2014-02-17 23:43:58 +01:00
|
|
|
if (g_Config.bScreenshotsAsPNG)
|
2021-05-30 10:29:16 -07:00
|
|
|
filename = path / StringFromFormat("%s_%05d.png", gameId.c_str(), i);
|
2013-07-07 14:56:18 -04:00
|
|
|
else
|
2021-05-30 10:29:16 -07:00
|
|
|
filename = path / StringFromFormat("%s_%05d.jpg", gameId.c_str(), i);
|
2021-04-25 20:38:22 +02:00
|
|
|
File::FileInfo info;
|
|
|
|
if (!File::Exists(filename))
|
2013-06-22 22:27:59 +02:00
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2017-12-21 15:44:49 -08:00
|
|
|
bool success = TakeGameScreenshot(filename, g_Config.bScreenshotsAsPNG ? ScreenshotFormat::PNG : ScreenshotFormat::JPG, SCREENSHOT_OUTPUT);
|
2014-11-02 13:29:44 -08:00
|
|
|
if (success) {
|
2023-06-20 14:40:46 +02:00
|
|
|
g_OSD.Show(OSDType::MESSAGE_FILE_LINK, filename.ToString());
|
2014-11-02 13:29:44 -08:00
|
|
|
} else {
|
2023-04-06 00:34:50 +02:00
|
|
|
auto err = GetI18NCategory(I18NCat::ERRORS);
|
2023-06-20 14:40:46 +02:00
|
|
|
g_OSD.Show(OSDType::MESSAGE_ERROR, err->T("Could not save screenshot file"));
|
2014-11-02 13:29:44 -08:00
|
|
|
}
|
2013-06-22 22:27:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 19:03:33 +02:00
|
|
|
void CallbackPostRender(UIContext *dc, void *userdata) {
|
2017-05-16 14:09:15 +02:00
|
|
|
if (g_TakeScreenshot) {
|
|
|
|
TakeScreenshot();
|
2023-08-23 19:03:33 +02:00
|
|
|
g_TakeScreenshot = false;
|
2013-11-29 16:33:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-10 15:53:05 +02:00
|
|
|
static Matrix4x4 ComputeOrthoMatrix(float xres, float yres) {
|
2023-08-13 13:33:38 +02:00
|
|
|
// TODO: Should be able to share the y-flip logic here with the one in postprocessing/presentation, for example.
|
2023-08-10 15:53:05 +02:00
|
|
|
Matrix4x4 ortho;
|
|
|
|
switch (GetGPUBackend()) {
|
|
|
|
case GPUBackend::VULKAN:
|
|
|
|
ortho.setOrthoD3D(0.0f, xres, 0, yres, -1.0f, 1.0f);
|
|
|
|
break;
|
|
|
|
case GPUBackend::DIRECT3D9:
|
|
|
|
ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
|
|
|
|
Matrix4x4 translation;
|
|
|
|
// Account for the small window adjustment.
|
|
|
|
translation.setTranslation(Vec3(
|
|
|
|
-0.5f * g_display.dpi_scale_x / g_display.dpi_scale_real_x,
|
|
|
|
-0.5f * g_display.dpi_scale_y / g_display.dpi_scale_real_y, 0.0f));
|
|
|
|
ortho = translation * ortho;
|
|
|
|
break;
|
|
|
|
case GPUBackend::DIRECT3D11:
|
|
|
|
ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
|
|
|
|
break;
|
|
|
|
case GPUBackend::OPENGL:
|
|
|
|
default:
|
|
|
|
ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compensate for rotated display if needed.
|
|
|
|
if (g_display.rotation != DisplayRotation::ROTATE_0) {
|
|
|
|
ortho = ortho * g_display.rot_matrix;
|
|
|
|
}
|
|
|
|
return ortho;
|
|
|
|
}
|
|
|
|
|
2023-12-09 21:40:09 +01:00
|
|
|
static void SendMouseDeltaAxis();
|
|
|
|
|
2023-08-07 22:44:06 +02:00
|
|
|
void NativeFrame(GraphicsContext *graphicsContext) {
|
|
|
|
PROFILE_END_FRAME();
|
|
|
|
|
2024-01-18 17:57:14 +01:00
|
|
|
// This can only be accessed from Windows currently, and causes linking errors with headless etc.
|
|
|
|
if (g_restartGraphics) {
|
|
|
|
// Used for debugging only.
|
|
|
|
NativeShutdownGraphics();
|
|
|
|
NativeInitGraphics(graphicsContext);
|
|
|
|
g_restartGraphics = false;
|
|
|
|
}
|
|
|
|
|
2023-12-11 12:41:44 +01:00
|
|
|
double startTime = time_now_d();
|
2023-10-04 16:57:06 +02:00
|
|
|
|
2023-12-17 19:40:59 +01:00
|
|
|
ProcessWheelRelease(NKCODE_EXT_MOUSEWHEEL_UP, startTime, false);
|
|
|
|
ProcessWheelRelease(NKCODE_EXT_MOUSEWHEEL_DOWN, startTime, false);
|
|
|
|
|
2023-08-07 22:44:06 +02:00
|
|
|
std::vector<PendingMessage> toProcess;
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(pendingMutex);
|
|
|
|
toProcess = std::move(pendingMessages);
|
|
|
|
pendingMessages.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &item : toProcess) {
|
2023-09-30 11:21:22 +02:00
|
|
|
if (HandleGlobalMessage(item.message, item.value)) {
|
|
|
|
// TODO: Add a to-string thingy.
|
|
|
|
INFO_LOG(SYSTEM, "Handled global message: %d / %s", (int)item.message, item.value.c_str());
|
2023-08-30 23:30:49 +02:00
|
|
|
}
|
2023-09-30 11:21:22 +02:00
|
|
|
g_screenManager->sendMessage(item.message, item.value.c_str());
|
2023-08-07 22:44:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_requestManager.ProcessRequests();
|
|
|
|
|
|
|
|
// it's ok to call this redundantly with DoFrame from EmuScreen
|
|
|
|
Achievements::Idle();
|
|
|
|
|
|
|
|
g_DownloadManager.Update();
|
|
|
|
|
|
|
|
g_Discord.Update();
|
|
|
|
|
|
|
|
g_OSD.Update();
|
|
|
|
|
|
|
|
UI::SetSoundEnabled(g_Config.bUISound);
|
|
|
|
|
2022-12-06 16:32:56 +01:00
|
|
|
_dbg_assert_(graphicsContext != nullptr);
|
2023-03-22 09:42:31 +01:00
|
|
|
_dbg_assert_(g_screenManager != nullptr);
|
2021-02-13 12:49:48 -08:00
|
|
|
|
2013-11-20 14:42:48 +01:00
|
|
|
g_GameManager.Update();
|
2017-05-16 14:09:15 +02:00
|
|
|
|
2019-09-27 23:53:31 +02:00
|
|
|
if (GetUIState() != UISTATE_INGAME) {
|
2023-08-07 22:44:06 +02:00
|
|
|
// Note: We do this from NativeFrame so that the graphics context is
|
2019-09-27 23:53:31 +02:00
|
|
|
// guaranteed valid, to be safe - g_gameInfoCache messes around with textures.
|
2020-08-02 19:44:48 +02:00
|
|
|
g_BackgroundAudio.Update();
|
2019-09-27 23:53:31 +02:00
|
|
|
}
|
|
|
|
|
2023-12-10 12:37:35 +01:00
|
|
|
g_iconCache.FrameUpdate();
|
|
|
|
|
|
|
|
g_screenManager->update();
|
|
|
|
|
2014-02-10 12:38:23 +01:00
|
|
|
// Apply the UIContext bounds as a 2D transformation matrix.
|
2017-05-16 14:09:15 +02:00
|
|
|
// TODO: This should be moved into the draw context...
|
2023-08-10 15:53:05 +02:00
|
|
|
Matrix4x4 ortho = ComputeOrthoMatrix(g_display.dp_xres, g_display.dp_yres);
|
2017-03-05 01:39:26 +01:00
|
|
|
|
2022-12-27 15:32:35 -08:00
|
|
|
Draw::DebugFlags debugFlags = Draw::DebugFlags::NONE;
|
2023-08-03 16:19:18 +02:00
|
|
|
if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::GPU_PROFILE)
|
2022-12-27 15:32:35 -08:00
|
|
|
debugFlags |= Draw::DebugFlags::PROFILE_TIMESTAMPS;
|
|
|
|
if (g_Config.bGpuLogProfiler)
|
|
|
|
debugFlags |= Draw::DebugFlags::PROFILE_SCOPES;
|
|
|
|
|
2023-08-13 13:33:38 +02:00
|
|
|
g_frameTiming.Reset(g_draw);
|
|
|
|
|
2023-08-10 15:53:05 +02:00
|
|
|
g_draw->BeginFrame(debugFlags);
|
2023-08-10 15:44:27 +02:00
|
|
|
|
|
|
|
ui_draw2d.PushDrawMatrix(ortho);
|
|
|
|
|
|
|
|
g_screenManager->getUIContext()->SetTintSaturation(g_Config.fUITint, g_Config.fUISaturation);
|
|
|
|
|
2017-05-16 14:09:15 +02:00
|
|
|
// All actual rendering happen in here.
|
2023-12-11 12:41:44 +01:00
|
|
|
ScreenRenderFlags renderFlags = g_screenManager->render();
|
2023-03-22 09:42:31 +01:00
|
|
|
if (g_screenManager->getUIContext()->Text()) {
|
|
|
|
g_screenManager->getUIContext()->Text()->OncePerFrame();
|
2013-11-15 13:11:44 +01:00
|
|
|
}
|
2023-08-10 15:44:27 +02:00
|
|
|
|
|
|
|
ui_draw2d.PopDrawMatrix();
|
|
|
|
|
2023-08-09 23:20:08 +02:00
|
|
|
g_draw->EndFrame();
|
|
|
|
|
2023-08-10 13:51:35 +02:00
|
|
|
// This, between EndFrame and Present, is where we should actually wait to do present time management.
|
|
|
|
// There might not be a meaningful distinction here for all backends..
|
2023-12-18 13:44:32 +01:00
|
|
|
g_frameTiming.PostSubmit();
|
2023-08-10 13:51:35 +02:00
|
|
|
|
2023-08-10 15:44:27 +02:00
|
|
|
if (renderCounter < 10 && ++renderCounter == 10) {
|
|
|
|
// We're rendering fine, clear out failure info.
|
|
|
|
ClearFailedGPUBackends();
|
|
|
|
}
|
|
|
|
|
2023-08-13 13:33:38 +02:00
|
|
|
int interval;
|
|
|
|
Draw::PresentMode presentMode = ComputePresentMode(g_draw, &interval);
|
|
|
|
g_draw->Present(presentMode, interval);
|
2023-08-10 13:51:35 +02:00
|
|
|
|
2015-02-01 18:04:06 +01:00
|
|
|
if (resized) {
|
2020-08-15 16:25:50 +02:00
|
|
|
INFO_LOG(G3D, "Resized flag set - recalculating bounds");
|
2015-02-01 18:04:06 +01:00
|
|
|
resized = false;
|
2017-02-23 09:25:33 +01:00
|
|
|
|
|
|
|
if (uiContext) {
|
|
|
|
// Modifying the bounds here can be used to "inset" the whole image to gain borders for TV overscan etc.
|
|
|
|
// The UI now supports any offset but not the EmuScreen yet.
|
2023-02-25 13:09:44 +01:00
|
|
|
uiContext->SetBounds(Bounds(0, 0, g_display.dp_xres, g_display.dp_yres));
|
2017-02-23 09:25:33 +01:00
|
|
|
|
|
|
|
// OSX 10.6 and SDL 1.2 bug.
|
|
|
|
#if defined(__APPLE__) && !defined(USING_QT_UI)
|
2023-02-25 13:09:44 +01:00
|
|
|
static int dp_xres_old = g_display.dp_xres;
|
|
|
|
if (g_display.dp_xres != dp_xres_old) {
|
|
|
|
dp_xres_old = g_display.dp_xres;
|
2017-02-23 09:25:33 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-12-07 14:56:19 +01:00
|
|
|
graphicsContext->Resize();
|
2023-03-22 09:42:31 +01:00
|
|
|
g_screenManager->resized();
|
2017-12-07 14:56:19 +01:00
|
|
|
|
2020-06-24 01:04:41 +02:00
|
|
|
// TODO: Move this to the GraphicsContext objects for each backend.
|
2020-07-28 19:06:29 +02:00
|
|
|
#if !PPSSPP_PLATFORM(WINDOWS) && !defined(ANDROID)
|
2023-02-25 13:09:44 +01:00
|
|
|
PSP_CoreParameter().pixelWidth = g_display.pixel_xres;
|
|
|
|
PSP_CoreParameter().pixelHeight = g_display.pixel_yres;
|
2023-09-30 11:21:22 +02:00
|
|
|
System_PostUIMessage(UIMessage::GPU_DISPLAY_RESIZED);
|
2015-12-31 16:59:40 +01:00
|
|
|
#endif
|
2020-06-21 22:34:37 +02:00
|
|
|
} else {
|
2020-08-15 16:25:50 +02:00
|
|
|
// INFO_LOG(G3D, "Polling graphics context");
|
2020-06-21 22:34:37 +02:00
|
|
|
graphicsContext->Poll();
|
2015-02-01 18:04:06 +01:00
|
|
|
}
|
2023-10-04 16:57:06 +02:00
|
|
|
|
2023-12-11 12:41:44 +01:00
|
|
|
if (!(renderFlags & ScreenRenderFlags::HANDLED_THROTTLING)) {
|
2023-10-04 16:57:06 +02:00
|
|
|
float refreshRate = System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE);
|
|
|
|
// Simple throttling to not burn the GPU in the menu.
|
|
|
|
// TODO: This should move into NativeFrame. Also, it's only necessary in MAILBOX or IMMEDIATE presentation modes.
|
|
|
|
double diffTime = time_now_d() - startTime;
|
|
|
|
int sleepTime = (int)(1000.0 / refreshRate) - (int)(diffTime * 1000.0);
|
|
|
|
if (sleepTime > 0)
|
|
|
|
sleep_ms(sleepTime);
|
2023-12-11 12:41:44 +01:00
|
|
|
|
|
|
|
// TODO: We should ideally mix this with game audio.
|
|
|
|
g_BackgroundAudio.Play();
|
2023-10-04 16:57:06 +02:00
|
|
|
}
|
2023-12-09 21:40:09 +01:00
|
|
|
|
|
|
|
SendMouseDeltaAxis();
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2023-09-30 11:21:22 +02:00
|
|
|
bool HandleGlobalMessage(UIMessage message, const std::string &value) {
|
2024-01-18 17:57:14 +01:00
|
|
|
if (message == UIMessage::RESTART_GRAPHICS) {
|
|
|
|
g_restartGraphics = true;
|
|
|
|
} else if (message == UIMessage::SAVESTATE_DISPLAY_SLOT) {
|
2023-04-06 00:34:50 +02:00
|
|
|
auto sy = GetI18NCategory(I18NCat::SYSTEM);
|
2016-05-27 20:53:20 -07:00
|
|
|
std::string msg = StringFromFormat("%s: %d", sy->T("Savestate Slot"), SaveState::GetCurrentSlot() + 1);
|
2016-05-27 20:53:58 -07:00
|
|
|
// Show for the same duration as the preview.
|
2023-06-20 14:40:46 +02:00
|
|
|
g_OSD.Show(OSDType::MESSAGE_INFO, msg, 2.0f, "savestate_slot");
|
2023-08-30 23:30:49 +02:00
|
|
|
return true;
|
2016-05-27 20:53:20 -07:00
|
|
|
}
|
2023-09-30 11:21:22 +02:00
|
|
|
else if (message == UIMessage::GPU_DISPLAY_RESIZED) {
|
2016-09-28 22:35:09 -07:00
|
|
|
if (gpu) {
|
2022-11-21 15:14:20 +01:00
|
|
|
gpu->NotifyDisplayResized();
|
|
|
|
}
|
2023-08-30 23:30:49 +02:00
|
|
|
return true;
|
2022-11-21 15:14:20 +01:00
|
|
|
}
|
2023-09-30 11:21:22 +02:00
|
|
|
else if (message == UIMessage::GPU_RENDER_RESIZED) {
|
2022-11-21 15:14:20 +01:00
|
|
|
if (gpu) {
|
|
|
|
gpu->NotifyRenderResized();
|
|
|
|
}
|
2023-08-30 23:30:49 +02:00
|
|
|
return true;
|
2022-11-21 15:14:20 +01:00
|
|
|
}
|
2023-09-30 11:21:22 +02:00
|
|
|
else if (message == UIMessage::GPU_CONFIG_CHANGED) {
|
2022-11-21 15:14:20 +01:00
|
|
|
if (gpu) {
|
|
|
|
gpu->NotifyConfigChanged();
|
2016-09-28 22:35:09 -07:00
|
|
|
}
|
|
|
|
Reporting::UpdateConfig();
|
2023-08-30 23:30:49 +02:00
|
|
|
return true;
|
2016-09-28 22:35:09 -07:00
|
|
|
}
|
2023-09-30 11:21:22 +02:00
|
|
|
else if (message == UIMessage::POWER_SAVING) {
|
2016-07-24 17:04:06 -07:00
|
|
|
if (value != "false") {
|
2023-04-06 00:34:50 +02:00
|
|
|
auto sy = GetI18NCategory(I18NCat::SYSTEM);
|
2020-07-28 19:06:29 +02:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
2023-06-20 14:40:46 +02:00
|
|
|
g_OSD.Show(OSDType::MESSAGE_WARNING, sy->T("WARNING: Android battery save mode is on"), 2.0f, "core_powerSaving");
|
2016-10-10 17:32:25 -07:00
|
|
|
#else
|
2023-06-20 14:40:46 +02:00
|
|
|
g_OSD.Show(OSDType::MESSAGE_WARNING, sy->T("WARNING: Battery save mode is on"), 2.0f, "core_powerSaving");
|
2016-10-10 17:32:25 -07:00
|
|
|
#endif
|
2016-07-24 17:04:06 -07:00
|
|
|
}
|
|
|
|
Core_SetPowerSaving(value != "false");
|
2023-08-30 23:30:49 +02:00
|
|
|
return true;
|
2016-07-24 17:04:06 -07:00
|
|
|
}
|
2023-09-30 11:21:22 +02:00
|
|
|
else if (message == UIMessage::PERMISSION_GRANTED && value == "storage") {
|
2023-08-18 15:04:20 +02:00
|
|
|
CreateSysDirectories();
|
2018-03-24 12:51:54 +01:00
|
|
|
// We must have failed to load the config before, so load it now to avoid overwriting the old config
|
|
|
|
// with a freshly generated one.
|
2019-09-17 10:50:25 +02:00
|
|
|
// NOTE: If graphics backend isn't what's in the config (due to error fallback, or not matching the default
|
|
|
|
// and then getting permission), it will get out of sync. So we save and restore g_Config.iGPUBackend.
|
2023-08-18 15:04:20 +02:00
|
|
|
// Ideally we should simply reinitialize graphics to the mode from the config, but there are potential issues.
|
2019-09-17 10:50:25 +02:00
|
|
|
int gpuBackend = g_Config.iGPUBackend;
|
2020-08-15 16:25:50 +02:00
|
|
|
INFO_LOG(IO, "Reloading config after storage permission grant.");
|
2020-03-08 15:25:20 -07:00
|
|
|
g_Config.Reload();
|
2018-04-29 11:45:32 -07:00
|
|
|
PostLoadConfig();
|
2019-09-17 10:50:25 +02:00
|
|
|
g_Config.iGPUBackend = gpuBackend;
|
2023-08-30 23:30:49 +02:00
|
|
|
return true;
|
2023-09-30 11:21:22 +02:00
|
|
|
} else if (message == UIMessage::APP_RESUMED || message == UIMessage::GOT_FOCUS) {
|
2021-09-11 07:36:02 -07:00
|
|
|
// Assume that the user may have modified things.
|
|
|
|
MemoryStick_NotifyWrite();
|
2023-08-30 23:30:49 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2021-09-11 07:36:02 -07:00
|
|
|
}
|
2014-05-19 23:29:35 +02:00
|
|
|
}
|
|
|
|
|
2013-06-01 23:34:50 +02:00
|
|
|
bool NativeIsAtTopLevel() {
|
2018-05-26 17:50:37 +02:00
|
|
|
// This might need some synchronization?
|
2023-03-22 09:42:31 +01:00
|
|
|
if (!g_screenManager) {
|
2020-08-15 16:25:50 +02:00
|
|
|
ERROR_LOG(SYSTEM, "No screen manager active");
|
2018-05-26 17:50:37 +02:00
|
|
|
return false;
|
|
|
|
}
|
2023-03-22 09:42:31 +01:00
|
|
|
Screen *currentScreen = g_screenManager->topScreen();
|
2013-09-04 10:51:14 +02:00
|
|
|
if (currentScreen) {
|
|
|
|
bool top = currentScreen->isTopLevel();
|
2020-08-15 16:25:50 +02:00
|
|
|
INFO_LOG(SYSTEM, "Screen toplevel: %i", (int)top);
|
2013-09-04 10:51:14 +02:00
|
|
|
return currentScreen->isTopLevel();
|
|
|
|
} else {
|
2020-08-15 16:25:50 +02:00
|
|
|
ERROR_LOG(SYSTEM, "No current screen");
|
2013-09-04 10:51:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2022-12-31 21:36:16 +01:00
|
|
|
void NativeTouch(const TouchInput &touch) {
|
2023-03-22 09:42:31 +01:00
|
|
|
if (!g_screenManager) {
|
2022-12-31 21:36:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Brute force prevent NaNs from getting into the UI system.
|
|
|
|
// Don't think this is actually necessary in practice.
|
|
|
|
if (my_isnan(touch.x) || my_isnan(touch.y)) {
|
|
|
|
return;
|
2014-06-15 12:13:59 +02:00
|
|
|
}
|
2023-03-22 09:42:31 +01:00
|
|
|
g_screenManager->touch(touch);
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2023-12-17 19:40:59 +01:00
|
|
|
// up, down
|
|
|
|
static double g_wheelReleaseTime[2]{};
|
|
|
|
|
|
|
|
static void ProcessWheelRelease(InputKeyCode keyCode, double now, bool keyPress) {
|
|
|
|
int dir = keyCode - NKCODE_EXT_MOUSEWHEEL_UP;
|
|
|
|
if (g_wheelReleaseTime[dir] != 0.0 && (keyPress || now >= g_wheelReleaseTime[dir])) {
|
|
|
|
g_wheelReleaseTime[dir] = 0.0;
|
|
|
|
KeyInput key{};
|
|
|
|
key.deviceId = DEVICE_ID_MOUSE;
|
|
|
|
key.keyCode = keyCode;
|
|
|
|
key.flags = KEY_UP;
|
|
|
|
NativeKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keyPress) {
|
2023-12-20 11:39:37 +01:00
|
|
|
float releaseTime = (float)g_Config.iMouseWheelUpDelayMs * (1.0f / 1000.0f);
|
|
|
|
g_wheelReleaseTime[dir] = now + releaseTime;
|
2023-12-17 19:40:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-15 12:13:59 +02:00
|
|
|
bool NativeKey(const KeyInput &key) {
|
2023-12-17 19:40:59 +01:00
|
|
|
double now = time_now_d();
|
|
|
|
|
2022-11-17 10:22:01 +01:00
|
|
|
// VR actions
|
|
|
|
if (IsVREnabled() && !UpdateVRKeys(key)) {
|
2022-11-07 17:13:08 +01:00
|
|
|
return false;
|
2022-08-15 16:53:00 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 21:01:00 +04:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
2023-08-24 06:33:36 +04:00
|
|
|
// Ignore if key sent from OnKeyDown/OnKeyUp/XInput while text edit active
|
2023-08-23 21:01:00 +04:00
|
|
|
// it's already handled by `OnCharacterReceived`
|
|
|
|
if (IgnoreInput(key.keyCode) && !(key.flags & KEY_CHAR)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-08-15 16:25:50 +02:00
|
|
|
// INFO_LOG(SYSTEM, "Key code: %i flags: %i", key.keyCode, key.flags);
|
2014-04-26 01:00:45 -04:00
|
|
|
#if !defined(MOBILE_DEVICE)
|
2014-04-26 01:54:32 -04:00
|
|
|
if (g_Config.bPauseExitsEmulator) {
|
2023-05-01 12:16:45 +02:00
|
|
|
std::vector<int> pspKeys;
|
2014-04-26 01:54:32 -04:00
|
|
|
pspKeys.clear();
|
2023-03-29 11:59:31 +02:00
|
|
|
if (KeyMap::InputMappingToPspButton(InputMapping(key.deviceId, key.keyCode), &pspKeys)) {
|
2014-04-26 01:54:32 -04:00
|
|
|
if (std::find(pspKeys.begin(), pspKeys.end(), VIRTKEY_PAUSE) != pspKeys.end()) {
|
2023-03-22 22:07:29 +01:00
|
|
|
System_ExitApp();
|
2014-06-15 12:13:59 +02:00
|
|
|
return true;
|
2014-04-26 01:54:32 -04:00
|
|
|
}
|
|
|
|
}
|
2014-04-26 01:00:45 -04:00
|
|
|
}
|
|
|
|
#endif
|
2023-05-01 12:16:45 +02:00
|
|
|
|
2023-12-17 19:40:59 +01:00
|
|
|
if (!g_screenManager) {
|
|
|
|
return false;
|
2022-12-04 23:46:01 +03:00
|
|
|
}
|
2023-04-06 12:24:31 +02:00
|
|
|
|
2023-12-17 19:40:59 +01:00
|
|
|
// Handle releases of mousewheel keys.
|
|
|
|
if ((key.flags & KEY_DOWN) && key.deviceId == DEVICE_ID_MOUSE && (key.keyCode == NKCODE_EXT_MOUSEWHEEL_UP || key.keyCode == NKCODE_EXT_MOUSEWHEEL_DOWN)) {
|
|
|
|
ProcessWheelRelease(key.keyCode, now, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
HLEPlugins::SetKey(key.keyCode, (key.flags & KEY_DOWN) ? 1 : 0);
|
|
|
|
// Dispatch the key event.
|
|
|
|
bool retval = g_screenManager->key(key);
|
|
|
|
|
2023-04-06 12:24:31 +02:00
|
|
|
// The Mode key can have weird consequences on some devices, see #17245.
|
|
|
|
if (key.keyCode == NKCODE_BUTTON_MODE) {
|
|
|
|
// Tell the caller that we handled the key.
|
|
|
|
retval = true;
|
|
|
|
}
|
|
|
|
|
2014-06-15 13:04:59 +02:00
|
|
|
return retval;
|
2013-07-06 19:08:59 +02:00
|
|
|
}
|
|
|
|
|
2023-09-27 17:22:11 +02:00
|
|
|
void NativeAxis(const AxisInput *axes, size_t count) {
|
2022-11-17 10:22:01 +01:00
|
|
|
// VR actions
|
2023-09-27 17:22:11 +02:00
|
|
|
if (IsVREnabled() && !UpdateVRAxis(axes, count)) {
|
2022-12-31 21:44:52 +01:00
|
|
|
return;
|
2022-11-17 10:22:01 +01:00
|
|
|
}
|
|
|
|
|
2023-03-22 09:42:31 +01:00
|
|
|
if (!g_screenManager) {
|
2021-07-05 12:37:52 +02:00
|
|
|
// Too early.
|
2022-12-31 21:44:52 +01:00
|
|
|
return;
|
2021-07-05 12:37:52 +02:00
|
|
|
}
|
|
|
|
|
2023-09-27 17:24:13 +02:00
|
|
|
g_screenManager->axis(axes, count);
|
|
|
|
|
2023-08-31 11:41:34 +02:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2023-09-27 17:22:11 +02:00
|
|
|
const AxisInput &axis = axes[i];
|
|
|
|
HLEPlugins::PluginDataAxis[axis.axisId] = axis.value;
|
2023-08-31 11:41:34 +02:00
|
|
|
}
|
2023-09-27 11:34:31 +02:00
|
|
|
}
|
2023-08-31 11:41:34 +02:00
|
|
|
|
2023-12-14 19:30:03 +01:00
|
|
|
// Called from NativeFrame and from NativeMouseDelta.
|
2023-12-09 21:40:09 +01:00
|
|
|
static void SendMouseDeltaAxis() {
|
2023-12-14 19:00:01 +01:00
|
|
|
float mx, my;
|
|
|
|
MouseEventProcessor::MouseDeltaToAxes(time_now_d(), &mx, &my);
|
2023-12-09 21:40:09 +01:00
|
|
|
|
|
|
|
AxisInput axis[2];
|
|
|
|
axis[0].axisId = JOYSTICK_AXIS_MOUSE_REL_X;
|
|
|
|
axis[0].deviceId = DEVICE_ID_MOUSE;
|
|
|
|
axis[0].value = mx;
|
|
|
|
axis[1].axisId = JOYSTICK_AXIS_MOUSE_REL_Y;
|
|
|
|
axis[1].deviceId = DEVICE_ID_MOUSE;
|
|
|
|
axis[1].value = my;
|
|
|
|
|
|
|
|
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_X] = mx;
|
|
|
|
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_Y] = my;
|
|
|
|
|
|
|
|
//NOTICE_LOG(SYSTEM, "delta: %0.2f %0.2f mx/my: %0.2f %0.2f dpi: %f sens: %f ",
|
|
|
|
// g_mouseDeltaX, g_mouseDeltaY, mx, my, g_display.dpi_scale_x, g_Config.fMouseSensitivity);
|
|
|
|
|
|
|
|
if (GetUIState() == UISTATE_INGAME || g_Config.bMapMouse) {
|
|
|
|
NativeAxis(axis, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-14 19:30:03 +01:00
|
|
|
void NativeMouseDelta(float dx, float dy) {
|
|
|
|
// Remap, shared code. Then send it as a regular axis event.
|
|
|
|
if (!g_Config.bMouseControl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MouseEventProcessor::ProcessDelta(time_now_d(), dx, dy);
|
|
|
|
|
|
|
|
SendMouseDeltaAxis();
|
|
|
|
}
|
|
|
|
|
2023-09-27 11:34:31 +02:00
|
|
|
void NativeAccelerometer(float tiltX, float tiltY, float tiltZ) {
|
2023-08-31 11:41:34 +02:00
|
|
|
if (g_Config.iTiltInputType == TILT_NULL) {
|
|
|
|
// if tilt events are disabled, don't do anything special.
|
|
|
|
return;
|
2013-10-31 11:06:54 +01:00
|
|
|
}
|
2013-11-11 17:22:04 +05:30
|
|
|
|
2023-02-02 11:59:56 +01:00
|
|
|
// create the base coordinate tilt system from the calibration data.
|
|
|
|
float tiltBaseAngleY = g_Config.fTiltBaseAngleY;
|
|
|
|
|
2023-02-01 14:17:01 +01:00
|
|
|
// Figure out the sensitivity of the tilt. (sensitivity is originally 0 - 100)
|
|
|
|
// We divide by 50, so that the rest of the 50 units can be used to overshoot the
|
|
|
|
// target. If you want precise control, you'd keep the sensitivity ~50.
|
|
|
|
// For games that don't need much control but need fast reactions,
|
|
|
|
// then a value of 70-80 is the way to go.
|
2013-11-11 17:22:04 +05:30
|
|
|
float xSensitivity = g_Config.iTiltSensitivityX / 50.0;
|
|
|
|
float ySensitivity = g_Config.iTiltSensitivityY / 50.0;
|
2022-11-21 15:14:20 +01:00
|
|
|
|
2023-02-01 23:47:42 +01:00
|
|
|
// x and y are flipped if we are in landscape orientation. The events are
|
|
|
|
// sent with respect to the portrait coordinate system, while we
|
|
|
|
// take all events in landscape.
|
|
|
|
// see [http://developer.android.com/guide/topics/sensors/sensors_overview.html] for details
|
2023-02-25 13:09:44 +01:00
|
|
|
bool landscape = g_display.dp_yres < g_display.dp_xres;
|
2023-02-01 14:17:01 +01:00
|
|
|
// now transform out current tilt to the calibrated coordinate system
|
2023-08-31 11:41:34 +02:00
|
|
|
TiltEventProcessor::ProcessTilt(landscape, tiltBaseAngleY, tiltX, tiltY, tiltZ,
|
2023-02-11 23:42:55 +01:00
|
|
|
g_Config.bInvertTiltX, g_Config.bInvertTiltY,
|
2023-02-01 16:07:01 +01:00
|
|
|
xSensitivity, ySensitivity);
|
2023-09-27 11:34:31 +02:00
|
|
|
|
|
|
|
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_X] = tiltX;
|
|
|
|
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_Y] = tiltY;
|
|
|
|
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_Z] = tiltZ;
|
2013-07-06 19:08:59 +02:00
|
|
|
}
|
|
|
|
|
2023-09-30 11:21:22 +02:00
|
|
|
void System_PostUIMessage(UIMessage message, const std::string &value) {
|
2017-02-27 21:57:46 +01:00
|
|
|
std::lock_guard<std::mutex> lock(pendingMutex);
|
2014-02-13 17:47:02 +01:00
|
|
|
PendingMessage pendingMessage;
|
2023-09-30 11:21:22 +02:00
|
|
|
pendingMessage.message = message;
|
2014-02-13 17:47:02 +01:00
|
|
|
pendingMessage.value = value;
|
|
|
|
pendingMessages.push_back(pendingMessage);
|
2012-12-01 10:39:20 +01:00
|
|
|
}
|
|
|
|
|
2013-12-16 16:21:10 +01:00
|
|
|
void NativeResized() {
|
2017-02-23 09:25:33 +01:00
|
|
|
// NativeResized can come from any thread so we just set a flag, then process it later.
|
2023-01-30 14:30:24 +01:00
|
|
|
VERBOSE_LOG(G3D, "NativeResized - setting flag");
|
2020-02-29 19:31:58 -08:00
|
|
|
resized = true;
|
2013-12-16 16:21:10 +01:00
|
|
|
}
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2017-04-15 16:30:37 -07:00
|
|
|
void NativeSetRestarting() {
|
|
|
|
restarting = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeIsRestarting() {
|
|
|
|
return restarting;
|
|
|
|
}
|
|
|
|
|
2013-07-16 22:50:53 +02:00
|
|
|
void NativeShutdown() {
|
2023-06-16 13:04:20 +02:00
|
|
|
Achievements::Shutdown();
|
|
|
|
|
2023-07-12 20:04:02 +02:00
|
|
|
if (g_Config.bAchievementsEnable) {
|
|
|
|
FILE *iconCacheFile = File::OpenCFile(GetSysDirectory(DIRECTORY_CACHE) / "icon.cache", "wb");
|
|
|
|
if (iconCacheFile) {
|
|
|
|
g_iconCache.SaveToFile(iconCacheFile);
|
|
|
|
fclose(iconCacheFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-22 09:42:31 +01:00
|
|
|
if (g_screenManager) {
|
|
|
|
g_screenManager->shutdown();
|
|
|
|
delete g_screenManager;
|
|
|
|
g_screenManager = nullptr;
|
2023-01-03 11:02:26 +01:00
|
|
|
}
|
2017-04-29 12:02:07 -07:00
|
|
|
|
2019-02-23 10:49:49 +01:00
|
|
|
g_Config.Save("NativeShutdown");
|
2017-04-15 16:30:37 -07:00
|
|
|
|
2020-08-15 16:25:50 +02:00
|
|
|
INFO_LOG(SYSTEM, "NativeShutdown called");
|
2014-02-09 23:16:08 +01:00
|
|
|
|
2023-04-07 10:20:00 +02:00
|
|
|
g_i18nrepo.LogMissingKeys();
|
2022-06-01 18:37:46 +02:00
|
|
|
|
2020-02-29 18:45:14 -08:00
|
|
|
ShutdownWebServer();
|
|
|
|
|
2023-03-22 22:07:29 +01:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS)
|
|
|
|
System_ExitApp();
|
|
|
|
#endif
|
2017-03-06 10:51:28 +01:00
|
|
|
|
2023-07-20 23:55:35 +02:00
|
|
|
g_PortManager.Shutdown();
|
|
|
|
|
2017-03-06 10:51:28 +01:00
|
|
|
net::Shutdown();
|
|
|
|
|
2018-08-13 00:08:56 +02:00
|
|
|
g_Discord.Shutdown();
|
|
|
|
|
2021-01-04 23:51:34 +01:00
|
|
|
ShaderTranslationShutdown();
|
|
|
|
|
2021-01-01 08:38:27 -08:00
|
|
|
// Avoid shutting this down when restarting core.
|
|
|
|
if (!restarting)
|
|
|
|
LogManager::Shutdown();
|
|
|
|
|
2020-08-15 20:02:07 +02:00
|
|
|
if (logger) {
|
|
|
|
delete logger;
|
|
|
|
logger = nullptr;
|
|
|
|
}
|
|
|
|
|
2021-07-25 15:33:11 +02:00
|
|
|
g_threadManager.Teardown();
|
|
|
|
|
2023-03-22 22:07:29 +01:00
|
|
|
#if !(PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS))
|
|
|
|
System_ExitApp();
|
|
|
|
#endif
|
|
|
|
|
2017-05-31 11:12:11 +02:00
|
|
|
// Previously we did exit() here on Android but that makes it hard to do things like restart on backend change.
|
|
|
|
// I think we handle most globals correctly or correct-enough now.
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
2023-06-26 00:35:03 +02:00
|
|
|
|
2023-06-26 17:09:35 +02:00
|
|
|
// In the future, we might make this more sophisticated, such as storing in the app private directory on Android.
|
|
|
|
// Right now we just store secrets in separate files next to ppsspp.ini. The important thing is keeping them out of it
|
|
|
|
// since we often ask people to post or send the ini for debugging.
|
2023-06-26 17:21:39 +02:00
|
|
|
static Path GetSecretPath(const char *nameOfSecret) {
|
|
|
|
return GetSysDirectory(DIRECTORY_SYSTEM) / ("ppsspp_" + std::string(nameOfSecret) + ".dat");
|
2023-06-26 00:35:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// name should be simple alphanumerics to avoid problems on Windows.
|
2023-09-06 10:34:32 +02:00
|
|
|
bool NativeSaveSecret(const char *nameOfSecret, const std::string &data) {
|
2023-06-26 00:35:03 +02:00
|
|
|
Path path = GetSecretPath(nameOfSecret);
|
2023-06-27 09:47:35 +02:00
|
|
|
if (!File::WriteDataToFile(false, data.data(), (unsigned int)data.size(), path)) {
|
2023-06-26 10:01:20 +02:00
|
|
|
WARN_LOG(SYSTEM, "Failed to write secret '%s' to path '%s'", nameOfSecret, path.c_str());
|
2023-09-06 10:34:32 +02:00
|
|
|
return false;
|
2023-06-26 10:01:20 +02:00
|
|
|
}
|
2023-09-06 10:34:32 +02:00
|
|
|
return true;
|
2023-06-26 00:35:03 +02:00
|
|
|
}
|
|
|
|
|
2023-09-06 10:34:32 +02:00
|
|
|
// On failure, returns an empty string. Good enough since any real secret is non-empty.
|
2023-06-26 00:35:03 +02:00
|
|
|
std::string NativeLoadSecret(const char *nameOfSecret) {
|
|
|
|
Path path = GetSecretPath(nameOfSecret);
|
|
|
|
std::string data;
|
2023-06-26 10:01:20 +02:00
|
|
|
if (!File::ReadFileToString(false, path, data)) {
|
2023-09-06 10:34:32 +02:00
|
|
|
data.clear(); // just to be sure.
|
2023-06-26 10:01:20 +02:00
|
|
|
}
|
2023-06-26 00:35:03 +02:00
|
|
|
return data;
|
|
|
|
}
|