mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 17:19:44 -06:00
Reformat all the things. Have fun with merge conflicts.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
#include <disasm.h> // Bochs
|
||||
#include <disasm.h> // Bochs
|
||||
|
||||
#if defined(HAS_LLVM)
|
||||
// PowerPC.h defines PC.
|
||||
@ -10,170 +10,178 @@
|
||||
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
#include "Core/PowerPC/JitInterface.h"
|
||||
#include "Core/PowerPC/JitCommon/JitBase.h"
|
||||
#include "Core/PowerPC/JitCommon/JitCache.h"
|
||||
#include "Core/PowerPC/JitInterface.h"
|
||||
|
||||
#include "UICommon/Disassembler.h"
|
||||
|
||||
class HostDisassemblerX86 : public HostDisassembler
|
||||
{
|
||||
public:
|
||||
HostDisassemblerX86();
|
||||
HostDisassemblerX86();
|
||||
|
||||
private:
|
||||
disassembler m_disasm;
|
||||
disassembler m_disasm;
|
||||
|
||||
std::string DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count, u64 starting_pc) override;
|
||||
std::string DisassembleHostBlock(const u8* code_start, const u32 code_size,
|
||||
u32* host_instructions_count, u64 starting_pc) override;
|
||||
};
|
||||
|
||||
#if defined(HAS_LLVM)
|
||||
class HostDisassemblerLLVM : public HostDisassembler
|
||||
{
|
||||
public:
|
||||
HostDisassemblerLLVM(const std::string& host_disasm, int inst_size = -1, const std::string& cpu = "");
|
||||
~HostDisassemblerLLVM()
|
||||
{
|
||||
if (m_can_disasm)
|
||||
LLVMDisasmDispose(m_llvm_context);
|
||||
}
|
||||
HostDisassemblerLLVM(const std::string& host_disasm, int inst_size = -1,
|
||||
const std::string& cpu = "");
|
||||
~HostDisassemblerLLVM()
|
||||
{
|
||||
if (m_can_disasm)
|
||||
LLVMDisasmDispose(m_llvm_context);
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_can_disasm;
|
||||
LLVMDisasmContextRef m_llvm_context;
|
||||
int m_instruction_size;
|
||||
bool m_can_disasm;
|
||||
LLVMDisasmContextRef m_llvm_context;
|
||||
int m_instruction_size;
|
||||
|
||||
std::string DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count, u64 starting_pc) override;
|
||||
std::string DisassembleHostBlock(const u8* code_start, const u32 code_size,
|
||||
u32* host_instructions_count, u64 starting_pc) override;
|
||||
};
|
||||
|
||||
HostDisassemblerLLVM::HostDisassemblerLLVM(const std::string& host_disasm, int inst_size, const std::string& cpu)
|
||||
: m_can_disasm(false), m_instruction_size(inst_size)
|
||||
HostDisassemblerLLVM::HostDisassemblerLLVM(const std::string& host_disasm, int inst_size,
|
||||
const std::string& cpu)
|
||||
: m_can_disasm(false), m_instruction_size(inst_size)
|
||||
{
|
||||
LLVMInitializeAllTargetInfos();
|
||||
LLVMInitializeAllTargetMCs();
|
||||
LLVMInitializeAllDisassemblers();
|
||||
LLVMInitializeAllTargetInfos();
|
||||
LLVMInitializeAllTargetMCs();
|
||||
LLVMInitializeAllDisassemblers();
|
||||
|
||||
m_llvm_context = LLVMCreateDisasmCPU(host_disasm.c_str(), cpu.c_str(), nullptr, 0, 0, nullptr);
|
||||
m_llvm_context = LLVMCreateDisasmCPU(host_disasm.c_str(), cpu.c_str(), nullptr, 0, 0, nullptr);
|
||||
|
||||
// Couldn't create llvm context
|
||||
if (!m_llvm_context)
|
||||
return;
|
||||
// Couldn't create llvm context
|
||||
if (!m_llvm_context)
|
||||
return;
|
||||
|
||||
LLVMSetDisasmOptions(m_llvm_context,
|
||||
LLVMDisassembler_Option_AsmPrinterVariant |
|
||||
LLVMDisassembler_Option_PrintLatency);
|
||||
LLVMSetDisasmOptions(m_llvm_context, LLVMDisassembler_Option_AsmPrinterVariant |
|
||||
LLVMDisassembler_Option_PrintLatency);
|
||||
|
||||
m_can_disasm = true;
|
||||
m_can_disasm = true;
|
||||
}
|
||||
|
||||
std::string HostDisassemblerLLVM::DisassembleHostBlock(const u8* code_start, const u32 code_size, u32 *host_instructions_count, u64 starting_pc)
|
||||
std::string HostDisassemblerLLVM::DisassembleHostBlock(const u8* code_start, const u32 code_size,
|
||||
u32* host_instructions_count,
|
||||
u64 starting_pc)
|
||||
{
|
||||
if (!m_can_disasm)
|
||||
return "(No LLVM context)";
|
||||
if (!m_can_disasm)
|
||||
return "(No LLVM context)";
|
||||
|
||||
u8* disasmPtr = (u8*)code_start;
|
||||
const u8 *end = code_start + code_size;
|
||||
u8* disasmPtr = (u8*)code_start;
|
||||
const u8* end = code_start + code_size;
|
||||
|
||||
std::ostringstream x86_disasm;
|
||||
while ((u8*)disasmPtr < end)
|
||||
{
|
||||
char inst_disasm[256];
|
||||
size_t inst_size = LLVMDisasmInstruction(m_llvm_context, disasmPtr, (u64)(end - disasmPtr), starting_pc, inst_disasm, 256);
|
||||
std::ostringstream x86_disasm;
|
||||
while ((u8*)disasmPtr < end)
|
||||
{
|
||||
char inst_disasm[256];
|
||||
size_t inst_size = LLVMDisasmInstruction(m_llvm_context, disasmPtr, (u64)(end - disasmPtr),
|
||||
starting_pc, inst_disasm, 256);
|
||||
|
||||
x86_disasm << "0x" << std::hex << starting_pc << "\t";
|
||||
if (!inst_size)
|
||||
{
|
||||
x86_disasm << "Invalid inst:";
|
||||
x86_disasm << "0x" << std::hex << starting_pc << "\t";
|
||||
if (!inst_size)
|
||||
{
|
||||
x86_disasm << "Invalid inst:";
|
||||
|
||||
if (m_instruction_size != -1)
|
||||
{
|
||||
// If we are on an architecture that has a fixed instruction size
|
||||
// We can continue onward past this bad instruction.
|
||||
std::string inst_str = "";
|
||||
for (int i = 0; i < m_instruction_size; ++i)
|
||||
inst_str += StringFromFormat("%02x", disasmPtr[i]);
|
||||
if (m_instruction_size != -1)
|
||||
{
|
||||
// If we are on an architecture that has a fixed instruction size
|
||||
// We can continue onward past this bad instruction.
|
||||
std::string inst_str = "";
|
||||
for (int i = 0; i < m_instruction_size; ++i)
|
||||
inst_str += StringFromFormat("%02x", disasmPtr[i]);
|
||||
|
||||
x86_disasm << inst_str << std::endl;
|
||||
disasmPtr += m_instruction_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We can't continue if we are on an architecture that has flexible instruction sizes
|
||||
// Dump the rest of the block instead
|
||||
std::string code_block = "";
|
||||
for (int i = 0; (disasmPtr + i) < end; ++i)
|
||||
code_block += StringFromFormat("%02x", disasmPtr[i]);
|
||||
x86_disasm << inst_str << std::endl;
|
||||
disasmPtr += m_instruction_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We can't continue if we are on an architecture that has flexible instruction sizes
|
||||
// Dump the rest of the block instead
|
||||
std::string code_block = "";
|
||||
for (int i = 0; (disasmPtr + i) < end; ++i)
|
||||
code_block += StringFromFormat("%02x", disasmPtr[i]);
|
||||
|
||||
x86_disasm << code_block << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x86_disasm << inst_disasm << std::endl;
|
||||
disasmPtr += inst_size;
|
||||
starting_pc += inst_size;
|
||||
}
|
||||
x86_disasm << code_block << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x86_disasm << inst_disasm << std::endl;
|
||||
disasmPtr += inst_size;
|
||||
starting_pc += inst_size;
|
||||
}
|
||||
|
||||
(*host_instructions_count)++;
|
||||
}
|
||||
(*host_instructions_count)++;
|
||||
}
|
||||
|
||||
return x86_disasm.str();
|
||||
return x86_disasm.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
HostDisassemblerX86::HostDisassemblerX86()
|
||||
{
|
||||
m_disasm.set_syntax_intel();
|
||||
m_disasm.set_syntax_intel();
|
||||
}
|
||||
|
||||
std::string HostDisassemblerX86::DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count, u64 starting_pc)
|
||||
std::string HostDisassemblerX86::DisassembleHostBlock(const u8* code_start, const u32 code_size,
|
||||
u32* host_instructions_count, u64 starting_pc)
|
||||
{
|
||||
u64 disasmPtr = (u64)code_start;
|
||||
const u8* end = code_start + code_size;
|
||||
u64 disasmPtr = (u64)code_start;
|
||||
const u8* end = code_start + code_size;
|
||||
|
||||
std::ostringstream x86_disasm;
|
||||
while ((u8*)disasmPtr < end)
|
||||
{
|
||||
char inst_disasm[256];
|
||||
disasmPtr += m_disasm.disasm64(disasmPtr, disasmPtr, (u8*)disasmPtr, inst_disasm);
|
||||
x86_disasm << inst_disasm << std::endl;
|
||||
(*host_instructions_count)++;
|
||||
}
|
||||
std::ostringstream x86_disasm;
|
||||
while ((u8*)disasmPtr < end)
|
||||
{
|
||||
char inst_disasm[256];
|
||||
disasmPtr += m_disasm.disasm64(disasmPtr, disasmPtr, (u8*)disasmPtr, inst_disasm);
|
||||
x86_disasm << inst_disasm << std::endl;
|
||||
(*host_instructions_count)++;
|
||||
}
|
||||
|
||||
return x86_disasm.str();
|
||||
return x86_disasm.str();
|
||||
}
|
||||
|
||||
HostDisassembler* GetNewDisassembler(const std::string& arch)
|
||||
{
|
||||
#if defined(HAS_LLVM)
|
||||
if (arch == "x86")
|
||||
return new HostDisassemblerLLVM("x86_64-none-unknown");
|
||||
else if (arch == "aarch64")
|
||||
return new HostDisassemblerLLVM("aarch64-none-unknown", 4, "cortex-a57");
|
||||
else if (arch == "armv7")
|
||||
return new HostDisassemblerLLVM("armv7-none-unknown", 4, "cortex-a15");
|
||||
if (arch == "x86")
|
||||
return new HostDisassemblerLLVM("x86_64-none-unknown");
|
||||
else if (arch == "aarch64")
|
||||
return new HostDisassemblerLLVM("aarch64-none-unknown", 4, "cortex-a57");
|
||||
else if (arch == "armv7")
|
||||
return new HostDisassemblerLLVM("armv7-none-unknown", 4, "cortex-a15");
|
||||
#elif defined(_M_X86)
|
||||
if (arch == "x86")
|
||||
return new HostDisassemblerX86();
|
||||
if (arch == "x86")
|
||||
return new HostDisassemblerX86();
|
||||
#endif
|
||||
return new HostDisassembler();
|
||||
return new HostDisassembler();
|
||||
}
|
||||
|
||||
std::string DisassembleBlock(HostDisassembler* disasm, u32* address, u32* host_instructions_count, u32* code_size)
|
||||
std::string DisassembleBlock(HostDisassembler* disasm, u32* address, u32* host_instructions_count,
|
||||
u32* code_size)
|
||||
{
|
||||
const u8* code;
|
||||
int res = JitInterface::GetHostCode(address, &code, code_size);
|
||||
const u8* code;
|
||||
int res = JitInterface::GetHostCode(address, &code, code_size);
|
||||
|
||||
if (res == 1)
|
||||
{
|
||||
*host_instructions_count = 0;
|
||||
return "(No JIT active)";
|
||||
}
|
||||
else if (res == 2)
|
||||
{
|
||||
host_instructions_count = 0;
|
||||
return "(No translation)";
|
||||
}
|
||||
return disasm->DisassembleHostBlock(code, *code_size, host_instructions_count, (u64)code);
|
||||
if (res == 1)
|
||||
{
|
||||
*host_instructions_count = 0;
|
||||
return "(No JIT active)";
|
||||
}
|
||||
else if (res == 2)
|
||||
{
|
||||
host_instructions_count = 0;
|
||||
return "(No translation)";
|
||||
}
|
||||
return disasm->DisassembleHostBlock(code, *code_size, host_instructions_count, (u64)code);
|
||||
}
|
||||
|
@ -9,9 +9,14 @@
|
||||
class HostDisassembler
|
||||
{
|
||||
public:
|
||||
virtual ~HostDisassembler() {}
|
||||
virtual std::string DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count, u64 starting_pc) { return "(No disassembler)"; }
|
||||
virtual ~HostDisassembler() {}
|
||||
virtual std::string DisassembleHostBlock(const u8* code_start, const u32 code_size,
|
||||
u32* host_instructions_count, u64 starting_pc)
|
||||
{
|
||||
return "(No disassembler)";
|
||||
}
|
||||
};
|
||||
|
||||
HostDisassembler* GetNewDisassembler(const std::string& arch);
|
||||
std::string DisassembleBlock(HostDisassembler* disasm, u32* address, u32* host_instructions_count, u32* code_size);
|
||||
std::string DisassembleBlock(HostDisassembler* disasm, u32* address, u32* host_instructions_count,
|
||||
u32* code_size);
|
||||
|
@ -3,7 +3,7 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <shlobj.h> // for SHGetFolderPath
|
||||
#include <shlobj.h> // for SHGetFolderPath
|
||||
#endif
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
@ -21,163 +21,167 @@
|
||||
|
||||
namespace UICommon
|
||||
{
|
||||
|
||||
void Init()
|
||||
{
|
||||
LogManager::Init();
|
||||
SConfig::Init();
|
||||
VideoBackendBase::PopulateList();
|
||||
WiimoteReal::LoadSettings();
|
||||
GCAdapter::Init();
|
||||
VideoBackendBase::ActivateBackend(SConfig::GetInstance().m_strVideoBackend);
|
||||
LogManager::Init();
|
||||
SConfig::Init();
|
||||
VideoBackendBase::PopulateList();
|
||||
WiimoteReal::LoadSettings();
|
||||
GCAdapter::Init();
|
||||
VideoBackendBase::ActivateBackend(SConfig::GetInstance().m_strVideoBackend);
|
||||
|
||||
SetEnableAlert(SConfig::GetInstance().bUsePanicHandlers);
|
||||
SetEnableAlert(SConfig::GetInstance().bUsePanicHandlers);
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
GCAdapter::Shutdown();
|
||||
WiimoteReal::Shutdown();
|
||||
VideoBackendBase::ClearList();
|
||||
SConfig::Shutdown();
|
||||
LogManager::Shutdown();
|
||||
GCAdapter::Shutdown();
|
||||
WiimoteReal::Shutdown();
|
||||
VideoBackendBase::ClearList();
|
||||
SConfig::Shutdown();
|
||||
LogManager::Shutdown();
|
||||
}
|
||||
|
||||
void CreateDirectories()
|
||||
{
|
||||
// Copy initial Wii NAND data from Sys to User.
|
||||
File::CopyDir(File::GetSysDirectory() + WII_USER_DIR,
|
||||
File::GetUserPath(D_WIIROOT_IDX));
|
||||
// Copy initial Wii NAND data from Sys to User.
|
||||
File::CopyDir(File::GetSysDirectory() + WII_USER_DIR, File::GetUserPath(D_WIIROOT_IDX));
|
||||
|
||||
File::CreateFullPath(File::GetUserPath(D_USER_IDX));
|
||||
File::CreateFullPath(File::GetUserPath(D_CACHE_IDX));
|
||||
File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX));
|
||||
File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX));
|
||||
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));
|
||||
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));
|
||||
File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX) + ANAGLYPH_DIR DIR_SEP);
|
||||
File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX));
|
||||
File::CreateFullPath(File::GetUserPath(D_THEMES_IDX));
|
||||
File::CreateFullPath(File::GetUserPath(D_USER_IDX));
|
||||
File::CreateFullPath(File::GetUserPath(D_CACHE_IDX));
|
||||
File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX));
|
||||
File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX));
|
||||
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));
|
||||
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));
|
||||
File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX) + ANAGLYPH_DIR DIR_SEP);
|
||||
File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX));
|
||||
File::CreateFullPath(File::GetUserPath(D_THEMES_IDX));
|
||||
}
|
||||
|
||||
void SetUserDirectory(const std::string& custom_path)
|
||||
{
|
||||
if (!custom_path.empty())
|
||||
{
|
||||
File::CreateFullPath(custom_path + DIR_SEP);
|
||||
File::SetUserPath(D_USER_IDX, custom_path + DIR_SEP);
|
||||
return;
|
||||
}
|
||||
if (!custom_path.empty())
|
||||
{
|
||||
File::CreateFullPath(custom_path + DIR_SEP);
|
||||
File::SetUserPath(D_USER_IDX, custom_path + DIR_SEP);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string user_path = "";
|
||||
std::string user_path = "";
|
||||
#ifdef _WIN32
|
||||
// Detect where the User directory is. There are five different cases (on top of the
|
||||
// command line flag, which overrides all this):
|
||||
// 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
|
||||
// 4. My Documents exists
|
||||
// -> Use My Documents\Dolphin Emulator as the User directory path
|
||||
// 5. Default
|
||||
// -> Use GetExeDirectory()\User
|
||||
// Detect where the User directory is. There are five different cases (on top of the
|
||||
// command line flag, which overrides all this):
|
||||
// 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
|
||||
// 4. My Documents exists
|
||||
// -> Use My Documents\Dolphin Emulator as the User directory path
|
||||
// 5. Default
|
||||
// -> Use GetExeDirectory()\User
|
||||
|
||||
// Check our registry keys
|
||||
HKEY hkey;
|
||||
DWORD local = 0;
|
||||
TCHAR configPath[MAX_PATH] = {0};
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
|
||||
{
|
||||
DWORD size = 4;
|
||||
if (RegQueryValueEx(hkey, TEXT("LocalUserConfig"), nullptr, nullptr, reinterpret_cast<LPBYTE>(&local), &size) != ERROR_SUCCESS)
|
||||
local = 0;
|
||||
// Check our registry keys
|
||||
HKEY hkey;
|
||||
DWORD local = 0;
|
||||
TCHAR configPath[MAX_PATH] = {0};
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE,
|
||||
&hkey) == ERROR_SUCCESS)
|
||||
{
|
||||
DWORD size = 4;
|
||||
if (RegQueryValueEx(hkey, TEXT("LocalUserConfig"), nullptr, nullptr,
|
||||
reinterpret_cast<LPBYTE>(&local), &size) != ERROR_SUCCESS)
|
||||
local = 0;
|
||||
|
||||
size = MAX_PATH;
|
||||
if (RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr, (LPBYTE)configPath, &size) != ERROR_SUCCESS)
|
||||
configPath[0] = 0;
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
size = MAX_PATH;
|
||||
if (RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr, (LPBYTE)configPath,
|
||||
&size) != ERROR_SUCCESS)
|
||||
configPath[0] = 0;
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
|
||||
local = local || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt");
|
||||
local = local || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt");
|
||||
|
||||
// Get Program Files path in case we need it.
|
||||
TCHAR my_documents[MAX_PATH];
|
||||
bool my_documents_found = SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
|
||||
// Get Program Files path in case we need it.
|
||||
TCHAR my_documents[MAX_PATH];
|
||||
bool my_documents_found = SUCCEEDED(
|
||||
SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
|
||||
|
||||
if (local) // Case 1-2
|
||||
user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
|
||||
else if (configPath[0]) // Case 3
|
||||
user_path = TStrToUTF8(configPath);
|
||||
else if (my_documents_found) // Case 4
|
||||
user_path = TStrToUTF8(my_documents) + DIR_SEP "Dolphin Emulator" DIR_SEP;
|
||||
else // Case 5
|
||||
user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
|
||||
if (local) // Case 1-2
|
||||
user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
|
||||
else if (configPath[0]) // Case 3
|
||||
user_path = TStrToUTF8(configPath);
|
||||
else if (my_documents_found) // Case 4
|
||||
user_path = TStrToUTF8(my_documents) + DIR_SEP "Dolphin Emulator" DIR_SEP;
|
||||
else // Case 5
|
||||
user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
|
||||
|
||||
// Prettify the path: it will be displayed in some places, we don't want a mix of \ and /.
|
||||
user_path = ReplaceAll(user_path, "\\", DIR_SEP);
|
||||
// Prettify the path: it will be displayed in some places, we don't want a mix of \ and /.
|
||||
user_path = ReplaceAll(user_path, "\\", DIR_SEP);
|
||||
|
||||
// Make sure it ends in DIR_SEP.
|
||||
if (*user_path.rbegin() != DIR_SEP_CHR)
|
||||
user_path += DIR_SEP;
|
||||
// Make sure it ends in DIR_SEP.
|
||||
if (*user_path.rbegin() != DIR_SEP_CHR)
|
||||
user_path += DIR_SEP;
|
||||
#else
|
||||
if (File::Exists(ROOT_DIR DIR_SEP USERDATA_DIR))
|
||||
{
|
||||
user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* home = getenv("HOME");
|
||||
if (!home)
|
||||
home = getenv("PWD");
|
||||
if (!home)
|
||||
home = "";
|
||||
std::string home_path = std::string(home) + DIR_SEP;
|
||||
if (File::Exists(ROOT_DIR DIR_SEP USERDATA_DIR))
|
||||
{
|
||||
user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* home = getenv("HOME");
|
||||
if (!home)
|
||||
home = getenv("PWD");
|
||||
if (!home)
|
||||
home = "";
|
||||
std::string home_path = std::string(home) + DIR_SEP;
|
||||
|
||||
#if defined(__APPLE__) || defined(ANDROID)
|
||||
user_path = home_path + DOLPHIN_DATA_DIR DIR_SEP;
|
||||
user_path = home_path + DOLPHIN_DATA_DIR DIR_SEP;
|
||||
#else
|
||||
// We are on a non-Apple and non-Android POSIX system, let's respect XDG basedir.
|
||||
// The only case we don't is when there is an existing ~/.dolphin-emu directory.
|
||||
// See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
// We are on a non-Apple and non-Android POSIX system, let's respect XDG basedir.
|
||||
// The only case we don't is when there is an existing ~/.dolphin-emu directory.
|
||||
// See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
|
||||
user_path = home_path + "." DOLPHIN_DATA_DIR DIR_SEP;
|
||||
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")) + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
|
||||
user_path = home_path + "." DOLPHIN_DATA_DIR DIR_SEP;
|
||||
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")) +
|
||||
DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
|
||||
|
||||
const char* config_home = getenv("XDG_CONFIG_HOME");
|
||||
std::string config_path = std::string(config_home && config_home[0] == '/' ?
|
||||
config_home :
|
||||
(home_path + ".config")) + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
|
||||
const char* config_home = getenv("XDG_CONFIG_HOME");
|
||||
std::string config_path =
|
||||
std::string(config_home && config_home[0] == '/' ? config_home :
|
||||
(home_path + ".config")) +
|
||||
DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
|
||||
|
||||
const char* cache_home = getenv("XDG_CACHE_HOME");
|
||||
std::string cache_path = std::string(cache_home && cache_home[0] == '/' ?
|
||||
cache_home :
|
||||
(home_path + ".cache")) + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
|
||||
const char* cache_home = getenv("XDG_CACHE_HOME");
|
||||
std::string cache_path =
|
||||
std::string(cache_home && cache_home[0] == '/' ? cache_home : (home_path + ".cache")) +
|
||||
DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
|
||||
|
||||
File::SetUserPath(D_USER_IDX, data_path);
|
||||
File::SetUserPath(D_CONFIG_IDX, config_path);
|
||||
File::SetUserPath(D_CACHE_IDX, cache_path);
|
||||
return;
|
||||
}
|
||||
File::SetUserPath(D_USER_IDX, data_path);
|
||||
File::SetUserPath(D_CONFIG_IDX, config_path);
|
||||
File::SetUserPath(D_CACHE_IDX, cache_path);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
File::SetUserPath(D_USER_IDX, user_path);
|
||||
File::SetUserPath(D_USER_IDX, user_path);
|
||||
}
|
||||
|
||||
} // namespace UICommon
|
||||
} // namespace UICommon
|
||||
|
@ -6,11 +6,10 @@
|
||||
|
||||
namespace UICommon
|
||||
{
|
||||
|
||||
void Init();
|
||||
void Shutdown();
|
||||
|
||||
void CreateDirectories();
|
||||
void SetUserDirectory(const std::string& custom_path);
|
||||
|
||||
} // namespace UICommon
|
||||
} // namespace UICommon
|
||||
|
Reference in New Issue
Block a user