2014-10-04 19:12:15 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-10-04 19:12:15 +00:00
|
|
|
|
2021-12-10 02:22:16 +00:00
|
|
|
#include "UICommon/UICommon.h"
|
|
|
|
|
2017-07-21 10:46:12 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <clocale>
|
2017-12-31 19:33:36 +00:00
|
|
|
#include <cmath>
|
2018-04-01 10:26:50 +00:00
|
|
|
#include <iomanip>
|
2017-07-21 10:46:12 +00:00
|
|
|
#include <locale>
|
2017-06-24 19:41:53 +00:00
|
|
|
#include <memory>
|
2018-04-01 10:26:50 +00:00
|
|
|
#include <sstream>
|
2015-02-25 09:23:42 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <shlobj.h> // for SHGetFolderPath
|
2023-02-12 14:01:21 +00:00
|
|
|
|
|
|
|
#include <wil/resource.h>
|
2015-02-25 09:23:42 +00:00
|
|
|
#endif
|
|
|
|
|
2017-12-31 19:33:36 +00:00
|
|
|
#include "Common/Common.h"
|
2014-10-04 19:12:15 +00:00
|
|
|
#include "Common/CommonPaths.h"
|
2017-05-13 21:29:55 +00:00
|
|
|
#include "Common/Config/Config.h"
|
2014-10-04 19:12:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2019-06-07 22:25:32 +00:00
|
|
|
#include "Common/IniFile.h"
|
2014-10-04 19:12:15 +00:00
|
|
|
#include "Common/Logging/LogManager.h"
|
2017-12-31 19:33:36 +00:00
|
|
|
#include "Common/MathUtil.h"
|
2016-10-07 20:55:13 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2017-12-31 19:33:36 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2014-10-04 19:12:15 +00:00
|
|
|
|
2018-05-23 13:55:48 +00:00
|
|
|
#include "Core/Config/MainSettings.h"
|
2017-05-13 21:29:55 +00:00
|
|
|
#include "Core/ConfigLoaders/BaseConfigLoader.h"
|
2014-10-04 19:12:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2017-06-24 19:41:53 +00:00
|
|
|
#include "Core/Core.h"
|
2021-04-27 21:43:04 +00:00
|
|
|
#include "Core/FreeLookManager.h"
|
|
|
|
#include "Core/HW/GBAPad.h"
|
|
|
|
#include "Core/HW/GCKeyboard.h"
|
|
|
|
#include "Core/HW/GCPad.h"
|
2017-06-24 19:41:53 +00:00
|
|
|
#include "Core/HW/ProcessorInterface.h"
|
2014-10-04 19:12:15 +00:00
|
|
|
#include "Core/HW/Wiimote.h"
|
2021-04-27 21:43:04 +00:00
|
|
|
#include "Core/HotkeyManager.h"
|
2017-06-24 19:41:53 +00:00
|
|
|
#include "Core/IOS/IOS.h"
|
|
|
|
#include "Core/IOS/STM/STM.h"
|
2023-01-04 01:52:40 +00:00
|
|
|
#include "Core/System.h"
|
2020-03-16 12:02:35 +00:00
|
|
|
#include "Core/WiiRoot.h"
|
2014-10-04 19:12:15 +00:00
|
|
|
|
2021-04-27 21:43:04 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
2015-12-31 16:27:51 +00:00
|
|
|
#include "InputCommon/GCAdapter.h"
|
|
|
|
|
2018-05-27 04:24:13 +00:00
|
|
|
#include "UICommon/DiscordPresence.h"
|
2016-11-11 00:33:52 +00:00
|
|
|
#include "UICommon/USBUtils.h"
|
2014-10-04 19:12:15 +00:00
|
|
|
|
2021-02-03 00:25:06 +00:00
|
|
|
#ifdef HAVE_X11
|
2018-01-01 21:03:50 +00:00
|
|
|
#include "UICommon/X11Utils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <IOKit/pwr_mgt/IOPMLib.h>
|
|
|
|
#endif
|
|
|
|
|
2014-10-04 19:12:15 +00:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
|
|
|
|
|
|
|
namespace UICommon
|
|
|
|
{
|
2022-09-24 10:35:10 +00:00
|
|
|
static size_t s_config_changed_callback_id;
|
|
|
|
|
2021-11-22 02:44:33 +00:00
|
|
|
static void CreateDumpPath(std::string path)
|
2018-05-23 13:55:48 +00:00
|
|
|
{
|
2018-06-06 12:42:41 +00:00
|
|
|
if (!path.empty())
|
2021-11-22 02:44:33 +00:00
|
|
|
File::SetUserPath(D_DUMP_IDX, std::move(path));
|
2018-05-23 13:55:48 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_DUMPAUDIO_IDX));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_DUMPSSL_IDX));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_DUMPFRAMES_IDX));
|
2018-06-06 12:42:41 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_DUMPOBJECTS_IDX));
|
2018-05-23 13:55:48 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_DUMPTEXTURES_IDX));
|
|
|
|
}
|
|
|
|
|
2021-11-22 02:44:33 +00:00
|
|
|
static void CreateLoadPath(std::string path)
|
2019-10-06 05:51:42 +00:00
|
|
|
{
|
|
|
|
if (!path.empty())
|
2021-11-22 02:44:33 +00:00
|
|
|
File::SetUserPath(D_LOAD_IDX, std::move(path));
|
2019-10-06 05:51:42 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_HIRESTEXTURES_IDX));
|
2021-09-26 04:16:55 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_RIIVOLUTION_IDX));
|
2022-03-02 06:34:54 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_GRAPHICSMOD_IDX));
|
2023-02-26 21:07:48 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_DYNAMICINPUT_IDX));
|
2019-10-06 05:51:42 +00:00
|
|
|
}
|
|
|
|
|
2021-11-22 02:44:33 +00:00
|
|
|
static void CreateResourcePackPath(std::string path)
|
2019-10-06 06:21:06 +00:00
|
|
|
{
|
|
|
|
if (!path.empty())
|
2021-11-22 02:44:33 +00:00
|
|
|
File::SetUserPath(D_RESOURCEPACK_IDX, std::move(path));
|
2019-10-06 06:21:06 +00:00
|
|
|
}
|
|
|
|
|
2021-12-17 00:29:57 +00:00
|
|
|
static void CreateWFSPath(const std::string& path)
|
|
|
|
{
|
|
|
|
if (!path.empty())
|
|
|
|
File::SetUserPath(D_WFSROOT_IDX, path + '/');
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:55:48 +00:00
|
|
|
static void InitCustomPaths()
|
|
|
|
{
|
|
|
|
File::SetUserPath(D_WIIROOT_IDX, Config::Get(Config::MAIN_FS_PATH));
|
2019-10-06 05:51:42 +00:00
|
|
|
CreateLoadPath(Config::Get(Config::MAIN_LOAD_PATH));
|
2018-05-23 13:55:48 +00:00
|
|
|
CreateDumpPath(Config::Get(Config::MAIN_DUMP_PATH));
|
2019-10-06 06:21:06 +00:00
|
|
|
CreateResourcePackPath(Config::Get(Config::MAIN_RESOURCEPACK_PATH));
|
2021-12-17 00:29:57 +00:00
|
|
|
CreateWFSPath(Config::Get(Config::MAIN_WFS_PATH));
|
2022-04-17 01:28:34 +00:00
|
|
|
File::SetUserPath(F_WIISDCARDIMAGE_IDX, Config::Get(Config::MAIN_WII_SD_CARD_IMAGE_PATH));
|
2022-04-17 02:10:36 +00:00
|
|
|
File::SetUserPath(D_WIISDCARDSYNCFOLDER_IDX,
|
|
|
|
Config::Get(Config::MAIN_WII_SD_CARD_SYNC_FOLDER_PATH));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_WIISDCARDSYNCFOLDER_IDX));
|
2022-01-22 15:00:29 +00:00
|
|
|
#ifdef HAS_LIBMGBA
|
2021-07-04 10:51:36 +00:00
|
|
|
File::SetUserPath(F_GBABIOS_IDX, Config::Get(Config::MAIN_GBA_BIOS_PATH));
|
|
|
|
File::SetUserPath(D_GBASAVES_IDX, Config::Get(Config::MAIN_GBA_SAVES_PATH));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_GBASAVES_IDX));
|
2022-01-22 15:00:29 +00:00
|
|
|
#endif
|
2018-05-23 13:55:48 +00:00
|
|
|
}
|
|
|
|
|
2022-09-24 10:35:10 +00:00
|
|
|
static void RefreshConfig()
|
|
|
|
{
|
|
|
|
Common::SetEnableAlert(Config::Get(Config::MAIN_USE_PANIC_HANDLERS));
|
|
|
|
Common::SetAbortOnPanicAlert(Config::Get(Config::MAIN_ABORT_ON_PANIC_ALERT));
|
|
|
|
}
|
|
|
|
|
2014-10-04 19:12:15 +00:00
|
|
|
void Init()
|
|
|
|
{
|
2020-03-16 12:02:35 +00:00
|
|
|
Core::RestoreWiiSettings(Core::RestoreReason::CrashRecovery);
|
|
|
|
|
2017-05-13 21:29:55 +00:00
|
|
|
Config::Init();
|
2018-05-23 13:55:48 +00:00
|
|
|
Config::AddConfigChangedCallback(InitCustomPaths);
|
2017-07-31 08:26:46 +00:00
|
|
|
Config::AddLayer(ConfigLoaders::GenerateBaseConfigLoader());
|
2014-10-04 19:12:15 +00:00
|
|
|
SConfig::Init();
|
2018-05-27 04:24:13 +00:00
|
|
|
Discord::Init();
|
2019-11-28 09:19:24 +00:00
|
|
|
Common::Log::LogManager::Init();
|
2020-05-03 23:21:51 +00:00
|
|
|
VideoBackendBase::ActivateBackend(Config::Get(Config::MAIN_GFX_BACKEND));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-09-24 10:35:10 +00:00
|
|
|
s_config_changed_callback_id = Config::AddConfigChangedCallback(RefreshConfig);
|
|
|
|
RefreshConfig();
|
2014-10-04 19:12:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown()
|
|
|
|
{
|
2022-09-24 10:35:10 +00:00
|
|
|
Config::RemoveConfigChangedCallback(s_config_changed_callback_id);
|
|
|
|
|
2015-12-31 16:27:51 +00:00
|
|
|
GCAdapter::Shutdown();
|
2014-10-04 19:12:15 +00:00
|
|
|
WiimoteReal::Shutdown();
|
2019-11-28 09:19:24 +00:00
|
|
|
Common::Log::LogManager::Shutdown();
|
2018-05-27 04:24:13 +00:00
|
|
|
Discord::Shutdown();
|
2014-10-04 19:12:15 +00:00
|
|
|
SConfig::Shutdown();
|
2017-05-13 21:29:55 +00:00
|
|
|
Config::Shutdown();
|
2014-10-04 19:12:15 +00:00
|
|
|
}
|
|
|
|
|
2021-04-27 21:43:04 +00:00
|
|
|
void InitControllers(const WindowSystemInfo& wsi)
|
|
|
|
{
|
|
|
|
if (g_controller_interface.IsInit())
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_controller_interface.Initialize(wsi);
|
|
|
|
|
|
|
|
if (!g_controller_interface.HasDefaultDevice())
|
|
|
|
{
|
|
|
|
// Note that the CI default device could be still temporarily removed at any time
|
|
|
|
WARN_LOG_FMT(CONTROLLERINTERFACE, "No default device has been added in time. Premade control "
|
|
|
|
"mappings intended for the default device may not work.");
|
|
|
|
}
|
|
|
|
|
|
|
|
GCAdapter::Init();
|
|
|
|
Pad::Initialize();
|
|
|
|
Pad::InitializeGBA();
|
|
|
|
Keyboard::Initialize();
|
|
|
|
Wiimote::Initialize(Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES);
|
|
|
|
HotkeyManagerEmu::Initialize();
|
|
|
|
FreeLook::Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShutdownControllers()
|
|
|
|
{
|
|
|
|
Pad::Shutdown();
|
|
|
|
Pad::ShutdownGBA();
|
|
|
|
Keyboard::Shutdown();
|
|
|
|
Wiimote::Shutdown();
|
|
|
|
HotkeyManagerEmu::Shutdown();
|
|
|
|
FreeLook::Shutdown();
|
|
|
|
|
|
|
|
g_controller_interface.Shutdown();
|
|
|
|
}
|
|
|
|
|
2017-07-21 10:46:12 +00:00
|
|
|
void SetLocale(std::string locale_name)
|
|
|
|
{
|
|
|
|
auto set_locale = [](const std::string& locale) {
|
|
|
|
#ifdef __linux__
|
|
|
|
std::string adjusted_locale = locale;
|
|
|
|
if (!locale.empty())
|
|
|
|
adjusted_locale += ".UTF-8";
|
|
|
|
#else
|
|
|
|
const std::string& adjusted_locale = locale;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// setlocale sets the C locale, and global sets the C and C++ locales, so the call to setlocale
|
|
|
|
// would be redundant if it wasn't for not having any other good way to check whether
|
|
|
|
// the locale name is valid. (Constructing a std::locale object for an unsupported
|
|
|
|
// locale name throws std::runtime_error, and exception handling is disabled in Dolphin.)
|
|
|
|
if (!std::setlocale(LC_ALL, adjusted_locale.c_str()))
|
|
|
|
return false;
|
|
|
|
std::locale::global(std::locale(adjusted_locale));
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
constexpr char PREFERRED_SEPARATOR = '-';
|
|
|
|
constexpr char OTHER_SEPARATOR = '_';
|
|
|
|
#else
|
|
|
|
constexpr char PREFERRED_SEPARATOR = '_';
|
|
|
|
constexpr char OTHER_SEPARATOR = '-';
|
|
|
|
#endif
|
|
|
|
|
2017-07-21 11:35:35 +00:00
|
|
|
// Users who use a system language other than English are unlikely to prefer American date and
|
|
|
|
// time formats, so let's explicitly request "en_GB" if Dolphin's language is set to "en".
|
|
|
|
// (The settings window only allows setting "en", not anything like "en_US" or "en_GB".)
|
|
|
|
// Users who prefer the American formats are likely to have their system language set to en_US,
|
|
|
|
// and are thus likely to leave Dolphin's language as the default value "" (<System Language>).
|
|
|
|
if (locale_name == "en")
|
|
|
|
locale_name = "en_GB";
|
|
|
|
|
2017-07-21 10:46:12 +00:00
|
|
|
std::replace(locale_name.begin(), locale_name.end(), OTHER_SEPARATOR, PREFERRED_SEPARATOR);
|
|
|
|
|
|
|
|
// Use the specified locale if supported.
|
|
|
|
if (set_locale(locale_name))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Remove subcodes until we get a supported locale. If that doesn't give us a supported locale,
|
|
|
|
// "" is passed to set_locale in order to get the system default locale.
|
|
|
|
while (!locale_name.empty())
|
|
|
|
{
|
|
|
|
const size_t separator_index = locale_name.rfind(PREFERRED_SEPARATOR);
|
|
|
|
locale_name.erase(separator_index == std::string::npos ? 0 : separator_index);
|
|
|
|
if (set_locale(locale_name))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If none of the locales tried above are supported, we just keep using whatever locale is set
|
|
|
|
// (which is the classic locale by default).
|
|
|
|
}
|
|
|
|
|
2014-10-04 19:12:15 +00:00
|
|
|
void CreateDirectories()
|
|
|
|
{
|
2018-11-17 15:36:28 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_RESOURCEPACK_IDX));
|
2014-10-04 19:12:15 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_USER_IDX));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_CACHE_IDX));
|
2018-07-30 01:16:37 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_COVERCACHE_IDX));
|
2014-10-04 19:12:15 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX));
|
2022-03-02 06:34:54 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX) + GRAPHICSMOD_CONFIG_DIR DIR_SEP);
|
2014-10-04 19:12:15 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX));
|
2015-07-11 08:31:03 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_DUMPSSL_IDX));
|
2014-10-04 19:12:15 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_DUMPTEXTURES_IDX));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_GAMESETTINGS_IDX));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + USA_DIR DIR_SEP);
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + EUR_DIR DIR_SEP);
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + JAP_DIR DIR_SEP);
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_HIRESTEXTURES_IDX));
|
2022-03-02 06:34:54 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_GRAPHICSMOD_IDX));
|
2014-10-04 19:12:15 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_MAILLOGS_IDX));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_MAPS_IDX));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX));
|
|
|
|
File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX));
|
2015-01-03 00:33:30 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX) + ANAGLYPH_DIR DIR_SEP);
|
2014-10-04 19:12:15 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX));
|
2017-09-09 09:27:24 +00:00
|
|
|
#ifndef ANDROID
|
2014-10-04 19:12:15 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_THEMES_IDX));
|
2018-05-06 16:25:37 +00:00
|
|
|
File::CreateFullPath(File::GetUserPath(D_STYLES_IDX));
|
2018-08-15 08:37:00 +00:00
|
|
|
#else
|
2018-08-15 11:41:55 +00:00
|
|
|
// Disable media scanning in directories with a .nomedia file
|
2018-08-15 08:37:00 +00:00
|
|
|
File::CreateEmptyFile(File::GetUserPath(D_COVERCACHE_IDX) + DIR_SEP NOMEDIA_FILE);
|
2017-09-09 09:27:24 +00:00
|
|
|
#endif
|
2014-10-04 19:12:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-22 02:44:33 +00:00
|
|
|
void SetUserDirectory(std::string custom_path)
|
2015-02-25 09:23:42 +00:00
|
|
|
{
|
2015-03-15 13:51:13 +00:00
|
|
|
if (!custom_path.empty())
|
2015-02-25 09:23:42 +00:00
|
|
|
{
|
|
|
|
File::CreateFullPath(custom_path + DIR_SEP);
|
2021-11-22 02:44:33 +00:00
|
|
|
File::SetUserPath(D_USER_IDX, std::move(custom_path));
|
2015-02-25 09:23:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-03-02 18:42:25 +00:00
|
|
|
std::string user_path;
|
2015-02-25 09:23:42 +00:00
|
|
|
#ifdef _WIN32
|
2016-02-10 05:42:32 +00:00
|
|
|
// Detect where the User directory is. There are five different cases
|
|
|
|
// (on top of the command line flag, which overrides all this):
|
2015-02-25 09:23:42 +00:00
|
|
|
// 1. GetExeDirectory()\portable.txt exists
|
|
|
|
// -> Use GetExeDirectory()\User
|
|
|
|
// 2. HKCU\Software\Dolphin Emulator\LocalUserConfig exists and is true
|
|
|
|
// -> Use GetExeDirectory()\User
|
|
|
|
// 3. HKCU\Software\Dolphin Emulator\UserConfigPath exists
|
|
|
|
// -> Use this as the user directory path
|
2022-05-29 22:31:17 +00:00
|
|
|
// 4. My Documents\Dolphin Emulator exists (default user folder before PR 10708)
|
|
|
|
// -> Use this as the user directory path
|
|
|
|
// 5. AppData\Roaming exists
|
2022-05-29 22:10:10 +00:00
|
|
|
// -> Use AppData\Roaming\Dolphin Emulator as the User directory path
|
2022-05-29 22:31:17 +00:00
|
|
|
// 6. Default
|
2015-02-25 09:23:42 +00:00
|
|
|
// -> Use GetExeDirectory()\User
|
2023-01-17 20:03:11 +00:00
|
|
|
//
|
|
|
|
// On Steam builds, we take a simplified approach:
|
|
|
|
// 1. GetExeDirectory()\portable.txt exists
|
|
|
|
// -> Use GetExeDirectory()\User
|
|
|
|
// 2. AppData\Roaming exists
|
|
|
|
// -> Use AppData\Roaming\Dolphin Emulator (Steam) as the User directory path
|
|
|
|
// 3. Default
|
|
|
|
// -> Use GetExeDirectory()\User
|
|
|
|
|
|
|
|
// Get AppData path in case we need it.
|
2023-02-12 14:01:21 +00:00
|
|
|
wil::unique_cotaskmem_string appdata;
|
|
|
|
bool appdata_found = SUCCEEDED(
|
|
|
|
SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, nullptr, appdata.put()));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2023-01-17 20:03:11 +00:00
|
|
|
#ifndef STEAM
|
2015-02-25 09:23:42 +00:00
|
|
|
// Check our registry keys
|
2023-02-12 14:01:21 +00:00
|
|
|
wil::unique_hkey hkey;
|
2015-02-25 09:23:42 +00:00
|
|
|
DWORD local = 0;
|
2019-10-06 19:37:51 +00:00
|
|
|
std::unique_ptr<TCHAR[]> configPath;
|
2015-02-25 09:23:42 +00:00
|
|
|
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE,
|
2023-02-12 14:01:21 +00:00
|
|
|
hkey.put()) == ERROR_SUCCESS)
|
2015-02-25 09:23:42 +00:00
|
|
|
{
|
2023-02-12 14:01:21 +00:00
|
|
|
DWORD size = sizeof(local);
|
|
|
|
if (RegQueryValueEx(hkey.get(), TEXT("LocalUserConfig"), nullptr, nullptr,
|
2015-02-25 09:23:42 +00:00
|
|
|
reinterpret_cast<LPBYTE>(&local), &size) != ERROR_SUCCESS)
|
2019-10-06 19:37:51 +00:00
|
|
|
{
|
2015-02-25 09:23:42 +00:00
|
|
|
local = 0;
|
2019-10-06 19:37:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size = 0;
|
2023-02-12 14:01:21 +00:00
|
|
|
RegQueryValueEx(hkey.get(), TEXT("UserConfigPath"), nullptr, nullptr, nullptr, &size);
|
2019-10-06 19:37:51 +00:00
|
|
|
configPath = std::make_unique<TCHAR[]>(size / sizeof(TCHAR));
|
2023-02-12 14:01:21 +00:00
|
|
|
if (RegQueryValueEx(hkey.get(), TEXT("UserConfigPath"), nullptr, nullptr,
|
2019-10-06 19:37:51 +00:00
|
|
|
reinterpret_cast<LPBYTE>(configPath.get()), &size) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
configPath.reset();
|
|
|
|
}
|
2015-02-25 09:23:42 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-10-06 19:37:51 +00:00
|
|
|
local = local != 0 || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt");
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2023-02-12 14:01:21 +00:00
|
|
|
// Attempt to check if the old User directory exists in Documents.
|
|
|
|
wil::unique_cotaskmem_string documents;
|
|
|
|
bool documents_found = SUCCEEDED(
|
|
|
|
SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, documents.put()));
|
2022-05-29 22:31:17 +00:00
|
|
|
|
|
|
|
std::optional<std::string> old_user_folder;
|
|
|
|
if (documents_found)
|
|
|
|
{
|
2023-02-12 14:01:21 +00:00
|
|
|
old_user_folder = TStrToUTF8(documents.get()) + DIR_SEP NORMAL_USER_DIR DIR_SEP;
|
2022-05-29 22:31:17 +00:00
|
|
|
}
|
|
|
|
|
2015-02-25 09:23:42 +00:00
|
|
|
if (local) // Case 1-2
|
2022-05-29 23:20:41 +00:00
|
|
|
{
|
2023-01-17 19:13:14 +00:00
|
|
|
user_path = File::GetExeDirectory() + DIR_SEP PORTABLE_USER_DIR DIR_SEP;
|
2022-05-29 23:20:41 +00:00
|
|
|
}
|
2019-10-06 19:37:51 +00:00
|
|
|
else if (configPath) // Case 3
|
2022-05-29 23:20:41 +00:00
|
|
|
{
|
2019-10-06 19:37:51 +00:00
|
|
|
user_path = TStrToUTF8(configPath.get());
|
2022-05-29 23:20:41 +00:00
|
|
|
}
|
2022-05-29 22:31:17 +00:00
|
|
|
else if (old_user_folder && File::Exists(old_user_folder.value())) // Case 4
|
2022-05-29 23:20:41 +00:00
|
|
|
{
|
2022-05-29 22:31:17 +00:00
|
|
|
user_path = old_user_folder.value();
|
2022-05-29 23:20:41 +00:00
|
|
|
}
|
2022-05-29 22:31:17 +00:00
|
|
|
else if (appdata_found) // Case 5
|
2022-05-29 23:20:41 +00:00
|
|
|
{
|
2023-02-12 14:01:21 +00:00
|
|
|
user_path = TStrToUTF8(appdata.get()) + DIR_SEP NORMAL_USER_DIR DIR_SEP;
|
2022-05-29 23:20:41 +00:00
|
|
|
|
|
|
|
// Set the UserConfigPath value in the registry for backwards compatibility with older Dolphin
|
|
|
|
// builds, which will look for the default User directory in Documents. If we set this key,
|
|
|
|
// they will use this as the User directory instead.
|
|
|
|
// (If we're in this case, then this key doesn't exist, so it's OK to set it.)
|
|
|
|
std::wstring wstr_path = UTF8ToWString(user_path);
|
|
|
|
RegSetKeyValueW(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), TEXT("UserConfigPath"),
|
|
|
|
REG_SZ, wstr_path.c_str(),
|
|
|
|
static_cast<DWORD>((wstr_path.size() + 1) * sizeof(wchar_t)));
|
|
|
|
}
|
2022-05-29 22:31:17 +00:00
|
|
|
else // Case 6
|
2022-05-29 23:20:41 +00:00
|
|
|
{
|
2023-01-17 19:13:14 +00:00
|
|
|
user_path = File::GetExeDirectory() + DIR_SEP PORTABLE_USER_DIR DIR_SEP;
|
2022-05-29 23:20:41 +00:00
|
|
|
}
|
2023-01-17 20:03:11 +00:00
|
|
|
#else // ifndef STEAM
|
|
|
|
if (File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt")) // Case 1
|
|
|
|
{
|
|
|
|
user_path = File::GetExeDirectory() + DIR_SEP PORTABLE_USER_DIR DIR_SEP;
|
|
|
|
}
|
|
|
|
else if (appdata_found) // Case 2
|
|
|
|
{
|
2023-02-12 14:01:21 +00:00
|
|
|
user_path = TStrToUTF8(appdata.get()) + DIR_SEP NORMAL_USER_DIR DIR_SEP;
|
2023-01-17 20:03:11 +00:00
|
|
|
}
|
|
|
|
else // Case 3
|
|
|
|
{
|
|
|
|
user_path = File::GetExeDirectory() + DIR_SEP PORTABLE_USER_DIR DIR_SEP;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-25 09:23:42 +00:00
|
|
|
#else
|
2023-01-17 19:17:10 +00:00
|
|
|
if (File::IsDirectory(ROOT_DIR DIR_SEP EMBEDDED_USER_DIR))
|
2015-04-18 15:44:11 +00:00
|
|
|
{
|
2023-01-17 19:17:10 +00:00
|
|
|
user_path = ROOT_DIR DIR_SEP EMBEDDED_USER_DIR DIR_SEP;
|
2015-04-18 15:44:11 +00:00
|
|
|
}
|
2015-02-25 09:23:42 +00:00
|
|
|
else
|
2015-04-18 15:44:11 +00:00
|
|
|
{
|
2016-12-20 16:15:09 +00:00
|
|
|
const char* env_path = getenv("DOLPHIN_EMU_USERPATH");
|
2015-04-18 15:44:11 +00:00
|
|
|
const char* home = getenv("HOME");
|
|
|
|
if (!home)
|
|
|
|
home = getenv("PWD");
|
|
|
|
if (!home)
|
|
|
|
home = "";
|
|
|
|
std::string home_path = std::string(home) + DIR_SEP;
|
|
|
|
|
2022-02-03 18:16:16 +00:00
|
|
|
// On a non-Apple and non-Android POSIX system, there are 4 cases:
|
2016-02-10 05:42:32 +00:00
|
|
|
// 1. GetExeDirectory()/portable.txt exists
|
2016-12-20 16:15:09 +00:00
|
|
|
// -> Use GetExeDirectory()/User
|
|
|
|
// 2. $DOLPHIN_EMU_USERPATH is set
|
|
|
|
// -> Use $DOLPHIN_EMU_USERPATH
|
|
|
|
// 3. ~/.dolphin-emu directory exists
|
2016-02-10 05:42:32 +00:00
|
|
|
// -> Use ~/.dolphin-emu
|
2016-12-20 16:15:09 +00:00
|
|
|
// 4. Default
|
2016-02-10 05:42:32 +00:00
|
|
|
// -> Use XDG basedir, see
|
|
|
|
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
2022-02-03 18:16:16 +00:00
|
|
|
//
|
|
|
|
// On macOS:
|
|
|
|
// 1. GetExeDirectory()/portable.txt exists
|
|
|
|
// -> Use GetExeDirectory()/User
|
|
|
|
// 2. $DOLPHIN_EMU_USERPATH is set
|
|
|
|
// -> Use $DOLPHIN_EMU_USERPATH
|
|
|
|
// 3. Default
|
|
|
|
//
|
|
|
|
// On Android, custom_path is set, so this code path is never reached.
|
2016-02-10 05:42:32 +00:00
|
|
|
std::string exe_path = File::GetExeDirectory();
|
|
|
|
if (File::Exists(exe_path + DIR_SEP "portable.txt"))
|
|
|
|
{
|
2023-01-17 19:17:10 +00:00
|
|
|
user_path = exe_path + DIR_SEP PORTABLE_USER_DIR DIR_SEP;
|
2016-02-10 05:42:32 +00:00
|
|
|
}
|
2016-12-20 16:15:09 +00:00
|
|
|
else if (env_path)
|
|
|
|
{
|
|
|
|
user_path = env_path;
|
|
|
|
}
|
2022-02-03 18:16:16 +00:00
|
|
|
#if defined(__APPLE__) || defined(ANDROID)
|
|
|
|
else
|
2015-04-18 15:44:11 +00:00
|
|
|
{
|
2023-01-17 19:13:36 +00:00
|
|
|
user_path = home_path + NORMAL_USER_DIR DIR_SEP;
|
2022-02-03 18:16:16 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
else
|
|
|
|
{
|
2023-01-17 19:13:36 +00:00
|
|
|
user_path = home_path + "." NORMAL_USER_DIR DIR_SEP;
|
2022-02-03 18:16:16 +00:00
|
|
|
|
|
|
|
if (!File::Exists(user_path))
|
|
|
|
{
|
|
|
|
const char* data_home = getenv("XDG_DATA_HOME");
|
|
|
|
std::string data_path =
|
|
|
|
std::string(data_home && data_home[0] == '/' ? data_home :
|
|
|
|
(home_path + ".local" DIR_SEP "share")) +
|
2023-01-17 19:13:36 +00:00
|
|
|
DIR_SEP NORMAL_USER_DIR DIR_SEP;
|
2022-02-03 18:16:16 +00:00
|
|
|
|
|
|
|
const char* config_home = getenv("XDG_CONFIG_HOME");
|
|
|
|
std::string config_path =
|
|
|
|
std::string(config_home && config_home[0] == '/' ? config_home :
|
|
|
|
(home_path + ".config")) +
|
2023-01-17 19:13:36 +00:00
|
|
|
DIR_SEP NORMAL_USER_DIR DIR_SEP;
|
2022-02-03 18:16:16 +00:00
|
|
|
|
|
|
|
const char* cache_home = getenv("XDG_CACHE_HOME");
|
|
|
|
std::string cache_path =
|
|
|
|
std::string(cache_home && cache_home[0] == '/' ? cache_home : (home_path + ".cache")) +
|
2023-01-17 19:13:36 +00:00
|
|
|
DIR_SEP NORMAL_USER_DIR DIR_SEP;
|
2022-02-03 18:16:16 +00:00
|
|
|
|
|
|
|
File::SetUserPath(D_USER_IDX, data_path);
|
|
|
|
File::SetUserPath(D_CONFIG_IDX, config_path);
|
|
|
|
File::SetUserPath(D_CACHE_IDX, cache_path);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-18 15:44:11 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2015-02-25 09:23:42 +00:00
|
|
|
#endif
|
2019-10-06 19:37:51 +00:00
|
|
|
File::SetUserPath(D_USER_IDX, std::move(user_path));
|
2015-02-25 09:23:42 +00:00
|
|
|
}
|
|
|
|
|
2017-06-24 19:41:53 +00:00
|
|
|
bool TriggerSTMPowerEvent()
|
|
|
|
{
|
|
|
|
const auto ios = IOS::HLE::GetIOS();
|
|
|
|
if (!ios)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto stm = ios->GetDeviceByName("/dev/stm/eventhook");
|
2021-02-11 23:54:13 +00:00
|
|
|
if (!stm || !std::static_pointer_cast<IOS::HLE::STMEventHookDevice>(stm)->HasHookInstalled())
|
2017-06-24 19:41:53 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Core::DisplayMessage("Shutting down", 30000);
|
2023-01-04 01:52:40 +00:00
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
system.GetProcessorInterface().PowerButton_Tap();
|
2017-06-24 19:41:53 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-03 00:25:06 +00:00
|
|
|
#ifdef HAVE_X11
|
2020-10-18 18:06:11 +00:00
|
|
|
void InhibitScreenSaver(Window win, bool inhibit)
|
2018-01-01 21:03:50 +00:00
|
|
|
#else
|
2020-10-18 18:06:11 +00:00
|
|
|
void InhibitScreenSaver(bool inhibit)
|
2018-01-01 21:03:50 +00:00
|
|
|
#endif
|
|
|
|
{
|
2019-05-05 23:48:12 +00:00
|
|
|
// Inhibit the screensaver. Depending on the operating system this may also
|
|
|
|
// disable low-power states and/or screen dimming.
|
2018-01-01 21:03:50 +00:00
|
|
|
|
2021-02-03 00:25:06 +00:00
|
|
|
#ifdef HAVE_X11
|
2020-10-18 18:06:11 +00:00
|
|
|
X11Utils::InhibitScreensaver(win, inhibit);
|
2018-01-01 21:03:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Prevents Windows from sleeping, turning off the display, or idling
|
2020-10-18 18:06:11 +00:00
|
|
|
SetThreadExecutionState(ES_CONTINUOUS |
|
|
|
|
(inhibit ? (ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED) : 0));
|
2018-01-01 21:03:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
static IOPMAssertionID s_power_assertion = kIOPMNullAssertionID;
|
2020-10-18 18:06:11 +00:00
|
|
|
if (inhibit)
|
2018-01-01 21:03:50 +00:00
|
|
|
{
|
2020-10-18 18:06:11 +00:00
|
|
|
CFStringRef reason_for_activity = CFSTR("Emulation Running");
|
|
|
|
if (IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
|
|
|
|
kIOPMAssertionLevelOn, reason_for_activity,
|
|
|
|
&s_power_assertion) != kIOReturnSuccess)
|
2018-01-01 21:03:50 +00:00
|
|
|
{
|
2020-10-18 18:06:11 +00:00
|
|
|
s_power_assertion = kIOPMNullAssertionID;
|
2018-01-01 21:03:50 +00:00
|
|
|
}
|
2020-10-18 18:06:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (s_power_assertion != kIOPMNullAssertionID)
|
2018-01-01 21:03:50 +00:00
|
|
|
{
|
2020-10-18 18:06:11 +00:00
|
|
|
IOPMAssertionRelease(s_power_assertion);
|
|
|
|
s_power_assertion = kIOPMNullAssertionID;
|
2018-01-01 21:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-04-10 13:14:03 +00:00
|
|
|
std::string FormatSize(u64 bytes, int decimals)
|
2017-12-31 19:33:36 +00:00
|
|
|
{
|
|
|
|
// i18n: The symbol for the unit "bytes"
|
|
|
|
const char* const unit_symbols[] = {_trans("B"), _trans("KiB"), _trans("MiB"), _trans("GiB"),
|
|
|
|
_trans("TiB"), _trans("PiB"), _trans("EiB")};
|
|
|
|
|
|
|
|
// Find largest power of 2 less than size.
|
|
|
|
// div 10 to get largest named unit less than size
|
|
|
|
// 10 == log2(1024) (number of B in a KiB, KiB in a MiB, etc)
|
|
|
|
// Max value is 63 / 10 = 6
|
2023-04-15 07:27:35 +00:00
|
|
|
const int unit = MathUtil::IntLog2(std::max<u64>(bytes, 1)) / 10;
|
2017-12-31 19:33:36 +00:00
|
|
|
|
|
|
|
// Don't need exact values, only 5 most significant digits
|
|
|
|
const double unit_size = std::pow(2, unit * 10);
|
2019-09-14 20:40:34 +00:00
|
|
|
std::ostringstream ss;
|
2020-04-10 13:14:03 +00:00
|
|
|
ss << std::fixed << std::setprecision(decimals);
|
2019-06-17 03:45:37 +00:00
|
|
|
ss << bytes / unit_size << ' ' << Common::GetStringT(unit_symbols[unit]);
|
2018-04-01 10:26:50 +00:00
|
|
|
return ss.str();
|
2017-12-31 19:33:36 +00:00
|
|
|
}
|
|
|
|
|
2014-10-04 19:12:15 +00:00
|
|
|
} // namespace UICommon
|