Add support for non portable mode (#356)

This commit is contained in:
SSimco
2022-10-12 08:03:26 +02:00
committed by GitHub
parent 2b9edced81
commit d6ba61cf64
38 changed files with 233 additions and 163 deletions
+5
View File
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.21.1)
option(ENABLE_VCPKG "Enable the vcpkg package manager" ON)
option(PORTABLE "All data created and maintained by Cemu will be in the directory where the executable file is located" ON)
set(EXPERIMENTAL_VERSION "" CACHE STRING "") # used by CI script to set experimental version
if (EXPERIMENTAL_VERSION)
@@ -30,6 +31,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_definitions($<$<CONFIG:Debug>:CEMU_DEBUG_ASSERT>) # if build type is debug, set CEMU_DEBUG_ASSERT
if(PORTABLE)
add_compile_definitions(PORTABLE)
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# enable link time optimization for release builds
+2 -2
View File
@@ -424,7 +424,7 @@ OnlineValidator Account::ValidateOnlineFiles() const
{
OnlineValidator result{};
const auto otp = ActiveSettings::GetPath("otp.bin");
const auto otp = ActiveSettings::GetUserDataPath("otp.bin");
if (!fs::exists(otp))
result.otp = OnlineValidator::FileState::Missing;
else if (fs::file_size(otp) != 1024)
@@ -432,7 +432,7 @@ OnlineValidator Account::ValidateOnlineFiles() const
else
result.otp = OnlineValidator::FileState::Ok;
const auto seeprom = ActiveSettings::GetPath("seeprom.bin");
const auto seeprom = ActiveSettings::GetUserDataPath("seeprom.bin");
if (!fs::exists(seeprom))
result.seeprom = OnlineValidator::FileState::Missing;
else if (fs::file_size(seeprom) != 512)
+3 -3
View File
@@ -289,7 +289,7 @@ uint32 loadSharedData()
for (sint32 i = 0; i < sizeof(shareddataDef) / sizeof(shareddataDef[0]); i++)
{
bool existsInMLC = fs::exists(ActiveSettings::GetMlcPath(shareddataDef[i].mlcPath));
bool existsInResources = fs::exists(ActiveSettings::GetPath(shareddataDef[i].resourcePath));
bool existsInResources = fs::exists(ActiveSettings::GetDataPath(shareddataDef[i].resourcePath));
if (!existsInMLC && !existsInResources)
{
@@ -314,7 +314,7 @@ uint32 loadSharedData()
// alternatively fall back to our shared fonts
if (!fontFile)
{
path = ActiveSettings::GetPath(shareddataDef[i].resourcePath);
path = ActiveSettings::GetDataPath(shareddataDef[i].resourcePath);
fontFile = FileStream::openFile2(path);
}
if (!fontFile)
@@ -340,7 +340,7 @@ uint32 loadSharedData()
return memory_getVirtualOffsetFromPointer(dataWritePtr);
}
// alternative method: load RAM dump
const auto path = ActiveSettings::GetPath("shareddata.bin");
const auto path = ActiveSettings::GetUserDataPath("shareddata.bin");
FileStream* ramDumpFile = FileStream::openFile2(path);
if (ramDumpFile)
{
+1 -1
View File
@@ -59,7 +59,7 @@ void KeyCache_Prepare()
sKeyCachePrepared = true;
g_keyCache.clear();
// load keys
auto keysPath = ActiveSettings::GetPath("keys.txt");
auto keysPath = ActiveSettings::GetUserDataPath("keys.txt");
FileStream* fs_keys = FileStream::openFile2(keysPath);
if( !fs_keys )
{
+8 -3
View File
@@ -180,12 +180,12 @@ void gameProfile_load()
bool GameProfile::Load(uint64_t title_id)
{
auto gameProfilePath = ActiveSettings::GetPath("gameProfiles/{:016x}.ini", title_id);
auto gameProfilePath = ActiveSettings::GetConfigPath("gameProfiles/{:016x}.ini", title_id);
std::optional<std::vector<uint8>> profileContents = FileStream::LoadIntoMemory(gameProfilePath);
if (!profileContents)
{
gameProfilePath = ActiveSettings::GetPath("gameProfiles/default/{:016x}.ini", title_id);
gameProfilePath = ActiveSettings::GetDataPath("gameProfiles/default/{:016x}.ini", title_id);
profileContents = FileStream::LoadIntoMemory(gameProfilePath);
if (!profileContents)
return false;
@@ -276,7 +276,12 @@ bool GameProfile::Load(uint64_t title_id)
void GameProfile::Save(uint64_t title_id)
{
auto gameProfilePath = ActiveSettings::GetPath("gameProfiles/{:016x}.ini", title_id);
auto gameProfileDir = ActiveSettings::GetConfigPath("gameProfiles");
if (std::error_code ex_ec; !fs::exists(gameProfileDir, ex_ec) && !ex_ec) {
std::error_code cr_ec;
fs::create_directories(gameProfileDir, cr_ec);
}
auto gameProfilePath = gameProfileDir / fmt::format("{:016x}.ini", title_id);
FileStream* fs = FileStream::createFile2(gameProfilePath);
if (!fs)
{
+2 -2
View File
@@ -63,7 +63,7 @@ void GraphicPack2::LoadGraphicPack(fs::path graphicPackPath)
void GraphicPack2::LoadAll()
{
std::error_code ec;
fs::path basePath = ActiveSettings::GetPath("graphicPacks");
fs::path basePath = ActiveSettings::GetUserDataPath("graphicPacks");
for (fs::recursive_directory_iterator it(basePath, ec); it != end(it); ++it)
{
if (!it->is_directory(ec))
@@ -93,7 +93,7 @@ bool GraphicPack2::LoadGraphicPack(const std::wstring& filename, IniParser& rule
if (it == config_entries.cend())
{
// check for relative path
it = config_entries.find(MakeRelativePath(gp->GetFilename2()).lexically_normal());
it = config_entries.find(MakeRelativePath(ActiveSettings::GetUserDataPath(), gp->GetFilename2()).lexically_normal());
}
if (it != config_entries.cend())
+5 -5
View File
@@ -197,17 +197,17 @@ void LatteShaderCache_load()
LatteShaderCache_initCompileQueue();
// create directories
std::error_code ec;
fs::create_directories(ActiveSettings::GetPath("shaderCache/transferable"), ec);
fs::create_directories(ActiveSettings::GetPath("shaderCache/precompiled"), ec);
fs::create_directories(ActiveSettings::GetCachePath("shaderCache/transferable"), ec);
fs::create_directories(ActiveSettings::GetCachePath("shaderCache/precompiled"), ec);
// initialize renderer specific caches
if (g_renderer->GetType() == RendererAPI::Vulkan)
RendererShaderVk::ShaderCacheLoading_begin(cacheTitleId);
else if (g_renderer->GetType() == RendererAPI::OpenGL)
RendererShaderGL::ShaderCacheLoading_begin(cacheTitleId);
// get cache file name
const auto pathGeneric = ActiveSettings::GetPath("shaderCache/transferable/{:016x}_shaders.bin", cacheTitleId);
const auto pathGenericPre1_25_0 = ActiveSettings::GetPath("shaderCache/transferable/{:016x}.bin", cacheTitleId); // before 1.25.0
const auto pathGenericPre1_16_0 = ActiveSettings::GetPath("shaderCache/transferable/{:08x}.bin", CafeSystem::GetRPXHashBase()); // before 1.16.0
const auto pathGeneric = ActiveSettings::GetCachePath("shaderCache/transferable/{:016x}_shaders.bin", cacheTitleId);
const auto pathGenericPre1_25_0 = ActiveSettings::GetCachePath("shaderCache/transferable/{:016x}.bin", cacheTitleId); // before 1.25.0
const auto pathGenericPre1_16_0 = ActiveSettings::GetCachePath("shaderCache/transferable/{:08x}.bin", CafeSystem::GetRPXHashBase()); // before 1.16.0
LatteShaderCache_handleDeprecatedCacheFiles(pathGeneric, pathGenericPre1_25_0, pathGenericPre1_16_0);
// calculate extraVersion for transferable and precompiled shader cache
@@ -279,7 +279,7 @@ void RendererShaderGL::ShaderCacheLoading_begin(uint64 cacheTitleId)
{
const uint32 cacheMagic = GeneratePrecompiledCacheId();
const std::string cacheFilename = fmt::format("{:016x}_gl.bin", cacheTitleId);
const std::wstring cachePath = ActiveSettings::GetPath("shaderCache/precompiled/{}", cacheFilename).generic_wstring();
const std::wstring cachePath = ActiveSettings::GetCachePath("shaderCache/precompiled/{}", cacheFilename).generic_wstring();
g_programBinaryCache = FileCache::Open(cachePath, true, cacheMagic);
if (g_programBinaryCache == nullptr)
cemuLog_log(LogType::Force, "Unable to open OpenGL precompiled cache {}", cacheFilename);
+1 -1
View File
@@ -133,7 +133,7 @@ void Renderer::SaveScreenshot(const std::vector<uint8>& rgb_data, int width, int
// save to png file
if (save_screenshot)
{
fs::path screendir = ActiveSettings::GetPath("screenshots");
fs::path screendir = ActiveSettings::GetUserDataPath("screenshots");
if (!fs::exists(screendir))
fs::create_directory(screendir);
@@ -442,7 +442,7 @@ void RendererShaderVk::ShaderCacheLoading_begin(uint64 cacheTitleId)
}
uint32 spirvCacheMagic = GeneratePrecompiledCacheId();
const std::string cacheFilename = fmt::format("{:016x}_spirv.bin", cacheTitleId);
const std::wstring cachePath = ActiveSettings::GetPath("shaderCache/precompiled/{}", cacheFilename).generic_wstring();
const std::wstring cachePath = ActiveSettings::GetCachePath("shaderCache/precompiled/{}", cacheFilename).generic_wstring();
s_spirvCache = FileCache::Open(cachePath, true, spirvCacheMagic);
if (s_spirvCache == nullptr)
cemuLog_log(LogType::Force, "Unable to open SPIR-V cache {}", cacheFilename);
@@ -32,8 +32,8 @@ VulkanPipelineStableCache& VulkanPipelineStableCache::GetInstance()
uint32 VulkanPipelineStableCache::BeginLoading(uint64 cacheTitleId)
{
std::error_code ec;
fs::create_directories(ActiveSettings::GetPath("shaderCache/transferable"), ec);
const auto pathCacheFile = ActiveSettings::GetPath("shaderCache/transferable/{:016x}_vkpipeline.bin", cacheTitleId);
fs::create_directories(ActiveSettings::GetCachePath("shaderCache/transferable"), ec);
const auto pathCacheFile = ActiveSettings::GetCachePath("shaderCache/transferable/{:016x}_vkpipeline.bin", cacheTitleId);
// init cache loader state
g_vkCacheState.pipelineLoadIndex = 0;
@@ -2326,7 +2326,7 @@ void VulkanRenderer::WaitCommandBufferFinished(uint64 commandBufferId)
void VulkanRenderer::PipelineCacheSaveThread(size_t cache_size)
{
const auto dir = ActiveSettings::GetPath("shaderCache/driver/vk");
const auto dir = ActiveSettings::GetCachePath("shaderCache/driver/vk");
if (!fs::exists(dir))
{
try
@@ -2403,7 +2403,7 @@ void VulkanRenderer::PipelineCacheSaveThread(size_t cache_size)
void VulkanRenderer::CreatePipelineCache()
{
std::vector<uint8_t> cacheData;
const auto dir = ActiveSettings::GetPath("shaderCache/driver/vk");
const auto dir = ActiveSettings::GetCachePath("shaderCache/driver/vk");
if (fs::exists(dir))
{
const auto filename = dir / fmt::format("{:016x}.bin", CafeSystem::GetForegroundTitleId());
+1 -1
View File
@@ -409,7 +409,7 @@ void memory_writeDumpFile(uint32 startAddr, uint32 size, const fs::path& path)
void memory_createDump()
{
const uint32 pageSize = MemMapper::GetPageSize();
fs::path path = ActiveSettings::GetPath("dump/ramDump{:}", (uint32)time(nullptr));
fs::path path = ActiveSettings::GetUserDataPath("dump/ramDump{:}", (uint32)time(nullptr));
fs::create_directories(path);
for (auto& itr : g_mmuRanges)
+4 -4
View File
@@ -563,7 +563,7 @@ void iosuCrypto_loadSSLCertificates()
void iosuCrypto_init()
{
// load OTP dump
if (std::ifstream otp_file(ActiveSettings::GetPath("otp.bin"), std::ifstream::in | std::ios::binary); otp_file.is_open())
if (std::ifstream otp_file(ActiveSettings::GetUserDataPath("otp.bin"), std::ifstream::in | std::ios::binary); otp_file.is_open())
{
otp_file.seekg(0, std::ifstream::end);
const auto length = otp_file.tellg();
@@ -586,7 +586,7 @@ void iosuCrypto_init()
hasOtpMem = false;
}
if (std::ifstream seeprom_file(ActiveSettings::GetPath("seeprom.bin"), std::ifstream::in | std::ios::binary); seeprom_file.is_open())
if (std::ifstream seeprom_file(ActiveSettings::GetUserDataPath("seeprom.bin"), std::ifstream::in | std::ios::binary); seeprom_file.is_open())
{
seeprom_file.seekg(0, std::ifstream::end);
const auto length = seeprom_file.tellg();
@@ -630,13 +630,13 @@ sint32 iosuCrypt_checkRequirementsForOnlineMode(std::wstring& additionalErrorInf
{
std::error_code ec;
// check if otp.bin is present
const auto otp_file = ActiveSettings::GetPath("otp.bin");
const auto otp_file = ActiveSettings::GetUserDataPath("otp.bin");
if(!fs::exists(otp_file, ec))
return IOS_CRYPTO_ONLINE_REQ_OTP_MISSING;
if(fs::file_size(otp_file, ec) != 1024)
return IOS_CRYPTO_ONLINE_REQ_OTP_CORRUPTED;
// check if seeprom.bin is present
const auto seeprom_file = ActiveSettings::GetPath("seeprom.bin");
const auto seeprom_file = ActiveSettings::GetUserDataPath("seeprom.bin");
if (!fs::exists(seeprom_file, ec))
return IOS_CRYPTO_ONLINE_REQ_SEEPROM_MISSING;
if (fs::file_size(seeprom_file, ec) != 512)
+1 -1
View File
@@ -2116,7 +2116,7 @@ void RPLLoader_LoadDependency(rplDependency_t* dependency)
// attempt to load rpl from Cemu's /cafeLibs/ directory
if (ActiveSettings::LoadSharedLibrariesEnabled())
{
const auto filePath = ActiveSettings::GetPath("cafeLibs/{}", dependency->filepath);
const auto filePath = ActiveSettings::GetUserDataPath("cafeLibs/{}", dependency->filepath);
auto fileData = FileStream::LoadIntoMemory(filePath);
if (fileData)
{
+2 -2
View File
@@ -107,7 +107,7 @@ namespace coreinit
return;
std::error_code ec;
const auto path = ActiveSettings::GetPath("sdcard/");
const auto path = ActiveSettings::GetUserDataPath("sdcard/");
fs::create_directories(path, ec);
FSCDeviceHostFS_Mount("/vol/external01", _pathToUtf8(path), FSC_PRIORITY_BASE);
@@ -140,7 +140,7 @@ namespace coreinit
return FS_RESULT::ERR_PLACEHOLDER;
std::error_code ec;
const auto path = ActiveSettings::GetPath("sdcard/");
const auto path = ActiveSettings::GetUserDataPath("sdcard/");
fs::create_directories(path, ec);
if (!FSCDeviceHostFS_Mount(mountPathOut, _pathToUtf8(path), FSC_PRIORITY_BASE))
return FS_RESULT::ERR_PLACEHOLDER;
+1 -1
View File
@@ -291,7 +291,7 @@ void TitleInfo::CalcUID()
fs::path normalizedPath;
if (m_fullPath.is_relative())
{
normalizedPath = ActiveSettings::GetPath();
normalizedPath = ActiveSettings::GetUserDataPath();
normalizedPath /= m_fullPath;
}
else
+1 -1
View File
@@ -98,7 +98,7 @@ void cemuLog_createLogFile(bool triggeredByCrash)
if (LogContext.file_stream.is_open())
return;
const auto path = ActiveSettings::GetPath("log.txt");
const auto path = ActiveSettings::GetUserDataPath("log.txt");
LogContext.file_stream.open(path, std::ios::out);
if (LogContext.file_stream.fail())
{
@@ -61,7 +61,7 @@ bool CreateMiniDump(CrashDump dump, EXCEPTION_POINTERS* pep)
if (dump == CrashDump::Disabled)
return true;
fs::path p = ActiveSettings::GetPath("crashdump");
fs::path p = ActiveSettings::GetUserDataPath("crashdump");
std::error_code ec;
fs::create_directories(p, ec);
@@ -356,11 +356,11 @@ void createCrashlog(EXCEPTION_POINTERS* e, PCONTEXT context)
const auto temp_time = std::chrono::system_clock::to_time_t(now);
const auto& time = *std::gmtime(&temp_time);
fs::path p = ActiveSettings::GetPath("crashdump");
fs::path p = ActiveSettings::GetUserDataPath("crashdump");
p /= fmt::format("log_{:04d}{:02d}{:02d}_{:02d}{:02d}{:02d}.txt", 1900 + time.tm_year, time.tm_mon + 1, time.tm_mday, time.tm_year, time.tm_hour, time.tm_min, time.tm_sec);
std::error_code ec;
fs::copy_file(ActiveSettings::GetPath("log.txt"), p, ec);
fs::copy_file(ActiveSettings::GetUserDataPath("log.txt"), p, ec);
}
exit(0);
+29 -4
View File
@@ -1,6 +1,7 @@
#include "config/ActiveSettings.h"
#include "Cafe/GameProfile/GameProfile.h"
#include "Cemu/Logging/CemuLogging.h"
#include "LaunchSettings.h"
#include "util/helpers/helpers.h"
@@ -12,17 +13,41 @@
extern bool alwaysDisplayDRC;
void ActiveSettings::LoadOnce()
std::set<fs::path>
ActiveSettings::LoadOnce(const fs::path& user_data_path,
const fs::path& config_path,
const fs::path& cache_path,
const fs::path& data_path)
{
s_full_path = boost::dll::program_location().generic_wstring();
s_path = s_full_path.parent_path();
s_user_data_path = user_data_path;
s_config_path = config_path;
s_cache_path = cache_path;
s_data_path = data_path;
std::set<fs::path> failed_write_access;
for (auto&& path : {user_data_path, config_path, cache_path})
{
if (!fs::exists(path))
{
std::error_code ec;
fs::create_directories(path, ec);
}
if (!TestWriteAccess(path))
{
cemuLog_log(LogType::Force, "Failed to write to {}", path.generic_string());
failed_write_access.insert(path);
}
}
s_filename = s_full_path.filename();
g_config.SetFilename(GetPath("settings.xml").generic_wstring());
g_config.SetFilename(GetConfigPath("settings.xml").generic_wstring());
g_config.Load();
LaunchSettings::ChangeNetworkServiceURL(GetConfig().account.active_service);
std::wstring additionalErrorInfo;
s_has_required_online_files = iosuCrypt_checkRequirementsForOnlineMode(additionalErrorInfo) == IOS_CRYPTO_ONLINE_REQ_OK;
return failed_write_access;
}
bool ActiveSettings::LoadSharedLibrariesEnabled()
@@ -226,6 +251,6 @@ fs::path ActiveSettings::GetMlcPath()
fs::path ActiveSettings::GetDefaultMLCPath()
{
return GetPath("mlc01");
return GetUserDataPath("mlc01");
}

Some files were not shown because too many files have changed in this diff Show More