2015-01-01 18:39:27 +01:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-06-21 16:44:11 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
2015-01-01 18:39:27 +01:00
|
|
|
#include "common/file_util.h"
|
2015-05-06 09:06:12 +02:00
|
|
|
#include "common/logging/log.h"
|
2015-02-06 14:53:14 +01:00
|
|
|
#include "common/make_unique.h"
|
2015-06-20 23:24:01 +02:00
|
|
|
#include "common/string_util.h"
|
2015-01-01 18:39:27 +01:00
|
|
|
|
|
|
|
#include "core/file_sys/archive_savedatacheck.h"
|
2015-06-21 16:44:11 +02:00
|
|
|
#include "core/file_sys/ivfc_archive.h"
|
2015-01-04 02:46:05 +01:00
|
|
|
#include "core/hle/service/fs/archive.h"
|
2015-01-01 18:39:27 +01:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FileSys namespace
|
|
|
|
|
|
|
|
namespace FileSys {
|
|
|
|
|
2015-01-06 21:02:30 +01:00
|
|
|
static std::string GetSaveDataCheckContainerPath(const std::string& nand_directory) {
|
|
|
|
return Common::StringFromFormat("%s%s/title/", nand_directory.c_str(), SYSTEM_ID.c_str());
|
2015-01-04 02:46:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::string GetSaveDataCheckPath(const std::string& mount_point, u32 high, u32 low) {
|
|
|
|
return Common::StringFromFormat("%s%08x/%08x/content/00000000.app.romfs",
|
|
|
|
mount_point.c_str(), high, low);
|
|
|
|
}
|
|
|
|
|
2015-02-06 14:53:14 +01:00
|
|
|
ArchiveFactory_SaveDataCheck::ArchiveFactory_SaveDataCheck(const std::string& nand_directory) :
|
2015-01-06 21:02:30 +01:00
|
|
|
mount_point(GetSaveDataCheckContainerPath(nand_directory)) {
|
2015-01-01 18:39:27 +01:00
|
|
|
}
|
|
|
|
|
2015-02-06 14:53:14 +01:00
|
|
|
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(const Path& path) {
|
2015-01-01 18:39:27 +01:00
|
|
|
auto vec = path.AsBinary();
|
|
|
|
const u32* data = reinterpret_cast<u32*>(vec.data());
|
2015-01-04 02:46:05 +01:00
|
|
|
std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]);
|
2015-01-01 18:39:27 +01:00
|
|
|
FileUtil::IOFile file(file_path, "rb");
|
|
|
|
|
|
|
|
if (!file.IsOpen()) {
|
|
|
|
return ResultCode(-1); // TODO(Subv): Find the right error code
|
|
|
|
}
|
|
|
|
auto size = file.GetSize();
|
2015-02-06 14:53:14 +01:00
|
|
|
auto raw_data = std::make_shared<std::vector<u8>>(size);
|
|
|
|
file.ReadBytes(raw_data->data(), size);
|
2015-01-01 18:39:27 +01:00
|
|
|
file.Close();
|
2015-02-06 14:53:14 +01:00
|
|
|
|
|
|
|
auto archive = Common::make_unique<IVFCArchive>(std::move(raw_data));
|
|
|
|
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode ArchiveFactory_SaveDataCheck::Format(const Path& path) {
|
|
|
|
LOG_ERROR(Service_FS, "Attempted to format a SaveDataCheck archive.");
|
|
|
|
// TODO: Verify error code
|
|
|
|
return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS,
|
|
|
|
ErrorSummary::NotSupported, ErrorLevel::Permanent);
|
2015-01-01 18:39:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace FileSys
|