fs::get_config_dir, fs::get_executable_dir

This commit is contained in:
Nekotekina 2015-12-16 22:50:45 +03:00
parent 56ba5a765b
commit 321e6d3a86
21 changed files with 249 additions and 178 deletions

View file

@ -33,7 +33,7 @@ spu_recompiler::spu_recompiler()
LOG_SUCCESS(SPU, "SPU Recompiler (ASMJIT) created...");
fs::file("SPUJIT.log", fom::rewrite) << fmt::format("SPU JIT initialization...\n\nTitle: %s\nTitle ID: %s\n\n", Emu.GetTitle().c_str(), Emu.GetTitleID().c_str());
fs::file(fs::get_config_dir() + "SPUJIT.log", fom::rewrite) << fmt::format("SPU JIT initialization...\n\nTitle: %s\nTitle ID: %s\n\n", Emu.GetTitle().c_str(), Emu.GetTitleID().c_str());
}
void spu_recompiler::compile(spu_function_t& f)
@ -218,7 +218,7 @@ void spu_recompiler::compile(spu_function_t& f)
log += "\n\n\n";
// Append log file
fs::file("SPUJIT.log", fom::write | fom::append) << log;
fs::file(fs::get_config_dir() + "SPUJIT.log", fom::write | fom::append) << log;
}
spu_recompiler::XmmLink spu_recompiler::XmmAlloc() // get empty xmm register

View file

@ -480,7 +480,6 @@ void VFS::Init(const std::string& path)
}
std::string mpath = entry.path;
// TODO: This shouldn't use current dir
// If no value assigned to SysEmulationDirPath in INI, use the path that with executable.
if (rpcs3::config.system.emulation_dir_path_enable.value())
{
@ -488,7 +487,7 @@ void VFS::Init(const std::string& path)
}
else
{
fmt::Replace(mpath, "$(EmulatorDir)", Emu.GetEmulatorPath());
fmt::Replace(mpath, "$(EmulatorDir)", fs::get_executable_dir());
}
fmt::Replace(mpath, "$(GameDir)", cwd);
Mount(entry.mount, mpath, dev);
@ -531,7 +530,7 @@ void VFS::SaveLoadDevices(std::vector<VFSManagerEntry>& res, bool is_load)
if (dir.empty())
{
rpcs3::config.system.emulation_dir_path = Emu.GetEmulatorPath();
rpcs3::config.system.emulation_dir_path = fs::get_executable_dir();
}
if (!fs::is_dir(dir))

View file

@ -166,8 +166,7 @@ struct D3D12Traits
}
}
// TODO: This shouldn't use current dir
fs::file("./FragmentProgram" + std::to_string(ID) + ".hlsl", fom::rewrite) << shader;
fs::file(fs::get_config_dir() + "FragmentProgram" + std::to_string(ID) + ".hlsl", fom::rewrite) << shader;
fragmentProgramData.id = (u32)ID;
}
@ -178,8 +177,7 @@ struct D3D12Traits
std::string shaderCode = VS.Decompile();
vertexProgramData.Compile(shaderCode, Shader::SHADER_TYPE::SHADER_TYPE_VERTEX);
vertexProgramData.vertex_shader_inputs = VS.input_slots;
// TODO: This shouldn't use current dir
fs::file("./VertexProgram" + std::to_string(ID) + ".hlsl", fom::rewrite) << shaderCode;
fs::file(fs::get_config_dir() + "VertexProgram" + std::to_string(ID) + ".hlsl", fom::rewrite) << shaderCode;
vertexProgramData.id = (u32)ID;
}

View file

@ -466,7 +466,7 @@ void GLTexture::save(rsx::texture& tex, const std::string& name)
return;
}
fs::file(name + ".raw", fom::rewrite).write(alldata, texPixelCount * 4);
fs::file(fs::get_config_dir() + name + ".raw", fom::rewrite).write(alldata, texPixelCount * 4);
u8* data = new u8[texPixelCount * 3];
u8* alpha = new u8[texPixelCount];
@ -496,10 +496,10 @@ void GLTexture::save(rsx::texture& tex)
static const std::string& dir_path = "textures";
static const std::string& file_fmt = dir_path + "/" + "tex[%d].png";
if (!fs::exists(dir_path)) fs::create_dir(dir_path);
if (!fs::is_dir(dir_path)) fs::create_dir(dir_path);
u32 count = 0;
while (fs::exists(fmt::format(file_fmt.c_str(), count))) count++;
while (fs::is_file(fmt::format(file_fmt.c_str(), count))) count++;
save(tex, fmt::format(file_fmt.c_str(), count));
}
@ -886,7 +886,7 @@ void GLGSRender::end()
size_t vertex_arrays_offsets[rsx::limits::vertex_count];
#if DUMP_VERTEX_DATA
fs::file dump("VertexDataArray.dump", o_create | o_write);
fs::file dump(fs::get_config_dir() + "VertexDataArray.dump", fom::rewrite);
Emu.Pause();
#endif

View file

@ -18,8 +18,7 @@ struct GLTraits
fragmentProgramData.Compile();
//checkForGlError("m_fragment_prog.Compile");
// TODO: This shouldn't use current dir
fs::file("./FragmentProgram.txt", fom::rewrite) << fragmentProgramData.shader;
fs::file(fs::get_config_dir() + "FragmentProgram.txt", fom::rewrite) << fragmentProgramData.shader;
}
static
@ -29,8 +28,7 @@ struct GLTraits
vertexProgramData.Compile();
//checkForGlError("m_vertex_prog.Compile");
// TODO: This shouldn't use current dir
fs::file("./VertexProgram.txt", fom::rewrite) << vertexProgramData.shader;
fs::file(fs::get_config_dir() + "VertexProgram.txt", fom::rewrite) << vertexProgramData.shader;
}
static

View file

@ -34,11 +34,32 @@
#include "Loader/ELF32.h"
#include "../Crypto/unself.h"
#include <fstream>
using namespace PPU_instr;
static const std::string& BreakPointsDBName = "BreakPoints.dat";
static const u16 bpdb_version = 0x1000;
// Draft (not used)
struct bpdb_header_t
{
le_t<u32> magic;
le_t<u32> version;
le_t<u32> count;
le_t<u32> marked;
// POD
bpdb_header_t() = default;
bpdb_header_t(u32 count, u32 marked)
: magic(*reinterpret_cast<const u32*>("BPDB"))
, version(0x00010000)
, count(count)
, marked(marked)
{
}
};
extern std::atomic<u32> g_thread_count;
extern u64 get_system_time();
@ -88,7 +109,7 @@ void Emulator::SetTitle(const std::string& title)
void Emulator::CreateConfig(const std::string& name)
{
const std::string& path = "data/" + name;
const std::string& path = fs::get_config_dir() + "data/" + name;
const std::string& ini_file = path + "/settings.ini";
if (!fs::is_dir("data"))
@ -264,7 +285,7 @@ void Emulator::Load()
{
title_id = title_id.substr(0, 4) + "-" + title_id.substr(4, 5);
CreateConfig(title_id);
rpcs3::config_t custom_config { "data/" + title_id + "/settings.ini" };
rpcs3::config_t custom_config { fs::get_config_dir() + "data/" + title_id + "/settings.ini" };
custom_config.load();
rpcs3::state.config = custom_config;
}
@ -300,7 +321,7 @@ void Emulator::Load()
return;
}
LoadPoints(BreakPointsDBName);
LoadPoints(fs::get_config_dir() + BreakPointsDBName);
GetGSManager().Init();
GetCallbackManager().Init();
@ -458,7 +479,7 @@ void Emulator::Stop()
// TODO: check finalization order
SavePoints(BreakPointsDBName);
SavePoints(fs::get_config_dir() + BreakPointsDBName);
m_break_points.clear();
m_marked_points.clear();
@ -482,84 +503,50 @@ void Emulator::Stop()
void Emulator::SavePoints(const std::string& path)
{
std::ofstream f(path, std::ios::binary | std::ios::trunc);
const u32 break_count = size32(m_break_points);
const u32 marked_count = size32(m_marked_points);
u32 break_count = (u32)m_break_points.size();
u32 marked_count = (u32)m_marked_points.size();
f.write((char*)(&bpdb_version), sizeof(bpdb_version));
f.write((char*)(&break_count), sizeof(break_count));
f.write((char*)(&marked_count), sizeof(marked_count));
if (break_count)
{
f.write((char*)(m_break_points.data()), sizeof(u64) * break_count);
}
if (marked_count)
{
f.write((char*)(m_marked_points.data()), sizeof(u64) * marked_count);
}
fs::file(path, fom::rewrite)
<< bpdb_version
<< break_count
<< marked_count
<< m_break_points
<< m_marked_points;
}
bool Emulator::LoadPoints(const std::string& path)
{
if (!fs::is_file(path)) return false;
std::ifstream f(path, std::ios::binary);
if (!f.is_open())
return false;
f.seekg(0, std::ios::end);
u64 length = (u64)f.tellg();
f.seekg(0, std::ios::beg);
u16 version;
u32 break_count, marked_count;
u64 expected_length = sizeof(bpdb_version) + sizeof(break_count) + sizeof(marked_count);
if (length < expected_length)
if (fs::file f{ path })
{
LOG_ERROR(LOADER,
"'%s' breakpoint db is broken (file is too short, length=0x%x)",
path, length);
return false;
}
u16 version;
u32 break_count;
u32 marked_count;
f.read((char*)(&version), sizeof(version));
if (!f.read(version) || !f.read(break_count) || !f.read(marked_count))
{
LOG_ERROR(LOADER, "BP file '%s' is broken (length=0x%llx)", path, f.size());
return false;
}
if (version != bpdb_version)
{
LOG_ERROR(LOADER,
"'%s' breakpoint db version is unsupported (version=0x%x, length=0x%x)",
path, version, length);
return false;
}
if (version != bpdb_version)
{
LOG_ERROR(LOADER, "BP file '%s' has unsupported version (version=0x%x)", path, version);
return false;
}
f.read((char*)(&break_count), sizeof(break_count));
f.read((char*)(&marked_count), sizeof(marked_count));
expected_length += break_count * sizeof(u64) + marked_count * sizeof(u64);
if (expected_length != length)
{
LOG_ERROR(LOADER,
"'%s' breakpoint db format is incorrect "
"(version=0x%x, break_count=0x%x, marked_count=0x%x, length=0x%x)",
path, version, break_count, marked_count, length);
return false;
}
if (break_count > 0)
{
m_break_points.resize(break_count);
f.read((char*)(m_break_points.data()), sizeof(u64) * break_count);
m_marked_points.resize(marked_count);
if (!f.read(m_break_points) || !f.read(m_marked_points))
{
LOG_ERROR(LOADER, "'BP file %s' is broken (length=0x%llx, break_count=%u, marked_count=%u)", path, f.size(), break_count, marked_count);
return false;
}
return true;
}
if (marked_count > 0)
{
m_marked_points.resize(marked_count);
f.read((char*)(m_marked_points.data()), sizeof(u64) * marked_count);
}
return true;
return false;
}
Emulator Emu;

View file

@ -102,7 +102,6 @@ class Emulator final
std::string m_path;
std::string m_elf_path;
std::string m_emu_path;
std::string m_title_id;
std::string m_title;
@ -170,11 +169,6 @@ public:
return m_elf_path;
}
const std::string& GetEmulatorPath() const
{
return m_emu_path;
}
const std::string& GetTitleID() const
{
return m_title_id;
@ -185,11 +179,6 @@ public:
return m_title;
}
void SetEmulatorPath(const std::string& path)
{
m_emu_path = path;
}
u64 GetPauseTime()
{
return m_pause_amend_time;