mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-12-29 11:06:07 +00:00
Save data: fix nullptr & concurrent file write (#1049)
* Save data: fix nullptr & concurrency file write * Save data memory: fix overriding icon
This commit is contained in:
parent
f97f73f0b5
commit
1620eea37b
|
@ -102,7 +102,12 @@ bool PSF::Encode(const std::filesystem::path& filepath) const {
|
|||
last_write = std::filesystem::file_time_type::clock::now();
|
||||
|
||||
const auto psf_buffer = Encode();
|
||||
return file.Write(psf_buffer) == psf_buffer.size();
|
||||
const size_t written = file.Write(psf_buffer);
|
||||
if (written != psf_buffer.size()) {
|
||||
LOG_ERROR(Core, "Failed to write PSF file. Written {} Expected {}", written,
|
||||
psf_buffer.size());
|
||||
}
|
||||
return written == psf_buffer.size();
|
||||
}
|
||||
|
||||
std::vector<u8> PSF::Encode() const {
|
||||
|
|
|
@ -119,7 +119,7 @@ static void BackupThreadBody() {
|
|||
std::scoped_lock lk{g_backup_queue_mutex};
|
||||
g_backup_queue.front().done = true;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10)); // Don't backup too often
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5)); // Don't backup too often
|
||||
{
|
||||
std::scoped_lock lk{g_backup_queue_mutex};
|
||||
g_backup_queue.pop_front();
|
||||
|
|
|
@ -190,14 +190,19 @@ void SetIcon(void* buf, size_t buf_size) {
|
|||
if (buf == nullptr) {
|
||||
const auto& src_icon = g_mnt->GetHostPath("/app0/sce_sys/save_data.png");
|
||||
if (fs::exists(src_icon)) {
|
||||
if (fs::exists(g_icon_path)) {
|
||||
fs::remove(g_icon_path);
|
||||
}
|
||||
fs::copy_file(src_icon, g_icon_path);
|
||||
}
|
||||
IOFile file(g_icon_path, Common::FS::FileAccessMode::Read);
|
||||
size_t size = file.GetSize();
|
||||
file.Seek(0);
|
||||
g_icon_memory.resize(size);
|
||||
file.ReadRaw<u8>(g_icon_memory.data(), size);
|
||||
file.Close();
|
||||
if (fs::exists(g_icon_path)) {
|
||||
IOFile file(g_icon_path, Common::FS::FileAccessMode::Read);
|
||||
size_t size = file.GetSize();
|
||||
file.Seek(0);
|
||||
g_icon_memory.resize(size);
|
||||
file.ReadRaw<u8>(g_icon_memory.data(), size);
|
||||
file.Close();
|
||||
}
|
||||
} else {
|
||||
g_icon_memory.resize(buf_size);
|
||||
std::memcpy(g_icon_memory.data(), buf, buf_size);
|
||||
|
|
|
@ -485,14 +485,14 @@ static Error Umount(const OrbisSaveDataMountPoint* mountPoint, bool call_backup
|
|||
if (instance.has_value()) {
|
||||
const auto& slot_name = instance->GetMountPoint();
|
||||
if (slot_name == mount_point_str) {
|
||||
// TODO: check if is busy
|
||||
instance->Umount();
|
||||
if (call_backup) {
|
||||
Backup::StartThread();
|
||||
Backup::NewRequest(instance->GetUserId(), instance->GetTitleId(),
|
||||
instance->GetDirName(),
|
||||
OrbisSaveDataEventType::UMOUNT_BACKUP);
|
||||
}
|
||||
// TODO: check if is busy
|
||||
instance->Umount();
|
||||
instance.reset();
|
||||
return Error::OK;
|
||||
}
|
||||
|
@ -581,10 +581,10 @@ Error PS4_SYSV_ABI sceSaveDataCheckBackupData(const OrbisSaveDataCheckBackupData
|
|||
LOG_INFO(Lib_SaveData, "called with invalid parameter");
|
||||
return Error::PARAMETER;
|
||||
}
|
||||
LOG_DEBUG(Lib_SaveData, "called with titleId={}", check->titleId->data.to_view());
|
||||
|
||||
const std::string_view title{check->titleId != nullptr ? std::string_view{check->titleId->data}
|
||||
: std::string_view{g_game_serial}};
|
||||
LOG_DEBUG(Lib_SaveData, "called with titleId={}", title);
|
||||
|
||||
const auto save_path =
|
||||
SaveInstance::MakeDirSavePath(check->userId, title, check->dirName->data);
|
||||
|
|
Loading…
Reference in a new issue