Compare commits
11 Commits
macros
...
diff-limit
Author | SHA1 | Date | |
---|---|---|---|
c23f367262 | |||
0e4e8aa45a | |||
12880e9170 | |||
f2ee9baec7 | |||
8e2037b3ff | |||
c6bcbc02de | |||
36db566428 | |||
9b147d3f9c | |||
7dd9174d31 | |||
5a7f615da1 | |||
811303ea54 |
32
dist/apple/Info.plist.in
vendored
32
dist/apple/Info.plist.in
vendored
@ -26,6 +26,38 @@
|
|||||||
<!-- Fixed -->
|
<!-- Fixed -->
|
||||||
<key>LSApplicationCategoryType</key>
|
<key>LSApplicationCategoryType</key>
|
||||||
<string>public.app-category.games</string>
|
<string>public.app-category.games</string>
|
||||||
|
<key>CFBundleDocumentTypes</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeExtensions</key>
|
||||||
|
<array>
|
||||||
|
<string>3ds</string>
|
||||||
|
<string>3dsx</string>
|
||||||
|
<string>cci</string>
|
||||||
|
<string>cxi</string>
|
||||||
|
<string>cia</string>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>Nintendo 3DS File</string>
|
||||||
|
<key>CFBundleTypeRole</key>
|
||||||
|
<string>Viewer</string>
|
||||||
|
<key>LSHandlerRank</key>
|
||||||
|
<string>Default</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeExtensions</key>
|
||||||
|
<array>
|
||||||
|
<string>elf</string>
|
||||||
|
<string>axf</string>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>Unix Executable and Linkable Format</string>
|
||||||
|
<key>CFBundleTypeRole</key>
|
||||||
|
<string>Viewer</string>
|
||||||
|
<key>LSHandlerRank</key>
|
||||||
|
<string>Alternate</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
<key>NSCameraUsageDescription</key>
|
<key>NSCameraUsageDescription</key>
|
||||||
<string>This app requires camera access to emulate the 3DS's cameras.</string>
|
<string>This app requires camera access to emulate the 3DS's cameras.</string>
|
||||||
<key>NSMicrophoneUsageDescription</key>
|
<key>NSMicrophoneUsageDescription</key>
|
||||||
|
@ -7,25 +7,13 @@ package org.citra.citra_emu.features.cheats.model
|
|||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
class CheatEngine(titleId: Long) {
|
object CheatEngine {
|
||||||
@Keep
|
external fun loadCheatFile(titleId: Long)
|
||||||
private val mPointer: Long
|
external fun saveCheatFile(titleId: Long)
|
||||||
|
|
||||||
init {
|
|
||||||
mPointer = initialize(titleId)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected external fun finalize()
|
|
||||||
|
|
||||||
external fun getCheats(): Array<Cheat>
|
external fun getCheats(): Array<Cheat>
|
||||||
|
|
||||||
external fun addCheat(cheat: Cheat?)
|
external fun addCheat(cheat: Cheat?)
|
||||||
external fun removeCheat(index: Int)
|
external fun removeCheat(index: Int)
|
||||||
external fun updateCheat(index: Int, newCheat: Cheat?)
|
external fun updateCheat(index: Int, newCheat: Cheat?)
|
||||||
external fun saveCheatFile()
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
@JvmStatic
|
|
||||||
private external fun initialize(titleId: Long): Long
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -47,18 +47,19 @@ class CheatsViewModel : ViewModel() {
|
|||||||
val detailsViewFocusChange get() = _detailsViewFocusChange.asStateFlow()
|
val detailsViewFocusChange get() = _detailsViewFocusChange.asStateFlow()
|
||||||
private val _detailsViewFocusChange = MutableStateFlow(false)
|
private val _detailsViewFocusChange = MutableStateFlow(false)
|
||||||
|
|
||||||
private var cheatEngine: CheatEngine? = null
|
private var titleId: Long = 0
|
||||||
lateinit var cheats: Array<Cheat>
|
lateinit var cheats: Array<Cheat>
|
||||||
private var cheatsNeedSaving = false
|
private var cheatsNeedSaving = false
|
||||||
private var selectedCheatPosition = -1
|
private var selectedCheatPosition = -1
|
||||||
|
|
||||||
fun initialize(titleId: Long) {
|
fun initialize(titleId_: Long) {
|
||||||
cheatEngine = CheatEngine(titleId)
|
titleId = titleId_;
|
||||||
load()
|
load()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun load() {
|
private fun load() {
|
||||||
cheats = cheatEngine!!.getCheats()
|
CheatEngine.loadCheatFile(titleId)
|
||||||
|
cheats = CheatEngine.getCheats()
|
||||||
for (i in cheats.indices) {
|
for (i in cheats.indices) {
|
||||||
cheats[i].setEnabledChangedCallback {
|
cheats[i].setEnabledChangedCallback {
|
||||||
cheatsNeedSaving = true
|
cheatsNeedSaving = true
|
||||||
@ -69,7 +70,7 @@ class CheatsViewModel : ViewModel() {
|
|||||||
|
|
||||||
fun saveIfNeeded() {
|
fun saveIfNeeded() {
|
||||||
if (cheatsNeedSaving) {
|
if (cheatsNeedSaving) {
|
||||||
cheatEngine!!.saveCheatFile()
|
CheatEngine.saveCheatFile(titleId)
|
||||||
cheatsNeedSaving = false
|
cheatsNeedSaving = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,7 +108,7 @@ class CheatsViewModel : ViewModel() {
|
|||||||
_isAdding.value = false
|
_isAdding.value = false
|
||||||
_isEditing.value = false
|
_isEditing.value = false
|
||||||
val position = cheats.size
|
val position = cheats.size
|
||||||
cheatEngine!!.addCheat(cheat)
|
CheatEngine.addCheat(cheat)
|
||||||
cheatsNeedSaving = true
|
cheatsNeedSaving = true
|
||||||
load()
|
load()
|
||||||
notifyCheatAdded(position)
|
notifyCheatAdded(position)
|
||||||
@ -123,7 +124,7 @@ class CheatsViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateSelectedCheat(newCheat: Cheat?) {
|
fun updateSelectedCheat(newCheat: Cheat?) {
|
||||||
cheatEngine!!.updateCheat(selectedCheatPosition, newCheat)
|
CheatEngine.updateCheat(selectedCheatPosition, newCheat)
|
||||||
cheatsNeedSaving = true
|
cheatsNeedSaving = true
|
||||||
load()
|
load()
|
||||||
notifyCheatUpdated(selectedCheatPosition)
|
notifyCheatUpdated(selectedCheatPosition)
|
||||||
@ -141,7 +142,7 @@ class CheatsViewModel : ViewModel() {
|
|||||||
fun deleteSelectedCheat() {
|
fun deleteSelectedCheat() {
|
||||||
val position = selectedCheatPosition
|
val position = selectedCheatPosition
|
||||||
setSelectedCheat(null, -1)
|
setSelectedCheat(null, -1)
|
||||||
cheatEngine!!.removeCheat(position)
|
CheatEngine.removeCheat(position)
|
||||||
cheatsNeedSaving = true
|
cheatsNeedSaving = true
|
||||||
load()
|
load()
|
||||||
notifyCheatDeleted(position)
|
notifyCheatDeleted(position)
|
||||||
|
@ -15,24 +15,24 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
static Cheats::CheatEngine* GetPointer(JNIEnv* env, jobject obj) {
|
static Cheats::CheatEngine& GetEngine() {
|
||||||
return reinterpret_cast<Cheats::CheatEngine*>(
|
Core::System& system{Core::System::GetInstance()};
|
||||||
env->GetLongField(obj, IDCache::GetCheatEnginePointer()));
|
return system.CheatEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jlong JNICALL Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_initialize(
|
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_loadCheatFile(
|
||||||
JNIEnv* env, jclass, jlong title_id) {
|
JNIEnv* env, jclass, jlong title_id) {
|
||||||
return reinterpret_cast<jlong>(new Cheats::CheatEngine(title_id, Core::System::GetInstance()));
|
GetEngine().LoadCheatFile(title_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_saveCheatFile(
|
||||||
Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_finalize(JNIEnv* env, jobject obj) {
|
JNIEnv* env, jclass, jlong title_id) {
|
||||||
delete GetPointer(env, obj);
|
GetEngine().SaveCheatFile(title_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jobjectArray JNICALL
|
JNIEXPORT jobjectArray JNICALL
|
||||||
Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_getCheats(JNIEnv* env, jobject obj) {
|
Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_getCheats(JNIEnv* env, jclass) {
|
||||||
auto cheats = GetPointer(env, obj)->GetCheats();
|
auto cheats = GetEngine().GetCheats();
|
||||||
|
|
||||||
const jobjectArray array =
|
const jobjectArray array =
|
||||||
env->NewObjectArray(static_cast<jsize>(cheats.size()), IDCache::GetCheatClass(), nullptr);
|
env->NewObjectArray(static_cast<jsize>(cheats.size()), IDCache::GetCheatClass(), nullptr);
|
||||||
@ -45,22 +45,19 @@ Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_getCheats(JNIEnv* en
|
|||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_addCheat(
|
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_addCheat(
|
||||||
JNIEnv* env, jobject obj, jobject j_cheat) {
|
JNIEnv* env, jclass, jobject j_cheat) {
|
||||||
GetPointer(env, obj)->AddCheat(*CheatFromJava(env, j_cheat));
|
auto cheat = *CheatFromJava(env, j_cheat);
|
||||||
|
GetEngine().AddCheat(std::move(cheat));
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_removeCheat(
|
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_removeCheat(
|
||||||
JNIEnv* env, jobject obj, jint index) {
|
JNIEnv* env, jclass, jint index) {
|
||||||
GetPointer(env, obj)->RemoveCheat(index);
|
GetEngine().RemoveCheat(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_updateCheat(
|
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_updateCheat(
|
||||||
JNIEnv* env, jobject obj, jint index, jobject j_new_cheat) {
|
JNIEnv* env, jclass, jint index, jobject j_new_cheat) {
|
||||||
GetPointer(env, obj)->UpdateCheat(index, *CheatFromJava(env, j_new_cheat));
|
auto cheat = *CheatFromJava(env, j_new_cheat);
|
||||||
}
|
GetEngine().UpdateCheat(index, std::move(cheat));
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_features_cheats_model_CheatEngine_saveCheatFile(
|
|
||||||
JNIEnv* env, jobject obj) {
|
|
||||||
GetPointer(env, obj)->SaveCheatFile();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,7 @@ void Config::ReadValues() {
|
|||||||
ReadSetting("Renderer", Settings::values.use_disk_shader_cache);
|
ReadSetting("Renderer", Settings::values.use_disk_shader_cache);
|
||||||
ReadSetting("Renderer", Settings::values.use_vsync_new);
|
ReadSetting("Renderer", Settings::values.use_vsync_new);
|
||||||
ReadSetting("Renderer", Settings::values.texture_filter);
|
ReadSetting("Renderer", Settings::values.texture_filter);
|
||||||
|
ReadSetting("Renderer", Settings::values.texture_sampling);
|
||||||
|
|
||||||
// Work around to map Android setting for enabling the frame limiter to the format Citra expects
|
// Work around to map Android setting for enabling the frame limiter to the format Citra expects
|
||||||
if (sdl2_config->GetBoolean("Renderer", "use_frame_limit", true)) {
|
if (sdl2_config->GetBoolean("Renderer", "use_frame_limit", true)) {
|
||||||
|
@ -35,8 +35,6 @@ static jclass s_cheat_class;
|
|||||||
static jfieldID s_cheat_pointer;
|
static jfieldID s_cheat_pointer;
|
||||||
static jmethodID s_cheat_constructor;
|
static jmethodID s_cheat_constructor;
|
||||||
|
|
||||||
static jfieldID s_cheat_engine_pointer;
|
|
||||||
|
|
||||||
static jfieldID s_game_info_pointer;
|
static jfieldID s_game_info_pointer;
|
||||||
|
|
||||||
static jclass s_disk_cache_progress_class;
|
static jclass s_disk_cache_progress_class;
|
||||||
@ -116,10 +114,6 @@ jmethodID GetCheatConstructor() {
|
|||||||
return s_cheat_constructor;
|
return s_cheat_constructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
jfieldID GetCheatEnginePointer() {
|
|
||||||
return s_cheat_engine_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
jfieldID GetGameInfoPointer() {
|
jfieldID GetGameInfoPointer() {
|
||||||
return s_game_info_pointer;
|
return s_game_info_pointer;
|
||||||
}
|
}
|
||||||
@ -195,12 +189,6 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
|||||||
s_cheat_constructor = env->GetMethodID(cheat_class, "<init>", "(J)V");
|
s_cheat_constructor = env->GetMethodID(cheat_class, "<init>", "(J)V");
|
||||||
env->DeleteLocalRef(cheat_class);
|
env->DeleteLocalRef(cheat_class);
|
||||||
|
|
||||||
// Initialize CheatEngine
|
|
||||||
const jclass cheat_engine_class =
|
|
||||||
env->FindClass("org/citra/citra_emu/features/cheats/model/CheatEngine");
|
|
||||||
s_cheat_engine_pointer = env->GetFieldID(cheat_engine_class, "mPointer", "J");
|
|
||||||
env->DeleteLocalRef(cheat_engine_class);
|
|
||||||
|
|
||||||
// Initialize GameInfo
|
// Initialize GameInfo
|
||||||
const jclass game_info_class = env->FindClass("org/citra/citra_emu/model/GameInfo");
|
const jclass game_info_class = env->FindClass("org/citra/citra_emu/model/GameInfo");
|
||||||
s_game_info_pointer = env->GetFieldID(game_info_class, "pointer", "J");
|
s_game_info_pointer = env->GetFieldID(game_info_class, "pointer", "J");
|
||||||
|
@ -35,8 +35,6 @@ jclass GetCheatClass();
|
|||||||
jfieldID GetCheatPointer();
|
jfieldID GetCheatPointer();
|
||||||
jmethodID GetCheatConstructor();
|
jmethodID GetCheatConstructor();
|
||||||
|
|
||||||
jfieldID GetCheatEnginePointer();
|
|
||||||
|
|
||||||
jfieldID GetGameInfoPointer();
|
jfieldID GetGameInfoPointer();
|
||||||
|
|
||||||
jclass GetDiskCacheProgressClass();
|
jclass GetDiskCacheProgressClass();
|
||||||
|
@ -4,11 +4,11 @@ add_library(audio_core STATIC
|
|||||||
codec.h
|
codec.h
|
||||||
dsp_interface.cpp
|
dsp_interface.cpp
|
||||||
dsp_interface.h
|
dsp_interface.h
|
||||||
|
hle/aac_decoder.cpp
|
||||||
|
hle/aac_decoder.h
|
||||||
hle/common.h
|
hle/common.h
|
||||||
hle/decoder.cpp
|
hle/decoder.cpp
|
||||||
hle/decoder.h
|
hle/decoder.h
|
||||||
hle/faad2_decoder.cpp
|
|
||||||
hle/faad2_decoder.h
|
|
||||||
hle/filter.cpp
|
hle/filter.cpp
|
||||||
hle/filter.h
|
hle/filter.h
|
||||||
hle/hle.cpp
|
hle/hle.cpp
|
||||||
|
@ -3,30 +3,11 @@
|
|||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <neaacdec.h>
|
#include <neaacdec.h>
|
||||||
#include "audio_core/hle/faad2_decoder.h"
|
#include "audio_core/hle/aac_decoder.h"
|
||||||
|
|
||||||
namespace AudioCore::HLE {
|
namespace AudioCore::HLE {
|
||||||
|
|
||||||
class FAAD2Decoder::Impl {
|
AACDecoder::AACDecoder(Memory::MemorySystem& memory) : memory(memory) {
|
||||||
public:
|
|
||||||
explicit Impl(Memory::MemorySystem& memory);
|
|
||||||
~Impl();
|
|
||||||
std::optional<BinaryMessage> ProcessRequest(const BinaryMessage& request);
|
|
||||||
bool IsValid() const {
|
|
||||||
return decoder != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::optional<BinaryMessage> Initalize(const BinaryMessage& request);
|
|
||||||
|
|
||||||
std::optional<BinaryMessage> Decode(const BinaryMessage& request);
|
|
||||||
|
|
||||||
Memory::MemorySystem& memory;
|
|
||||||
|
|
||||||
NeAACDecHandle decoder = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
FAAD2Decoder::Impl::Impl(Memory::MemorySystem& memory) : memory(memory) {
|
|
||||||
decoder = NeAACDecOpen();
|
decoder = NeAACDecOpen();
|
||||||
if (decoder == nullptr) {
|
if (decoder == nullptr) {
|
||||||
LOG_CRITICAL(Audio_DSP, "Could not open FAAD2 decoder.");
|
LOG_CRITICAL(Audio_DSP, "Could not open FAAD2 decoder.");
|
||||||
@ -46,7 +27,7 @@ FAAD2Decoder::Impl::Impl(Memory::MemorySystem& memory) : memory(memory) {
|
|||||||
LOG_INFO(Audio_DSP, "Created FAAD2 AAC decoder.");
|
LOG_INFO(Audio_DSP, "Created FAAD2 AAC decoder.");
|
||||||
}
|
}
|
||||||
|
|
||||||
FAAD2Decoder::Impl::~Impl() {
|
AACDecoder::~AACDecoder() {
|
||||||
if (decoder) {
|
if (decoder) {
|
||||||
NeAACDecClose(decoder);
|
NeAACDecClose(decoder);
|
||||||
decoder = nullptr;
|
decoder = nullptr;
|
||||||
@ -55,16 +36,23 @@ FAAD2Decoder::Impl::~Impl() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<BinaryMessage> FAAD2Decoder::Impl::ProcessRequest(const BinaryMessage& request) {
|
BinaryMessage AACDecoder::ProcessRequest(const BinaryMessage& request) {
|
||||||
if (request.header.codec != DecoderCodec::DecodeAAC) {
|
if (request.header.codec != DecoderCodec::DecodeAAC) {
|
||||||
LOG_ERROR(Audio_DSP, "FAAD2 AAC Decoder cannot handle such codec: {}",
|
LOG_ERROR(Audio_DSP, "AAC decoder received unsupported codec: {}",
|
||||||
static_cast<u16>(request.header.codec));
|
static_cast<u16>(request.header.codec));
|
||||||
return {};
|
return {
|
||||||
|
.header =
|
||||||
|
{
|
||||||
|
.result = ResultStatus::Error,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (request.header.cmd) {
|
switch (request.header.cmd) {
|
||||||
case DecoderCommand::Init: {
|
case DecoderCommand::Init: {
|
||||||
return Initalize(request);
|
BinaryMessage response = request;
|
||||||
|
response.header.result = ResultStatus::Success;
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
case DecoderCommand::EncodeDecode: {
|
case DecoderCommand::EncodeDecode: {
|
||||||
return Decode(request);
|
return Decode(request);
|
||||||
@ -72,26 +60,25 @@ std::optional<BinaryMessage> FAAD2Decoder::Impl::ProcessRequest(const BinaryMess
|
|||||||
case DecoderCommand::Shutdown:
|
case DecoderCommand::Shutdown:
|
||||||
case DecoderCommand::SaveState:
|
case DecoderCommand::SaveState:
|
||||||
case DecoderCommand::LoadState: {
|
case DecoderCommand::LoadState: {
|
||||||
LOG_WARNING(Audio_DSP, "Got unimplemented binary request: {}",
|
LOG_WARNING(Audio_DSP, "Got unimplemented AAC binary request: {}",
|
||||||
static_cast<u16>(request.header.cmd));
|
static_cast<u16>(request.header.cmd));
|
||||||
BinaryMessage response = request;
|
BinaryMessage response = request;
|
||||||
response.header.result = ResultStatus::Success;
|
response.header.result = ResultStatus::Success;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
LOG_ERROR(Audio_DSP, "Got unknown binary request: {}",
|
LOG_ERROR(Audio_DSP, "Got unknown AAC binary request: {}",
|
||||||
static_cast<u16>(request.header.cmd));
|
static_cast<u16>(request.header.cmd));
|
||||||
return {};
|
return {
|
||||||
|
.header =
|
||||||
|
{
|
||||||
|
.result = ResultStatus::Error,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<BinaryMessage> FAAD2Decoder::Impl::Initalize(const BinaryMessage& request) {
|
BinaryMessage AACDecoder::Decode(const BinaryMessage& request) {
|
||||||
BinaryMessage response = request;
|
|
||||||
response.header.result = ResultStatus::Success;
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<BinaryMessage> FAAD2Decoder::Impl::Decode(const BinaryMessage& request) {
|
|
||||||
BinaryMessage response{};
|
BinaryMessage response{};
|
||||||
response.header.codec = request.header.codec;
|
response.header.codec = request.header.codec;
|
||||||
response.header.cmd = request.header.cmd;
|
response.header.cmd = request.header.cmd;
|
||||||
@ -101,6 +88,10 @@ std::optional<BinaryMessage> FAAD2Decoder::Impl::Decode(const BinaryMessage& req
|
|||||||
response.decode_aac_response.num_channels = 2;
|
response.decode_aac_response.num_channels = 2;
|
||||||
response.decode_aac_response.num_samples = 1024;
|
response.decode_aac_response.num_samples = 1024;
|
||||||
|
|
||||||
|
if (decoder == nullptr) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
if (request.decode_aac_request.src_addr < Memory::FCRAM_PADDR ||
|
if (request.decode_aac_request.src_addr < Memory::FCRAM_PADDR ||
|
||||||
request.decode_aac_request.src_addr + request.decode_aac_request.size >
|
request.decode_aac_request.src_addr + request.decode_aac_request.size >
|
||||||
Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) {
|
Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) {
|
||||||
@ -171,16 +162,4 @@ std::optional<BinaryMessage> FAAD2Decoder::Impl::Decode(const BinaryMessage& req
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
FAAD2Decoder::FAAD2Decoder(Memory::MemorySystem& memory) : impl(std::make_unique<Impl>(memory)) {}
|
|
||||||
|
|
||||||
FAAD2Decoder::~FAAD2Decoder() = default;
|
|
||||||
|
|
||||||
std::optional<BinaryMessage> FAAD2Decoder::ProcessRequest(const BinaryMessage& request) {
|
|
||||||
return impl->ProcessRequest(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FAAD2Decoder::IsValid() const {
|
|
||||||
return impl->IsValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace AudioCore::HLE
|
} // namespace AudioCore::HLE
|
26
src/audio_core/hle/aac_decoder.h
Normal file
26
src/audio_core/hle/aac_decoder.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2023 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "audio_core/hle/decoder.h"
|
||||||
|
|
||||||
|
namespace AudioCore::HLE {
|
||||||
|
|
||||||
|
using NeAACDecHandle = void*;
|
||||||
|
|
||||||
|
class AACDecoder final : public DecoderBase {
|
||||||
|
public:
|
||||||
|
explicit AACDecoder(Memory::MemorySystem& memory);
|
||||||
|
~AACDecoder() override;
|
||||||
|
BinaryMessage ProcessRequest(const BinaryMessage& request) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BinaryMessage Decode(const BinaryMessage& request);
|
||||||
|
|
||||||
|
Memory::MemorySystem& memory;
|
||||||
|
NeAACDecHandle decoder = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace AudioCore::HLE
|
@ -32,34 +32,4 @@ DecoderSampleRate GetSampleRateEnum(u32 sample_rate) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DecoderBase::~DecoderBase(){};
|
|
||||||
|
|
||||||
NullDecoder::NullDecoder() = default;
|
|
||||||
|
|
||||||
NullDecoder::~NullDecoder() = default;
|
|
||||||
|
|
||||||
std::optional<BinaryMessage> NullDecoder::ProcessRequest(const BinaryMessage& request) {
|
|
||||||
BinaryMessage response{};
|
|
||||||
switch (request.header.cmd) {
|
|
||||||
case DecoderCommand::Init:
|
|
||||||
case DecoderCommand::Shutdown:
|
|
||||||
case DecoderCommand::SaveState:
|
|
||||||
case DecoderCommand::LoadState:
|
|
||||||
response = request;
|
|
||||||
response.header.result = ResultStatus::Success;
|
|
||||||
return response;
|
|
||||||
case DecoderCommand::EncodeDecode:
|
|
||||||
response.header.codec = request.header.codec;
|
|
||||||
response.header.cmd = request.header.cmd;
|
|
||||||
response.header.result = ResultStatus::Success;
|
|
||||||
response.decode_aac_response.num_channels = 2; // Just assume stereo here
|
|
||||||
response.decode_aac_response.size = request.decode_aac_request.size;
|
|
||||||
response.decode_aac_response.num_samples = 1024; // Just assume 1024 here
|
|
||||||
return response;
|
|
||||||
default:
|
|
||||||
LOG_ERROR(Audio_DSP, "Got unknown binary request: {}",
|
|
||||||
static_cast<u16>(request.header.cmd));
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace AudioCore::HLE
|
} // namespace AudioCore::HLE
|
||||||
|
@ -135,21 +135,8 @@ enum_le<DecoderSampleRate> GetSampleRateEnum(u32 sample_rate);
|
|||||||
|
|
||||||
class DecoderBase {
|
class DecoderBase {
|
||||||
public:
|
public:
|
||||||
virtual ~DecoderBase();
|
virtual ~DecoderBase() = default;
|
||||||
virtual std::optional<BinaryMessage> ProcessRequest(const BinaryMessage& request) = 0;
|
virtual BinaryMessage ProcessRequest(const BinaryMessage& request) = 0;
|
||||||
/// Return true if this Decoder can be loaded. Return false if the system cannot create the
|
|
||||||
/// decoder
|
|
||||||
virtual bool IsValid() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class NullDecoder final : public DecoderBase {
|
|
||||||
public:
|
|
||||||
NullDecoder();
|
|
||||||
~NullDecoder() override;
|
|
||||||
std::optional<BinaryMessage> ProcessRequest(const BinaryMessage& request) override;
|
|
||||||
bool IsValid() const override {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace AudioCore::HLE
|
} // namespace AudioCore::HLE
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
// Copyright 2023 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "audio_core/hle/decoder.h"
|
|
||||||
|
|
||||||
namespace AudioCore::HLE {
|
|
||||||
|
|
||||||
class FAAD2Decoder final : public DecoderBase {
|
|
||||||
public:
|
|
||||||
explicit FAAD2Decoder(Memory::MemorySystem& memory);
|
|
||||||
~FAAD2Decoder() override;
|
|
||||||
std::optional<BinaryMessage> ProcessRequest(const BinaryMessage& request) override;
|
|
||||||
bool IsValid() const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
class Impl;
|
|
||||||
std::unique_ptr<Impl> impl;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace AudioCore::HLE
|
|
@ -8,9 +8,9 @@
|
|||||||
#include <boost/serialization/vector.hpp>
|
#include <boost/serialization/vector.hpp>
|
||||||
#include <boost/serialization/weak_ptr.hpp>
|
#include <boost/serialization/weak_ptr.hpp>
|
||||||
#include "audio_core/audio_types.h"
|
#include "audio_core/audio_types.h"
|
||||||
|
#include "audio_core/hle/aac_decoder.h"
|
||||||
#include "audio_core/hle/common.h"
|
#include "audio_core/hle/common.h"
|
||||||
#include "audio_core/hle/decoder.h"
|
#include "audio_core/hle/decoder.h"
|
||||||
#include "audio_core/hle/faad2_decoder.h"
|
|
||||||
#include "audio_core/hle/hle.h"
|
#include "audio_core/hle/hle.h"
|
||||||
#include "audio_core/hle/mixers.h"
|
#include "audio_core/hle/mixers.h"
|
||||||
#include "audio_core/hle/shared_memory.h"
|
#include "audio_core/hle/shared_memory.h"
|
||||||
@ -24,16 +24,10 @@
|
|||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
|
||||||
SERIALIZE_EXPORT_IMPL(AudioCore::DspHle)
|
|
||||||
|
|
||||||
using InterruptType = Service::DSP::InterruptType;
|
using InterruptType = Service::DSP::InterruptType;
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
|
||||||
DspHle::DspHle()
|
|
||||||
: DspHle(Core::System::GetInstance(), Core::System::GetInstance().Memory(),
|
|
||||||
Core::System::GetInstance().CoreTiming()) {}
|
|
||||||
|
|
||||||
DspHle::DspHle(Core::System& system) : DspHle(system, system.Memory(), system.CoreTiming()) {}
|
DspHle::DspHle(Core::System& system) : DspHle(system, system.Memory(), system.CoreTiming()) {}
|
||||||
|
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
@ -98,7 +92,7 @@ private:
|
|||||||
Core::Timing& core_timing;
|
Core::Timing& core_timing;
|
||||||
Core::TimingEventType* tick_event{};
|
Core::TimingEventType* tick_event{};
|
||||||
|
|
||||||
std::unique_ptr<HLE::DecoderBase> decoder{};
|
std::unique_ptr<HLE::DecoderBase> aac_decoder{};
|
||||||
|
|
||||||
std::function<void(Service::DSP::InterruptType type, DspPipe pipe)> interrupt_handler{};
|
std::function<void(Service::DSP::InterruptType type, DspPipe pipe)> interrupt_handler{};
|
||||||
|
|
||||||
@ -114,13 +108,6 @@ private:
|
|||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::vector<std::function<std::unique_ptr<HLE::DecoderBase>(Memory::MemorySystem&)>>
|
|
||||||
decoder_backends = {
|
|
||||||
[](Memory::MemorySystem& memory) -> std::unique_ptr<HLE::DecoderBase> {
|
|
||||||
return std::make_unique<HLE::FAAD2Decoder>(memory);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
DspHle::Impl::Impl(DspHle& parent_, Memory::MemorySystem& memory, Core::Timing& timing)
|
DspHle::Impl::Impl(DspHle& parent_, Memory::MemorySystem& memory, Core::Timing& timing)
|
||||||
: parent(parent_), core_timing(timing) {
|
: parent(parent_), core_timing(timing) {
|
||||||
dsp_memory.raw_memory.fill(0);
|
dsp_memory.raw_memory.fill(0);
|
||||||
@ -129,19 +116,7 @@ DspHle::Impl::Impl(DspHle& parent_, Memory::MemorySystem& memory, Core::Timing&
|
|||||||
source.SetMemory(memory);
|
source.SetMemory(memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& factory : decoder_backends) {
|
aac_decoder = std::make_unique<HLE::AACDecoder>(memory);
|
||||||
decoder = factory(memory);
|
|
||||||
if (decoder && decoder->IsValid()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!decoder || !decoder->IsValid()) {
|
|
||||||
LOG_WARNING(Audio_DSP,
|
|
||||||
"Unable to load any decoders, this could cause missing audio in some games");
|
|
||||||
decoder = std::make_unique<HLE::NullDecoder>();
|
|
||||||
}
|
|
||||||
|
|
||||||
tick_event =
|
tick_event =
|
||||||
core_timing.RegisterEvent("AudioCore::DspHle::tick_event", [this](u64, s64 cycles_late) {
|
core_timing.RegisterEvent("AudioCore::DspHle::tick_event", [this](u64, s64 cycles_late) {
|
||||||
this->AudioTickCallback(cycles_late);
|
this->AudioTickCallback(cycles_late);
|
||||||
@ -291,12 +266,9 @@ void DspHle::Impl::PipeWrite(DspPipe pipe_number, std::span<const u8> buffer) {
|
|||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::optional<HLE::BinaryMessage> response = decoder->ProcessRequest(request);
|
const HLE::BinaryMessage response = aac_decoder->ProcessRequest(request);
|
||||||
if (response) {
|
pipe_data[static_cast<u32>(pipe_number)].resize(sizeof(response));
|
||||||
const HLE::BinaryMessage& value = *response;
|
std::memcpy(pipe_data[static_cast<u32>(pipe_number)].data(), &response, sizeof(response));
|
||||||
pipe_data[static_cast<u32>(pipe_number)].resize(sizeof(value));
|
|
||||||
std::memcpy(pipe_data[static_cast<u32>(pipe_number)].data(), &value, sizeof(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
interrupt_handler(InterruptType::Pipe, DspPipe::Binary);
|
interrupt_handler(InterruptType::Pipe, DspPipe::Binary);
|
||||||
break;
|
break;
|
||||||
|
@ -50,13 +50,9 @@ private:
|
|||||||
friend struct Impl;
|
friend struct Impl;
|
||||||
std::unique_ptr<Impl> impl;
|
std::unique_ptr<Impl> impl;
|
||||||
|
|
||||||
DspHle();
|
|
||||||
|
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
void serialize(Archive& ar, const unsigned int);
|
void serialize(Archive& ar, const unsigned int);
|
||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace AudioCore
|
} // namespace AudioCore
|
||||||
|
|
||||||
BOOST_CLASS_EXPORT_KEY(AudioCore::DspHle)
|
|
||||||
|
@ -24,8 +24,8 @@ namespace {
|
|||||||
constexpr std::array input_details = {
|
constexpr std::array input_details = {
|
||||||
#ifdef HAVE_CUBEB
|
#ifdef HAVE_CUBEB
|
||||||
InputDetails{InputType::Cubeb, "Real Device (Cubeb)", true,
|
InputDetails{InputType::Cubeb, "Real Device (Cubeb)", true,
|
||||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
[](Core::System& system, std::string_view device_id) -> std::unique_ptr<Input> {
|
||||||
if (!Core::System::GetInstance().HasMicPermission()) {
|
if (!system.HasMicPermission()) {
|
||||||
LOG_WARNING(Audio,
|
LOG_WARNING(Audio,
|
||||||
"Microphone permission denied, falling back to null input.");
|
"Microphone permission denied, falling back to null input.");
|
||||||
return std::make_unique<NullInput>();
|
return std::make_unique<NullInput>();
|
||||||
@ -36,8 +36,8 @@ constexpr std::array input_details = {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_OPENAL
|
#ifdef HAVE_OPENAL
|
||||||
InputDetails{InputType::OpenAL, "Real Device (OpenAL)", true,
|
InputDetails{InputType::OpenAL, "Real Device (OpenAL)", true,
|
||||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
[](Core::System& system, std::string_view device_id) -> std::unique_ptr<Input> {
|
||||||
if (!Core::System::GetInstance().HasMicPermission()) {
|
if (!system.HasMicPermission()) {
|
||||||
LOG_WARNING(Audio,
|
LOG_WARNING(Audio,
|
||||||
"Microphone permission denied, falling back to null input.");
|
"Microphone permission denied, falling back to null input.");
|
||||||
return std::make_unique<NullInput>();
|
return std::make_unique<NullInput>();
|
||||||
@ -47,12 +47,12 @@ constexpr std::array input_details = {
|
|||||||
&ListOpenALInputDevices},
|
&ListOpenALInputDevices},
|
||||||
#endif
|
#endif
|
||||||
InputDetails{InputType::Static, "Static Noise", false,
|
InputDetails{InputType::Static, "Static Noise", false,
|
||||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
[](Core::System& system, std::string_view device_id) -> std::unique_ptr<Input> {
|
||||||
return std::make_unique<StaticInput>();
|
return std::make_unique<StaticInput>();
|
||||||
},
|
},
|
||||||
[] { return std::vector<std::string>{"Static Noise"}; }},
|
[] { return std::vector<std::string>{"Static Noise"}; }},
|
||||||
InputDetails{InputType::Null, "None", false,
|
InputDetails{InputType::Null, "None", false,
|
||||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
[](Core::System& system, std::string_view device_id) -> std::unique_ptr<Input> {
|
||||||
return std::make_unique<NullInput>();
|
return std::make_unique<NullInput>();
|
||||||
},
|
},
|
||||||
[] { return std::vector<std::string>{"None"}; }},
|
[] { return std::vector<std::string>{"None"}; }},
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
|
||||||
class Input;
|
class Input;
|
||||||
@ -23,7 +27,7 @@ enum class InputType : u32 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct InputDetails {
|
struct InputDetails {
|
||||||
using FactoryFn = std::unique_ptr<Input> (*)(std::string_view device_id);
|
using FactoryFn = std::unique_ptr<Input> (*)(Core::System& system, std::string_view device_id);
|
||||||
using ListDevicesFn = std::vector<std::string> (*)();
|
using ListDevicesFn = std::vector<std::string> (*)();
|
||||||
|
|
||||||
/// Type of this input.
|
/// Type of this input.
|
||||||
|
@ -146,6 +146,7 @@ void Config::ReadValues() {
|
|||||||
ReadSetting("Renderer", Settings::values.frame_limit);
|
ReadSetting("Renderer", Settings::values.frame_limit);
|
||||||
ReadSetting("Renderer", Settings::values.use_vsync_new);
|
ReadSetting("Renderer", Settings::values.use_vsync_new);
|
||||||
ReadSetting("Renderer", Settings::values.texture_filter);
|
ReadSetting("Renderer", Settings::values.texture_filter);
|
||||||
|
ReadSetting("Renderer", Settings::values.texture_sampling);
|
||||||
|
|
||||||
ReadSetting("Renderer", Settings::values.mono_render_option);
|
ReadSetting("Renderer", Settings::values.mono_render_option);
|
||||||
ReadSetting("Renderer", Settings::values.render_3d);
|
ReadSetting("Renderer", Settings::values.render_3d);
|
||||||
|
@ -645,6 +645,7 @@ void Config::ReadRendererValues() {
|
|||||||
ReadGlobalSetting(Settings::values.bg_blue);
|
ReadGlobalSetting(Settings::values.bg_blue);
|
||||||
|
|
||||||
ReadGlobalSetting(Settings::values.texture_filter);
|
ReadGlobalSetting(Settings::values.texture_filter);
|
||||||
|
ReadGlobalSetting(Settings::values.texture_sampling);
|
||||||
|
|
||||||
if (global) {
|
if (global) {
|
||||||
ReadBasicSetting(Settings::values.use_shader_jit);
|
ReadBasicSetting(Settings::values.use_shader_jit);
|
||||||
@ -1130,6 +1131,7 @@ void Config::SaveRendererValues() {
|
|||||||
WriteGlobalSetting(Settings::values.bg_blue);
|
WriteGlobalSetting(Settings::values.bg_blue);
|
||||||
|
|
||||||
WriteGlobalSetting(Settings::values.texture_filter);
|
WriteGlobalSetting(Settings::values.texture_filter);
|
||||||
|
WriteGlobalSetting(Settings::values.texture_sampling);
|
||||||
|
|
||||||
if (global) {
|
if (global) {
|
||||||
WriteSetting(QStringLiteral("use_shader_jit"), Settings::values.use_shader_jit.GetValue(),
|
WriteSetting(QStringLiteral("use_shader_jit"), Settings::values.use_shader_jit.GetValue(),
|
||||||
|
@ -11,8 +11,10 @@
|
|||||||
#include "core/cheats/gateway_cheat.h"
|
#include "core/cheats/gateway_cheat.h"
|
||||||
#include "ui_configure_cheats.h"
|
#include "ui_configure_cheats.h"
|
||||||
|
|
||||||
ConfigureCheats::ConfigureCheats(Core::System& system, u64 title_id_, QWidget* parent)
|
ConfigureCheats::ConfigureCheats(Cheats::CheatEngine& cheat_engine_, u64 title_id_, QWidget* parent)
|
||||||
: QWidget(parent), ui(std::make_unique<Ui::ConfigureCheats>()), title_id{title_id_} {
|
: QWidget(parent),
|
||||||
|
ui(std::make_unique<Ui::ConfigureCheats>()), cheat_engine{cheat_engine_}, title_id{
|
||||||
|
title_id_} {
|
||||||
// Setup gui control settings
|
// Setup gui control settings
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->tableCheats->setColumnWidth(0, 30);
|
ui->tableCheats->setColumnWidth(0, 30);
|
||||||
@ -34,15 +36,14 @@ ConfigureCheats::ConfigureCheats(Core::System& system, u64 title_id_, QWidget* p
|
|||||||
[this] { SaveCheat(ui->tableCheats->currentRow()); });
|
[this] { SaveCheat(ui->tableCheats->currentRow()); });
|
||||||
connect(ui->buttonDelete, &QPushButton::clicked, this, &ConfigureCheats::OnDeleteCheat);
|
connect(ui->buttonDelete, &QPushButton::clicked, this, &ConfigureCheats::OnDeleteCheat);
|
||||||
|
|
||||||
cheat_engine = std::make_unique<Cheats::CheatEngine>(title_id, system);
|
cheat_engine.LoadCheatFile(title_id);
|
||||||
|
|
||||||
LoadCheats();
|
LoadCheats();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigureCheats::~ConfigureCheats() = default;
|
ConfigureCheats::~ConfigureCheats() = default;
|
||||||
|
|
||||||
void ConfigureCheats::LoadCheats() {
|
void ConfigureCheats::LoadCheats() {
|
||||||
cheats = cheat_engine->GetCheats();
|
cheats = cheat_engine.GetCheats();
|
||||||
const int cheats_count = static_cast<int>(cheats.size());
|
const int cheats_count = static_cast<int>(cheats.size());
|
||||||
|
|
||||||
ui->tableCheats->setRowCount(cheats_count);
|
ui->tableCheats->setRowCount(cheats_count);
|
||||||
@ -106,12 +107,12 @@ bool ConfigureCheats::SaveCheat(int row) {
|
|||||||
ui->textNotes->toPlainText().toStdString());
|
ui->textNotes->toPlainText().toStdString());
|
||||||
|
|
||||||
if (newly_created) {
|
if (newly_created) {
|
||||||
cheat_engine->AddCheat(cheat);
|
cheat_engine.AddCheat(std::move(cheat));
|
||||||
newly_created = false;
|
newly_created = false;
|
||||||
} else {
|
} else {
|
||||||
cheat_engine->UpdateCheat(row, cheat);
|
cheat_engine.UpdateCheat(row, std::move(cheat));
|
||||||
}
|
}
|
||||||
cheat_engine->SaveCheatFile();
|
cheat_engine.SaveCheatFile(title_id);
|
||||||
|
|
||||||
int previous_row = ui->tableCheats->currentRow();
|
int previous_row = ui->tableCheats->currentRow();
|
||||||
int previous_col = ui->tableCheats->currentColumn();
|
int previous_col = ui->tableCheats->currentColumn();
|
||||||
@ -161,7 +162,7 @@ void ConfigureCheats::OnCheckChanged(int state) {
|
|||||||
const QCheckBox* checkbox = qobject_cast<QCheckBox*>(sender());
|
const QCheckBox* checkbox = qobject_cast<QCheckBox*>(sender());
|
||||||
int row = static_cast<int>(checkbox->property("row").toInt());
|
int row = static_cast<int>(checkbox->property("row").toInt());
|
||||||
cheats[row]->SetEnabled(state);
|
cheats[row]->SetEnabled(state);
|
||||||
cheat_engine->SaveCheatFile();
|
cheat_engine.SaveCheatFile(title_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureCheats::OnTextEdited() {
|
void ConfigureCheats::OnTextEdited() {
|
||||||
@ -173,8 +174,8 @@ void ConfigureCheats::OnDeleteCheat() {
|
|||||||
if (newly_created) {
|
if (newly_created) {
|
||||||
newly_created = false;
|
newly_created = false;
|
||||||
} else {
|
} else {
|
||||||
cheat_engine->RemoveCheat(ui->tableCheats->currentRow());
|
cheat_engine.RemoveCheat(ui->tableCheats->currentRow());
|
||||||
cheat_engine->SaveCheatFile();
|
cheat_engine.SaveCheatFile(title_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadCheats();
|
LoadCheats();
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <span>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
@ -25,7 +26,8 @@ class ConfigureCheats : public QWidget {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ConfigureCheats(Core::System& system, u64 title_id, QWidget* parent = nullptr);
|
explicit ConfigureCheats(Cheats::CheatEngine& cheat_engine, u64 title_id_,
|
||||||
|
QWidget* parent = nullptr);
|
||||||
~ConfigureCheats();
|
~ConfigureCheats();
|
||||||
bool ApplyConfiguration();
|
bool ApplyConfiguration();
|
||||||
|
|
||||||
@ -58,9 +60,9 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::ConfigureCheats> ui;
|
std::unique_ptr<Ui::ConfigureCheats> ui;
|
||||||
std::vector<std::shared_ptr<Cheats::CheatBase>> cheats;
|
Cheats::CheatEngine& cheat_engine;
|
||||||
|
std::span<const std::shared_ptr<Cheats::CheatBase>> cheats;
|
||||||
bool edited = false, newly_created = false;
|
bool edited = false, newly_created = false;
|
||||||
int last_row = -1, last_col = -1;
|
int last_row = -1, last_col = -1;
|
||||||
u64 title_id;
|
u64 title_id;
|
||||||
std::unique_ptr<Cheats::CheatEngine> cheat_engine;
|
|
||||||
};
|
};
|
||||||
|
@ -38,7 +38,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const QString
|
|||||||
graphics_tab = std::make_unique<ConfigureGraphics>(physical_devices, is_powered_on, this);
|
graphics_tab = std::make_unique<ConfigureGraphics>(physical_devices, is_powered_on, this);
|
||||||
system_tab = std::make_unique<ConfigureSystem>(system, this);
|
system_tab = std::make_unique<ConfigureSystem>(system, this);
|
||||||
debug_tab = std::make_unique<ConfigureDebug>(is_powered_on, this);
|
debug_tab = std::make_unique<ConfigureDebug>(is_powered_on, this);
|
||||||
cheat_tab = std::make_unique<ConfigureCheats>(system, title_id, this);
|
cheat_tab = std::make_unique<ConfigureCheats>(system.CheatEngine(), title_id, this);
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ QString IPCRecorderWidget::GetStatusStr(const IPCDebugger::RequestRecord& record
|
|||||||
case IPCDebugger::RequestStatus::Handling:
|
case IPCDebugger::RequestStatus::Handling:
|
||||||
return tr("Handling");
|
return tr("Handling");
|
||||||
case IPCDebugger::RequestStatus::Handled:
|
case IPCDebugger::RequestStatus::Handled:
|
||||||
if (record.translated_reply_cmdbuf[1] == RESULT_SUCCESS.raw) {
|
if (record.translated_reply_cmdbuf[1] == ResultSuccess.raw) {
|
||||||
return tr("Success");
|
return tr("Success");
|
||||||
}
|
}
|
||||||
return tr("Error");
|
return tr("Error");
|
||||||
@ -88,7 +88,7 @@ void IPCRecorderWidget::OnEntryUpdated(IPCDebugger::RequestRecord record) {
|
|||||||
|
|
||||||
if (record.status == IPCDebugger::RequestStatus::HLEUnimplemented ||
|
if (record.status == IPCDebugger::RequestStatus::HLEUnimplemented ||
|
||||||
(record.status == IPCDebugger::RequestStatus::Handled &&
|
(record.status == IPCDebugger::RequestStatus::Handled &&
|
||||||
record.translated_reply_cmdbuf[1] != RESULT_SUCCESS.raw)) { // Unimplemented / Error
|
record.translated_reply_cmdbuf[1] != ResultSuccess.raw)) { // Unimplemented / Error
|
||||||
|
|
||||||
auto item = ui->main->invisibleRootItem()->child(row_id);
|
auto item = ui->main->invisibleRootItem()->child(row_id);
|
||||||
for (int column = 0; column < item->columnCount(); ++column) {
|
for (int column = 0; column < item->columnCount(); ++column) {
|
||||||
|
@ -229,6 +229,7 @@ GMainWindow::GMainWindow(Core::System& system_)
|
|||||||
SetDefaultUIGeometry();
|
SetDefaultUIGeometry();
|
||||||
RestoreUIState();
|
RestoreUIState();
|
||||||
|
|
||||||
|
ConnectAppEvents();
|
||||||
ConnectMenuEvents();
|
ConnectMenuEvents();
|
||||||
ConnectWidgetEvents();
|
ConnectWidgetEvents();
|
||||||
|
|
||||||
@ -761,6 +762,21 @@ void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GApplicationEventFilter::eventFilter(QObject* object, QEvent* event) {
|
||||||
|
if (event->type() == QEvent::FileOpen) {
|
||||||
|
emit FileOpen(static_cast<QFileOpenEvent*>(event));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GMainWindow::ConnectAppEvents() {
|
||||||
|
const auto filter = new GApplicationEventFilter();
|
||||||
|
QGuiApplication::instance()->installEventFilter(filter);
|
||||||
|
|
||||||
|
connect(filter, &GApplicationEventFilter::FileOpen, this, &GMainWindow::OnFileOpen);
|
||||||
|
}
|
||||||
|
|
||||||
void GMainWindow::ConnectWidgetEvents() {
|
void GMainWindow::ConnectWidgetEvents() {
|
||||||
connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile);
|
connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile);
|
||||||
connect(game_list, &GameList::OpenDirectory, this, &GMainWindow::OnGameListOpenDirectory);
|
connect(game_list, &GameList::OpenDirectory, this, &GMainWindow::OnGameListOpenDirectory);
|
||||||
@ -2752,6 +2768,10 @@ bool GMainWindow::DropAction(QDropEvent* event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GMainWindow::OnFileOpen(const QFileOpenEvent* event) {
|
||||||
|
BootGame(event->file());
|
||||||
|
}
|
||||||
|
|
||||||
void GMainWindow::dropEvent(QDropEvent* event) {
|
void GMainWindow::dropEvent(QDropEvent* event) {
|
||||||
DropAction(event);
|
DropAction(event);
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ class LoadingScreen;
|
|||||||
class MicroProfileDialog;
|
class MicroProfileDialog;
|
||||||
class MultiplayerState;
|
class MultiplayerState;
|
||||||
class ProfilerWidget;
|
class ProfilerWidget;
|
||||||
|
class QFileOpenEvent;
|
||||||
template <typename>
|
template <typename>
|
||||||
class QFutureWatcher;
|
class QFutureWatcher;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
@ -96,6 +97,8 @@ public:
|
|||||||
bool DropAction(QDropEvent* event);
|
bool DropAction(QDropEvent* event);
|
||||||
void AcceptDropEvent(QDropEvent* event);
|
void AcceptDropEvent(QDropEvent* event);
|
||||||
|
|
||||||
|
void OnFileOpen(const QFileOpenEvent* event);
|
||||||
|
|
||||||
void UninstallTitles(
|
void UninstallTitles(
|
||||||
const std::vector<std::tuple<Service::FS::MediaType, u64, QString>>& titles);
|
const std::vector<std::tuple<Service::FS::MediaType, u64, QString>>& titles);
|
||||||
|
|
||||||
@ -137,6 +140,7 @@ private:
|
|||||||
void SyncMenuUISettings();
|
void SyncMenuUISettings();
|
||||||
void RestoreUIState();
|
void RestoreUIState();
|
||||||
|
|
||||||
|
void ConnectAppEvents();
|
||||||
void ConnectWidgetEvents();
|
void ConnectWidgetEvents();
|
||||||
void ConnectMenuEvents();
|
void ConnectMenuEvents();
|
||||||
void UpdateMenuState();
|
void UpdateMenuState();
|
||||||
@ -382,5 +386,15 @@ protected:
|
|||||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GApplicationEventFilter : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void FileOpen(const QFileOpenEvent* event);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject* object, QEvent* event) override;
|
||||||
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(std::size_t);
|
Q_DECLARE_METATYPE(std::size_t);
|
||||||
Q_DECLARE_METATYPE(Service::AM::InstallStatus);
|
Q_DECLARE_METATYPE(Service::AM::InstallStatus);
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include "core/cheats/gateway_cheat.h"
|
#include "core/cheats/gateway_cheat.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "core/hle/kernel/process.h"
|
|
||||||
|
|
||||||
namespace Cheats {
|
namespace Cheats {
|
||||||
|
|
||||||
@ -18,11 +17,11 @@ namespace Cheats {
|
|||||||
// we use the same value
|
// we use the same value
|
||||||
constexpr u64 run_interval_ticks = 50'000'000;
|
constexpr u64 run_interval_ticks = 50'000'000;
|
||||||
|
|
||||||
CheatEngine::CheatEngine(u64 title_id_, Core::System& system_)
|
CheatEngine::CheatEngine(Core::System& system_) : system{system_} {}
|
||||||
: system(system_), title_id{title_id_} {
|
|
||||||
LoadCheatFile();
|
CheatEngine::~CheatEngine() {
|
||||||
if (system.IsPoweredOn()) {
|
if (system.IsPoweredOn()) {
|
||||||
Connect();
|
system.CoreTiming().UnscheduleEvent(event, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,24 +32,18 @@ void CheatEngine::Connect() {
|
|||||||
system.CoreTiming().ScheduleEvent(run_interval_ticks, event);
|
system.CoreTiming().ScheduleEvent(run_interval_ticks, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
CheatEngine::~CheatEngine() {
|
std::span<const std::shared_ptr<CheatBase>> CheatEngine::GetCheats() const {
|
||||||
if (system.IsPoweredOn()) {
|
std::shared_lock lock{cheats_list_mutex};
|
||||||
system.CoreTiming().UnscheduleEvent(event, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::shared_ptr<CheatBase>> CheatEngine::GetCheats() const {
|
|
||||||
std::shared_lock<std::shared_mutex> lock(cheats_list_mutex);
|
|
||||||
return cheats_list;
|
return cheats_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatEngine::AddCheat(const std::shared_ptr<CheatBase>& cheat) {
|
void CheatEngine::AddCheat(std::shared_ptr<CheatBase>&& cheat) {
|
||||||
std::unique_lock<std::shared_mutex> lock(cheats_list_mutex);
|
std::unique_lock lock{cheats_list_mutex};
|
||||||
cheats_list.push_back(cheat);
|
cheats_list.push_back(std::move(cheat));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatEngine::RemoveCheat(std::size_t index) {
|
void CheatEngine::RemoveCheat(std::size_t index) {
|
||||||
std::unique_lock<std::shared_mutex> lock(cheats_list_mutex);
|
std::unique_lock lock{cheats_list_mutex};
|
||||||
if (index < 0 || index >= cheats_list.size()) {
|
if (index < 0 || index >= cheats_list.size()) {
|
||||||
LOG_ERROR(Core_Cheats, "Invalid index {}", index);
|
LOG_ERROR(Core_Cheats, "Invalid index {}", index);
|
||||||
return;
|
return;
|
||||||
@ -58,16 +51,16 @@ void CheatEngine::RemoveCheat(std::size_t index) {
|
|||||||
cheats_list.erase(cheats_list.begin() + index);
|
cheats_list.erase(cheats_list.begin() + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatEngine::UpdateCheat(std::size_t index, const std::shared_ptr<CheatBase>& new_cheat) {
|
void CheatEngine::UpdateCheat(std::size_t index, std::shared_ptr<CheatBase>&& new_cheat) {
|
||||||
std::unique_lock<std::shared_mutex> lock(cheats_list_mutex);
|
std::unique_lock lock{cheats_list_mutex};
|
||||||
if (index < 0 || index >= cheats_list.size()) {
|
if (index < 0 || index >= cheats_list.size()) {
|
||||||
LOG_ERROR(Core_Cheats, "Invalid index {}", index);
|
LOG_ERROR(Core_Cheats, "Invalid index {}", index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cheats_list[index] = new_cheat;
|
cheats_list[index] = std::move(new_cheat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatEngine::SaveCheatFile() const {
|
void CheatEngine::SaveCheatFile(u64 title_id) const {
|
||||||
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
|
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
|
||||||
const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id);
|
const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id);
|
||||||
|
|
||||||
@ -82,7 +75,14 @@ void CheatEngine::SaveCheatFile() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatEngine::LoadCheatFile() {
|
void CheatEngine::LoadCheatFile(u64 title_id) {
|
||||||
|
{
|
||||||
|
std::unique_lock lock{cheats_list_mutex};
|
||||||
|
if (loaded_title_id.has_value() && loaded_title_id == title_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
|
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
|
||||||
const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id);
|
const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id);
|
||||||
|
|
||||||
@ -90,20 +90,22 @@ void CheatEngine::LoadCheatFile() {
|
|||||||
FileUtil::CreateDir(cheat_dir);
|
FileUtil::CreateDir(cheat_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FileUtil::Exists(filepath))
|
if (!FileUtil::Exists(filepath)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto gateway_cheats = GatewayCheat::LoadFile(filepath);
|
auto gateway_cheats = GatewayCheat::LoadFile(filepath);
|
||||||
{
|
{
|
||||||
std::unique_lock<std::shared_mutex> lock(cheats_list_mutex);
|
std::unique_lock lock{cheats_list_mutex};
|
||||||
std::move(gateway_cheats.begin(), gateway_cheats.end(), std::back_inserter(cheats_list));
|
loaded_title_id = title_id;
|
||||||
|
cheats_list = std::move(gateway_cheats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatEngine::RunCallback([[maybe_unused]] std::uintptr_t user_data, s64 cycles_late) {
|
void CheatEngine::RunCallback([[maybe_unused]] std::uintptr_t user_data, s64 cycles_late) {
|
||||||
{
|
{
|
||||||
std::shared_lock<std::shared_mutex> lock(cheats_list_mutex);
|
std::shared_lock lock{cheats_list_mutex};
|
||||||
for (auto& cheat : cheats_list) {
|
for (const auto& cheat : cheats_list) {
|
||||||
if (cheat->IsEnabled()) {
|
if (cheat->IsEnabled()) {
|
||||||
cheat->Execute(system);
|
cheat->Execute(system);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
|
#include <span>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
@ -24,22 +26,39 @@ class CheatBase;
|
|||||||
|
|
||||||
class CheatEngine {
|
class CheatEngine {
|
||||||
public:
|
public:
|
||||||
explicit CheatEngine(u64 title_id_, Core::System& system);
|
explicit CheatEngine(Core::System& system);
|
||||||
~CheatEngine();
|
~CheatEngine();
|
||||||
|
|
||||||
|
/// Registers the cheat execution callback.
|
||||||
void Connect();
|
void Connect();
|
||||||
std::vector<std::shared_ptr<CheatBase>> GetCheats() const;
|
|
||||||
void AddCheat(const std::shared_ptr<CheatBase>& cheat);
|
/// Returns a span of the currently active cheats.
|
||||||
|
std::span<const std::shared_ptr<CheatBase>> GetCheats() const;
|
||||||
|
|
||||||
|
/// Adds a cheat to the cheat engine.
|
||||||
|
void AddCheat(std::shared_ptr<CheatBase>&& cheat);
|
||||||
|
|
||||||
|
/// Removes a cheat at the specified index in the cheats list.
|
||||||
void RemoveCheat(std::size_t index);
|
void RemoveCheat(std::size_t index);
|
||||||
void UpdateCheat(std::size_t index, const std::shared_ptr<CheatBase>& new_cheat);
|
|
||||||
void SaveCheatFile() const;
|
/// Updates a cheat at the specified index in the cheats list.
|
||||||
|
void UpdateCheat(std::size_t index, std::shared_ptr<CheatBase>&& new_cheat);
|
||||||
|
|
||||||
|
/// Loads the cheat file from disk for the specified title id.
|
||||||
|
void LoadCheatFile(u64 title_id);
|
||||||
|
|
||||||
|
/// Saves currently active cheats to file for the specified title id.
|
||||||
|
void SaveCheatFile(u64 title_id) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadCheatFile();
|
/// The cheat execution callback.
|
||||||
void RunCallback(std::uintptr_t user_data, s64 cycles_late);
|
void RunCallback(std::uintptr_t user_data, s64 cycles_late);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Core::System& system;
|
||||||
|
Core::TimingEventType* event;
|
||||||
|
std::optional<u64> loaded_title_id;
|
||||||
std::vector<std::shared_ptr<CheatBase>> cheats_list;
|
std::vector<std::shared_ptr<CheatBase>> cheats_list;
|
||||||
mutable std::shared_mutex cheats_list_mutex;
|
mutable std::shared_mutex cheats_list_mutex;
|
||||||
Core::TimingEventType* event;
|
|
||||||
Core::System& system;
|
|
||||||
u64 title_id;
|
|
||||||
};
|
};
|
||||||
} // namespace Cheats
|
} // namespace Cheats
|
||||||
|
@ -472,8 +472,8 @@ std::string GatewayCheat::ToString() const {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::unique_ptr<CheatBase>> GatewayCheat::LoadFile(const std::string& filepath) {
|
std::vector<std::shared_ptr<CheatBase>> GatewayCheat::LoadFile(const std::string& filepath) {
|
||||||
std::vector<std::unique_ptr<CheatBase>> cheats;
|
std::vector<std::shared_ptr<CheatBase>> cheats;
|
||||||
|
|
||||||
boost::iostreams::stream<boost::iostreams::file_descriptor_source> file;
|
boost::iostreams::stream<boost::iostreams::file_descriptor_source> file;
|
||||||
FileUtil::OpenFStream<std::ios_base::in>(file, filepath);
|
FileUtil::OpenFStream<std::ios_base::in>(file, filepath);
|
||||||
@ -493,7 +493,7 @@ std::vector<std::unique_ptr<CheatBase>> GatewayCheat::LoadFile(const std::string
|
|||||||
line = Common::StripSpaces(line); // remove spaces at front and end
|
line = Common::StripSpaces(line); // remove spaces at front and end
|
||||||
if (line.length() >= 2 && line.front() == '[') {
|
if (line.length() >= 2 && line.front() == '[') {
|
||||||
if (!cheat_lines.empty()) {
|
if (!cheat_lines.empty()) {
|
||||||
cheats.push_back(std::make_unique<GatewayCheat>(name, cheat_lines, comments));
|
cheats.push_back(std::make_shared<GatewayCheat>(name, cheat_lines, comments));
|
||||||
cheats.back()->SetEnabled(enabled);
|
cheats.back()->SetEnabled(enabled);
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
@ -511,7 +511,7 @@ std::vector<std::unique_ptr<CheatBase>> GatewayCheat::LoadFile(const std::string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cheat_lines.empty()) {
|
if (!cheat_lines.empty()) {
|
||||||
cheats.push_back(std::make_unique<GatewayCheat>(name, cheat_lines, comments));
|
cheats.push_back(std::make_shared<GatewayCheat>(name, cheat_lines, comments));
|
||||||
cheats.back()->SetEnabled(enabled);
|
cheats.back()->SetEnabled(enabled);
|
||||||
}
|
}
|
||||||
return cheats;
|
return cheats;
|
||||||
|
@ -77,7 +77,7 @@ public:
|
|||||||
/// (there might be multiple lines of those hex numbers)
|
/// (there might be multiple lines of those hex numbers)
|
||||||
/// Comment lines start with a '*'
|
/// Comment lines start with a '*'
|
||||||
/// This function will pares the file for such structures
|
/// This function will pares the file for such structures
|
||||||
static std::vector<std::unique_ptr<CheatBase>> LoadFile(const std::string& filepath);
|
static std::vector<std::shared_ptr<CheatBase>> LoadFile(const std::string& filepath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::atomic<bool> enabled = false;
|
std::atomic<bool> enabled = false;
|
||||||
|
@ -72,7 +72,7 @@ Core::Timing& Global() {
|
|||||||
return System::GetInstance().CoreTiming();
|
return System::GetInstance().CoreTiming();
|
||||||
}
|
}
|
||||||
|
|
||||||
System::System() : movie{*this} {}
|
System::System() : movie{*this}, cheat_engine{*this} {}
|
||||||
|
|
||||||
System::~System() = default;
|
System::~System() = default;
|
||||||
|
|
||||||
@ -320,7 +320,10 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
|
|||||||
LOG_ERROR(Core, "Failed to find title id for ROM (Error {})",
|
LOG_ERROR(Core, "Failed to find title id for ROM (Error {})",
|
||||||
static_cast<u32>(load_result));
|
static_cast<u32>(load_result));
|
||||||
}
|
}
|
||||||
cheat_engine = std::make_unique<Cheats::CheatEngine>(title_id, *this);
|
|
||||||
|
cheat_engine.LoadCheatFile(title_id);
|
||||||
|
cheat_engine.Connect();
|
||||||
|
|
||||||
perf_stats = std::make_unique<PerfStats>(title_id);
|
perf_stats = std::make_unique<PerfStats>(title_id);
|
||||||
|
|
||||||
if (Settings::values.dump_textures) {
|
if (Settings::values.dump_textures) {
|
||||||
@ -446,6 +449,12 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window,
|
|||||||
gpu->SetInterruptHandler(
|
gpu->SetInterruptHandler(
|
||||||
[gsp](Service::GSP::InterruptId interrupt_id) { gsp->SignalInterrupt(interrupt_id); });
|
[gsp](Service::GSP::InterruptId interrupt_id) { gsp->SignalInterrupt(interrupt_id); });
|
||||||
|
|
||||||
|
auto plg_ldr = Service::PLGLDR::GetService(*this);
|
||||||
|
if (plg_ldr) {
|
||||||
|
plg_ldr->SetEnabled(Settings::values.plugin_loader_enabled.GetValue());
|
||||||
|
plg_ldr->SetAllowGameChangeState(Settings::values.allow_plugin_loader.GetValue());
|
||||||
|
}
|
||||||
|
|
||||||
LOG_DEBUG(Core, "Initialized OK");
|
LOG_DEBUG(Core, "Initialized OK");
|
||||||
|
|
||||||
is_powered_on = true;
|
is_powered_on = true;
|
||||||
@ -502,11 +511,11 @@ const Memory::MemorySystem& System::Memory() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Cheats::CheatEngine& System::CheatEngine() {
|
Cheats::CheatEngine& System::CheatEngine() {
|
||||||
return *cheat_engine;
|
return cheat_engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Cheats::CheatEngine& System::CheatEngine() const {
|
const Cheats::CheatEngine& System::CheatEngine() const {
|
||||||
return *cheat_engine;
|
return cheat_engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::RegisterVideoDumper(std::shared_ptr<VideoDumper::Backend> dumper) {
|
void System::RegisterVideoDumper(std::shared_ptr<VideoDumper::Backend> dumper) {
|
||||||
@ -560,7 +569,6 @@ void System::Shutdown(bool is_deserializing) {
|
|||||||
if (!is_deserializing) {
|
if (!is_deserializing) {
|
||||||
GDBStub::Shutdown();
|
GDBStub::Shutdown();
|
||||||
perf_stats.reset();
|
perf_stats.reset();
|
||||||
cheat_engine.reset();
|
|
||||||
app_loader.reset();
|
app_loader.reset();
|
||||||
}
|
}
|
||||||
custom_tex_manager.reset();
|
custom_tex_manager.reset();
|
||||||
@ -664,9 +672,11 @@ void System::ApplySettings() {
|
|||||||
Service::MIC::ReloadMic(*this);
|
Service::MIC::ReloadMic(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Service::PLGLDR::PLG_LDR::SetEnabled(Settings::values.plugin_loader_enabled.GetValue());
|
auto plg_ldr = Service::PLGLDR::GetService(*this);
|
||||||
Service::PLGLDR::PLG_LDR::SetAllowGameChangeState(
|
if (plg_ldr) {
|
||||||
Settings::values.allow_plugin_loader.GetValue());
|
plg_ldr->SetEnabled(Settings::values.plugin_loader_enabled.GetValue());
|
||||||
|
plg_ldr->SetAllowGameChangeState(Settings::values.allow_plugin_loader.GetValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
@ -718,7 +728,7 @@ void System::serialize(Archive& ar, const unsigned int file_version) {
|
|||||||
if (Archive::is_loading::value) {
|
if (Archive::is_loading::value) {
|
||||||
timing->UnlockEventQueue();
|
timing->UnlockEventQueue();
|
||||||
memory->SetDSP(*dsp_core);
|
memory->SetDSP(*dsp_core);
|
||||||
cheat_engine->Connect();
|
cheat_engine.Connect();
|
||||||
gpu->Sync();
|
gpu->Sync();
|
||||||
|
|
||||||
// Re-register gpu callback, because gsp service changed after service_manager got
|
// Re-register gpu callback, because gsp service changed after service_manager got
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <boost/serialization/version.hpp>
|
#include <boost/serialization/version.hpp>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/arm/arm_interface.h"
|
#include "core/arm/arm_interface.h"
|
||||||
|
#include "core/cheats/cheats.h"
|
||||||
#include "core/movie.h"
|
#include "core/movie.h"
|
||||||
#include "core/perf_stats.h"
|
#include "core/perf_stats.h"
|
||||||
|
|
||||||
@ -48,10 +49,6 @@ struct New3dsHwCapabilities;
|
|||||||
enum class MemoryMode : u8;
|
enum class MemoryMode : u8;
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
||||||
namespace Cheats {
|
|
||||||
class CheatEngine;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace VideoDumper {
|
namespace VideoDumper {
|
||||||
class Backend;
|
class Backend;
|
||||||
}
|
}
|
||||||
@ -401,7 +398,7 @@ private:
|
|||||||
Core::Movie movie;
|
Core::Movie movie;
|
||||||
|
|
||||||
/// Cheats manager
|
/// Cheats manager
|
||||||
std::unique_ptr<Cheats::CheatEngine> cheat_engine;
|
Cheats::CheatEngine cheat_engine;
|
||||||
|
|
||||||
/// Video dumper backend
|
/// Video dumper backend
|
||||||
std::shared_ptr<VideoDumper::Backend> video_dumper;
|
std::shared_ptr<VideoDumper::Backend> video_dumper;
|
||||||
|
@ -127,7 +127,7 @@ public:
|
|||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
virtual ResultCode DeleteFile(const Path& path) const = 0;
|
virtual Result DeleteFile(const Path& path) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename a File specified by its path
|
* Rename a File specified by its path
|
||||||
@ -135,21 +135,21 @@ public:
|
|||||||
* @param dest_path Destination path relative to the archive
|
* @param dest_path Destination path relative to the archive
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
virtual ResultCode RenameFile(const Path& src_path, const Path& dest_path) const = 0;
|
virtual Result RenameFile(const Path& src_path, const Path& dest_path) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a directory specified by its path
|
* Delete a directory specified by its path
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
virtual ResultCode DeleteDirectory(const Path& path) const = 0;
|
virtual Result DeleteDirectory(const Path& path) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a directory specified by its path and anything under it
|
* Delete a directory specified by its path and anything under it
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
virtual ResultCode DeleteDirectoryRecursively(const Path& path) const = 0;
|
virtual Result DeleteDirectoryRecursively(const Path& path) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a file specified by its path
|
* Create a file specified by its path
|
||||||
@ -157,14 +157,14 @@ public:
|
|||||||
* @param size The size of the new file, filled with zeroes
|
* @param size The size of the new file, filled with zeroes
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
virtual ResultCode CreateFile(const Path& path, u64 size) const = 0;
|
virtual Result CreateFile(const Path& path, u64 size) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a directory specified by its path
|
* Create a directory specified by its path
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
virtual ResultCode CreateDirectory(const Path& path) const = 0;
|
virtual Result CreateDirectory(const Path& path) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename a Directory specified by its path
|
* Rename a Directory specified by its path
|
||||||
@ -172,7 +172,7 @@ public:
|
|||||||
* @param dest_path Destination path relative to the archive
|
* @param dest_path Destination path relative to the archive
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
virtual ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const = 0;
|
virtual Result RenameDirectory(const Path& src_path, const Path& dest_path) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a directory specified by its path
|
* Open a directory specified by its path
|
||||||
@ -229,9 +229,9 @@ public:
|
|||||||
* @param path Path to the archive
|
* @param path Path to the archive
|
||||||
* @param format_info Format information for the new archive
|
* @param format_info Format information for the new archive
|
||||||
* @param program_id the program ID of the client that requests the operation
|
* @param program_id the program ID of the client that requests the operation
|
||||||
* @return ResultCode of the operation, 0 on success
|
* @return Result of the operation, 0 on success
|
||||||
*/
|
*/
|
||||||
virtual ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
virtual Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) = 0;
|
u64 program_id) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
ResultVal<std::size_t> Write(u64 offset, std::size_t length, bool flush,
|
ResultVal<std::size_t> Write(u64 offset, std::size_t length, bool flush,
|
||||||
const u8* buffer) override {
|
const u8* buffer) override {
|
||||||
if (offset > size) {
|
if (offset > size) {
|
||||||
return ERR_WRITE_BEYOND_END;
|
return ResultWriteBeyondEnd;
|
||||||
} else if (offset == size) {
|
} else if (offset == size) {
|
||||||
return 0ULL;
|
return 0ULL;
|
||||||
}
|
}
|
||||||
@ -108,17 +108,17 @@ public:
|
|||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode.hex == 0) {
|
if (mode.hex == 0) {
|
||||||
LOG_ERROR(Service_FS, "Empty open mode");
|
LOG_ERROR(Service_FS, "Empty open mode");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode.create_flag) {
|
if (mode.create_flag) {
|
||||||
LOG_ERROR(Service_FS, "Create flag is not supported");
|
LOG_ERROR(Service_FS, "Create flag is not supported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -126,17 +126,17 @@ public:
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_PATH_NOT_FOUND;
|
return ResultPathNotFound;
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
LOG_ERROR(Service_FS, "Unexpected file or directory in {}", full_path);
|
LOG_ERROR(Service_FS, "Unexpected file or directory in {}", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY;
|
return ResultUnexpectedFileOrDirectory;
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
LOG_ERROR(Service_FS, "{} not found", full_path);
|
LOG_ERROR(Service_FS, "{} not found", full_path);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ public:
|
|||||||
FileUtil::IOFile file(full_path, "r+b");
|
FileUtil::IOFile file(full_path, "r+b");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error opening {}", full_path);
|
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error opening {}", full_path);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mode rwmode;
|
Mode rwmode;
|
||||||
@ -155,10 +155,10 @@ public:
|
|||||||
std::move(delay_generator));
|
std::move(delay_generator));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode CreateFile(const Path& path, u64 size) const override {
|
Result CreateFile(const Path& path, u64 size) const override {
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
LOG_ERROR(Service_FS, "Zero-size file is not supported");
|
LOG_ERROR(Service_FS, "Zero-size file is not supported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
return SaveDataArchive::CreateFile(path, size);
|
return SaveDataArchive::CreateFile(path, size);
|
||||||
}
|
}
|
||||||
@ -250,16 +250,16 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_ExtSaveData::Open(cons
|
|||||||
// TODO(Subv): Verify the archive behavior of SharedExtSaveData compared to ExtSaveData.
|
// TODO(Subv): Verify the archive behavior of SharedExtSaveData compared to ExtSaveData.
|
||||||
// ExtSaveData seems to return FS_NotFound (120) when the archive doesn't exist.
|
// ExtSaveData seems to return FS_NotFound (120) when the archive doesn't exist.
|
||||||
if (type != ExtSaveDataType::Shared) {
|
if (type != ExtSaveDataType::Shared) {
|
||||||
return ERR_NOT_FOUND_INVALID_STATE;
|
return ResultNotFoundInvalidState;
|
||||||
} else {
|
} else {
|
||||||
return ERR_NOT_FORMATTED;
|
return ResultNotFormatted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<ExtSaveDataDelayGenerator>();
|
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<ExtSaveDataDelayGenerator>();
|
||||||
return std::make_unique<ExtSaveDataArchive>(fullpath, std::move(delay_generator));
|
return std::make_unique<ExtSaveDataArchive>(fullpath, std::move(delay_generator));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path,
|
Result ArchiveFactory_ExtSaveData::Format(const Path& path,
|
||||||
const FileSys::ArchiveFormatInfo& format_info,
|
const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) {
|
u64 program_id) {
|
||||||
auto corrected_path = GetCorrectedPath(path);
|
auto corrected_path = GetCorrectedPath(path);
|
||||||
@ -276,11 +276,11 @@ ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path,
|
|||||||
|
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
// TODO(Subv): Find the correct error code
|
// TODO(Subv): Find the correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.WriteBytes(&format_info, sizeof(format_info));
|
file.WriteBytes(&format_info, sizeof(format_info));
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Path& path,
|
ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Path& path,
|
||||||
@ -291,7 +291,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat
|
|||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_ERROR(Service_FS, "Could not open metadata information for archive");
|
LOG_ERROR(Service_FS, "Could not open metadata information for archive");
|
||||||
// TODO(Subv): Verify error code
|
// TODO(Subv): Verify error code
|
||||||
return ERR_NOT_FORMATTED;
|
return ResultNotFormatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchiveFormatInfo info = {};
|
ArchiveFormatInfo info = {};
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
||||||
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) override;
|
u64 program_id) override;
|
||||||
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
||||||
|
|
||||||
|
@ -73,13 +73,13 @@ ResultVal<std::unique_ptr<FileBackend>> NCCHArchive::OpenFile(const Path& path,
|
|||||||
const Mode& mode) const {
|
const Mode& mode) const {
|
||||||
if (path.GetType() != LowPathType::Binary) {
|
if (path.GetType() != LowPathType::Binary) {
|
||||||
LOG_ERROR(Service_FS, "Path need to be Binary");
|
LOG_ERROR(Service_FS, "Path need to be Binary");
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<u8> binary = path.AsBinary();
|
std::vector<u8> binary = path.AsBinary();
|
||||||
if (binary.size() != sizeof(NCCHFilePath)) {
|
if (binary.size() != sizeof(NCCHFilePath)) {
|
||||||
LOG_ERROR(Service_FS, "Wrong path size {}", binary.size());
|
LOG_ERROR(Service_FS, "Wrong path size {}", binary.size());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
NCCHFilePath openfile_path;
|
NCCHFilePath openfile_path;
|
||||||
@ -174,63 +174,63 @@ ResultVal<std::unique_ptr<FileBackend>> NCCHArchive::OpenFile(const Path& path,
|
|||||||
return std::make_unique<IVFCFileInMemory>(std::move(archive_data), romfs_offset,
|
return std::make_unique<IVFCFileInMemory>(std::move(archive_data), romfs_offset,
|
||||||
romfs_size, std::move(delay_generator));
|
romfs_size, std::move(delay_generator));
|
||||||
}
|
}
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode NCCHArchive::DeleteFile(const Path& path) const {
|
Result NCCHArchive::DeleteFile(const Path& path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to delete a file from an NCCH archive ({}).", GetName());
|
LOG_CRITICAL(Service_FS, "Attempted to delete a file from an NCCH archive ({}).", GetName());
|
||||||
// TODO(Subv): Verify error code
|
// TODO(Subv): Verify error code
|
||||||
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled,
|
return Result(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled,
|
||||||
ErrorLevel::Status);
|
ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode NCCHArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
|
Result NCCHArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to rename a file within an NCCH archive ({}).", GetName());
|
LOG_CRITICAL(Service_FS, "Attempted to rename a file within an NCCH archive ({}).", GetName());
|
||||||
// TODO(wwylele): Use correct error code
|
// TODO(wwylele): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode NCCHArchive::DeleteDirectory(const Path& path) const {
|
Result NCCHArchive::DeleteDirectory(const Path& path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an NCCH archive ({}).",
|
LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an NCCH archive ({}).",
|
||||||
GetName());
|
GetName());
|
||||||
// TODO(wwylele): Use correct error code
|
// TODO(wwylele): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode NCCHArchive::DeleteDirectoryRecursively(const Path& path) const {
|
Result NCCHArchive::DeleteDirectoryRecursively(const Path& path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an NCCH archive ({}).",
|
LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an NCCH archive ({}).",
|
||||||
GetName());
|
GetName());
|
||||||
// TODO(wwylele): Use correct error code
|
// TODO(wwylele): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode NCCHArchive::CreateFile(const Path& path, u64 size) const {
|
Result NCCHArchive::CreateFile(const Path& path, u64 size) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to create a file in an NCCH archive ({}).", GetName());
|
LOG_CRITICAL(Service_FS, "Attempted to create a file in an NCCH archive ({}).", GetName());
|
||||||
// TODO: Verify error code
|
// TODO: Verify error code
|
||||||
return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,
|
return Result(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,
|
||||||
ErrorLevel::Permanent);
|
ErrorLevel::Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode NCCHArchive::CreateDirectory(const Path& path) const {
|
Result NCCHArchive::CreateDirectory(const Path& path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to create a directory in an NCCH archive ({}).", GetName());
|
LOG_CRITICAL(Service_FS, "Attempted to create a directory in an NCCH archive ({}).", GetName());
|
||||||
// TODO(wwylele): Use correct error code
|
// TODO(wwylele): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode NCCHArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
|
Result NCCHArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to rename a file within an NCCH archive ({}).", GetName());
|
LOG_CRITICAL(Service_FS, "Attempted to rename a file within an NCCH archive ({}).", GetName());
|
||||||
// TODO(wwylele): Use correct error code
|
// TODO(wwylele): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<DirectoryBackend>> NCCHArchive::OpenDirectory(const Path& path) const {
|
ResultVal<std::unique_ptr<DirectoryBackend>> NCCHArchive::OpenDirectory(const Path& path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to open a directory within an NCCH archive ({}).",
|
LOG_CRITICAL(Service_FS, "Attempted to open a directory within an NCCH archive ({}).",
|
||||||
GetName().c_str());
|
GetName().c_str());
|
||||||
// TODO(shinyquagsire23): Use correct error code
|
// TODO(shinyquagsire23): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 NCCHArchive::GetFreeBytes() const {
|
u64 NCCHArchive::GetFreeBytes() const {
|
||||||
@ -276,13 +276,13 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path&
|
|||||||
u64 program_id) {
|
u64 program_id) {
|
||||||
if (path.GetType() != LowPathType::Binary) {
|
if (path.GetType() != LowPathType::Binary) {
|
||||||
LOG_ERROR(Service_FS, "Path need to be Binary");
|
LOG_ERROR(Service_FS, "Path need to be Binary");
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<u8> binary = path.AsBinary();
|
std::vector<u8> binary = path.AsBinary();
|
||||||
if (binary.size() != sizeof(NCCHArchivePath)) {
|
if (binary.size() != sizeof(NCCHArchivePath)) {
|
||||||
LOG_ERROR(Service_FS, "Wrong path size {}", binary.size());
|
LOG_ERROR(Service_FS, "Wrong path size {}", binary.size());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
NCCHArchivePath open_path;
|
NCCHArchivePath open_path;
|
||||||
@ -292,12 +292,11 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path&
|
|||||||
open_path.tid, static_cast<Service::FS::MediaType>(open_path.media_type & 0xFF));
|
open_path.tid, static_cast<Service::FS::MediaType>(open_path.media_type & 0xFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveFactory_NCCH::Format(const Path& path,
|
Result ArchiveFactory_NCCH::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
const FileSys::ArchiveFormatInfo& format_info,
|
|
||||||
u64 program_id) {
|
u64 program_id) {
|
||||||
LOG_ERROR(Service_FS, "Attempted to format a NCCH archive.");
|
LOG_ERROR(Service_FS, "Attempted to format a NCCH archive.");
|
||||||
// TODO: Verify error code
|
// TODO: Verify error code
|
||||||
return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,
|
return Result(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,
|
||||||
ErrorLevel::Permanent);
|
ErrorLevel::Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,7 +304,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_NCCH::GetFormatInfo(const Path& path
|
|||||||
u64 program_id) const {
|
u64 program_id) const {
|
||||||
// TODO(Subv): Implement
|
// TODO(Subv): Implement
|
||||||
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
|
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
@ -50,13 +50,13 @@ public:
|
|||||||
|
|
||||||
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
|
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
|
||||||
const Mode& mode) const override;
|
const Mode& mode) const override;
|
||||||
ResultCode DeleteFile(const Path& path) const override;
|
Result DeleteFile(const Path& path) const override;
|
||||||
ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
|
Result RenameFile(const Path& src_path, const Path& dest_path) const override;
|
||||||
ResultCode DeleteDirectory(const Path& path) const override;
|
Result DeleteDirectory(const Path& path) const override;
|
||||||
ResultCode DeleteDirectoryRecursively(const Path& path) const override;
|
Result DeleteDirectoryRecursively(const Path& path) const override;
|
||||||
ResultCode CreateFile(const Path& path, u64 size) const override;
|
Result CreateFile(const Path& path, u64 size) const override;
|
||||||
ResultCode CreateDirectory(const Path& path) const override;
|
Result CreateDirectory(const Path& path) const override;
|
||||||
ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
Result RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
||||||
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
|
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
|
||||||
u64 GetFreeBytes() const override;
|
u64 GetFreeBytes() const override;
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
||||||
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) override;
|
u64 program_id) override;
|
||||||
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
||||||
|
|
||||||
|
@ -25,14 +25,14 @@ template <typename T>
|
|||||||
ResultVal<std::tuple<MediaType, u64>> ParsePath(const Path& path, T program_id_reader) {
|
ResultVal<std::tuple<MediaType, u64>> ParsePath(const Path& path, T program_id_reader) {
|
||||||
if (path.GetType() != LowPathType::Binary) {
|
if (path.GetType() != LowPathType::Binary) {
|
||||||
LOG_ERROR(Service_FS, "Wrong path type {}", path.GetType());
|
LOG_ERROR(Service_FS, "Wrong path type {}", path.GetType());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<u8> vec_data = path.AsBinary();
|
std::vector<u8> vec_data = path.AsBinary();
|
||||||
|
|
||||||
if (vec_data.size() != 12) {
|
if (vec_data.size() != 12) {
|
||||||
LOG_ERROR(Service_FS, "Wrong path length {}", vec_data.size());
|
LOG_ERROR(Service_FS, "Wrong path length {}", vec_data.size());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32* data = reinterpret_cast<const u32*>(vec_data.data());
|
const u32* data = reinterpret_cast<const u32*>(vec_data.data());
|
||||||
@ -42,7 +42,7 @@ ResultVal<std::tuple<MediaType, u64>> ParsePath(const Path& path, T program_id_r
|
|||||||
LOG_ERROR(Service_FS, "Unsupported media type {}", media_type);
|
LOG_ERROR(Service_FS, "Unsupported media type {}", media_type);
|
||||||
|
|
||||||
// Note: this is strange, but the error code was verified with a real 3DS
|
// Note: this is strange, but the error code was verified with a real 3DS
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_tuple(media_type, program_id_reader(data));
|
return std::make_tuple(media_type, program_id_reader(data));
|
||||||
@ -72,16 +72,17 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataPermitted
|
|||||||
|
|
||||||
if (media_type == MediaType::GameCard) {
|
if (media_type == MediaType::GameCard) {
|
||||||
LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
|
LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
|
||||||
return ERROR_GAMECARD_NOT_INSERTED;
|
return ResultGamecardNotInserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sd_savedata_source->Open(program_id);
|
return sd_savedata_source->Open(program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveFactory_OtherSaveDataPermitted::Format(
|
Result ArchiveFactory_OtherSaveDataPermitted::Format(const Path& path,
|
||||||
const Path& path, const FileSys::ArchiveFormatInfo& format_info, u64 program_id) {
|
const FileSys::ArchiveFormatInfo& format_info,
|
||||||
|
u64 program_id) {
|
||||||
LOG_ERROR(Service_FS, "Attempted to format a OtherSaveDataPermitted archive.");
|
LOG_ERROR(Service_FS, "Attempted to format a OtherSaveDataPermitted archive.");
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataPermitted::GetFormatInfo(
|
ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataPermitted::GetFormatInfo(
|
||||||
@ -92,7 +93,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataPermitted::GetFormatInf
|
|||||||
|
|
||||||
if (media_type == MediaType::GameCard) {
|
if (media_type == MediaType::GameCard) {
|
||||||
LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
|
LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
|
||||||
return ERROR_GAMECARD_NOT_INSERTED;
|
return ResultGamecardNotInserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sd_savedata_source->GetFormatInfo(program_id);
|
return sd_savedata_source->GetFormatInfo(program_id);
|
||||||
@ -110,21 +111,22 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataGeneral::
|
|||||||
|
|
||||||
if (media_type == MediaType::GameCard) {
|
if (media_type == MediaType::GameCard) {
|
||||||
LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
|
LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
|
||||||
return ERROR_GAMECARD_NOT_INSERTED;
|
return ResultGamecardNotInserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sd_savedata_source->Open(program_id);
|
return sd_savedata_source->Open(program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveFactory_OtherSaveDataGeneral::Format(
|
Result ArchiveFactory_OtherSaveDataGeneral::Format(const Path& path,
|
||||||
const Path& path, const FileSys::ArchiveFormatInfo& format_info, u64 /*client_program_id*/) {
|
const FileSys::ArchiveFormatInfo& format_info,
|
||||||
|
u64 /*client_program_id*/) {
|
||||||
MediaType media_type;
|
MediaType media_type;
|
||||||
u64 program_id;
|
u64 program_id;
|
||||||
CASCADE_RESULT(std::tie(media_type, program_id), ParsePathGeneral(path));
|
CASCADE_RESULT(std::tie(media_type, program_id), ParsePathGeneral(path));
|
||||||
|
|
||||||
if (media_type == MediaType::GameCard) {
|
if (media_type == MediaType::GameCard) {
|
||||||
LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
|
LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
|
||||||
return ERROR_GAMECARD_NOT_INSERTED;
|
return ResultGamecardNotInserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sd_savedata_source->Format(program_id, format_info);
|
return sd_savedata_source->Format(program_id, format_info);
|
||||||
@ -138,7 +140,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataGeneral::GetFormatInfo(
|
|||||||
|
|
||||||
if (media_type == MediaType::GameCard) {
|
if (media_type == MediaType::GameCard) {
|
||||||
LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
|
LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
|
||||||
return ERROR_GAMECARD_NOT_INSERTED;
|
return ResultGamecardNotInserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sd_savedata_source->GetFormatInfo(program_id);
|
return sd_savedata_source->GetFormatInfo(program_id);
|
||||||
|
@ -22,7 +22,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
||||||
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) override;
|
u64 program_id) override;
|
||||||
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
||||||
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) override;
|
u64 program_id) override;
|
||||||
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveData::Open(const P
|
|||||||
return sd_savedata_source->Open(program_id);
|
return sd_savedata_source->Open(program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveFactory_SaveData::Format(const Path& path,
|
Result ArchiveFactory_SaveData::Format(const Path& path,
|
||||||
const FileSys::ArchiveFormatInfo& format_info,
|
const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) {
|
u64 program_id) {
|
||||||
return sd_savedata_source->Format(program_id, format_info);
|
return sd_savedata_source->Format(program_id, format_info);
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
||||||
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) override;
|
u64 program_id) override;
|
||||||
|
|
||||||
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
||||||
|
@ -62,17 +62,17 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCArchive::OpenFileBase(const Path& pa
|
|||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode.hex == 0) {
|
if (mode.hex == 0) {
|
||||||
LOG_ERROR(Service_FS, "Empty open mode");
|
LOG_ERROR(Service_FS, "Empty open mode");
|
||||||
return ERROR_INVALID_OPEN_FLAGS;
|
return ResultInvalidOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode.create_flag && !mode.write_flag) {
|
if (mode.create_flag && !mode.write_flag) {
|
||||||
LOG_ERROR(Service_FS, "Create flag set but write flag not set");
|
LOG_ERROR(Service_FS, "Create flag set but write flag not set");
|
||||||
return ERROR_INVALID_OPEN_FLAGS;
|
return ResultInvalidOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -80,19 +80,19 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCArchive::OpenFileBase(const Path& pa
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
LOG_ERROR(Service_FS, "{} is not a file", full_path);
|
LOG_ERROR(Service_FS, "{} is not a file", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC;
|
return ResultUnexpectedFileOrDirectorySdmc;
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
if (!mode.create_flag) {
|
if (!mode.create_flag) {
|
||||||
LOG_ERROR(Service_FS, "Non-existing file {} can't be open without mode create.",
|
LOG_ERROR(Service_FS, "Non-existing file {} can't be open without mode create.",
|
||||||
full_path);
|
full_path);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
} else {
|
} else {
|
||||||
// Create the file
|
// Create the file
|
||||||
FileUtil::CreateEmptyFile(full_path);
|
FileUtil::CreateEmptyFile(full_path);
|
||||||
@ -105,19 +105,19 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCArchive::OpenFileBase(const Path& pa
|
|||||||
FileUtil::IOFile file(full_path, mode.write_flag ? "r+b" : "rb");
|
FileUtil::IOFile file(full_path, mode.write_flag ? "r+b" : "rb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_CRITICAL(Service_FS, "Error opening {}: {}", full_path, Common::GetLastErrorMsg());
|
LOG_CRITICAL(Service_FS, "Error opening {}: {}", full_path, Common::GetLastErrorMsg());
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<SDMCDelayGenerator>();
|
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<SDMCDelayGenerator>();
|
||||||
return std::make_unique<DiskFile>(std::move(file), mode, std::move(delay_generator));
|
return std::make_unique<DiskFile>(std::move(file), mode, std::move(delay_generator));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SDMCArchive::DeleteFile(const Path& path) const {
|
Result SDMCArchive::DeleteFile(const Path& path) const {
|
||||||
const PathParser path_parser(path);
|
const PathParser path_parser(path);
|
||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -125,110 +125,109 @@ ResultCode SDMCArchive::DeleteFile(const Path& path) const {
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
LOG_DEBUG(Service_FS, "{} not found", full_path);
|
LOG_DEBUG(Service_FS, "{} not found", full_path);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
LOG_ERROR(Service_FS, "{} is not a file", full_path);
|
LOG_ERROR(Service_FS, "{} is not a file", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC;
|
return ResultUnexpectedFileOrDirectorySdmc;
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FileUtil::Delete(full_path)) {
|
if (FileUtil::Delete(full_path)) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error deleting {}", full_path);
|
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error deleting {}", full_path);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SDMCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
|
Result SDMCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
|
||||||
const PathParser path_parser_src(src_path);
|
const PathParser path_parser_src(src_path);
|
||||||
|
|
||||||
// TODO: Verify these return codes with HW
|
// TODO: Verify these return codes with HW
|
||||||
if (!path_parser_src.IsValid()) {
|
if (!path_parser_src.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PathParser path_parser_dest(dest_path);
|
const PathParser path_parser_dest(dest_path);
|
||||||
|
|
||||||
if (!path_parser_dest.IsValid()) {
|
if (!path_parser_dest.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
|
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
|
||||||
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
|
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
|
||||||
|
|
||||||
if (FileUtil::Rename(src_path_full, dest_path_full)) {
|
if (FileUtil::Rename(src_path_full, dest_path_full)) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
|
// TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
|
||||||
// exist or similar. Verify.
|
// exist or similar. Verify.
|
||||||
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
return Result(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
||||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static ResultCode DeleteDirectoryHelper(const Path& path, const std::string& mount_point,
|
static Result DeleteDirectoryHelper(const Path& path, const std::string& mount_point, T deleter) {
|
||||||
T deleter) {
|
|
||||||
const PathParser path_parser(path);
|
const PathParser path_parser(path);
|
||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path_parser.IsRootDirectory())
|
if (path_parser.IsRootDirectory())
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
|
|
||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path);
|
LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC;
|
return ResultUnexpectedFileOrDirectorySdmc;
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleter(full_path)) {
|
if (deleter(full_path)) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_FS, "Directory not empty {}", full_path);
|
LOG_ERROR(Service_FS, "Directory not empty {}", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC;
|
return ResultUnexpectedFileOrDirectorySdmc;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SDMCArchive::DeleteDirectory(const Path& path) const {
|
Result SDMCArchive::DeleteDirectory(const Path& path) const {
|
||||||
return DeleteDirectoryHelper(path, mount_point, FileUtil::DeleteDir);
|
return DeleteDirectoryHelper(path, mount_point, FileUtil::DeleteDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SDMCArchive::DeleteDirectoryRecursively(const Path& path) const {
|
Result SDMCArchive::DeleteDirectoryRecursively(const Path& path) const {
|
||||||
return DeleteDirectoryHelper(
|
return DeleteDirectoryHelper(
|
||||||
path, mount_point, [](const std::string& p) { return FileUtil::DeleteDirRecursively(p); });
|
path, mount_point, [](const std::string& p) { return FileUtil::DeleteDirRecursively(p); });
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SDMCArchive::CreateFile(const FileSys::Path& path, u64 size) const {
|
Result SDMCArchive::CreateFile(const FileSys::Path& path, u64 size) const {
|
||||||
const PathParser path_parser(path);
|
const PathParser path_parser(path);
|
||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -236,44 +235,44 @@ ResultCode SDMCArchive::CreateFile(const FileSys::Path& path, u64 size) const {
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
LOG_ERROR(Service_FS, "{} already exists", full_path);
|
LOG_ERROR(Service_FS, "{} already exists", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC;
|
return ResultUnexpectedFileOrDirectorySdmc;
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
LOG_ERROR(Service_FS, "{} already exists", full_path);
|
LOG_ERROR(Service_FS, "{} already exists", full_path);
|
||||||
return ERROR_ALREADY_EXISTS;
|
return ResultAlreadyExists;
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
FileUtil::CreateEmptyFile(full_path);
|
FileUtil::CreateEmptyFile(full_path);
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil::IOFile file(full_path, "wb");
|
FileUtil::IOFile file(full_path, "wb");
|
||||||
// Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
|
// Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
|
||||||
// We do this by seeking to the right size, then writing a single null byte.
|
// We do this by seeking to the right size, then writing a single null byte.
|
||||||
if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) {
|
if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_FS, "Too large file");
|
LOG_ERROR(Service_FS, "Too large file");
|
||||||
return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource,
|
return Result(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource,
|
||||||
ErrorLevel::Info);
|
ErrorLevel::Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SDMCArchive::CreateDirectory(const Path& path) const {
|
Result SDMCArchive::CreateDirectory(const Path& path) const {
|
||||||
const PathParser path_parser(path);
|
const PathParser path_parser(path);
|
||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -281,54 +280,54 @@ ResultCode SDMCArchive::CreateDirectory(const Path& path) const {
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
LOG_DEBUG(Service_FS, "{} already exists", full_path);
|
LOG_DEBUG(Service_FS, "{} already exists", full_path);
|
||||||
return ERROR_ALREADY_EXISTS;
|
return ResultAlreadyExists;
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FileUtil::CreateDir(mount_point + path.AsString())) {
|
if (FileUtil::CreateDir(mount_point + path.AsString())) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error creating {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error creating {}", mount_point);
|
||||||
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled,
|
return Result(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled,
|
||||||
ErrorLevel::Status);
|
ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SDMCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
|
Result SDMCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
|
||||||
const PathParser path_parser_src(src_path);
|
const PathParser path_parser_src(src_path);
|
||||||
|
|
||||||
// TODO: Verify these return codes with HW
|
// TODO: Verify these return codes with HW
|
||||||
if (!path_parser_src.IsValid()) {
|
if (!path_parser_src.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PathParser path_parser_dest(dest_path);
|
const PathParser path_parser_dest(dest_path);
|
||||||
|
|
||||||
if (!path_parser_dest.IsValid()) {
|
if (!path_parser_dest.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
|
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
|
||||||
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
|
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
|
||||||
|
|
||||||
if (FileUtil::Rename(src_path_full, dest_path_full)) {
|
if (FileUtil::Rename(src_path_full, dest_path_full)) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
|
// TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
|
||||||
// exist or similar. Verify.
|
// exist or similar. Verify.
|
||||||
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
return Result(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
||||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +336,7 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SDMCArchive::OpenDirectory(const Pa
|
|||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -345,15 +344,15 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SDMCArchive::OpenDirectory(const Pa
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
LOG_ERROR(Service_FS, "{} not found", full_path);
|
LOG_ERROR(Service_FS, "{} not found", full_path);
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path);
|
LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC;
|
return ResultUnexpectedFileOrDirectorySdmc;
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
@ -392,18 +391,17 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMC::Open(const Path&
|
|||||||
return std::make_unique<SDMCArchive>(sdmc_directory, std::move(delay_generator));
|
return std::make_unique<SDMCArchive>(sdmc_directory, std::move(delay_generator));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveFactory_SDMC::Format(const Path& path,
|
Result ArchiveFactory_SDMC::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
const FileSys::ArchiveFormatInfo& format_info,
|
|
||||||
u64 program_id) {
|
u64 program_id) {
|
||||||
// This is kind of an undesirable operation, so let's just ignore it. :)
|
// This is kind of an undesirable operation, so let's just ignore it. :)
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMC::GetFormatInfo(const Path& path,
|
ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMC::GetFormatInfo(const Path& path,
|
||||||
u64 program_id) const {
|
u64 program_id) const {
|
||||||
// TODO(Subv): Implement
|
// TODO(Subv): Implement
|
||||||
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
|
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
|
||||||
|
@ -29,13 +29,13 @@ public:
|
|||||||
|
|
||||||
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
|
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
|
||||||
const Mode& mode) const override;
|
const Mode& mode) const override;
|
||||||
ResultCode DeleteFile(const Path& path) const override;
|
Result DeleteFile(const Path& path) const override;
|
||||||
ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
|
Result RenameFile(const Path& src_path, const Path& dest_path) const override;
|
||||||
ResultCode DeleteDirectory(const Path& path) const override;
|
Result DeleteDirectory(const Path& path) const override;
|
||||||
ResultCode DeleteDirectoryRecursively(const Path& path) const override;
|
Result DeleteDirectoryRecursively(const Path& path) const override;
|
||||||
ResultCode CreateFile(const Path& path, u64 size) const override;
|
Result CreateFile(const Path& path, u64 size) const override;
|
||||||
ResultCode CreateDirectory(const Path& path) const override;
|
Result CreateDirectory(const Path& path) const override;
|
||||||
ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
Result RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
||||||
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
|
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
|
||||||
u64 GetFreeBytes() const override;
|
u64 GetFreeBytes() const override;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
||||||
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) override;
|
u64 program_id) override;
|
||||||
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCWriteOnlyArchive::OpenFile(const Pat
|
|||||||
const Mode& mode) const {
|
const Mode& mode) const {
|
||||||
if (mode.read_flag) {
|
if (mode.read_flag) {
|
||||||
LOG_ERROR(Service_FS, "Read flag is not supported");
|
LOG_ERROR(Service_FS, "Read flag is not supported");
|
||||||
return ERROR_INVALID_READ_FLAG;
|
return ResultInvalidReadFlag;
|
||||||
}
|
}
|
||||||
return SDMCArchive::OpenFileBase(path, mode);
|
return SDMCArchive::OpenFileBase(path, mode);
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCWriteOnlyArchive::OpenFile(const Pat
|
|||||||
ResultVal<std::unique_ptr<DirectoryBackend>> SDMCWriteOnlyArchive::OpenDirectory(
|
ResultVal<std::unique_ptr<DirectoryBackend>> SDMCWriteOnlyArchive::OpenDirectory(
|
||||||
const Path& path) const {
|
const Path& path) const {
|
||||||
LOG_ERROR(Service_FS, "Not supported");
|
LOG_ERROR(Service_FS, "Not supported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchiveFactory_SDMCWriteOnly::ArchiveFactory_SDMCWriteOnly(const std::string& mount_point)
|
ArchiveFactory_SDMCWriteOnly::ArchiveFactory_SDMCWriteOnly(const std::string& mount_point)
|
||||||
@ -81,19 +81,19 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMCWriteOnly::Open(co
|
|||||||
return std::make_unique<SDMCWriteOnlyArchive>(sdmc_directory, std::move(delay_generator));
|
return std::make_unique<SDMCWriteOnlyArchive>(sdmc_directory, std::move(delay_generator));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveFactory_SDMCWriteOnly::Format(const Path& path,
|
Result ArchiveFactory_SDMCWriteOnly::Format(const Path& path,
|
||||||
const FileSys::ArchiveFormatInfo& format_info,
|
const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) {
|
u64 program_id) {
|
||||||
// TODO(wwylele): hwtest this
|
// TODO(wwylele): hwtest this
|
||||||
LOG_ERROR(Service_FS, "Attempted to format a SDMC write-only archive.");
|
LOG_ERROR(Service_FS, "Attempted to format a SDMC write-only archive.");
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMCWriteOnly::GetFormatInfo(const Path& path,
|
ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMCWriteOnly::GetFormatInfo(const Path& path,
|
||||||
u64 program_id) const {
|
u64 program_id) const {
|
||||||
// TODO(Subv): Implement
|
// TODO(Subv): Implement
|
||||||
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
|
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
@ -54,7 +54,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
||||||
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) override;
|
u64 program_id) override;
|
||||||
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
||||||
|
|
||||||
|
@ -39,12 +39,12 @@ public:
|
|||||||
ResultVal<std::size_t> Read(u64 offset, std::size_t length, u8* buffer) const override {
|
ResultVal<std::size_t> Read(u64 offset, std::size_t length, u8* buffer) const override {
|
||||||
if (offset != 0) {
|
if (offset != 0) {
|
||||||
LOG_ERROR(Service_FS, "offset must be zero!");
|
LOG_ERROR(Service_FS, "offset must be zero!");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length != data->size()) {
|
if (length != data->size()) {
|
||||||
LOG_ERROR(Service_FS, "size must match the file size!");
|
LOG_ERROR(Service_FS, "size must match the file size!");
|
||||||
return ERROR_INCORRECT_EXEFS_READ_SIZE;
|
return ResultIncorrectExefsReadSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::memcpy(buffer, data->data(), data->size());
|
std::memcpy(buffer, data->data(), data->size());
|
||||||
@ -54,7 +54,7 @@ public:
|
|||||||
ResultVal<std::size_t> Write(u64 offset, std::size_t length, bool flush,
|
ResultVal<std::size_t> Write(u64 offset, std::size_t length, bool flush,
|
||||||
const u8* buffer) override {
|
const u8* buffer) override {
|
||||||
LOG_ERROR(Service_FS, "The file is read-only!");
|
LOG_ERROR(Service_FS, "The file is read-only!");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 GetSize() const override {
|
u64 GetSize() const override {
|
||||||
@ -99,13 +99,13 @@ public:
|
|||||||
|
|
||||||
if (path.GetType() != LowPathType::Binary) {
|
if (path.GetType() != LowPathType::Binary) {
|
||||||
LOG_ERROR(Service_FS, "Path need to be Binary");
|
LOG_ERROR(Service_FS, "Path need to be Binary");
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<u8> binary = path.AsBinary();
|
std::vector<u8> binary = path.AsBinary();
|
||||||
if (binary.size() != sizeof(SelfNCCHFilePath)) {
|
if (binary.size() != sizeof(SelfNCCHFilePath)) {
|
||||||
LOG_ERROR(Service_FS, "Wrong path size {}", binary.size());
|
LOG_ERROR(Service_FS, "Wrong path size {}", binary.size());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelfNCCHFilePath file_path;
|
SelfNCCHFilePath file_path;
|
||||||
@ -120,7 +120,7 @@ public:
|
|||||||
|
|
||||||
case SelfNCCHFilePathType::Code:
|
case SelfNCCHFilePathType::Code:
|
||||||
LOG_ERROR(Service_FS, "Reading the code section is not supported!");
|
LOG_ERROR(Service_FS, "Reading the code section is not supported!");
|
||||||
return ERROR_COMMAND_NOT_ALLOWED;
|
return ResultCommandNotAllowed;
|
||||||
|
|
||||||
case SelfNCCHFilePathType::ExeFS: {
|
case SelfNCCHFilePathType::ExeFS: {
|
||||||
const auto& raw = file_path.exefs_filename;
|
const auto& raw = file_path.exefs_filename;
|
||||||
@ -130,48 +130,48 @@ public:
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
LOG_ERROR(Service_FS, "Unknown file type {}!", file_path.type);
|
LOG_ERROR(Service_FS, "Unknown file type {}!", file_path.type);
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode DeleteFile(const Path& path) const override {
|
Result DeleteFile(const Path& path) const override {
|
||||||
LOG_ERROR(Service_FS, "Unsupported");
|
LOG_ERROR(Service_FS, "Unsupported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override {
|
Result RenameFile(const Path& src_path, const Path& dest_path) const override {
|
||||||
LOG_ERROR(Service_FS, "Unsupported");
|
LOG_ERROR(Service_FS, "Unsupported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode DeleteDirectory(const Path& path) const override {
|
Result DeleteDirectory(const Path& path) const override {
|
||||||
LOG_ERROR(Service_FS, "Unsupported");
|
LOG_ERROR(Service_FS, "Unsupported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode DeleteDirectoryRecursively(const Path& path) const override {
|
Result DeleteDirectoryRecursively(const Path& path) const override {
|
||||||
LOG_ERROR(Service_FS, "Unsupported");
|
LOG_ERROR(Service_FS, "Unsupported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode CreateFile(const Path& path, u64 size) const override {
|
Result CreateFile(const Path& path, u64 size) const override {
|
||||||
LOG_ERROR(Service_FS, "Unsupported");
|
LOG_ERROR(Service_FS, "Unsupported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode CreateDirectory(const Path& path) const override {
|
Result CreateDirectory(const Path& path) const override {
|
||||||
LOG_ERROR(Service_FS, "Unsupported");
|
LOG_ERROR(Service_FS, "Unsupported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override {
|
Result RenameDirectory(const Path& src_path, const Path& dest_path) const override {
|
||||||
LOG_ERROR(Service_FS, "Unsupported");
|
LOG_ERROR(Service_FS, "Unsupported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override {
|
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override {
|
||||||
LOG_ERROR(Service_FS, "Unsupported");
|
LOG_ERROR(Service_FS, "Unsupported");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 GetFreeBytes() const override {
|
u64 GetFreeBytes() const override {
|
||||||
@ -186,7 +186,7 @@ private:
|
|||||||
return std::make_unique<IVFCFile>(ncch_data.romfs_file, std::move(delay_generator));
|
return std::make_unique<IVFCFile>(ncch_data.romfs_file, std::move(delay_generator));
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(Service_FS, "Unable to read RomFS");
|
LOG_INFO(Service_FS, "Unable to read RomFS");
|
||||||
return ERROR_ROMFS_NOT_FOUND;
|
return ResultRomfsNotFound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ private:
|
|||||||
std::move(delay_generator));
|
std::move(delay_generator));
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(Service_FS, "Unable to read update RomFS");
|
LOG_INFO(Service_FS, "Unable to read update RomFS");
|
||||||
return ERROR_ROMFS_NOT_FOUND;
|
return ResultRomfsNotFound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_WARNING(Service_FS, "Unable to read icon");
|
LOG_WARNING(Service_FS, "Unable to read icon");
|
||||||
return ERROR_EXEFS_SECTION_NOT_FOUND;
|
return ResultExefsSectionNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename == "logo") {
|
if (filename == "logo") {
|
||||||
@ -218,7 +218,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_WARNING(Service_FS, "Unable to read logo");
|
LOG_WARNING(Service_FS, "Unable to read logo");
|
||||||
return ERROR_EXEFS_SECTION_NOT_FOUND;
|
return ResultExefsSectionNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename == "banner") {
|
if (filename == "banner") {
|
||||||
@ -227,11 +227,11 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_WARNING(Service_FS, "Unable to read banner");
|
LOG_WARNING(Service_FS, "Unable to read banner");
|
||||||
return ERROR_EXEFS_SECTION_NOT_FOUND;
|
return ResultExefsSectionNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_FS, "Unknown ExeFS section {}!", filename);
|
LOG_ERROR(Service_FS, "Unknown ExeFS section {}!", filename);
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
NCCHData ncch_data;
|
NCCHData ncch_data;
|
||||||
@ -296,16 +296,16 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SelfNCCH::Open(const P
|
|||||||
return std::make_unique<SelfNCCHArchive>(ncch_data[program_id]);
|
return std::make_unique<SelfNCCHArchive>(ncch_data[program_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveFactory_SelfNCCH::Format(const Path&, const FileSys::ArchiveFormatInfo&,
|
Result ArchiveFactory_SelfNCCH::Format(const Path&, const FileSys::ArchiveFormatInfo&,
|
||||||
u64 program_id) {
|
u64 program_id) {
|
||||||
LOG_ERROR(Service_FS, "Attempted to format a SelfNCCH archive.");
|
LOG_ERROR(Service_FS, "Attempted to format a SelfNCCH archive.");
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<ArchiveFormatInfo> ArchiveFactory_SelfNCCH::GetFormatInfo(const Path&,
|
ResultVal<ArchiveFormatInfo> ArchiveFactory_SelfNCCH::GetFormatInfo(const Path&,
|
||||||
u64 program_id) const {
|
u64 program_id) const {
|
||||||
LOG_ERROR(Service_FS, "Attempted to get format info of a SelfNCCH archive");
|
LOG_ERROR(Service_FS, "Attempted to get format info of a SelfNCCH archive");
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
@ -50,7 +50,7 @@ public:
|
|||||||
return "SelfNCCH";
|
return "SelfNCCH";
|
||||||
}
|
}
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
||||||
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) override;
|
u64 program_id) override;
|
||||||
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
||||||
|
|
||||||
|
@ -47,13 +47,13 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveSource_SDSaveData::Open(u64 pr
|
|||||||
// save file/directory structure expected by the game has not yet been initialized.
|
// save file/directory structure expected by the game has not yet been initialized.
|
||||||
// Returning the NotFormatted error code will signal the game to provision the SaveData
|
// Returning the NotFormatted error code will signal the game to provision the SaveData
|
||||||
// archive with the files and folders that it expects.
|
// archive with the files and folders that it expects.
|
||||||
return ERR_NOT_FORMATTED;
|
return ResultNotFormatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_unique<SaveDataArchive>(std::move(concrete_mount_point));
|
return std::make_unique<SaveDataArchive>(std::move(concrete_mount_point));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveSource_SDSaveData::Format(u64 program_id,
|
Result ArchiveSource_SDSaveData::Format(u64 program_id,
|
||||||
const FileSys::ArchiveFormatInfo& format_info) {
|
const FileSys::ArchiveFormatInfo& format_info) {
|
||||||
std::string concrete_mount_point = GetSaveDataPath(mount_point, program_id);
|
std::string concrete_mount_point = GetSaveDataPath(mount_point, program_id);
|
||||||
FileUtil::DeleteDirRecursively(concrete_mount_point);
|
FileUtil::DeleteDirRecursively(concrete_mount_point);
|
||||||
@ -65,9 +65,9 @@ ResultCode ArchiveSource_SDSaveData::Format(u64 program_id,
|
|||||||
|
|
||||||
if (file.IsOpen()) {
|
if (file.IsOpen()) {
|
||||||
file.WriteBytes(&format_info, sizeof(format_info));
|
file.WriteBytes(&format_info, sizeof(format_info));
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<ArchiveFormatInfo> ArchiveSource_SDSaveData::GetFormatInfo(u64 program_id) const {
|
ResultVal<ArchiveFormatInfo> ArchiveSource_SDSaveData::GetFormatInfo(u64 program_id) const {
|
||||||
@ -77,7 +77,7 @@ ResultVal<ArchiveFormatInfo> ArchiveSource_SDSaveData::GetFormatInfo(u64 program
|
|||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_ERROR(Service_FS, "Could not open metadata information for archive");
|
LOG_ERROR(Service_FS, "Could not open metadata information for archive");
|
||||||
// TODO(Subv): Verify error code
|
// TODO(Subv): Verify error code
|
||||||
return ERR_NOT_FORMATTED;
|
return ResultNotFormatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchiveFormatInfo info = {};
|
ArchiveFormatInfo info = {};
|
||||||
|
@ -19,7 +19,7 @@ public:
|
|||||||
explicit ArchiveSource_SDSaveData(const std::string& mount_point);
|
explicit ArchiveSource_SDSaveData(const std::string& mount_point);
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(u64 program_id);
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(u64 program_id);
|
||||||
ResultCode Format(u64 program_id, const FileSys::ArchiveFormatInfo& format_info);
|
Result Format(u64 program_id, const FileSys::ArchiveFormatInfo& format_info);
|
||||||
ResultVal<ArchiveFormatInfo> GetFormatInfo(u64 program_id) const;
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(u64 program_id) const;
|
||||||
|
|
||||||
static std::string GetSaveDataPathFor(const std::string& mount_point, u64 program_id);
|
static std::string GetSaveDataPathFor(const std::string& mount_point, u64 program_id);
|
||||||
|
@ -57,25 +57,25 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c
|
|||||||
std::string fullpath = GetSystemSaveDataPath(base_path, path);
|
std::string fullpath = GetSystemSaveDataPath(base_path, path);
|
||||||
if (!FileUtil::Exists(fullpath)) {
|
if (!FileUtil::Exists(fullpath)) {
|
||||||
// TODO(Subv): Check error code, this one is probably wrong
|
// TODO(Subv): Check error code, this one is probably wrong
|
||||||
return ERROR_NOT_FOUND;
|
return ResultNotFound;
|
||||||
}
|
}
|
||||||
return std::make_unique<SaveDataArchive>(fullpath);
|
return std::make_unique<SaveDataArchive>(fullpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path,
|
Result ArchiveFactory_SystemSaveData::Format(const Path& path,
|
||||||
const FileSys::ArchiveFormatInfo& format_info,
|
const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) {
|
u64 program_id) {
|
||||||
std::string fullpath = GetSystemSaveDataPath(base_path, path);
|
std::string fullpath = GetSystemSaveDataPath(base_path, path);
|
||||||
FileUtil::DeleteDirRecursively(fullpath);
|
FileUtil::DeleteDirRecursively(fullpath);
|
||||||
FileUtil::CreateFullPath(fullpath);
|
FileUtil::CreateFullPath(fullpath);
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<ArchiveFormatInfo> ArchiveFactory_SystemSaveData::GetFormatInfo(const Path& path,
|
ResultVal<ArchiveFormatInfo> ArchiveFactory_SystemSaveData::GetFormatInfo(const Path& path,
|
||||||
u64 program_id) const {
|
u64 program_id) const {
|
||||||
// TODO(Subv): Implement
|
// TODO(Subv): Implement
|
||||||
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
|
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
explicit ArchiveFactory_SystemSaveData(const std::string& mount_point);
|
explicit ArchiveFactory_SystemSaveData(const std::string& mount_point);
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
|
||||||
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
|
||||||
u64 program_id) override;
|
u64 program_id) override;
|
||||||
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ namespace FileSys {
|
|||||||
ResultVal<std::size_t> DiskFile::Read(const u64 offset, const std::size_t length,
|
ResultVal<std::size_t> DiskFile::Read(const u64 offset, const std::size_t length,
|
||||||
u8* buffer) const {
|
u8* buffer) const {
|
||||||
if (!mode.read_flag)
|
if (!mode.read_flag)
|
||||||
return ERROR_INVALID_OPEN_FLAGS;
|
return ResultInvalidOpenFlags;
|
||||||
|
|
||||||
file->Seek(offset, SEEK_SET);
|
file->Seek(offset, SEEK_SET);
|
||||||
return file->ReadBytes(buffer, length);
|
return file->ReadBytes(buffer, length);
|
||||||
@ -28,7 +28,7 @@ ResultVal<std::size_t> DiskFile::Read(const u64 offset, const std::size_t length
|
|||||||
ResultVal<std::size_t> DiskFile::Write(const u64 offset, const std::size_t length, const bool flush,
|
ResultVal<std::size_t> DiskFile::Write(const u64 offset, const std::size_t length, const bool flush,
|
||||||
const u8* buffer) {
|
const u8* buffer) {
|
||||||
if (!mode.write_flag)
|
if (!mode.write_flag)
|
||||||
return ERROR_INVALID_OPEN_FLAGS;
|
return ResultInvalidOpenFlags;
|
||||||
|
|
||||||
file->Seek(offset, SEEK_SET);
|
file->Seek(offset, SEEK_SET);
|
||||||
std::size_t written = file->WriteBytes(buffer, length);
|
std::size_t written = file->WriteBytes(buffer, length);
|
||||||
|
@ -35,63 +35,60 @@ enum {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ResultCode ERROR_INVALID_PATH(ErrCodes::InvalidPath, ErrorModule::FS,
|
constexpr Result ResultInvalidPath(ErrCodes::InvalidPath, ErrorModule::FS,
|
||||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||||
constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ErrCodes::UnsupportedOpenFlags, ErrorModule::FS,
|
constexpr Result ResultUnsupportedOpenFlags(ErrCodes::UnsupportedOpenFlags, ErrorModule::FS,
|
||||||
ErrorSummary::NotSupported, ErrorLevel::Usage);
|
ErrorSummary::NotSupported, ErrorLevel::Usage);
|
||||||
constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(ErrCodes::InvalidOpenFlags, ErrorModule::FS,
|
constexpr Result ResultInvalidOpenFlags(ErrCodes::InvalidOpenFlags, ErrorModule::FS,
|
||||||
ErrorSummary::Canceled, ErrorLevel::Status);
|
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||||
constexpr ResultCode ERROR_INVALID_READ_FLAG(ErrCodes::InvalidReadFlag, ErrorModule::FS,
|
constexpr Result ResultInvalidReadFlag(ErrCodes::InvalidReadFlag, ErrorModule::FS,
|
||||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||||
constexpr ResultCode ERROR_FILE_NOT_FOUND(ErrCodes::FileNotFound, ErrorModule::FS,
|
constexpr Result ResultFileNotFound(ErrCodes::FileNotFound, ErrorModule::FS, ErrorSummary::NotFound,
|
||||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
|
||||||
constexpr ResultCode ERROR_PATH_NOT_FOUND(ErrCodes::PathNotFound, ErrorModule::FS,
|
|
||||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
|
||||||
constexpr ResultCode ERROR_NOT_FOUND(ErrCodes::NotFound, ErrorModule::FS, ErrorSummary::NotFound,
|
|
||||||
ErrorLevel::Status);
|
ErrorLevel::Status);
|
||||||
constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ErrCodes::UnexpectedFileOrDirectory,
|
constexpr Result ResultPathNotFound(ErrCodes::PathNotFound, ErrorModule::FS, ErrorSummary::NotFound,
|
||||||
|
ErrorLevel::Status);
|
||||||
|
constexpr Result ResultNotFound(ErrCodes::NotFound, ErrorModule::FS, ErrorSummary::NotFound,
|
||||||
|
ErrorLevel::Status);
|
||||||
|
constexpr Result ResultUnexpectedFileOrDirectory(ErrCodes::UnexpectedFileOrDirectory,
|
||||||
ErrorModule::FS, ErrorSummary::NotSupported,
|
ErrorModule::FS, ErrorSummary::NotSupported,
|
||||||
ErrorLevel::Usage);
|
ErrorLevel::Usage);
|
||||||
constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC(ErrCodes::NotAFile, ErrorModule::FS,
|
constexpr Result ResultUnexpectedFileOrDirectorySdmc(ErrCodes::NotAFile, ErrorModule::FS,
|
||||||
ErrorSummary::Canceled,
|
|
||||||
ErrorLevel::Status);
|
|
||||||
constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ErrCodes::DirectoryAlreadyExists,
|
|
||||||
ErrorModule::FS, ErrorSummary::NothingHappened,
|
|
||||||
ErrorLevel::Status);
|
|
||||||
constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(ErrCodes::FileAlreadyExists, ErrorModule::FS,
|
|
||||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
|
||||||
constexpr ResultCode ERROR_ALREADY_EXISTS(ErrCodes::AlreadyExists, ErrorModule::FS,
|
|
||||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
|
||||||
constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrCodes::DirectoryNotEmpty, ErrorModule::FS,
|
|
||||||
ErrorSummary::Canceled, ErrorLevel::Status);
|
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||||
constexpr ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrCodes::GameCardNotInserted, ErrorModule::FS,
|
constexpr Result ResultDirectoryAlreadyExists(ErrCodes::DirectoryAlreadyExists, ErrorModule::FS,
|
||||||
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
|
constexpr Result ResultFileAlreadyExists(ErrCodes::FileAlreadyExists, ErrorModule::FS,
|
||||||
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
|
constexpr Result ResultAlreadyExists(ErrCodes::AlreadyExists, ErrorModule::FS,
|
||||||
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
|
constexpr Result ResultDirectoryNotEmpty(ErrCodes::DirectoryNotEmpty, ErrorModule::FS,
|
||||||
|
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||||
|
constexpr Result ResultGamecardNotInserted(ErrCodes::GameCardNotInserted, ErrorModule::FS,
|
||||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||||
constexpr ResultCode ERROR_INCORRECT_EXEFS_READ_SIZE(ErrCodes::IncorrectExeFSReadSize,
|
constexpr Result ResultIncorrectExefsReadSize(ErrCodes::IncorrectExeFSReadSize, ErrorModule::FS,
|
||||||
ErrorModule::FS, ErrorSummary::NotSupported,
|
ErrorSummary::NotSupported, ErrorLevel::Usage);
|
||||||
ErrorLevel::Usage);
|
constexpr Result ResultRomfsNotFound(ErrCodes::RomFSNotFound, ErrorModule::FS,
|
||||||
constexpr ResultCode ERROR_ROMFS_NOT_FOUND(ErrCodes::RomFSNotFound, ErrorModule::FS,
|
|
||||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||||
constexpr ResultCode ERROR_COMMAND_NOT_ALLOWED(ErrCodes::CommandNotAllowed, ErrorModule::FS,
|
constexpr Result ResultCommandNotAllowed(ErrCodes::CommandNotAllowed, ErrorModule::FS,
|
||||||
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
||||||
constexpr ResultCode ERROR_EXEFS_SECTION_NOT_FOUND(ErrCodes::ExeFSSectionNotFound, ErrorModule::FS,
|
constexpr Result ResultExefsSectionNotFound(ErrCodes::ExeFSSectionNotFound, ErrorModule::FS,
|
||||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||||
constexpr ResultCode ERROR_INSUFFICIENT_SPACE(ErrCodes::InsufficientSpace, ErrorModule::FS,
|
constexpr Result ResultInsufficientSpace(ErrCodes::InsufficientSpace, ErrorModule::FS,
|
||||||
ErrorSummary::OutOfResource, ErrorLevel::Status);
|
ErrorSummary::OutOfResource, ErrorLevel::Status);
|
||||||
|
|
||||||
/// Returned when a function is passed an invalid archive handle.
|
/// Returned when a function is passed an invalid archive handle.
|
||||||
constexpr ResultCode ERR_INVALID_ARCHIVE_HANDLE(ErrCodes::ArchiveNotMounted, ErrorModule::FS,
|
constexpr Result ResultInvalidArchiveHandle(ErrCodes::ArchiveNotMounted, ErrorModule::FS,
|
||||||
ErrorSummary::NotFound,
|
ErrorSummary::NotFound,
|
||||||
ErrorLevel::Status); // 0xC8804465
|
ErrorLevel::Status); // 0xC8804465
|
||||||
constexpr ResultCode ERR_WRITE_BEYOND_END(ErrCodes::WriteBeyondEnd, ErrorModule::FS,
|
constexpr Result ResultWriteBeyondEnd(ErrCodes::WriteBeyondEnd, ErrorModule::FS,
|
||||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variant of ERROR_NOT_FOUND returned in some places in the code. Unknown if these usages are
|
* Variant of ResultNotFound returned in some places in the code. Unknown if these usages are
|
||||||
* correct or a bug.
|
* correct or a bug.
|
||||||
*/
|
*/
|
||||||
constexpr ResultCode ERR_NOT_FOUND_INVALID_STATE(ErrCodes::NotFound, ErrorModule::FS,
|
constexpr Result ResultNotFoundInvalidState(ErrCodes::NotFound, ErrorModule::FS,
|
||||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||||
constexpr ResultCode ERR_NOT_FORMATTED(ErrCodes::NotFormatted, ErrorModule::FS,
|
constexpr Result ResultNotFormatted(ErrCodes::NotFormatted, ErrorModule::FS,
|
||||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||||
|
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
@ -34,50 +34,50 @@ ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path,
|
|||||||
return std::make_unique<IVFCFile>(romfs_file, std::move(delay_generator));
|
return std::make_unique<IVFCFile>(romfs_file, std::move(delay_generator));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode IVFCArchive::DeleteFile(const Path& path) const {
|
Result IVFCArchive::DeleteFile(const Path& path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive ({}).", GetName());
|
LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive ({}).", GetName());
|
||||||
// TODO(Subv): Verify error code
|
// TODO(Subv): Verify error code
|
||||||
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled,
|
return Result(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled,
|
||||||
ErrorLevel::Status);
|
ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
|
Result IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive ({}).", GetName());
|
LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive ({}).", GetName());
|
||||||
// TODO(wwylele): Use correct error code
|
// TODO(wwylele): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode IVFCArchive::DeleteDirectory(const Path& path) const {
|
Result IVFCArchive::DeleteDirectory(const Path& path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive ({}).",
|
LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive ({}).",
|
||||||
GetName());
|
GetName());
|
||||||
// TODO(wwylele): Use correct error code
|
// TODO(wwylele): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode IVFCArchive::DeleteDirectoryRecursively(const Path& path) const {
|
Result IVFCArchive::DeleteDirectoryRecursively(const Path& path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive ({}).",
|
LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive ({}).",
|
||||||
GetName());
|
GetName());
|
||||||
// TODO(wwylele): Use correct error code
|
// TODO(wwylele): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
|
Result IVFCArchive::CreateFile(const Path& path, u64 size) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive ({}).", GetName());
|
LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive ({}).", GetName());
|
||||||
// TODO: Verify error code
|
// TODO: Verify error code
|
||||||
return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,
|
return Result(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,
|
||||||
ErrorLevel::Permanent);
|
ErrorLevel::Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode IVFCArchive::CreateDirectory(const Path& path) const {
|
Result IVFCArchive::CreateDirectory(const Path& path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive ({}).", GetName());
|
LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive ({}).", GetName());
|
||||||
// TODO(wwylele): Use correct error code
|
// TODO(wwylele): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
|
Result IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive ({}).", GetName());
|
LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive ({}).", GetName());
|
||||||
// TODO(wwylele): Use correct error code
|
// TODO(wwylele): Use correct error code
|
||||||
return RESULT_UNKNOWN;
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<DirectoryBackend>> IVFCArchive::OpenDirectory(const Path& path) const {
|
ResultVal<std::unique_ptr<DirectoryBackend>> IVFCArchive::OpenDirectory(const Path& path) const {
|
||||||
|
@ -103,13 +103,13 @@ public:
|
|||||||
|
|
||||||
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
|
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
|
||||||
const Mode& mode) const override;
|
const Mode& mode) const override;
|
||||||
ResultCode DeleteFile(const Path& path) const override;
|
Result DeleteFile(const Path& path) const override;
|
||||||
ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
|
Result RenameFile(const Path& src_path, const Path& dest_path) const override;
|
||||||
ResultCode DeleteDirectory(const Path& path) const override;
|
Result DeleteDirectory(const Path& path) const override;
|
||||||
ResultCode DeleteDirectoryRecursively(const Path& path) const override;
|
Result DeleteDirectoryRecursively(const Path& path) const override;
|
||||||
ResultCode CreateFile(const Path& path, u64 size) const override;
|
Result CreateFile(const Path& path, u64 size) const override;
|
||||||
ResultCode CreateDirectory(const Path& path) const override;
|
Result CreateDirectory(const Path& path) const override;
|
||||||
ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
Result RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
||||||
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
|
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
|
||||||
u64 GetFreeBytes() const override;
|
u64 GetFreeBytes() const override;
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ static bool ReadSection(std::vector<u8>& data_out, FileUtil::IOFile& file, std::
|
|||||||
|
|
||||||
Loader::ResultStatus FileSys::Plugin3GXLoader::Load(
|
Loader::ResultStatus FileSys::Plugin3GXLoader::Load(
|
||||||
Service::PLGLDR::PLG_LDR::PluginLoaderContext& plg_context, Kernel::Process& process,
|
Service::PLGLDR::PLG_LDR::PluginLoaderContext& plg_context, Kernel::Process& process,
|
||||||
Kernel::KernelSystem& kernel) {
|
Kernel::KernelSystem& kernel, Service::PLGLDR::PLG_LDR& plg_ldr) {
|
||||||
FileUtil::IOFile file(plg_context.plugin_path, "rb");
|
FileUtil::IOFile file(plg_context.plugin_path, "rb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_ERROR(Service_PLGLDR, "Failed to load 3GX plugin. Not found: {}",
|
LOG_ERROR(Service_PLGLDR, "Failed to load 3GX plugin. Not found: {}",
|
||||||
@ -158,12 +158,12 @@ Loader::ResultStatus FileSys::Plugin3GXLoader::Load(
|
|||||||
return Loader::ResultStatus::Error;
|
return Loader::ResultStatus::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Map(plg_context, process, kernel);
|
return Map(plg_context, process, kernel, plg_ldr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader::ResultStatus FileSys::Plugin3GXLoader::Map(
|
Loader::ResultStatus FileSys::Plugin3GXLoader::Map(
|
||||||
Service::PLGLDR::PLG_LDR::PluginLoaderContext& plg_context, Kernel::Process& process,
|
Service::PLGLDR::PLG_LDR::PluginLoaderContext& plg_context, Kernel::Process& process,
|
||||||
Kernel::KernelSystem& kernel) {
|
Kernel::KernelSystem& kernel, Service::PLGLDR::PLG_LDR& plg_ldr) {
|
||||||
|
|
||||||
// Verify exe load checksum function is available
|
// Verify exe load checksum function is available
|
||||||
if (exe_load_func.empty() && plg_context.load_exe_func.empty()) {
|
if (exe_load_func.empty() && plg_context.load_exe_func.empty()) {
|
||||||
@ -195,7 +195,7 @@ Loader::ResultStatus FileSys::Plugin3GXLoader::Map(
|
|||||||
return Loader::ResultStatus::ErrorMemoryAllocationFailed;
|
return Loader::ResultStatus::ErrorMemoryAllocationFailed;
|
||||||
}
|
}
|
||||||
auto backing_memory_fb = kernel.memory.GetFCRAMRef(*offset_fb);
|
auto backing_memory_fb = kernel.memory.GetFCRAMRef(*offset_fb);
|
||||||
Service::PLGLDR::PLG_LDR::SetPluginFBAddr(Memory::FCRAM_PADDR + *offset_fb);
|
plg_ldr.SetPluginFBAddr(Memory::FCRAM_PADDR + *offset_fb);
|
||||||
std::fill(backing_memory_fb.GetPtr(), backing_memory_fb.GetPtr() + _3GX_fb_size, 0);
|
std::fill(backing_memory_fb.GetPtr(), backing_memory_fb.GetPtr() + _3GX_fb_size, 0);
|
||||||
|
|
||||||
auto vma_heap_fb = process.vm_manager.MapBackingMemory(
|
auto vma_heap_fb = process.vm_manager.MapBackingMemory(
|
||||||
|
@ -43,7 +43,8 @@ class FileBackend;
|
|||||||
class Plugin3GXLoader {
|
class Plugin3GXLoader {
|
||||||
public:
|
public:
|
||||||
Loader::ResultStatus Load(Service::PLGLDR::PLG_LDR::PluginLoaderContext& plg_context,
|
Loader::ResultStatus Load(Service::PLGLDR::PLG_LDR::PluginLoaderContext& plg_context,
|
||||||
Kernel::Process& process, Kernel::KernelSystem& kernel);
|
Kernel::Process& process, Kernel::KernelSystem& kernel,
|
||||||
|
Service::PLGLDR::PLG_LDR& plg_ldr);
|
||||||
|
|
||||||
struct PluginHeader {
|
struct PluginHeader {
|
||||||
u32_le magic;
|
u32_le magic;
|
||||||
@ -68,7 +69,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Loader::ResultStatus Map(Service::PLGLDR::PLG_LDR::PluginLoaderContext& plg_context,
|
Loader::ResultStatus Map(Service::PLGLDR::PLG_LDR::PluginLoaderContext& plg_context,
|
||||||
Kernel::Process& process, Kernel::KernelSystem& kernel);
|
Kernel::Process& process, Kernel::KernelSystem& kernel,
|
||||||
|
Service::PLGLDR::PLG_LDR& plg_ldr);
|
||||||
|
|
||||||
static constexpr size_t bootloader_memory_size = 0x1000;
|
static constexpr size_t bootloader_memory_size = 0x1000;
|
||||||
static void MapBootloader(Kernel::Process& process, Kernel::KernelSystem& kernel,
|
static void MapBootloader(Kernel::Process& process, Kernel::KernelSystem& kernel,
|
||||||
|
@ -43,17 +43,17 @@ ResultVal<std::unique_ptr<FileBackend>> SaveDataArchive::OpenFile(const Path& pa
|
|||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode.hex == 0) {
|
if (mode.hex == 0) {
|
||||||
LOG_ERROR(Service_FS, "Empty open mode");
|
LOG_ERROR(Service_FS, "Empty open mode");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode.create_flag && !mode.write_flag) {
|
if (mode.create_flag && !mode.write_flag) {
|
||||||
LOG_ERROR(Service_FS, "Create flag set but write flag not set");
|
LOG_ERROR(Service_FS, "Create flag set but write flag not set");
|
||||||
return ERROR_UNSUPPORTED_OPEN_FLAGS;
|
return ResultUnsupportedOpenFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -61,19 +61,19 @@ ResultVal<std::unique_ptr<FileBackend>> SaveDataArchive::OpenFile(const Path& pa
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_PATH_NOT_FOUND;
|
return ResultPathNotFound;
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
LOG_ERROR(Service_FS, "Unexpected file or directory in {}", full_path);
|
LOG_ERROR(Service_FS, "Unexpected file or directory in {}", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY;
|
return ResultUnexpectedFileOrDirectory;
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
if (!mode.create_flag) {
|
if (!mode.create_flag) {
|
||||||
LOG_ERROR(Service_FS, "Non-existing file {} can't be open without mode create.",
|
LOG_ERROR(Service_FS, "Non-existing file {} can't be open without mode create.",
|
||||||
full_path);
|
full_path);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
} else {
|
} else {
|
||||||
// Create the file
|
// Create the file
|
||||||
FileUtil::CreateEmptyFile(full_path);
|
FileUtil::CreateEmptyFile(full_path);
|
||||||
@ -86,19 +86,19 @@ ResultVal<std::unique_ptr<FileBackend>> SaveDataArchive::OpenFile(const Path& pa
|
|||||||
FileUtil::IOFile file(full_path, mode.write_flag ? "r+b" : "rb");
|
FileUtil::IOFile file(full_path, mode.write_flag ? "r+b" : "rb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error opening {}", full_path);
|
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error opening {}", full_path);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<SaveDataDelayGenerator>();
|
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<SaveDataDelayGenerator>();
|
||||||
return std::make_unique<DiskFile>(std::move(file), mode, std::move(delay_generator));
|
return std::make_unique<DiskFile>(std::move(file), mode, std::move(delay_generator));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SaveDataArchive::DeleteFile(const Path& path) const {
|
Result SaveDataArchive::DeleteFile(const Path& path) const {
|
||||||
const PathParser path_parser(path);
|
const PathParser path_parser(path);
|
||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -106,110 +106,109 @@ ResultCode SaveDataArchive::DeleteFile(const Path& path) const {
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_PATH_NOT_FOUND;
|
return ResultPathNotFound;
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
LOG_ERROR(Service_FS, "File not found {}", full_path);
|
LOG_ERROR(Service_FS, "File not found {}", full_path);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FileUtil::Delete(full_path)) {
|
if (FileUtil::Delete(full_path)) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error deleting {}", full_path);
|
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error deleting {}", full_path);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SaveDataArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
|
Result SaveDataArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
|
||||||
const PathParser path_parser_src(src_path);
|
const PathParser path_parser_src(src_path);
|
||||||
|
|
||||||
// TODO: Verify these return codes with HW
|
// TODO: Verify these return codes with HW
|
||||||
if (!path_parser_src.IsValid()) {
|
if (!path_parser_src.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PathParser path_parser_dest(dest_path);
|
const PathParser path_parser_dest(dest_path);
|
||||||
|
|
||||||
if (!path_parser_dest.IsValid()) {
|
if (!path_parser_dest.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
|
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
|
||||||
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
|
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
|
||||||
|
|
||||||
if (FileUtil::Rename(src_path_full, dest_path_full)) {
|
if (FileUtil::Rename(src_path_full, dest_path_full)) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
|
// TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
|
||||||
// exist or similar. Verify.
|
// exist or similar. Verify.
|
||||||
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
return Result(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
||||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static ResultCode DeleteDirectoryHelper(const Path& path, const std::string& mount_point,
|
static Result DeleteDirectoryHelper(const Path& path, const std::string& mount_point, T deleter) {
|
||||||
T deleter) {
|
|
||||||
const PathParser path_parser(path);
|
const PathParser path_parser(path);
|
||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path_parser.IsRootDirectory())
|
if (path_parser.IsRootDirectory())
|
||||||
return ERROR_DIRECTORY_NOT_EMPTY;
|
return ResultDirectoryNotEmpty;
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
|
|
||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_PATH_NOT_FOUND;
|
return ResultPathNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_PATH_NOT_FOUND;
|
return ResultPathNotFound;
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
LOG_ERROR(Service_FS, "Unexpected file or directory {}", full_path);
|
LOG_ERROR(Service_FS, "Unexpected file or directory {}", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY;
|
return ResultUnexpectedFileOrDirectory;
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleter(full_path)) {
|
if (deleter(full_path)) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_FS, "Directory not empty {}", full_path);
|
LOG_ERROR(Service_FS, "Directory not empty {}", full_path);
|
||||||
return ERROR_DIRECTORY_NOT_EMPTY;
|
return ResultDirectoryNotEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SaveDataArchive::DeleteDirectory(const Path& path) const {
|
Result SaveDataArchive::DeleteDirectory(const Path& path) const {
|
||||||
return DeleteDirectoryHelper(path, mount_point, FileUtil::DeleteDir);
|
return DeleteDirectoryHelper(path, mount_point, FileUtil::DeleteDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SaveDataArchive::DeleteDirectoryRecursively(const Path& path) const {
|
Result SaveDataArchive::DeleteDirectoryRecursively(const Path& path) const {
|
||||||
return DeleteDirectoryHelper(
|
return DeleteDirectoryHelper(
|
||||||
path, mount_point, [](const std::string& p) { return FileUtil::DeleteDirRecursively(p); });
|
path, mount_point, [](const std::string& p) { return FileUtil::DeleteDirRecursively(p); });
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SaveDataArchive::CreateFile(const FileSys::Path& path, u64 size) const {
|
Result SaveDataArchive::CreateFile(const FileSys::Path& path, u64 size) const {
|
||||||
const PathParser path_parser(path);
|
const PathParser path_parser(path);
|
||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -217,44 +216,44 @@ ResultCode SaveDataArchive::CreateFile(const FileSys::Path& path, u64 size) cons
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_PATH_NOT_FOUND;
|
return ResultPathNotFound;
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path);
|
LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY;
|
return ResultUnexpectedFileOrDirectory;
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
LOG_ERROR(Service_FS, "{} already exists", full_path);
|
LOG_ERROR(Service_FS, "{} already exists", full_path);
|
||||||
return ERROR_FILE_ALREADY_EXISTS;
|
return ResultFileAlreadyExists;
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
FileUtil::CreateEmptyFile(full_path);
|
FileUtil::CreateEmptyFile(full_path);
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil::IOFile file(full_path, "wb");
|
FileUtil::IOFile file(full_path, "wb");
|
||||||
// Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
|
// Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
|
||||||
// We do this by seeking to the right size, then writing a single null byte.
|
// We do this by seeking to the right size, then writing a single null byte.
|
||||||
if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) {
|
if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_FS, "Too large file");
|
LOG_ERROR(Service_FS, "Too large file");
|
||||||
return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource,
|
return Result(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource,
|
||||||
ErrorLevel::Info);
|
ErrorLevel::Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SaveDataArchive::CreateDirectory(const Path& path) const {
|
Result SaveDataArchive::CreateDirectory(const Path& path) const {
|
||||||
const PathParser path_parser(path);
|
const PathParser path_parser(path);
|
||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -262,56 +261,56 @@ ResultCode SaveDataArchive::CreateDirectory(const Path& path) const {
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_PATH_NOT_FOUND;
|
return ResultPathNotFound;
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path);
|
LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY;
|
return ResultUnexpectedFileOrDirectory;
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
LOG_ERROR(Service_FS, "{} already exists", full_path);
|
LOG_ERROR(Service_FS, "{} already exists", full_path);
|
||||||
return ERROR_DIRECTORY_ALREADY_EXISTS;
|
return ResultDirectoryAlreadyExists;
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FileUtil::CreateDir(mount_point + path.AsString())) {
|
if (FileUtil::CreateDir(mount_point + path.AsString())) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error creating {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error creating {}", mount_point);
|
||||||
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled,
|
return Result(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled,
|
||||||
ErrorLevel::Status);
|
ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SaveDataArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
|
Result SaveDataArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
|
||||||
const PathParser path_parser_src(src_path);
|
const PathParser path_parser_src(src_path);
|
||||||
|
|
||||||
// TODO: Verify these return codes with HW
|
// TODO: Verify these return codes with HW
|
||||||
if (!path_parser_src.IsValid()) {
|
if (!path_parser_src.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PathParser path_parser_dest(dest_path);
|
const PathParser path_parser_dest(dest_path);
|
||||||
|
|
||||||
if (!path_parser_dest.IsValid()) {
|
if (!path_parser_dest.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
|
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
|
||||||
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
|
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
|
||||||
|
|
||||||
if (FileUtil::Rename(src_path_full, dest_path_full)) {
|
if (FileUtil::Rename(src_path_full, dest_path_full)) {
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
|
// TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
|
||||||
// exist or similar. Verify.
|
// exist or similar. Verify.
|
||||||
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
return Result(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
||||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,7 +320,7 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SaveDataArchive::OpenDirectory(
|
|||||||
|
|
||||||
if (!path_parser.IsValid()) {
|
if (!path_parser.IsValid()) {
|
||||||
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr());
|
||||||
return ERROR_INVALID_PATH;
|
return ResultInvalidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto full_path = path_parser.BuildHostPath(mount_point);
|
const auto full_path = path_parser.BuildHostPath(mount_point);
|
||||||
@ -329,15 +328,15 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SaveDataArchive::OpenDirectory(
|
|||||||
switch (path_parser.GetHostStatus(mount_point)) {
|
switch (path_parser.GetHostStatus(mount_point)) {
|
||||||
case PathParser::InvalidMountPoint:
|
case PathParser::InvalidMountPoint:
|
||||||
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point);
|
||||||
return ERROR_FILE_NOT_FOUND;
|
return ResultFileNotFound;
|
||||||
case PathParser::PathNotFound:
|
case PathParser::PathNotFound:
|
||||||
case PathParser::NotFound:
|
case PathParser::NotFound:
|
||||||
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
LOG_ERROR(Service_FS, "Path not found {}", full_path);
|
||||||
return ERROR_PATH_NOT_FOUND;
|
return ResultPathNotFound;
|
||||||
case PathParser::FileInPath:
|
case PathParser::FileInPath:
|
||||||
case PathParser::FileFound:
|
case PathParser::FileFound:
|
||||||
LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path);
|
LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path);
|
||||||
return ERROR_UNEXPECTED_FILE_OR_DIRECTORY;
|
return ResultUnexpectedFileOrDirectory;
|
||||||
case PathParser::DirectoryFound:
|
case PathParser::DirectoryFound:
|
||||||
break; // Expected 'success' case
|
break; // Expected 'success' case
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,13 @@ public:
|
|||||||
|
|
||||||
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
|
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
|
||||||
const Mode& mode) const override;
|
const Mode& mode) const override;
|
||||||
ResultCode DeleteFile(const Path& path) const override;
|
Result DeleteFile(const Path& path) const override;
|
||||||
ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
|
Result RenameFile(const Path& src_path, const Path& dest_path) const override;
|
||||||
ResultCode DeleteDirectory(const Path& path) const override;
|
Result DeleteDirectory(const Path& path) const override;
|
||||||
ResultCode DeleteDirectoryRecursively(const Path& path) const override;
|
Result DeleteDirectoryRecursively(const Path& path) const override;
|
||||||
ResultCode CreateFile(const Path& path, u64 size) const override;
|
Result CreateFile(const Path& path, u64 size) const override;
|
||||||
ResultCode CreateDirectory(const Path& path) const override;
|
Result CreateDirectory(const Path& path) const override;
|
||||||
ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
Result RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
||||||
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
|
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
|
||||||
u64 GetFreeBytes() const override;
|
u64 GetFreeBytes() const override;
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace Frontend {
|
namespace Frontend {
|
||||||
void RegisterDefaultApplets(Core::System& system) {
|
void RegisterDefaultApplets(Core::System& system) {
|
||||||
system.RegisterSoftwareKeyboard(std::make_shared<DefaultKeyboard>());
|
system.RegisterSoftwareKeyboard(std::make_shared<DefaultKeyboard>(system));
|
||||||
system.RegisterMiiSelector(std::make_shared<DefaultMiiSelector>());
|
system.RegisterMiiSelector(std::make_shared<DefaultMiiSelector>());
|
||||||
}
|
}
|
||||||
} // namespace Frontend
|
} // namespace Frontend
|
||||||
|
@ -144,10 +144,12 @@ const KeyboardData& SoftwareKeyboard::ReceiveData() {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefaultKeyboard::DefaultKeyboard(Core::System& system_) : system(system_) {}
|
||||||
|
|
||||||
void DefaultKeyboard::Execute(const Frontend::KeyboardConfig& config_) {
|
void DefaultKeyboard::Execute(const Frontend::KeyboardConfig& config_) {
|
||||||
SoftwareKeyboard::Execute(config_);
|
SoftwareKeyboard::Execute(config_);
|
||||||
|
|
||||||
auto cfg = Service::CFG::GetModule(Core::System::GetInstance());
|
auto cfg = Service::CFG::GetModule(system);
|
||||||
std::string username = Common::UTF16ToUTF8(cfg->GetUsername());
|
std::string username = Common::UTF16ToUTF8(cfg->GetUsername());
|
||||||
switch (this->config.button_config) {
|
switch (this->config.button_config) {
|
||||||
case ButtonConfig::None:
|
case ButtonConfig::None:
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Frontend {
|
namespace Frontend {
|
||||||
|
|
||||||
enum class AcceptedInput {
|
enum class AcceptedInput {
|
||||||
@ -137,8 +141,12 @@ protected:
|
|||||||
|
|
||||||
class DefaultKeyboard final : public SoftwareKeyboard {
|
class DefaultKeyboard final : public SoftwareKeyboard {
|
||||||
public:
|
public:
|
||||||
|
explicit DefaultKeyboard(Core::System& system_);
|
||||||
void Execute(const KeyboardConfig& config) override;
|
void Execute(const KeyboardConfig& config) override;
|
||||||
void ShowError(const std::string& error) override;
|
void ShowError(const std::string& error) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Core::System& system;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Frontend
|
} // namespace Frontend
|
||||||
|
@ -173,8 +173,7 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
|
|||||||
TouchPressed(framebuffer_x, framebuffer_y);
|
TouchPressed(framebuffer_x, framebuffer_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height,
|
void EmuWindow::UpdateCurrentFramebufferLayout(u32 width, u32 height, bool is_portrait_mode) {
|
||||||
bool is_portrait_mode) {
|
|
||||||
Layout::FramebufferLayout layout;
|
Layout::FramebufferLayout layout;
|
||||||
|
|
||||||
// If in portrait mode, only the MobilePortrait option really makes sense
|
// If in portrait mode, only the MobilePortrait option really makes sense
|
||||||
@ -200,7 +199,8 @@ void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height,
|
|||||||
layout =
|
layout =
|
||||||
Layout::LargeFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
Layout::LargeFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
||||||
Settings::values.upright_screen.GetValue(),
|
Settings::values.upright_screen.GetValue(),
|
||||||
Settings::values.large_screen_proportion.GetValue());
|
Settings::values.large_screen_proportion.GetValue(),
|
||||||
|
Layout::VerticalAlignment::Bottom);
|
||||||
break;
|
break;
|
||||||
case Settings::LayoutOption::HybridScreen:
|
case Settings::LayoutOption::HybridScreen:
|
||||||
layout =
|
layout =
|
||||||
@ -208,8 +208,10 @@ void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height,
|
|||||||
Settings::values.upright_screen.GetValue());
|
Settings::values.upright_screen.GetValue());
|
||||||
break;
|
break;
|
||||||
case Settings::LayoutOption::SideScreen:
|
case Settings::LayoutOption::SideScreen:
|
||||||
layout = Layout::SideFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
layout =
|
||||||
Settings::values.upright_screen.GetValue());
|
Layout::LargeFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
||||||
|
Settings::values.upright_screen.GetValue(), 1.0f,
|
||||||
|
Layout::VerticalAlignment::Bottom);
|
||||||
break;
|
break;
|
||||||
#ifndef ANDROID
|
#ifndef ANDROID
|
||||||
case Settings::LayoutOption::SeparateWindows:
|
case Settings::LayoutOption::SeparateWindows:
|
||||||
@ -222,8 +224,9 @@ void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height,
|
|||||||
Settings::values.swap_screen.GetValue());
|
Settings::values.swap_screen.GetValue());
|
||||||
break;
|
break;
|
||||||
case Settings::LayoutOption::MobileLandscape:
|
case Settings::LayoutOption::MobileLandscape:
|
||||||
layout = Layout::MobileLandscapeFrameLayout(
|
layout =
|
||||||
width, height, Settings::values.swap_screen.GetValue(), 2.25f, false);
|
Layout::LargeFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
||||||
|
false, 2.25f, Layout::VerticalAlignment::Top);
|
||||||
break;
|
break;
|
||||||
case Settings::LayoutOption::Default:
|
case Settings::LayoutOption::Default:
|
||||||
default:
|
default:
|
||||||
|
@ -30,7 +30,7 @@ u32 FramebufferLayout::GetScalingRatio() const {
|
|||||||
|
|
||||||
// Finds the largest size subrectangle contained in window area that is confined to the aspect ratio
|
// Finds the largest size subrectangle contained in window area that is confined to the aspect ratio
|
||||||
template <class T>
|
template <class T>
|
||||||
static Common::Rectangle<T> maxRectangle(Common::Rectangle<T> window_area,
|
static Common::Rectangle<T> MaxRectangle(Common::Rectangle<T> window_area,
|
||||||
float screen_aspect_ratio) {
|
float screen_aspect_ratio) {
|
||||||
float scale = std::min(static_cast<float>(window_area.GetWidth()),
|
float scale = std::min(static_cast<float>(window_area.GetWidth()),
|
||||||
window_area.GetHeight() / screen_aspect_ratio);
|
window_area.GetHeight() / screen_aspect_ratio);
|
||||||
@ -50,15 +50,15 @@ FramebufferLayout DefaultFrameLayout(u32 width, u32 height, bool swapped, bool u
|
|||||||
if (upright) {
|
if (upright) {
|
||||||
// Default layout gives equal screen sizes to the top and bottom screen
|
// Default layout gives equal screen sizes to the top and bottom screen
|
||||||
screen_window_area = {0, 0, width / 2, height};
|
screen_window_area = {0, 0, width / 2, height};
|
||||||
top_screen = maxRectangle(screen_window_area, TOP_SCREEN_UPRIGHT_ASPECT_RATIO);
|
top_screen = MaxRectangle(screen_window_area, TOP_SCREEN_UPRIGHT_ASPECT_RATIO);
|
||||||
bot_screen = maxRectangle(screen_window_area, BOT_SCREEN_UPRIGHT_ASPECT_RATIO);
|
bot_screen = MaxRectangle(screen_window_area, BOT_SCREEN_UPRIGHT_ASPECT_RATIO);
|
||||||
// both screens width are taken into account by dividing by 2
|
// both screens width are taken into account by dividing by 2
|
||||||
emulation_aspect_ratio = TOP_SCREEN_UPRIGHT_ASPECT_RATIO / 2;
|
emulation_aspect_ratio = TOP_SCREEN_UPRIGHT_ASPECT_RATIO / 2;
|
||||||
} else {
|
} else {
|
||||||
// Default layout gives equal screen sizes to the top and bottom screen
|
// Default layout gives equal screen sizes to the top and bottom screen
|
||||||
screen_window_area = {0, 0, width, height / 2};
|
screen_window_area = {0, 0, width, height / 2};
|
||||||
top_screen = maxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO);
|
top_screen = MaxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO);
|
||||||
bot_screen = maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
|
bot_screen = MaxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
|
||||||
// both screens height are taken into account by multiplying by 2
|
// both screens height are taken into account by multiplying by 2
|
||||||
emulation_aspect_ratio = TOP_SCREEN_ASPECT_RATIO * 2;
|
emulation_aspect_ratio = TOP_SCREEN_ASPECT_RATIO * 2;
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ FramebufferLayout DefaultFrameLayout(u32 width, u32 height, bool swapped, bool u
|
|||||||
// Recalculate the bottom screen to account for the height difference between right and
|
// Recalculate the bottom screen to account for the height difference between right and
|
||||||
// left
|
// left
|
||||||
screen_window_area = {0, 0, top_screen.GetWidth(), height};
|
screen_window_area = {0, 0, top_screen.GetWidth(), height};
|
||||||
bot_screen = maxRectangle(screen_window_area, BOT_SCREEN_UPRIGHT_ASPECT_RATIO);
|
bot_screen = MaxRectangle(screen_window_area, BOT_SCREEN_UPRIGHT_ASPECT_RATIO);
|
||||||
bot_screen =
|
bot_screen =
|
||||||
bot_screen.TranslateY((top_screen.GetHeight() - bot_screen.GetHeight()) / 2);
|
bot_screen.TranslateY((top_screen.GetHeight() - bot_screen.GetHeight()) / 2);
|
||||||
if (swapped) {
|
if (swapped) {
|
||||||
@ -96,7 +96,7 @@ FramebufferLayout DefaultFrameLayout(u32 width, u32 height, bool swapped, bool u
|
|||||||
// Recalculate the bottom screen to account for the width difference between top and
|
// Recalculate the bottom screen to account for the width difference between top and
|
||||||
// bottom
|
// bottom
|
||||||
screen_window_area = {0, 0, width, top_screen.GetHeight()};
|
screen_window_area = {0, 0, width, top_screen.GetHeight()};
|
||||||
bot_screen = maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
|
bot_screen = MaxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
|
||||||
bot_screen = bot_screen.TranslateX((top_screen.GetWidth() - bot_screen.GetWidth()) / 2);
|
bot_screen = bot_screen.TranslateX((top_screen.GetWidth() - bot_screen.GetWidth()) / 2);
|
||||||
if (swapped) {
|
if (swapped) {
|
||||||
bot_screen = bot_screen.TranslateY(height / 2 - bot_screen.GetHeight());
|
bot_screen = bot_screen.TranslateY(height / 2 - bot_screen.GetHeight());
|
||||||
@ -124,8 +124,8 @@ FramebufferLayout MobilePortraitFrameLayout(u32 width, u32 height, bool swapped)
|
|||||||
FramebufferLayout res{width, height, true, true, {}, {}};
|
FramebufferLayout res{width, height, true, true, {}, {}};
|
||||||
// Default layout gives equal screen sizes to the top and bottom screen
|
// Default layout gives equal screen sizes to the top and bottom screen
|
||||||
Common::Rectangle<u32> screen_window_area{0, 0, width, height / 2};
|
Common::Rectangle<u32> screen_window_area{0, 0, width, height / 2};
|
||||||
Common::Rectangle<u32> top_screen = maxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO);
|
Common::Rectangle<u32> top_screen = MaxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO);
|
||||||
Common::Rectangle<u32> bot_screen = maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
|
Common::Rectangle<u32> bot_screen = MaxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
|
||||||
|
|
||||||
float window_aspect_ratio = static_cast<float>(height) / width;
|
float window_aspect_ratio = static_cast<float>(height) / width;
|
||||||
// both screens height are taken into account by multiplying by 2
|
// both screens height are taken into account by multiplying by 2
|
||||||
@ -151,48 +151,6 @@ FramebufferLayout MobilePortraitFrameLayout(u32 width, u32 height, bool swapped)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
FramebufferLayout MobileLandscapeFrameLayout(u32 width, u32 height, bool swapped,
|
|
||||||
float scale_factor, bool center_vertical) {
|
|
||||||
ASSERT(width > 0);
|
|
||||||
ASSERT(height > 0);
|
|
||||||
|
|
||||||
FramebufferLayout res{width, height, true, true, {}, {}};
|
|
||||||
// Split the window into two parts. Give 4x width to the main screen and 1x width to the small
|
|
||||||
// To do that, find the total emulation box and maximize that based on window size
|
|
||||||
float window_aspect_ratio = static_cast<float>(height) / width;
|
|
||||||
float emulation_aspect_ratio =
|
|
||||||
swapped ? Core::kScreenBottomHeight * scale_factor /
|
|
||||||
(Core::kScreenBottomWidth * scale_factor + Core::kScreenTopWidth)
|
|
||||||
: Core::kScreenTopHeight * scale_factor /
|
|
||||||
(Core::kScreenTopWidth * scale_factor + Core::kScreenBottomWidth);
|
|
||||||
float large_screen_aspect_ratio = swapped ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO;
|
|
||||||
float small_screen_aspect_ratio = swapped ? TOP_SCREEN_ASPECT_RATIO : BOT_SCREEN_ASPECT_RATIO;
|
|
||||||
|
|
||||||
Common::Rectangle<u32> screen_window_area{0, 0, width, height};
|
|
||||||
Common::Rectangle<u32> total_rect = maxRectangle(screen_window_area, emulation_aspect_ratio);
|
|
||||||
Common::Rectangle<u32> large_screen = maxRectangle(total_rect, large_screen_aspect_ratio);
|
|
||||||
Common::Rectangle<u32> fourth_size_rect = total_rect.Scale(1.f / scale_factor);
|
|
||||||
Common::Rectangle<u32> small_screen = maxRectangle(fourth_size_rect, small_screen_aspect_ratio);
|
|
||||||
|
|
||||||
if (window_aspect_ratio < emulation_aspect_ratio) {
|
|
||||||
large_screen =
|
|
||||||
large_screen.TranslateX((screen_window_area.GetWidth() - total_rect.GetWidth()) / 2);
|
|
||||||
} else if (center_vertical) {
|
|
||||||
large_screen = large_screen.TranslateY((height - total_rect.GetHeight()) / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shift the small screen to the bottom right corner
|
|
||||||
small_screen = small_screen.TranslateX(large_screen.right);
|
|
||||||
if (center_vertical) {
|
|
||||||
small_screen = small_screen.TranslateY(large_screen.GetHeight() + large_screen.top -
|
|
||||||
small_screen.GetHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
res.top_screen = swapped ? small_screen : large_screen;
|
|
||||||
res.bottom_screen = swapped ? large_screen : small_screen;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool swapped, bool upright) {
|
FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool swapped, bool upright) {
|
||||||
ASSERT(width > 0);
|
ASSERT(width > 0);
|
||||||
ASSERT(height > 0);
|
ASSERT(height > 0);
|
||||||
@ -205,13 +163,13 @@ FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool swapped, bool up
|
|||||||
Common::Rectangle<u32> bot_screen;
|
Common::Rectangle<u32> bot_screen;
|
||||||
float emulation_aspect_ratio;
|
float emulation_aspect_ratio;
|
||||||
if (upright) {
|
if (upright) {
|
||||||
top_screen = maxRectangle(screen_window_area, TOP_SCREEN_UPRIGHT_ASPECT_RATIO);
|
top_screen = MaxRectangle(screen_window_area, TOP_SCREEN_UPRIGHT_ASPECT_RATIO);
|
||||||
bot_screen = maxRectangle(screen_window_area, BOT_SCREEN_UPRIGHT_ASPECT_RATIO);
|
bot_screen = MaxRectangle(screen_window_area, BOT_SCREEN_UPRIGHT_ASPECT_RATIO);
|
||||||
emulation_aspect_ratio =
|
emulation_aspect_ratio =
|
||||||
(swapped) ? BOT_SCREEN_UPRIGHT_ASPECT_RATIO : TOP_SCREEN_UPRIGHT_ASPECT_RATIO;
|
(swapped) ? BOT_SCREEN_UPRIGHT_ASPECT_RATIO : TOP_SCREEN_UPRIGHT_ASPECT_RATIO;
|
||||||
} else {
|
} else {
|
||||||
top_screen = maxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO);
|
top_screen = MaxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO);
|
||||||
bot_screen = maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
|
bot_screen = MaxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
|
||||||
emulation_aspect_ratio = (swapped) ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO;
|
emulation_aspect_ratio = (swapped) ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +190,7 @@ FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool swapped, bool up
|
|||||||
}
|
}
|
||||||
|
|
||||||
FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool swapped, bool upright,
|
FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool swapped, bool upright,
|
||||||
float scale_factor) {
|
float scale_factor, VerticalAlignment vertical_alignment) {
|
||||||
ASSERT(width > 0);
|
ASSERT(width > 0);
|
||||||
ASSERT(height > 0);
|
ASSERT(height > 0);
|
||||||
|
|
||||||
@ -274,10 +232,10 @@ FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool swapped, bool upr
|
|||||||
}
|
}
|
||||||
|
|
||||||
Common::Rectangle<u32> screen_window_area{0, 0, width, height};
|
Common::Rectangle<u32> screen_window_area{0, 0, width, height};
|
||||||
Common::Rectangle<u32> total_rect = maxRectangle(screen_window_area, emulation_aspect_ratio);
|
Common::Rectangle<u32> total_rect = MaxRectangle(screen_window_area, emulation_aspect_ratio);
|
||||||
Common::Rectangle<u32> large_screen = maxRectangle(total_rect, large_screen_aspect_ratio);
|
Common::Rectangle<u32> large_screen = MaxRectangle(total_rect, large_screen_aspect_ratio);
|
||||||
Common::Rectangle<u32> fourth_size_rect = total_rect.Scale(1.f / scale_factor);
|
Common::Rectangle<u32> scaled_rect = total_rect.Scale(1.f / scale_factor);
|
||||||
Common::Rectangle<u32> small_screen = maxRectangle(fourth_size_rect, small_screen_aspect_ratio);
|
Common::Rectangle<u32> small_screen = MaxRectangle(scaled_rect, small_screen_aspect_ratio);
|
||||||
|
|
||||||
if (window_aspect_ratio < emulation_aspect_ratio) {
|
if (window_aspect_ratio < emulation_aspect_ratio) {
|
||||||
large_screen = large_screen.TranslateX((width - total_rect.GetWidth()) / 2);
|
large_screen = large_screen.TranslateX((width - total_rect.GetWidth()) / 2);
|
||||||
@ -286,13 +244,46 @@ FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool swapped, bool upr
|
|||||||
}
|
}
|
||||||
if (upright) {
|
if (upright) {
|
||||||
large_screen = large_screen.TranslateY(small_screen.GetHeight());
|
large_screen = large_screen.TranslateY(small_screen.GetHeight());
|
||||||
small_screen = small_screen.TranslateX(large_screen.right - small_screen.GetWidth())
|
small_screen = small_screen.TranslateY(large_screen.top - small_screen.GetHeight());
|
||||||
.TranslateY(large_screen.top - small_screen.GetHeight());
|
switch (vertical_alignment) {
|
||||||
} else {
|
case VerticalAlignment::Top:
|
||||||
|
// Shift the small screen to the top right corner
|
||||||
|
small_screen = small_screen.TranslateX(large_screen.left);
|
||||||
|
break;
|
||||||
|
case VerticalAlignment::Middle:
|
||||||
|
// Shift the small screen to the center right
|
||||||
|
small_screen = small_screen.TranslateX(
|
||||||
|
((large_screen.GetWidth() - small_screen.GetWidth()) / 2) + large_screen.left);
|
||||||
|
break;
|
||||||
|
case VerticalAlignment::Bottom:
|
||||||
// Shift the small screen to the bottom right corner
|
// Shift the small screen to the bottom right corner
|
||||||
small_screen =
|
small_screen = small_screen.TranslateX(large_screen.right - small_screen.GetWidth());
|
||||||
small_screen.TranslateX(large_screen.right)
|
break;
|
||||||
.TranslateY(large_screen.GetHeight() + large_screen.top - small_screen.GetHeight());
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
small_screen = small_screen.TranslateX(large_screen.right);
|
||||||
|
switch (vertical_alignment) {
|
||||||
|
case VerticalAlignment::Top:
|
||||||
|
// Shift the small screen to the top right corner
|
||||||
|
small_screen = small_screen.TranslateY(large_screen.top);
|
||||||
|
break;
|
||||||
|
case VerticalAlignment::Middle:
|
||||||
|
// Shift the small screen to the center right
|
||||||
|
small_screen = small_screen.TranslateY(
|
||||||
|
((large_screen.GetHeight() - small_screen.GetHeight()) / 2) + large_screen.top);
|
||||||
|
break;
|
||||||
|
case VerticalAlignment::Bottom:
|
||||||
|
// Shift the small screen to the bottom right corner
|
||||||
|
small_screen = small_screen.TranslateY(large_screen.bottom - small_screen.GetHeight());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
res.top_screen = swapped ? small_screen : large_screen;
|
res.top_screen = swapped ? small_screen : large_screen;
|
||||||
res.bottom_screen = swapped ? large_screen : small_screen;
|
res.bottom_screen = swapped ? large_screen : small_screen;
|
||||||
@ -331,11 +322,11 @@ FramebufferLayout HybridScreenLayout(u32 width, u32 height, bool swapped, bool u
|
|||||||
}
|
}
|
||||||
|
|
||||||
Common::Rectangle<u32> screen_window_area{0, 0, width, height};
|
Common::Rectangle<u32> screen_window_area{0, 0, width, height};
|
||||||
Common::Rectangle<u32> total_rect = maxRectangle(screen_window_area, hybrid_area_aspect_ratio);
|
Common::Rectangle<u32> total_rect = MaxRectangle(screen_window_area, hybrid_area_aspect_ratio);
|
||||||
Common::Rectangle<u32> large_main_screen = maxRectangle(total_rect, main_screen_aspect_ratio);
|
Common::Rectangle<u32> large_main_screen = MaxRectangle(total_rect, main_screen_aspect_ratio);
|
||||||
Common::Rectangle<u32> side_rect = total_rect.Scale(1.f / scale_factor);
|
Common::Rectangle<u32> side_rect = total_rect.Scale(1.f / scale_factor);
|
||||||
Common::Rectangle<u32> small_top_screen = maxRectangle(side_rect, top_screen_aspect_ratio);
|
Common::Rectangle<u32> small_top_screen = MaxRectangle(side_rect, top_screen_aspect_ratio);
|
||||||
Common::Rectangle<u32> small_bottom_screen = maxRectangle(side_rect, bot_screen_aspect_ratio);
|
Common::Rectangle<u32> small_bottom_screen = MaxRectangle(side_rect, bot_screen_aspect_ratio);
|
||||||
|
|
||||||
if (window_aspect_ratio < hybrid_area_aspect_ratio) {
|
if (window_aspect_ratio < hybrid_area_aspect_ratio) {
|
||||||
large_main_screen = large_main_screen.TranslateX((width - total_rect.GetWidth()) / 2);
|
large_main_screen = large_main_screen.TranslateX((width - total_rect.GetWidth()) / 2);
|
||||||
@ -373,54 +364,6 @@ FramebufferLayout HybridScreenLayout(u32 width, u32 height, bool swapped, bool u
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
FramebufferLayout SideFrameLayout(u32 width, u32 height, bool swapped, bool upright) {
|
|
||||||
ASSERT(width > 0);
|
|
||||||
ASSERT(height > 0);
|
|
||||||
|
|
||||||
FramebufferLayout res{width, height, true, true, {}, {}, !upright};
|
|
||||||
|
|
||||||
// Aspect ratio of both screens side by side
|
|
||||||
float emulation_aspect_ratio =
|
|
||||||
upright ? static_cast<float>(Core::kScreenTopWidth + Core::kScreenBottomWidth) /
|
|
||||||
Core::kScreenTopHeight
|
|
||||||
: static_cast<float>(Core::kScreenTopHeight) /
|
|
||||||
(Core::kScreenTopWidth + Core::kScreenBottomWidth);
|
|
||||||
|
|
||||||
float window_aspect_ratio = static_cast<float>(height) / width;
|
|
||||||
Common::Rectangle<u32> screen_window_area{0, 0, width, height};
|
|
||||||
// Find largest Rectangle that can fit in the window size with the given aspect ratio
|
|
||||||
Common::Rectangle<u32> screen_rect = maxRectangle(screen_window_area, emulation_aspect_ratio);
|
|
||||||
// Find sizes of top and bottom screen
|
|
||||||
Common::Rectangle<u32> top_screen =
|
|
||||||
upright ? maxRectangle(screen_rect, TOP_SCREEN_UPRIGHT_ASPECT_RATIO)
|
|
||||||
: maxRectangle(screen_rect, TOP_SCREEN_ASPECT_RATIO);
|
|
||||||
Common::Rectangle<u32> bot_screen =
|
|
||||||
upright ? maxRectangle(screen_rect, BOT_SCREEN_UPRIGHT_ASPECT_RATIO)
|
|
||||||
: maxRectangle(screen_rect, BOT_SCREEN_ASPECT_RATIO);
|
|
||||||
|
|
||||||
if (window_aspect_ratio < emulation_aspect_ratio) {
|
|
||||||
// Apply borders to the left and right sides of the window.
|
|
||||||
u32 shift_horizontal = (screen_window_area.GetWidth() - screen_rect.GetWidth()) / 2;
|
|
||||||
top_screen = top_screen.TranslateX(shift_horizontal);
|
|
||||||
bot_screen = bot_screen.TranslateX(shift_horizontal);
|
|
||||||
} else {
|
|
||||||
// Window is narrower than the emulation content => apply borders to the top and bottom
|
|
||||||
u32 shift_vertical = (screen_window_area.GetHeight() - screen_rect.GetHeight()) / 2;
|
|
||||||
top_screen = top_screen.TranslateY(shift_vertical);
|
|
||||||
bot_screen = bot_screen.TranslateY(shift_vertical);
|
|
||||||
}
|
|
||||||
if (upright) {
|
|
||||||
// Leave the top screen at the top if we are swapped.
|
|
||||||
res.top_screen = swapped ? top_screen : top_screen.TranslateY(bot_screen.GetHeight());
|
|
||||||
res.bottom_screen = swapped ? bot_screen.TranslateY(top_screen.GetHeight()) : bot_screen;
|
|
||||||
} else {
|
|
||||||
// Move the top screen to the right if we are swapped.
|
|
||||||
res.top_screen = swapped ? top_screen.TranslateX(bot_screen.GetWidth()) : top_screen;
|
|
||||||
res.bottom_screen = swapped ? bot_screen : bot_screen.TranslateX(top_screen.GetWidth());
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
FramebufferLayout SeparateWindowsLayout(u32 width, u32 height, bool is_secondary, bool upright) {
|
FramebufferLayout SeparateWindowsLayout(u32 width, u32 height, bool is_secondary, bool upright) {
|
||||||
// When is_secondary is true, we disable the top screen, and enable the bottom screen.
|
// When is_secondary is true, we disable the top screen, and enable the bottom screen.
|
||||||
// The same logic is found in the SingleFrameLayout using the is_swapped bool.
|
// The same logic is found in the SingleFrameLayout using the is_swapped bool.
|
||||||
@ -454,14 +397,14 @@ FramebufferLayout CustomFrameLayout(u32 width, u32 height, bool is_swapped) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondary) {
|
FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondary) {
|
||||||
FramebufferLayout layout;
|
|
||||||
if (Settings::values.custom_layout.GetValue() == true) {
|
if (Settings::values.custom_layout.GetValue() == true) {
|
||||||
layout = CustomFrameLayout(std::max(Settings::values.custom_top_right.GetValue(),
|
return CustomFrameLayout(std::max(Settings::values.custom_top_right.GetValue(),
|
||||||
Settings::values.custom_bottom_right.GetValue()),
|
Settings::values.custom_bottom_right.GetValue()),
|
||||||
std::max(Settings::values.custom_top_bottom.GetValue(),
|
std::max(Settings::values.custom_top_bottom.GetValue(),
|
||||||
Settings::values.custom_bottom_bottom.GetValue()),
|
Settings::values.custom_bottom_bottom.GetValue()),
|
||||||
Settings::values.swap_screen.GetValue());
|
Settings::values.swap_screen.GetValue());
|
||||||
} else {
|
}
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
switch (Settings::values.layout_option.GetValue()) {
|
switch (Settings::values.layout_option.GetValue()) {
|
||||||
case Settings::LayoutOption::SingleScreen:
|
case Settings::LayoutOption::SingleScreen:
|
||||||
@ -470,15 +413,6 @@ FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondar
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
const bool swap_screens = is_secondary || Settings::values.swap_screen.GetValue();
|
const bool swap_screens = is_secondary || Settings::values.swap_screen.GetValue();
|
||||||
if (Settings::values.upright_screen.GetValue()) {
|
|
||||||
if (swap_screens) {
|
|
||||||
width = Core::kScreenBottomHeight * res_scale;
|
|
||||||
height = Core::kScreenBottomWidth * res_scale;
|
|
||||||
} else {
|
|
||||||
width = Core::kScreenTopHeight * res_scale;
|
|
||||||
height = Core::kScreenTopWidth * res_scale;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (swap_screens) {
|
if (swap_screens) {
|
||||||
width = Core::kScreenBottomWidth * res_scale;
|
width = Core::kScreenBottomWidth * res_scale;
|
||||||
height = Core::kScreenBottomHeight * res_scale;
|
height = Core::kScreenBottomHeight * res_scale;
|
||||||
@ -486,99 +420,80 @@ FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondar
|
|||||||
width = Core::kScreenTopWidth * res_scale;
|
width = Core::kScreenTopWidth * res_scale;
|
||||||
height = Core::kScreenTopHeight * res_scale;
|
height = Core::kScreenTopHeight * res_scale;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
layout = SingleFrameLayout(width, height, swap_screens,
|
|
||||||
Settings::values.upright_screen.GetValue());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Settings::LayoutOption::LargeScreen:
|
|
||||||
if (Settings::values.upright_screen.GetValue()) {
|
if (Settings::values.upright_screen.GetValue()) {
|
||||||
if (Settings::values.swap_screen.GetValue()) {
|
std::swap(width, height);
|
||||||
width = Core::kScreenBottomHeight * res_scale;
|
|
||||||
height =
|
|
||||||
(Core::kScreenBottomWidth +
|
|
||||||
static_cast<int>(Core::kScreenTopWidth /
|
|
||||||
Settings::values.large_screen_proportion.GetValue())) *
|
|
||||||
res_scale;
|
|
||||||
} else {
|
|
||||||
width = Core::kScreenTopHeight * res_scale;
|
|
||||||
height =
|
|
||||||
(Core::kScreenTopWidth +
|
|
||||||
static_cast<int>(Core::kScreenBottomWidth /
|
|
||||||
Settings::values.large_screen_proportion.GetValue())) *
|
|
||||||
res_scale;
|
|
||||||
}
|
}
|
||||||
} else {
|
return SingleFrameLayout(width, height, swap_screens,
|
||||||
|
Settings::values.upright_screen.GetValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
case Settings::LayoutOption::LargeScreen:
|
||||||
if (Settings::values.swap_screen.GetValue()) {
|
if (Settings::values.swap_screen.GetValue()) {
|
||||||
width = (Core::kScreenBottomWidth +
|
width = (Core::kScreenBottomWidth +
|
||||||
Core::kScreenTopWidth /
|
Core::kScreenTopWidth /
|
||||||
static_cast<int>(
|
static_cast<int>(Settings::values.large_screen_proportion.GetValue())) *
|
||||||
Settings::values.large_screen_proportion.GetValue())) *
|
|
||||||
res_scale;
|
res_scale;
|
||||||
height = Core::kScreenBottomHeight * res_scale;
|
height = Core::kScreenBottomHeight * res_scale;
|
||||||
} else {
|
} else {
|
||||||
width = (Core::kScreenTopWidth +
|
width = (Core::kScreenTopWidth +
|
||||||
Core::kScreenBottomWidth /
|
Core::kScreenBottomWidth /
|
||||||
static_cast<int>(
|
static_cast<int>(Settings::values.large_screen_proportion.GetValue())) *
|
||||||
Settings::values.large_screen_proportion.GetValue())) *
|
|
||||||
res_scale;
|
res_scale;
|
||||||
height = Core::kScreenTopHeight * res_scale;
|
height = Core::kScreenTopHeight * res_scale;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
layout = LargeFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
|
||||||
Settings::values.upright_screen.GetValue(),
|
|
||||||
Settings::values.large_screen_proportion.GetValue());
|
|
||||||
break;
|
|
||||||
case Settings::LayoutOption::SideScreen:
|
|
||||||
if (Settings::values.upright_screen.GetValue()) {
|
if (Settings::values.upright_screen.GetValue()) {
|
||||||
width = Core::kScreenTopHeight * res_scale;
|
std::swap(width, height);
|
||||||
height = (Core::kScreenTopWidth + Core::kScreenBottomWidth) * res_scale;
|
}
|
||||||
} else {
|
return LargeFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
||||||
|
Settings::values.upright_screen.GetValue(),
|
||||||
|
Settings::values.large_screen_proportion.GetValue(),
|
||||||
|
VerticalAlignment::Bottom);
|
||||||
|
|
||||||
|
case Settings::LayoutOption::SideScreen:
|
||||||
width = (Core::kScreenTopWidth + Core::kScreenBottomWidth) * res_scale;
|
width = (Core::kScreenTopWidth + Core::kScreenBottomWidth) * res_scale;
|
||||||
height = Core::kScreenTopHeight * res_scale;
|
height = Core::kScreenTopHeight * res_scale;
|
||||||
|
|
||||||
|
if (Settings::values.upright_screen.GetValue()) {
|
||||||
|
std::swap(width, height);
|
||||||
}
|
}
|
||||||
layout = SideFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
return LargeFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
||||||
Settings::values.upright_screen.GetValue());
|
Settings::values.upright_screen.GetValue(), 1,
|
||||||
break;
|
VerticalAlignment::Middle);
|
||||||
|
|
||||||
case Settings::LayoutOption::MobilePortrait:
|
case Settings::LayoutOption::MobilePortrait:
|
||||||
width = Core::kScreenTopWidth * res_scale;
|
width = Core::kScreenTopWidth * res_scale;
|
||||||
height = (Core::kScreenTopHeight + Core::kScreenBottomHeight) * res_scale;
|
height = (Core::kScreenTopHeight + Core::kScreenBottomHeight) * res_scale;
|
||||||
layout =
|
return MobilePortraitFrameLayout(width, height, Settings::values.swap_screen.GetValue());
|
||||||
MobilePortraitFrameLayout(width, height, Settings::values.swap_screen.GetValue());
|
|
||||||
break;
|
case Settings::LayoutOption::MobileLandscape: {
|
||||||
case Settings::LayoutOption::MobileLandscape:
|
constexpr float large_screen_proportion = 2.25f;
|
||||||
if (Settings::values.swap_screen.GetValue()) {
|
if (Settings::values.swap_screen.GetValue()) {
|
||||||
width =
|
width = (Core::kScreenBottomWidth +
|
||||||
(Core::kScreenBottomWidth + static_cast<int>(Core::kScreenTopWidth / 2.25f)) *
|
static_cast<int>(Core::kScreenTopWidth / large_screen_proportion)) *
|
||||||
res_scale;
|
res_scale;
|
||||||
height = Core::kScreenBottomHeight * res_scale;
|
height = Core::kScreenBottomHeight * res_scale;
|
||||||
} else {
|
} else {
|
||||||
width =
|
width = (Core::kScreenTopWidth +
|
||||||
(Core::kScreenTopWidth + static_cast<int>(Core::kScreenBottomWidth / 2.25f)) *
|
static_cast<int>(Core::kScreenBottomWidth / large_screen_proportion)) *
|
||||||
res_scale;
|
res_scale;
|
||||||
height = Core::kScreenTopHeight * res_scale;
|
height = Core::kScreenTopHeight * res_scale;
|
||||||
}
|
}
|
||||||
layout = MobileLandscapeFrameLayout(
|
return LargeFrameLayout(width, height, Settings::values.swap_screen.GetValue(), false,
|
||||||
width, height, Settings::values.swap_screen.GetValue(), 2.25f, false);
|
large_screen_proportion, VerticalAlignment::Top);
|
||||||
break;
|
}
|
||||||
|
|
||||||
case Settings::LayoutOption::Default:
|
case Settings::LayoutOption::Default:
|
||||||
default:
|
default:
|
||||||
if (Settings::values.upright_screen.GetValue()) {
|
|
||||||
width = (Core::kScreenTopHeight + Core::kScreenBottomHeight) * res_scale;
|
|
||||||
height = Core::kScreenTopWidth * res_scale;
|
|
||||||
} else {
|
|
||||||
width = Core::kScreenTopWidth * res_scale;
|
width = Core::kScreenTopWidth * res_scale;
|
||||||
height = (Core::kScreenTopHeight + Core::kScreenBottomHeight) * res_scale;
|
height = (Core::kScreenTopHeight + Core::kScreenBottomHeight) * res_scale;
|
||||||
|
|
||||||
|
if (Settings::values.upright_screen.GetValue()) {
|
||||||
|
std::swap(width, height);
|
||||||
}
|
}
|
||||||
layout = DefaultFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
return DefaultFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
|
||||||
Settings::values.upright_screen.GetValue());
|
Settings::values.upright_screen.GetValue());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
UNREACHABLE();
|
||||||
if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::CardboardVR) {
|
|
||||||
layout = Layout::GetCardboardSettings(layout);
|
|
||||||
}
|
|
||||||
return layout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FramebufferLayout GetCardboardSettings(const FramebufferLayout& layout) {
|
FramebufferLayout GetCardboardSettings(const FramebufferLayout& layout) {
|
||||||
|
@ -20,6 +20,31 @@ enum class DisplayOrientation {
|
|||||||
PortraitFlipped, // 3DS rotated 270 degrees counter-clockwise
|
PortraitFlipped, // 3DS rotated 270 degrees counter-clockwise
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Describes the vertical alignment of the top and bottom screens in LargeFrameLayout
|
||||||
|
/// Top
|
||||||
|
/// +-------------+-----+
|
||||||
|
/// | | |
|
||||||
|
/// | +-----+
|
||||||
|
/// | |
|
||||||
|
/// +-------------+
|
||||||
|
/// Middle
|
||||||
|
/// +-------------+
|
||||||
|
/// | +-----+
|
||||||
|
/// | | |
|
||||||
|
/// | +-----+
|
||||||
|
/// +-------------+
|
||||||
|
/// Bottom
|
||||||
|
/// +-------------+
|
||||||
|
/// | |
|
||||||
|
/// | +-----+
|
||||||
|
/// | | |
|
||||||
|
/// +-------------+-----+
|
||||||
|
enum class VerticalAlignment {
|
||||||
|
Top,
|
||||||
|
Middle,
|
||||||
|
Bottom,
|
||||||
|
};
|
||||||
|
|
||||||
/// Describes the horizontal coordinates for the right eye screen when using Cardboard VR
|
/// Describes the horizontal coordinates for the right eye screen when using Cardboard VR
|
||||||
struct CardboardSettings {
|
struct CardboardSettings {
|
||||||
u32 top_screen_right_eye;
|
u32 top_screen_right_eye;
|
||||||
@ -43,7 +68,7 @@ struct FramebufferLayout {
|
|||||||
CardboardSettings cardboard;
|
CardboardSettings cardboard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ration of pixel size of the top screen, compared to the native size of the 3DS
|
* Returns the ratio of pixel size of the top screen, compared to the native size of the 3DS
|
||||||
* screen.
|
* screen.
|
||||||
*/
|
*/
|
||||||
u32 GetScalingRatio() const;
|
u32 GetScalingRatio() const;
|
||||||
@ -54,6 +79,7 @@ struct FramebufferLayout {
|
|||||||
* @param width Window framebuffer width in pixels
|
* @param width Window framebuffer width in pixels
|
||||||
* @param height Window framebuffer height in pixels
|
* @param height Window framebuffer height in pixels
|
||||||
* @param is_swapped if true, the bottom screen will be displayed above the top screen
|
* @param is_swapped if true, the bottom screen will be displayed above the top screen
|
||||||
|
* @param upright if true, the screens will be rotated 90 degrees anti-clockwise
|
||||||
* @return Newly created FramebufferLayout object with default screen regions initialized
|
* @return Newly created FramebufferLayout object with default screen regions initialized
|
||||||
*/
|
*/
|
||||||
FramebufferLayout DefaultFrameLayout(u32 width, u32 height, bool is_swapped, bool upright);
|
FramebufferLayout DefaultFrameLayout(u32 width, u32 height, bool is_swapped, bool upright);
|
||||||
@ -67,25 +93,12 @@ FramebufferLayout DefaultFrameLayout(u32 width, u32 height, bool is_swapped, boo
|
|||||||
*/
|
*/
|
||||||
FramebufferLayout MobilePortraitFrameLayout(u32 width, u32 height, bool is_swapped);
|
FramebufferLayout MobilePortraitFrameLayout(u32 width, u32 height, bool is_swapped);
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method for constructing a Frame with the a 4x size Top screen with a 1x size bottom
|
|
||||||
* screen on the right
|
|
||||||
* This is useful in particular because it matches well with a 1920x1080 resolution monitor
|
|
||||||
* @param width Window framebuffer width in pixels
|
|
||||||
* @param height Window framebuffer height in pixels
|
|
||||||
* @param is_swapped if true, the bottom screen will be the large display
|
|
||||||
* @param scale_factor Scale factor to use for bottom screen with respect to top screen
|
|
||||||
* @param center_vertical When true, centers the top and bottom screens vertically
|
|
||||||
* @return Newly created FramebufferLayout object with default screen regions initialized
|
|
||||||
*/
|
|
||||||
FramebufferLayout MobileLandscapeFrameLayout(u32 width, u32 height, bool is_swapped,
|
|
||||||
float scale_factor, bool center_vertical);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method for constructing a FramebufferLayout with only the top or bottom screen
|
* Factory method for constructing a FramebufferLayout with only the top or bottom screen
|
||||||
* @param width Window framebuffer width in pixels
|
* @param width Window framebuffer width in pixels
|
||||||
* @param height Window framebuffer height in pixels
|
* @param height Window framebuffer height in pixels
|
||||||
* @param is_swapped if true, the bottom screen will be displayed (and the top won't be displayed)
|
* @param is_swapped if true, the bottom screen will be displayed (and the top won't be displayed)
|
||||||
|
* @param upright if true, the screens will be rotated 90 degrees anti-clockwise
|
||||||
* @return Newly created FramebufferLayout object with default screen regions initialized
|
* @return Newly created FramebufferLayout object with default screen regions initialized
|
||||||
*/
|
*/
|
||||||
FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool is_swapped, bool upright);
|
FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool is_swapped, bool upright);
|
||||||
@ -97,32 +110,25 @@ FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool is_swapped, bool
|
|||||||
* @param width Window framebuffer width in pixels
|
* @param width Window framebuffer width in pixels
|
||||||
* @param height Window framebuffer height in pixels
|
* @param height Window framebuffer height in pixels
|
||||||
* @param is_swapped if true, the bottom screen will be the large display
|
* @param is_swapped if true, the bottom screen will be the large display
|
||||||
|
* @param upright if true, the screens will be rotated 90 degrees anti-clockwise
|
||||||
* @param scale_factor The ratio between the large screen with respect to the smaller screen
|
* @param scale_factor The ratio between the large screen with respect to the smaller screen
|
||||||
|
* @param vertical_alignment The vertical alignment of the smaller screen relative to the larger
|
||||||
|
* screen
|
||||||
* @return Newly created FramebufferLayout object with default screen regions initialized
|
* @return Newly created FramebufferLayout object with default screen regions initialized
|
||||||
*/
|
*/
|
||||||
FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool is_swapped, bool upright,
|
FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool is_swapped, bool upright,
|
||||||
float scale_factor);
|
float scale_factor, VerticalAlignment vertical_alignment);
|
||||||
/**
|
/**
|
||||||
* Factory method for constructing a frame with 2.5 times bigger top screen on the right,
|
* Factory method for constructing a frame with 2.5 times bigger top screen on the right,
|
||||||
* and 1x top and bottom screen on the left
|
* and 1x top and bottom screen on the left
|
||||||
* @param width Window framebuffer width in pixels
|
* @param width Window framebuffer width in pixels
|
||||||
* @param height Window framebuffer height in pixels
|
* @param height Window framebuffer height in pixels
|
||||||
* @param is_swapped if true, the bottom screen will be the large display
|
* @param is_swapped if true, the bottom screen will be the large display
|
||||||
|
* @param upright if true, the screens will be rotated 90 degrees anti-clockwise
|
||||||
* @return Newly created FramebufferLayout object with default screen regions initialized
|
* @return Newly created FramebufferLayout object with default screen regions initialized
|
||||||
*/
|
*/
|
||||||
FramebufferLayout HybridScreenLayout(u32 width, u32 height, bool swapped, bool upright);
|
FramebufferLayout HybridScreenLayout(u32 width, u32 height, bool swapped, bool upright);
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method for constructing a Frame with the Top screen and bottom
|
|
||||||
* screen side by side
|
|
||||||
* This is useful for devices with small screens, like the GPDWin
|
|
||||||
* @param width Window framebuffer width in pixels
|
|
||||||
* @param height Window framebuffer height in pixels
|
|
||||||
* @param is_swapped if true, the bottom screen will be the left display
|
|
||||||
* @return Newly created FramebufferLayout object with default screen regions initialized
|
|
||||||
*/
|
|
||||||
FramebufferLayout SideFrameLayout(u32 width, u32 height, bool is_swapped, bool upright);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method for constructing a Frame with the Top screen and bottom
|
* Factory method for constructing a Frame with the Top screen and bottom
|
||||||
* screen on separate windows
|
* screen on separate windows
|
||||||
|
@ -5,97 +5,16 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "core/hle/applets/applet.h"
|
#include "core/hle/applets/applet.h"
|
||||||
#include "core/hle/applets/erreula.h"
|
|
||||||
#include "core/hle/applets/mii_selector.h"
|
|
||||||
#include "core/hle/applets/mint.h"
|
|
||||||
#include "core/hle/applets/swkbd.h"
|
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
namespace HLE::Applets {
|
namespace HLE::Applets {
|
||||||
|
|
||||||
static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets;
|
|
||||||
/// The CoreTiming event identifier for the Applet update callback.
|
|
||||||
static Core::TimingEventType* applet_update_event = nullptr;
|
|
||||||
/// The interval at which the Applet update callback will be called, 16.6ms
|
|
||||||
static const u64 applet_update_interval_us = 16666;
|
|
||||||
|
|
||||||
ResultCode Applet::Create(Service::APT::AppletId id, Service::APT::AppletId parent, bool preload,
|
|
||||||
const std::shared_ptr<Service::APT::AppletManager>& manager) {
|
|
||||||
switch (id) {
|
|
||||||
case Service::APT::AppletId::SoftwareKeyboard1:
|
|
||||||
case Service::APT::AppletId::SoftwareKeyboard2:
|
|
||||||
applets[id] = std::make_shared<SoftwareKeyboard>(id, parent, preload, manager);
|
|
||||||
break;
|
|
||||||
case Service::APT::AppletId::Ed1:
|
|
||||||
case Service::APT::AppletId::Ed2:
|
|
||||||
applets[id] = std::make_shared<MiiSelector>(id, parent, preload, manager);
|
|
||||||
break;
|
|
||||||
case Service::APT::AppletId::Error:
|
|
||||||
case Service::APT::AppletId::Error2:
|
|
||||||
applets[id] = std::make_shared<ErrEula>(id, parent, preload, manager);
|
|
||||||
break;
|
|
||||||
case Service::APT::AppletId::Mint:
|
|
||||||
case Service::APT::AppletId::Mint2:
|
|
||||||
applets[id] = std::make_shared<Mint>(id, parent, preload, manager);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG_ERROR(Service_APT, "Could not create applet {}", id);
|
|
||||||
// TODO(Subv): Find the right error code
|
|
||||||
return ResultCode(ErrorDescription::NotFound, ErrorModule::Applet,
|
|
||||||
ErrorSummary::NotSupported, ErrorLevel::Permanent);
|
|
||||||
}
|
|
||||||
|
|
||||||
Service::APT::AppletAttributes attributes;
|
|
||||||
attributes.applet_pos.Assign(Service::APT::AppletPos::AutoLibrary);
|
|
||||||
attributes.is_home_menu.Assign(false);
|
|
||||||
const auto lock_handle_data = manager->GetLockHandle(attributes);
|
|
||||||
|
|
||||||
manager->Initialize(id, lock_handle_data->corrected_attributes);
|
|
||||||
manager->Enable(lock_handle_data->corrected_attributes);
|
|
||||||
if (preload) {
|
|
||||||
manager->FinishPreloadingLibraryApplet(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Schedule the update event
|
|
||||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(
|
|
||||||
usToCycles(applet_update_interval_us), applet_update_event, static_cast<u64>(id));
|
|
||||||
return RESULT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Applet> Applet::Get(Service::APT::AppletId id) {
|
|
||||||
auto itr = applets.find(id);
|
|
||||||
if (itr != applets.end())
|
|
||||||
return itr->second;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handles updating the current Applet every time it's called.
|
|
||||||
static void AppletUpdateEvent(u64 applet_id, s64 cycles_late) {
|
|
||||||
const auto id = static_cast<Service::APT::AppletId>(applet_id);
|
|
||||||
const auto applet = Applet::Get(id);
|
|
||||||
ASSERT_MSG(applet != nullptr, "Applet doesn't exist! applet_id={:08X}", id);
|
|
||||||
|
|
||||||
if (applet->IsActive()) {
|
|
||||||
applet->Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the applet is still running after the last update, reschedule the event
|
|
||||||
if (applet->IsRunning()) {
|
|
||||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(
|
|
||||||
usToCycles(applet_update_interval_us) - cycles_late, applet_update_event, applet_id);
|
|
||||||
} else {
|
|
||||||
// Otherwise the applet has terminated, in which case we should clean it up
|
|
||||||
applets[id] = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Applet::IsRunning() const {
|
bool Applet::IsRunning() const {
|
||||||
return is_running;
|
return is_running;
|
||||||
}
|
}
|
||||||
@ -104,10 +23,10 @@ bool Applet::IsActive() const {
|
|||||||
return is_active;
|
return is_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode Applet::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
|
Result Applet::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
|
||||||
switch (parameter.signal) {
|
switch (parameter.signal) {
|
||||||
case Service::APT::SignalType::Wakeup: {
|
case Service::APT::SignalType::Wakeup: {
|
||||||
ResultCode result = Start(parameter);
|
Result result = Start(parameter);
|
||||||
if (!result.IsError()) {
|
if (!result.IsError()) {
|
||||||
is_active = true;
|
is_active = true;
|
||||||
}
|
}
|
||||||
@ -140,13 +59,4 @@ void Applet::CloseApplet(std::shared_ptr<Kernel::Object> object, const std::vect
|
|||||||
is_running = false;
|
is_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init() {
|
|
||||||
// Register the applet update callback
|
|
||||||
applet_update_event = Core::System::GetInstance().CoreTiming().RegisterEvent(
|
|
||||||
"HLE Applet Update Event", AppletUpdateEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shutdown() {
|
|
||||||
Core::System::GetInstance().CoreTiming().RemoveEvent(applet_update_event);
|
|
||||||
}
|
|
||||||
} // namespace HLE::Applets
|
} // namespace HLE::Applets
|
||||||
|
@ -14,30 +14,12 @@ class Applet {
|
|||||||
public:
|
public:
|
||||||
virtual ~Applet() = default;
|
virtual ~Applet() = default;
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an instance of the Applet subclass identified by the parameter.
|
|
||||||
* and stores it in a global map.
|
|
||||||
* @param id Id of the applet to create.
|
|
||||||
* @param parent Id of the applet's parent.
|
|
||||||
* @param preload Whether the applet is being preloaded.
|
|
||||||
* @returns ResultCode Whether the operation was successful or not.
|
|
||||||
*/
|
|
||||||
static ResultCode Create(Service::APT::AppletId id, Service::APT::AppletId parent, bool preload,
|
|
||||||
const std::shared_ptr<Service::APT::AppletManager>& manager);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the Applet instance identified by the specified id.
|
|
||||||
* @param id Id of the Applet to retrieve.
|
|
||||||
* @returns Requested Applet or nullptr if not found.
|
|
||||||
*/
|
|
||||||
static std::shared_ptr<Applet> Get(Service::APT::AppletId id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a parameter from the application.
|
* Handles a parameter from the application.
|
||||||
* @param parameter Parameter data to handle.
|
* @param parameter Parameter data to handle.
|
||||||
* @returns ResultCode Whether the operation was successful or not.
|
* @returns Result Whether the operation was successful or not.
|
||||||
*/
|
*/
|
||||||
ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter);
|
Result ReceiveParameter(const Service::APT::MessageParameter& parameter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the applet is currently running.
|
* Whether the applet is currently running.
|
||||||
@ -55,29 +37,31 @@ public:
|
|||||||
virtual void Update() = 0;
|
virtual void Update() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Applet(Service::APT::AppletId id, Service::APT::AppletId parent, bool preload,
|
Applet(Core::System& system, Service::APT::AppletId id, Service::APT::AppletId parent,
|
||||||
std::weak_ptr<Service::APT::AppletManager> manager)
|
bool preload, std::weak_ptr<Service::APT::AppletManager> manager)
|
||||||
: id(id), parent(parent), preload(preload), manager(std::move(manager)) {}
|
: system(system), id(id), parent(parent), preload(preload), manager(std::move(manager)) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a parameter from the application.
|
* Handles a parameter from the application.
|
||||||
* @param parameter Parameter data to handle.
|
* @param parameter Parameter data to handle.
|
||||||
* @returns ResultCode Whether the operation was successful or not.
|
* @returns Result Whether the operation was successful or not.
|
||||||
*/
|
*/
|
||||||
virtual ResultCode ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) = 0;
|
virtual Result ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the Applet start event, triggered from the application.
|
* Handles the Applet start event, triggered from the application.
|
||||||
* @param parameter Parameter data to handle.
|
* @param parameter Parameter data to handle.
|
||||||
* @returns ResultCode Whether the operation was successful or not.
|
* @returns Result Whether the operation was successful or not.
|
||||||
*/
|
*/
|
||||||
virtual ResultCode Start(const Service::APT::MessageParameter& parameter) = 0;
|
virtual Result Start(const Service::APT::MessageParameter& parameter) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the LibAppletClosing signal to the application,
|
* Sends the LibAppletClosing signal to the application,
|
||||||
* along with the relevant data buffers.
|
* along with the relevant data buffers.
|
||||||
*/
|
*/
|
||||||
virtual ResultCode Finalize() = 0;
|
virtual Result Finalize() = 0;
|
||||||
|
|
||||||
|
Core::System& system;
|
||||||
|
|
||||||
Service::APT::AppletId id; ///< Id of this Applet
|
Service::APT::AppletId id; ///< Id of this Applet
|
||||||
Service::APT::AppletId parent; ///< Id of this Applet's parent
|
Service::APT::AppletId parent; ///< Id of this Applet's parent
|
||||||
@ -97,9 +81,4 @@ private:
|
|||||||
std::weak_ptr<Service::APT::AppletManager> manager;
|
std::weak_ptr<Service::APT::AppletManager> manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Initializes the HLE applets
|
|
||||||
void Init();
|
|
||||||
|
|
||||||
/// Shuts down the HLE applets
|
|
||||||
void Shutdown();
|
|
||||||
} // namespace HLE::Applets
|
} // namespace HLE::Applets
|
||||||
|
@ -9,12 +9,12 @@
|
|||||||
|
|
||||||
namespace HLE::Applets {
|
namespace HLE::Applets {
|
||||||
|
|
||||||
ResultCode ErrEula::ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) {
|
Result ErrEula::ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) {
|
||||||
if (parameter.signal != Service::APT::SignalType::Request) {
|
if (parameter.signal != Service::APT::SignalType::Request) {
|
||||||
LOG_ERROR(Service_APT, "unsupported signal {}", parameter.signal);
|
LOG_ERROR(Service_APT, "unsupported signal {}", parameter.signal);
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
// TODO(Subv): Find the right error code
|
// TODO(Subv): Find the right error code
|
||||||
return ResultCode(-1);
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The LibAppJustStarted message contains a buffer with the size of the framebuffer shared
|
// The LibAppJustStarted message contains a buffer with the size of the framebuffer shared
|
||||||
@ -28,7 +28,7 @@ ResultCode ErrEula::ReceiveParameterImpl(const Service::APT::MessageParameter& p
|
|||||||
// TODO: allocated memory never released
|
// TODO: allocated memory never released
|
||||||
using Kernel::MemoryPermission;
|
using Kernel::MemoryPermission;
|
||||||
// Create a SharedMemory that directly points to this heap block.
|
// Create a SharedMemory that directly points to this heap block.
|
||||||
framebuffer_memory = Core::System::GetInstance().Kernel().CreateSharedMemoryForApplet(
|
framebuffer_memory = system.Kernel().CreateSharedMemoryForApplet(
|
||||||
0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
||||||
"ErrEula Memory");
|
"ErrEula Memory");
|
||||||
|
|
||||||
@ -40,10 +40,10 @@ ResultCode ErrEula::ReceiveParameterImpl(const Service::APT::MessageParameter& p
|
|||||||
.object = framebuffer_memory,
|
.object = framebuffer_memory,
|
||||||
});
|
});
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ErrEula::Start(const Service::APT::MessageParameter& parameter) {
|
Result ErrEula::Start(const Service::APT::MessageParameter& parameter) {
|
||||||
startup_param = parameter.buffer;
|
startup_param = parameter.buffer;
|
||||||
|
|
||||||
// TODO(Subv): Set the expected fields in the response buffer before resending it to the
|
// TODO(Subv): Set the expected fields in the response buffer before resending it to the
|
||||||
@ -52,14 +52,14 @@ ResultCode ErrEula::Start(const Service::APT::MessageParameter& parameter) {
|
|||||||
|
|
||||||
// Let the application know that we're closing.
|
// Let the application know that we're closing.
|
||||||
Finalize();
|
Finalize();
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ErrEula::Finalize() {
|
Result ErrEula::Finalize() {
|
||||||
std::vector<u8> buffer(startup_param.size());
|
std::vector<u8> buffer(startup_param.size());
|
||||||
std::fill(buffer.begin(), buffer.end(), 0);
|
std::fill(buffer.begin(), buffer.end(), 0);
|
||||||
CloseApplet(nullptr, buffer);
|
CloseApplet(nullptr, buffer);
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrEula::Update() {}
|
void ErrEula::Update() {}
|
||||||
|
@ -11,13 +11,13 @@ namespace HLE::Applets {
|
|||||||
|
|
||||||
class ErrEula final : public Applet {
|
class ErrEula final : public Applet {
|
||||||
public:
|
public:
|
||||||
explicit ErrEula(Service::APT::AppletId id, Service::APT::AppletId parent, bool preload,
|
explicit ErrEula(Core::System& system, Service::APT::AppletId id, Service::APT::AppletId parent,
|
||||||
std::weak_ptr<Service::APT::AppletManager> manager)
|
bool preload, std::weak_ptr<Service::APT::AppletManager> manager)
|
||||||
: Applet(id, parent, preload, std::move(manager)) {}
|
: Applet(system, id, parent, preload, std::move(manager)) {}
|
||||||
|
|
||||||
ResultCode ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) override;
|
Result ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) override;
|
||||||
ResultCode Start(const Service::APT::MessageParameter& parameter) override;
|
Result Start(const Service::APT::MessageParameter& parameter) override;
|
||||||
ResultCode Finalize() override;
|
Result Finalize() override;
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -17,12 +17,12 @@
|
|||||||
|
|
||||||
namespace HLE::Applets {
|
namespace HLE::Applets {
|
||||||
|
|
||||||
ResultCode MiiSelector::ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) {
|
Result MiiSelector::ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) {
|
||||||
if (parameter.signal != Service::APT::SignalType::Request) {
|
if (parameter.signal != Service::APT::SignalType::Request) {
|
||||||
LOG_ERROR(Service_APT, "unsupported signal {}", parameter.signal);
|
LOG_ERROR(Service_APT, "unsupported signal {}", parameter.signal);
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
// TODO(Subv): Find the right error code
|
// TODO(Subv): Find the right error code
|
||||||
return ResultCode(-1);
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The LibAppJustStarted message contains a buffer with the size of the framebuffer shared
|
// The LibAppJustStarted message contains a buffer with the size of the framebuffer shared
|
||||||
@ -35,7 +35,7 @@ ResultCode MiiSelector::ReceiveParameterImpl(const Service::APT::MessageParamete
|
|||||||
|
|
||||||
using Kernel::MemoryPermission;
|
using Kernel::MemoryPermission;
|
||||||
// Create a SharedMemory that directly points to this heap block.
|
// Create a SharedMemory that directly points to this heap block.
|
||||||
framebuffer_memory = Core::System::GetInstance().Kernel().CreateSharedMemoryForApplet(
|
framebuffer_memory = system.Kernel().CreateSharedMemoryForApplet(
|
||||||
0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
||||||
"MiiSelector Memory");
|
"MiiSelector Memory");
|
||||||
|
|
||||||
@ -47,23 +47,23 @@ ResultCode MiiSelector::ReceiveParameterImpl(const Service::APT::MessageParamete
|
|||||||
.object = framebuffer_memory,
|
.object = framebuffer_memory,
|
||||||
});
|
});
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode MiiSelector::Start(const Service::APT::MessageParameter& parameter) {
|
Result MiiSelector::Start(const Service::APT::MessageParameter& parameter) {
|
||||||
ASSERT_MSG(parameter.buffer.size() == sizeof(config),
|
ASSERT_MSG(parameter.buffer.size() == sizeof(config),
|
||||||
"The size of the parameter (MiiConfig) is wrong");
|
"The size of the parameter (MiiConfig) is wrong");
|
||||||
|
|
||||||
std::memcpy(&config, parameter.buffer.data(), parameter.buffer.size());
|
std::memcpy(&config, parameter.buffer.data(), parameter.buffer.size());
|
||||||
|
|
||||||
using namespace Frontend;
|
using namespace Frontend;
|
||||||
frontend_applet = Core::System::GetInstance().GetMiiSelector();
|
frontend_applet = system.GetMiiSelector();
|
||||||
ASSERT(frontend_applet);
|
ASSERT(frontend_applet);
|
||||||
|
|
||||||
MiiSelectorConfig frontend_config = ToFrontendConfig(config);
|
MiiSelectorConfig frontend_config = ToFrontendConfig(config);
|
||||||
frontend_applet->Setup(frontend_config);
|
frontend_applet->Setup(frontend_config);
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MiiSelector::Update() {
|
void MiiSelector::Update() {
|
||||||
@ -78,11 +78,11 @@ void MiiSelector::Update() {
|
|||||||
Finalize();
|
Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode MiiSelector::Finalize() {
|
Result MiiSelector::Finalize() {
|
||||||
std::vector<u8> buffer(sizeof(MiiResult));
|
std::vector<u8> buffer(sizeof(MiiResult));
|
||||||
std::memcpy(buffer.data(), &result, buffer.size());
|
std::memcpy(buffer.data(), &result, buffer.size());
|
||||||
CloseApplet(nullptr, buffer);
|
CloseApplet(nullptr, buffer);
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
MiiResult MiiSelector::GetStandardMiiResult() {
|
MiiResult MiiSelector::GetStandardMiiResult() {
|
||||||
|
@ -62,13 +62,13 @@ ASSERT_REG_POSITION(guest_mii_name, 0x6C);
|
|||||||
|
|
||||||
class MiiSelector final : public Applet {
|
class MiiSelector final : public Applet {
|
||||||
public:
|
public:
|
||||||
MiiSelector(Service::APT::AppletId id, Service::APT::AppletId parent, bool preload,
|
MiiSelector(Core::System& system, Service::APT::AppletId id, Service::APT::AppletId parent,
|
||||||
std::weak_ptr<Service::APT::AppletManager> manager)
|
bool preload, std::weak_ptr<Service::APT::AppletManager> manager)
|
||||||
: Applet(id, parent, preload, std::move(manager)) {}
|
: Applet(system, id, parent, preload, std::move(manager)) {}
|
||||||
|
|
||||||
ResultCode ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) override;
|
Result ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) override;
|
||||||
ResultCode Start(const Service::APT::MessageParameter& parameter) override;
|
Result Start(const Service::APT::MessageParameter& parameter) override;
|
||||||
ResultCode Finalize() override;
|
Result Finalize() override;
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
||||||
static MiiResult GetStandardMiiResult();
|
static MiiResult GetStandardMiiResult();
|
||||||
|
@ -9,12 +9,12 @@
|
|||||||
|
|
||||||
namespace HLE::Applets {
|
namespace HLE::Applets {
|
||||||
|
|
||||||
ResultCode Mint::ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) {
|
Result Mint::ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) {
|
||||||
if (parameter.signal != Service::APT::SignalType::Request) {
|
if (parameter.signal != Service::APT::SignalType::Request) {
|
||||||
LOG_ERROR(Service_APT, "unsupported signal {}", parameter.signal);
|
LOG_ERROR(Service_APT, "unsupported signal {}", parameter.signal);
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
// TODO(Subv): Find the right error code
|
// TODO(Subv): Find the right error code
|
||||||
return ResultCode(-1);
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Request message contains a buffer with the size of the framebuffer shared
|
// The Request message contains a buffer with the size of the framebuffer shared
|
||||||
@ -28,7 +28,7 @@ ResultCode Mint::ReceiveParameterImpl(const Service::APT::MessageParameter& para
|
|||||||
// TODO: allocated memory never released
|
// TODO: allocated memory never released
|
||||||
using Kernel::MemoryPermission;
|
using Kernel::MemoryPermission;
|
||||||
// Create a SharedMemory that directly points to this heap block.
|
// Create a SharedMemory that directly points to this heap block.
|
||||||
framebuffer_memory = Core::System::GetInstance().Kernel().CreateSharedMemoryForApplet(
|
framebuffer_memory = system.Kernel().CreateSharedMemoryForApplet(
|
||||||
0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
||||||
"Mint Memory");
|
"Mint Memory");
|
||||||
|
|
||||||
@ -40,10 +40,10 @@ ResultCode Mint::ReceiveParameterImpl(const Service::APT::MessageParameter& para
|
|||||||
.object = framebuffer_memory,
|
.object = framebuffer_memory,
|
||||||
});
|
});
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode Mint::Start(const Service::APT::MessageParameter& parameter) {
|
Result Mint::Start(const Service::APT::MessageParameter& parameter) {
|
||||||
startup_param = parameter.buffer;
|
startup_param = parameter.buffer;
|
||||||
|
|
||||||
// TODO(Subv): Set the expected fields in the response buffer before resending it to the
|
// TODO(Subv): Set the expected fields in the response buffer before resending it to the
|
||||||
@ -52,14 +52,14 @@ ResultCode Mint::Start(const Service::APT::MessageParameter& parameter) {
|
|||||||
|
|
||||||
// Let the application know that we're closing
|
// Let the application know that we're closing
|
||||||
Finalize();
|
Finalize();
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode Mint::Finalize() {
|
Result Mint::Finalize() {
|
||||||
std::vector<u8> buffer(startup_param.size());
|
std::vector<u8> buffer(startup_param.size());
|
||||||
std::fill(buffer.begin(), buffer.end(), 0);
|
std::fill(buffer.begin(), buffer.end(), 0);
|
||||||
CloseApplet(nullptr, buffer);
|
CloseApplet(nullptr, buffer);
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mint::Update() {}
|
void Mint::Update() {}
|
||||||
|
@ -11,13 +11,13 @@ namespace HLE::Applets {
|
|||||||
|
|
||||||
class Mint final : public Applet {
|
class Mint final : public Applet {
|
||||||
public:
|
public:
|
||||||
explicit Mint(Service::APT::AppletId id, Service::APT::AppletId parent, bool preload,
|
explicit Mint(Core::System& system, Service::APT::AppletId id, Service::APT::AppletId parent,
|
||||||
std::weak_ptr<Service::APT::AppletManager> manager)
|
bool preload, std::weak_ptr<Service::APT::AppletManager> manager)
|
||||||
: Applet(id, parent, preload, std::move(manager)) {}
|
: Applet(system, id, parent, preload, std::move(manager)) {}
|
||||||
|
|
||||||
ResultCode ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) override;
|
Result ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) override;
|
||||||
ResultCode Start(const Service::APT::MessageParameter& parameter) override;
|
Result Start(const Service::APT::MessageParameter& parameter) override;
|
||||||
ResultCode Finalize() override;
|
Result Finalize() override;
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
namespace HLE::Applets {
|
namespace HLE::Applets {
|
||||||
|
|
||||||
ResultCode SoftwareKeyboard::ReceiveParameterImpl(Service::APT::MessageParameter const& parameter) {
|
Result SoftwareKeyboard::ReceiveParameterImpl(Service::APT::MessageParameter const& parameter) {
|
||||||
switch (parameter.signal) {
|
switch (parameter.signal) {
|
||||||
case Service::APT::SignalType::Request: {
|
case Service::APT::SignalType::Request: {
|
||||||
// The LibAppJustStarted message contains a buffer with the size of the framebuffer shared
|
// The LibAppJustStarted message contains a buffer with the size of the framebuffer shared
|
||||||
@ -32,7 +32,7 @@ ResultCode SoftwareKeyboard::ReceiveParameterImpl(Service::APT::MessageParameter
|
|||||||
|
|
||||||
using Kernel::MemoryPermission;
|
using Kernel::MemoryPermission;
|
||||||
// Create a SharedMemory that directly points to this heap block.
|
// Create a SharedMemory that directly points to this heap block.
|
||||||
framebuffer_memory = Core::System::GetInstance().Kernel().CreateSharedMemoryForApplet(
|
framebuffer_memory = system.Kernel().CreateSharedMemoryForApplet(
|
||||||
0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
||||||
"SoftwareKeyboard Memory");
|
"SoftwareKeyboard Memory");
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ ResultCode SoftwareKeyboard::ReceiveParameterImpl(Service::APT::MessageParameter
|
|||||||
.object = framebuffer_memory,
|
.object = framebuffer_memory,
|
||||||
});
|
});
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Service::APT::SignalType::Message: {
|
case Service::APT::SignalType::Message: {
|
||||||
@ -58,7 +58,7 @@ ResultCode SoftwareKeyboard::ReceiveParameterImpl(Service::APT::MessageParameter
|
|||||||
case SoftwareKeyboardCallbackResult::OK:
|
case SoftwareKeyboardCallbackResult::OK:
|
||||||
// Finish execution
|
// Finish execution
|
||||||
Finalize();
|
Finalize();
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
|
|
||||||
case SoftwareKeyboardCallbackResult::Close:
|
case SoftwareKeyboardCallbackResult::Close:
|
||||||
// Let the frontend display error and quit
|
// Let the frontend display error and quit
|
||||||
@ -66,14 +66,14 @@ ResultCode SoftwareKeyboard::ReceiveParameterImpl(Service::APT::MessageParameter
|
|||||||
config.return_code = SoftwareKeyboardResult::BannedInput;
|
config.return_code = SoftwareKeyboardResult::BannedInput;
|
||||||
config.text_offset = config.text_length = 0;
|
config.text_offset = config.text_length = 0;
|
||||||
Finalize();
|
Finalize();
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
|
|
||||||
case SoftwareKeyboardCallbackResult::Continue:
|
case SoftwareKeyboardCallbackResult::Continue:
|
||||||
// Let the frontend display error and get input again
|
// Let the frontend display error and get input again
|
||||||
// The input will be sent for validation again on next Update().
|
// The input will be sent for validation again on next Update().
|
||||||
frontend_applet->ShowError(Common::UTF16BufferToUTF8(config.callback_msg));
|
frontend_applet->ShowError(Common::UTF16BufferToUTF8(config.callback_msg));
|
||||||
frontend_applet->Execute(ToFrontendConfig(config));
|
frontend_applet->Execute(ToFrontendConfig(config));
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
@ -84,12 +84,12 @@ ResultCode SoftwareKeyboard::ReceiveParameterImpl(Service::APT::MessageParameter
|
|||||||
LOG_ERROR(Service_APT, "unsupported signal {}", parameter.signal);
|
LOG_ERROR(Service_APT, "unsupported signal {}", parameter.signal);
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
// TODO(Subv): Find the right error code
|
// TODO(Subv): Find the right error code
|
||||||
return ResultCode(-1);
|
return ResultUnknown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SoftwareKeyboard::Start(Service::APT::MessageParameter const& parameter) {
|
Result SoftwareKeyboard::Start(Service::APT::MessageParameter const& parameter) {
|
||||||
ASSERT_MSG(parameter.buffer.size() == sizeof(config),
|
ASSERT_MSG(parameter.buffer.size() == sizeof(config),
|
||||||
"The size of the parameter (SoftwareKeyboardConfig) is wrong");
|
"The size of the parameter (SoftwareKeyboardConfig) is wrong");
|
||||||
|
|
||||||
@ -99,12 +99,12 @@ ResultCode SoftwareKeyboard::Start(Service::APT::MessageParameter const& paramet
|
|||||||
DrawScreenKeyboard();
|
DrawScreenKeyboard();
|
||||||
|
|
||||||
using namespace Frontend;
|
using namespace Frontend;
|
||||||
frontend_applet = Core::System::GetInstance().GetSoftwareKeyboard();
|
frontend_applet = system.GetSoftwareKeyboard();
|
||||||
ASSERT(frontend_applet);
|
ASSERT(frontend_applet);
|
||||||
|
|
||||||
frontend_applet->Execute(ToFrontendConfig(config));
|
frontend_applet->Execute(ToFrontendConfig(config));
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoftwareKeyboard::Update() {
|
void SoftwareKeyboard::Update() {
|
||||||
@ -166,12 +166,12 @@ void SoftwareKeyboard::DrawScreenKeyboard() {
|
|||||||
// TODO(Subv): Draw the HLE keyboard, for now just do nothing
|
// TODO(Subv): Draw the HLE keyboard, for now just do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SoftwareKeyboard::Finalize() {
|
Result SoftwareKeyboard::Finalize() {
|
||||||
std::vector<u8> buffer(sizeof(SoftwareKeyboardConfig));
|
std::vector<u8> buffer(sizeof(SoftwareKeyboardConfig));
|
||||||
std::memcpy(buffer.data(), &config, buffer.size());
|
std::memcpy(buffer.data(), &config, buffer.size());
|
||||||
CloseApplet(nullptr, buffer);
|
CloseApplet(nullptr, buffer);
|
||||||
text_memory = nullptr;
|
text_memory = nullptr;
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Frontend::KeyboardConfig SoftwareKeyboard::ToFrontendConfig(
|
Frontend::KeyboardConfig SoftwareKeyboard::ToFrontendConfig(
|
||||||
|
@ -175,13 +175,13 @@ static_assert(sizeof(SoftwareKeyboardConfig) == 0x400, "Software Keyboard Config
|
|||||||
|
|
||||||
class SoftwareKeyboard final : public Applet {
|
class SoftwareKeyboard final : public Applet {
|
||||||
public:
|
public:
|
||||||
SoftwareKeyboard(Service::APT::AppletId id, Service::APT::AppletId parent, bool preload,
|
SoftwareKeyboard(Core::System& system, Service::APT::AppletId id, Service::APT::AppletId parent,
|
||||||
std::weak_ptr<Service::APT::AppletManager> manager)
|
bool preload, std::weak_ptr<Service::APT::AppletManager> manager)
|
||||||
: Applet(id, parent, preload, std::move(manager)) {}
|
: Applet(system, id, parent, preload, std::move(manager)) {}
|
||||||
|
|
||||||
ResultCode ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) override;
|
Result ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) override;
|
||||||
ResultCode Start(const Service::APT::MessageParameter& parameter) override;
|
Result Start(const Service::APT::MessageParameter& parameter) override;
|
||||||
ResultCode Finalize() override;
|
Result Finalize() override;
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,8 +20,8 @@ constexpr std::size_t MAX_STATIC_BUFFERS = 16;
|
|||||||
// These errors are commonly returned by invalid IPC translations, so alias them here for
|
// These errors are commonly returned by invalid IPC translations, so alias them here for
|
||||||
// convenience.
|
// convenience.
|
||||||
// TODO(yuriks): These will probably go away once translation is implemented inside the kernel.
|
// TODO(yuriks): These will probably go away once translation is implemented inside the kernel.
|
||||||
using Kernel::ERR_INVALID_BUFFER_DESCRIPTOR;
|
using Kernel::ResultInvalidBufferDescriptor;
|
||||||
constexpr auto ERR_INVALID_HANDLE = Kernel::ERR_INVALID_HANDLE_OS;
|
constexpr auto ResultInvalidHandle = Kernel::ResultInvalidHandleOs;
|
||||||
|
|
||||||
enum DescriptorType : u32 {
|
enum DescriptorType : u32 {
|
||||||
// Buffer related descriptors types (mask : 0x0F)
|
// Buffer related descriptors types (mask : 0x0F)
|
||||||
|
@ -161,7 +161,7 @@ inline void RequestBuilder::Push(bool value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void RequestBuilder::Push(ResultCode value) {
|
inline void RequestBuilder::Push(Result value) {
|
||||||
Push(value.raw);
|
Push(value.raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,8 +371,8 @@ inline bool RequestParser::Pop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline ResultCode RequestParser::Pop() {
|
inline Result RequestParser::Pop() {
|
||||||
return ResultCode{Pop<u32>()};
|
return Result{Pop<u32>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -108,7 +108,7 @@ void AddressArbiter::WakeUp(ThreadWakeupReason reason, std::shared_ptr<Thread> t
|
|||||||
waiting_threads.end());
|
waiting_threads.end());
|
||||||
};
|
};
|
||||||
|
|
||||||
ResultCode AddressArbiter::ArbitrateAddress(std::shared_ptr<Thread> thread, ArbitrationType type,
|
Result AddressArbiter::ArbitrateAddress(std::shared_ptr<Thread> thread, ArbitrationType type,
|
||||||
VAddr address, s32 value, u64 nanoseconds) {
|
VAddr address, s32 value, u64 nanoseconds) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
@ -171,17 +171,16 @@ ResultCode AddressArbiter::ArbitrateAddress(std::shared_ptr<Thread> thread, Arbi
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
LOG_ERROR(Kernel, "unknown type={}", type);
|
LOG_ERROR(Kernel, "unknown type={}", type);
|
||||||
return ERR_INVALID_ENUM_VALUE_FND;
|
return ResultInvalidEnumValueFnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The calls that use a timeout seem to always return a Timeout error even if they did not put
|
// The calls that use a timeout seem to always return a Timeout error even if they did not put
|
||||||
// the thread to sleep
|
// the thread to sleep
|
||||||
if (type == ArbitrationType::WaitIfLessThanWithTimeout ||
|
if (type == ArbitrationType::WaitIfLessThanWithTimeout ||
|
||||||
type == ArbitrationType::DecrementAndWaitIfLessThanWithTimeout) {
|
type == ArbitrationType::DecrementAndWaitIfLessThanWithTimeout) {
|
||||||
|
return ResultTimeout;
|
||||||
return RESULT_TIMEOUT;
|
|
||||||
}
|
}
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -55,7 +55,7 @@ public:
|
|||||||
std::shared_ptr<ResourceLimit> resource_limit;
|
std::shared_ptr<ResourceLimit> resource_limit;
|
||||||
std::string name; ///< Name of address arbiter object (optional)
|
std::string name; ///< Name of address arbiter object (optional)
|
||||||
|
|
||||||
ResultCode ArbitrateAddress(std::shared_ptr<Thread> thread, ArbitrationType type, VAddr address,
|
Result ArbitrateAddress(std::shared_ptr<Thread> thread, ArbitrationType type, VAddr address,
|
||||||
s32 value, u64 nanoseconds);
|
s32 value, u64 nanoseconds);
|
||||||
|
|
||||||
class Callback;
|
class Callback;
|
||||||
|
@ -20,32 +20,31 @@ namespace Kernel {
|
|||||||
ClientPort::ClientPort(KernelSystem& kernel) : Object(kernel), kernel(kernel) {}
|
ClientPort::ClientPort(KernelSystem& kernel) : Object(kernel), kernel(kernel) {}
|
||||||
ClientPort::~ClientPort() = default;
|
ClientPort::~ClientPort() = default;
|
||||||
|
|
||||||
ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() {
|
Result ClientPort::Connect(std::shared_ptr<ClientSession>* out_client_session) {
|
||||||
// Note: Threads do not wait for the server endpoint to call
|
// Note: Threads do not wait for the server endpoint to call
|
||||||
// AcceptSession before returning from this call.
|
// AcceptSession before returning from this call.
|
||||||
|
|
||||||
if (active_sessions >= max_sessions) {
|
R_UNLESS(active_sessions < max_sessions, ResultMaxConnectionsReached);
|
||||||
return ERR_MAX_CONNECTIONS_REACHED;
|
|
||||||
}
|
|
||||||
active_sessions++;
|
active_sessions++;
|
||||||
|
|
||||||
// Create a new session pair, let the created sessions inherit the parent port's HLE handler.
|
// Create a new session pair, let the created sessions inherit the parent port's HLE handler.
|
||||||
auto [server, client] = kernel.CreateSessionPair(server_port->GetName(), SharedFrom(this));
|
auto [server, client] = kernel.CreateSessionPair(server_port->GetName(), SharedFrom(this));
|
||||||
|
|
||||||
if (server_port->hle_handler)
|
if (server_port->hle_handler) {
|
||||||
server_port->hle_handler->ClientConnected(server);
|
server_port->hle_handler->ClientConnected(server);
|
||||||
else
|
} else {
|
||||||
server_port->pending_sessions.push_back(server);
|
server_port->pending_sessions.push_back(server);
|
||||||
|
}
|
||||||
|
|
||||||
// Wake the threads waiting on the ServerPort
|
// Wake the threads waiting on the ServerPort
|
||||||
server_port->WakeupAllWaitingThreads();
|
server_port->WakeupAllWaitingThreads();
|
||||||
|
|
||||||
return client;
|
*out_client_session = client;
|
||||||
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPort::ConnectionClosed() {
|
void ClientPort::ConnectionClosed() {
|
||||||
ASSERT(active_sessions > 0);
|
ASSERT(active_sessions > 0);
|
||||||
|
|
||||||
--active_sessions;
|
--active_sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public:
|
|||||||
* waiting on it to awake.
|
* waiting on it to awake.
|
||||||
* @returns ClientSession The client endpoint of the created Session pair, or error code.
|
* @returns ClientSession The client endpoint of the created Session pair, or error code.
|
||||||
*/
|
*/
|
||||||
ResultVal<std::shared_ptr<ClientSession>> Connect();
|
Result Connect(std::shared_ptr<ClientSession>* out_client_session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signifies that a previously active connection has been closed,
|
* Signifies that a previously active connection has been closed,
|
||||||
|
@ -44,11 +44,10 @@ ClientSession::~ClientSession() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ClientSession::SendSyncRequest(std::shared_ptr<Thread> thread) {
|
Result ClientSession::SendSyncRequest(std::shared_ptr<Thread> thread) {
|
||||||
// Keep ServerSession alive until we're done working with it.
|
// Keep ServerSession alive until we're done working with it.
|
||||||
std::shared_ptr<ServerSession> server = SharedFrom(parent->server);
|
std::shared_ptr<ServerSession> server = SharedFrom(parent->server);
|
||||||
if (server == nullptr)
|
R_UNLESS(server, ResultSessionClosed);
|
||||||
return ERR_SESSION_CLOSED_BY_REMOTE;
|
|
||||||
|
|
||||||
// Signal the server session that new data is available
|
// Signal the server session that new data is available
|
||||||
return server->HandleSyncRequest(std::move(thread));
|
return server->HandleSyncRequest(std::move(thread));
|
||||||
|
@ -42,9 +42,9 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Sends an SyncRequest from the current emulated thread.
|
* Sends an SyncRequest from the current emulated thread.
|
||||||
* @param thread Thread that initiated the request.
|
* @param thread Thread that initiated the request.
|
||||||
* @return ResultCode of the operation.
|
* @return Result of the operation.
|
||||||
*/
|
*/
|
||||||
ResultCode SendSyncRequest(std::shared_ptr<Thread> thread);
|
Result SendSyncRequest(std::shared_ptr<Thread> thread);
|
||||||
|
|
||||||
std::string name; ///< Name of client port (optional)
|
std::string name; ///< Name of client port (optional)
|
||||||
|
|
||||||
|
@ -31,84 +31,82 @@ enum {
|
|||||||
// WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always
|
// WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always
|
||||||
// double check that the code matches before re-using the constant.
|
// double check that the code matches before re-using the constant.
|
||||||
|
|
||||||
constexpr ResultCode ERR_OUT_OF_HANDLES(ErrCodes::OutOfHandles, ErrorModule::Kernel,
|
constexpr Result ResultOutOfHandles(ErrCodes::OutOfHandles, ErrorModule::Kernel,
|
||||||
ErrorSummary::OutOfResource,
|
ErrorSummary::OutOfResource,
|
||||||
ErrorLevel::Permanent); // 0xD8600413
|
ErrorLevel::Permanent); // 0xD8600413
|
||||||
constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(ErrCodes::SessionClosedByRemote, ErrorModule::OS,
|
constexpr Result ResultSessionClosed(ErrCodes::SessionClosedByRemote, ErrorModule::OS,
|
||||||
ErrorSummary::Canceled,
|
ErrorSummary::Canceled,
|
||||||
ErrorLevel::Status); // 0xC920181A
|
ErrorLevel::Status); // 0xC920181A
|
||||||
constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrCodes::PortNameTooLong, ErrorModule::OS,
|
constexpr Result ResultPortNameTooLong(ErrCodes::PortNameTooLong, ErrorModule::OS,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Usage); // 0xE0E0181E
|
ErrorLevel::Usage); // 0xE0E0181E
|
||||||
constexpr ResultCode ERR_WRONG_PERMISSION(ErrCodes::WrongPermission, ErrorModule::OS,
|
constexpr Result ResultWrongPermission(ErrCodes::WrongPermission, ErrorModule::OS,
|
||||||
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
||||||
constexpr ResultCode ERR_INVALID_BUFFER_DESCRIPTOR(ErrCodes::InvalidBufferDescriptor,
|
constexpr Result ResultInvalidBufferDescriptor(ErrCodes::InvalidBufferDescriptor, ErrorModule::OS,
|
||||||
ErrorModule::OS, ErrorSummary::WrongArgument,
|
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
||||||
ErrorLevel::Permanent);
|
constexpr Result ResultMaxConnectionsReached(ErrCodes::MaxConnectionsReached, ErrorModule::OS,
|
||||||
constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(ErrCodes::MaxConnectionsReached, ErrorModule::OS,
|
|
||||||
ErrorSummary::WouldBlock,
|
ErrorSummary::WouldBlock,
|
||||||
ErrorLevel::Temporary); // 0xD0401834
|
ErrorLevel::Temporary); // 0xD0401834
|
||||||
|
|
||||||
constexpr ResultCode ERR_NOT_AUTHORIZED(ErrorDescription::NotAuthorized, ErrorModule::OS,
|
constexpr Result ResultNotAuthorized(ErrorDescription::NotAuthorized, ErrorModule::OS,
|
||||||
ErrorSummary::WrongArgument,
|
ErrorSummary::WrongArgument,
|
||||||
ErrorLevel::Permanent); // 0xD9001BEA
|
ErrorLevel::Permanent); // 0xD9001BEA
|
||||||
constexpr ResultCode ERR_INVALID_ENUM_VALUE(ErrorDescription::InvalidEnumValue, ErrorModule::Kernel,
|
constexpr Result ResultInvalidEnumValue(ErrorDescription::InvalidEnumValue, ErrorModule::Kernel,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Permanent); // 0xD8E007ED
|
ErrorLevel::Permanent); // 0xD8E007ED
|
||||||
constexpr ResultCode ERR_INVALID_ENUM_VALUE_FND(ErrorDescription::InvalidEnumValue,
|
constexpr Result ResultInvalidEnumValueFnd(ErrorDescription::InvalidEnumValue, ErrorModule::FND,
|
||||||
ErrorModule::FND, ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Permanent); // 0xD8E093ED
|
ErrorLevel::Permanent); // 0xD8E093ED
|
||||||
constexpr ResultCode ERR_INVALID_COMBINATION(ErrorDescription::InvalidCombination, ErrorModule::OS,
|
constexpr Result ResultInvalidCombination(ErrorDescription::InvalidCombination, ErrorModule::OS,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Usage); // 0xE0E01BEE
|
ErrorLevel::Usage); // 0xE0E01BEE
|
||||||
constexpr ResultCode ERR_INVALID_COMBINATION_KERNEL(ErrorDescription::InvalidCombination,
|
constexpr Result ResultInvalidCombinationKernel(ErrorDescription::InvalidCombination,
|
||||||
ErrorModule::Kernel,
|
ErrorModule::Kernel, ErrorSummary::WrongArgument,
|
||||||
ErrorSummary::WrongArgument,
|
|
||||||
ErrorLevel::Permanent); // 0xD90007EE
|
ErrorLevel::Permanent); // 0xD90007EE
|
||||||
constexpr ResultCode ERR_MISALIGNED_ADDRESS(ErrorDescription::MisalignedAddress, ErrorModule::OS,
|
constexpr Result ResultMisalignedAddress(ErrorDescription::MisalignedAddress, ErrorModule::OS,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Usage); // 0xE0E01BF1
|
ErrorLevel::Usage); // 0xE0E01BF1
|
||||||
constexpr ResultCode ERR_MISALIGNED_SIZE(ErrorDescription::MisalignedSize, ErrorModule::OS,
|
constexpr Result ResultMisalignedSize(ErrorDescription::MisalignedSize, ErrorModule::OS,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Usage); // 0xE0E01BF2
|
ErrorLevel::Usage); // 0xE0E01BF2
|
||||||
constexpr ResultCode ERR_OUT_OF_MEMORY(ErrorDescription::OutOfMemory, ErrorModule::Kernel,
|
constexpr Result ResultOutOfMemory(ErrorDescription::OutOfMemory, ErrorModule::Kernel,
|
||||||
ErrorSummary::OutOfResource,
|
ErrorSummary::OutOfResource,
|
||||||
ErrorLevel::Permanent); // 0xD86007F3
|
ErrorLevel::Permanent); // 0xD86007F3
|
||||||
/// Returned when out of heap or linear heap memory when allocating
|
/// Returned when out of heap or linear heap memory when allocating
|
||||||
constexpr ResultCode ERR_OUT_OF_HEAP_MEMORY(ErrorDescription::OutOfMemory, ErrorModule::OS,
|
constexpr Result ResultOutOfHeapMemory(ErrorDescription::OutOfMemory, ErrorModule::OS,
|
||||||
ErrorSummary::OutOfResource,
|
ErrorSummary::OutOfResource,
|
||||||
ErrorLevel::Status); // 0xC860180A
|
ErrorLevel::Status); // 0xC860180A
|
||||||
constexpr ResultCode ERR_NOT_IMPLEMENTED(ErrorDescription::NotImplemented, ErrorModule::OS,
|
constexpr Result ResultNotImplemented(ErrorDescription::NotImplemented, ErrorModule::OS,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Usage); // 0xE0E01BF4
|
ErrorLevel::Usage); // 0xE0E01BF4
|
||||||
constexpr ResultCode ERR_INVALID_ADDRESS(ErrorDescription::InvalidAddress, ErrorModule::OS,
|
constexpr Result ResultInvalidAddress(ErrorDescription::InvalidAddress, ErrorModule::OS,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Usage); // 0xE0E01BF5
|
ErrorLevel::Usage); // 0xE0E01BF5
|
||||||
constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorDescription::InvalidAddress, ErrorModule::OS,
|
constexpr Result ResultInvalidAddressState(ErrorDescription::InvalidAddress, ErrorModule::OS,
|
||||||
ErrorSummary::InvalidState,
|
ErrorSummary::InvalidState,
|
||||||
ErrorLevel::Usage); // 0xE0A01BF5
|
ErrorLevel::Usage); // 0xE0A01BF5
|
||||||
constexpr ResultCode ERR_INVALID_POINTER(ErrorDescription::InvalidPointer, ErrorModule::Kernel,
|
constexpr Result ResultInvalidPointer(ErrorDescription::InvalidPointer, ErrorModule::Kernel,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Permanent); // 0xD8E007F6
|
ErrorLevel::Permanent); // 0xD8E007F6
|
||||||
constexpr ResultCode ERR_INVALID_HANDLE(ErrorDescription::InvalidHandle, ErrorModule::Kernel,
|
constexpr Result ResultInvalidHandle(ErrorDescription::InvalidHandle, ErrorModule::Kernel,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Permanent); // 0xD8E007F7
|
ErrorLevel::Permanent); // 0xD8E007F7
|
||||||
/// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths.
|
/// Alternate code returned instead of ResultInvalidHandle in some code paths.
|
||||||
constexpr ResultCode ERR_INVALID_HANDLE_OS(ErrorDescription::InvalidHandle, ErrorModule::OS,
|
constexpr Result ResultInvalidHandleOs(ErrorDescription::InvalidHandle, ErrorModule::OS,
|
||||||
ErrorSummary::WrongArgument,
|
ErrorSummary::WrongArgument,
|
||||||
ErrorLevel::Permanent); // 0xD9001BF7
|
ErrorLevel::Permanent); // 0xD9001BF7
|
||||||
constexpr ResultCode ERR_NOT_FOUND(ErrorDescription::NotFound, ErrorModule::Kernel,
|
constexpr Result ResultNotFound(ErrorDescription::NotFound, ErrorModule::Kernel,
|
||||||
ErrorSummary::NotFound, ErrorLevel::Permanent); // 0xD88007FA
|
ErrorSummary::NotFound, ErrorLevel::Permanent); // 0xD88007FA
|
||||||
constexpr ResultCode ERR_OUT_OF_RANGE(ErrorDescription::OutOfRange, ErrorModule::OS,
|
constexpr Result ResultOutOfRange(ErrorDescription::OutOfRange, ErrorModule::OS,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Usage); // 0xE0E01BFD
|
ErrorLevel::Usage); // 0xE0E01BFD
|
||||||
constexpr ResultCode ERR_OUT_OF_RANGE_KERNEL(ErrorDescription::OutOfRange, ErrorModule::Kernel,
|
constexpr Result ResultOutOfRangeKernel(ErrorDescription::OutOfRange, ErrorModule::Kernel,
|
||||||
ErrorSummary::InvalidArgument,
|
ErrorSummary::InvalidArgument,
|
||||||
ErrorLevel::Permanent); // 0xD8E007FD
|
ErrorLevel::Permanent); // 0xD8E007FD
|
||||||
constexpr ResultCode RESULT_TIMEOUT(ErrorDescription::Timeout, ErrorModule::OS,
|
constexpr Result ResultTimeout(ErrorDescription::Timeout, ErrorModule::OS,
|
||||||
ErrorSummary::StatusChanged, ErrorLevel::Info);
|
ErrorSummary::StatusChanged, ErrorLevel::Info);
|
||||||
/// Returned when Accept() is called on a port with no sessions to be accepted.
|
/// Returned when Accept() is called on a port with no sessions to be accepted.
|
||||||
constexpr ResultCode ERR_NO_PENDING_SESSIONS(ErrCodes::NoPendingSessions, ErrorModule::OS,
|
constexpr Result ResultNoPendingSessions(ErrCodes::NoPendingSessions, ErrorModule::OS,
|
||||||
ErrorSummary::WouldBlock,
|
ErrorSummary::WouldBlock,
|
||||||
ErrorLevel::Permanent); // 0xD8401823
|
ErrorLevel::Permanent); // 0xD8401823
|
||||||
|
|
||||||
|
@ -36,9 +36,10 @@ bool Event::ShouldWait(const Thread* thread) const {
|
|||||||
void Event::Acquire(Thread* thread) {
|
void Event::Acquire(Thread* thread) {
|
||||||
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
|
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
|
||||||
|
|
||||||
if (reset_type == ResetType::OneShot)
|
if (reset_type == ResetType::OneShot) {
|
||||||
signaled = false;
|
signaled = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Event::Signal() {
|
void Event::Signal() {
|
||||||
signaled = true;
|
signaled = true;
|
||||||
@ -52,8 +53,9 @@ void Event::Clear() {
|
|||||||
void Event::WakeupAllWaitingThreads() {
|
void Event::WakeupAllWaitingThreads() {
|
||||||
WaitObject::WakeupAllWaitingThreads();
|
WaitObject::WakeupAllWaitingThreads();
|
||||||
|
|
||||||
if (reset_type == ResetType::Pulse)
|
if (reset_type == ResetType::Pulse) {
|
||||||
signaled = false;
|
signaled = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -28,56 +28,48 @@ HandleTable::HandleTable(KernelSystem& kernel) : kernel(kernel) {
|
|||||||
|
|
||||||
HandleTable::~HandleTable() = default;
|
HandleTable::~HandleTable() = default;
|
||||||
|
|
||||||
ResultVal<Handle> HandleTable::Create(std::shared_ptr<Object> obj) {
|
Result HandleTable::Create(Handle* out_handle, std::shared_ptr<Object> obj) {
|
||||||
DEBUG_ASSERT(obj != nullptr);
|
DEBUG_ASSERT(obj != nullptr);
|
||||||
|
|
||||||
u16 slot = next_free_slot;
|
u16 slot = next_free_slot;
|
||||||
if (slot >= generations.size()) {
|
R_UNLESS(slot < generations.size(), ResultOutOfHandles);
|
||||||
LOG_ERROR(Kernel, "Unable to allocate Handle, too many slots in use.");
|
|
||||||
return ERR_OUT_OF_HANDLES;
|
|
||||||
}
|
|
||||||
next_free_slot = generations[slot];
|
next_free_slot = generations[slot];
|
||||||
|
|
||||||
u16 generation = next_generation++;
|
u16 generation = next_generation++;
|
||||||
|
|
||||||
// Overflow count so it fits in the 15 bits dedicated to the generation in the handle.
|
// Overflow count so it fits in the 15 bits dedicated to the generation in the handle.
|
||||||
// CTR-OS doesn't use generation 0, so skip straight to 1.
|
// CTR-OS doesn't use generation 0, so skip straight to 1.
|
||||||
if (next_generation >= (1 << 15))
|
if (next_generation >= (1 << 15)) {
|
||||||
next_generation = 1;
|
next_generation = 1;
|
||||||
|
}
|
||||||
|
|
||||||
generations[slot] = generation;
|
generations[slot] = generation;
|
||||||
objects[slot] = std::move(obj);
|
objects[slot] = std::move(obj);
|
||||||
|
|
||||||
Handle handle = generation | (slot << 15);
|
*out_handle = generation | (slot << 15);
|
||||||
return handle;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<Handle> HandleTable::Duplicate(Handle handle) {
|
Result HandleTable::Duplicate(Handle* out_handle, Handle handle) {
|
||||||
std::shared_ptr<Object> object = GetGeneric(handle);
|
std::shared_ptr<Object> object = GetGeneric(handle);
|
||||||
if (object == nullptr) {
|
R_UNLESS(object, ResultInvalidHandle);
|
||||||
LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle);
|
return Create(out_handle, std::move(object));
|
||||||
return ERR_INVALID_HANDLE;
|
|
||||||
}
|
|
||||||
return Create(std::move(object));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode HandleTable::Close(Handle handle) {
|
Result HandleTable::Close(Handle handle) {
|
||||||
if (!IsValid(handle))
|
R_UNLESS(IsValid(handle), ResultInvalidHandle);
|
||||||
return ERR_INVALID_HANDLE;
|
|
||||||
|
|
||||||
u16 slot = GetSlot(handle);
|
|
||||||
|
|
||||||
|
const u16 slot = GetSlot(handle);
|
||||||
objects[slot] = nullptr;
|
objects[slot] = nullptr;
|
||||||
|
|
||||||
generations[slot] = next_free_slot;
|
generations[slot] = next_free_slot;
|
||||||
next_free_slot = slot;
|
next_free_slot = slot;
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HandleTable::IsValid(Handle handle) const {
|
bool HandleTable::IsValid(Handle handle) const {
|
||||||
std::size_t slot = GetSlot(handle);
|
const u16 slot = GetSlot(handle);
|
||||||
u16 generation = GetGeneration(handle);
|
const u16 generation = GetGeneration(handle);
|
||||||
|
|
||||||
return slot < MAX_COUNT && objects[slot] != nullptr && generations[slot] == generation;
|
return slot < MAX_COUNT && objects[slot] != nullptr && generations[slot] == generation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,24 +51,24 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Allocates a handle for the given object.
|
* Allocates a handle for the given object.
|
||||||
* @return The created Handle or one of the following errors:
|
* @return The created Handle or one of the following errors:
|
||||||
* - `ERR_OUT_OF_HANDLES`: the maximum number of handles has been exceeded.
|
* - `ResultOutOfHandles`: the maximum number of handles has been exceeded.
|
||||||
*/
|
*/
|
||||||
ResultVal<Handle> Create(std::shared_ptr<Object> obj);
|
Result Create(Handle* out_handle, std::shared_ptr<Object> obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new handle that points to the same object as the passed in handle.
|
* Returns a new handle that points to the same object as the passed in handle.
|
||||||
* @return The duplicated Handle or one of the following errors:
|
* @return The duplicated Handle or one of the following errors:
|
||||||
* - `ERR_INVALID_HANDLE`: an invalid handle was passed in.
|
* - `ResultInvalidHandle`: an invalid handle was passed in.
|
||||||
* - Any errors returned by `Create()`.
|
* - Any errors returned by `Create()`.
|
||||||
*/
|
*/
|
||||||
ResultVal<Handle> Duplicate(Handle handle);
|
Result Duplicate(Handle* out_handle, Handle handle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes a handle, removing it from the table and decreasing the object's ref-count.
|
* Closes a handle, removing it from the table and decreasing the object's ref-count.
|
||||||
* @return `RESULT_SUCCESS` or one of the following errors:
|
* @return `ResultSuccess` or one of the following errors:
|
||||||
* - `ERR_INVALID_HANDLE`: an invalid handle was passed in.
|
* - `ResultInvalidHandle`: an invalid handle was passed in.
|
||||||
*/
|
*/
|
||||||
ResultCode Close(Handle handle);
|
Result Close(Handle handle);
|
||||||
|
|
||||||
/// Checks if a handle is valid and points to an existing object.
|
/// Checks if a handle is valid and points to an existing object.
|
||||||
bool IsValid(Handle handle) const;
|
bool IsValid(Handle handle) const;
|
||||||
|
@ -126,8 +126,8 @@ void HLERequestContext::AddStaticBuffer(u8 buffer_id, std::vector<u8> data) {
|
|||||||
static_buffers[buffer_id] = std::move(data);
|
static_buffers[buffer_id] = std::move(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(
|
Result HLERequestContext::PopulateFromIncomingCommandBuffer(const u32_le* src_cmdbuf,
|
||||||
const u32_le* src_cmdbuf, std::shared_ptr<Process> src_process_) {
|
std::shared_ptr<Process> src_process_) {
|
||||||
auto& src_process = *src_process_;
|
auto& src_process = *src_process_;
|
||||||
IPC::Header header{src_cmdbuf[0]};
|
IPC::Header header{src_cmdbuf[0]};
|
||||||
|
|
||||||
@ -203,10 +203,10 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(
|
|||||||
std::move(translated_cmdbuf));
|
std::move(translated_cmdbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf,
|
Result HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf,
|
||||||
Process& dst_process) const {
|
Process& dst_process) const {
|
||||||
IPC::Header header{cmd_buf[0]};
|
IPC::Header header{cmd_buf[0]};
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf,
|
|||||||
Handle handle = 0;
|
Handle handle = 0;
|
||||||
if (object != nullptr) {
|
if (object != nullptr) {
|
||||||
// TODO(yuriks): Figure out the proper error handling for if this fails
|
// TODO(yuriks): Figure out the proper error handling for if this fails
|
||||||
handle = dst_process.handle_table.Create(object).Unwrap();
|
R_ASSERT(dst_process.handle_table.Create(std::addressof(handle), object));
|
||||||
}
|
}
|
||||||
dst_cmdbuf[i++] = handle;
|
dst_cmdbuf[i++] = handle;
|
||||||
}
|
}
|
||||||
@ -281,7 +281,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf,
|
|||||||
std::move(translated_cmdbuf));
|
std::move(translated_cmdbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
MappedBuffer& HLERequestContext::GetMappedBuffer(u32 id_from_cmdbuf) {
|
MappedBuffer& HLERequestContext::GetMappedBuffer(u32 id_from_cmdbuf) {
|
||||||
|
@ -363,10 +363,10 @@ public:
|
|||||||
MappedBuffer& GetMappedBuffer(u32 id_from_cmdbuf);
|
MappedBuffer& GetMappedBuffer(u32 id_from_cmdbuf);
|
||||||
|
|
||||||
/// Populates this context with data from the requesting process/thread.
|
/// Populates this context with data from the requesting process/thread.
|
||||||
ResultCode PopulateFromIncomingCommandBuffer(const u32_le* src_cmdbuf,
|
Result PopulateFromIncomingCommandBuffer(const u32_le* src_cmdbuf,
|
||||||
std::shared_ptr<Process> src_process);
|
std::shared_ptr<Process> src_process);
|
||||||
/// Writes data from this context back to the requesting process/thread.
|
/// Writes data from this context back to the requesting process/thread.
|
||||||
ResultCode WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, Process& dst_process) const;
|
Result WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, Process& dst_process) const;
|
||||||
|
|
||||||
/// Reports an unimplemented function.
|
/// Reports an unimplemented function.
|
||||||
void ReportUnimplemented() const;
|
void ReportUnimplemented() const;
|
||||||
|
@ -18,12 +18,11 @@
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
ResultCode TranslateCommandBuffer(Kernel::KernelSystem& kernel, Memory::MemorySystem& memory,
|
Result TranslateCommandBuffer(Kernel::KernelSystem& kernel, Memory::MemorySystem& memory,
|
||||||
std::shared_ptr<Thread> src_thread,
|
std::shared_ptr<Thread> src_thread,
|
||||||
std::shared_ptr<Thread> dst_thread, VAddr src_address,
|
std::shared_ptr<Thread> dst_thread, VAddr src_address,
|
||||||
VAddr dst_address,
|
VAddr dst_address,
|
||||||
std::vector<MappedBufferContext>& mapped_buffer_context,
|
std::vector<MappedBufferContext>& mapped_buffer_context, bool reply) {
|
||||||
bool reply) {
|
|
||||||
auto src_process = src_thread->owner_process.lock();
|
auto src_process = src_thread->owner_process.lock();
|
||||||
auto dst_process = dst_thread->owner_process.lock();
|
auto dst_process = dst_thread->owner_process.lock();
|
||||||
ASSERT(src_process && dst_process);
|
ASSERT(src_process && dst_process);
|
||||||
@ -60,7 +59,7 @@ ResultCode TranslateCommandBuffer(Kernel::KernelSystem& kernel, Memory::MemorySy
|
|||||||
// Note: The real kernel does not check that the number of handles fits into the command
|
// Note: The real kernel does not check that the number of handles fits into the command
|
||||||
// buffer before writing them, only after finishing.
|
// buffer before writing them, only after finishing.
|
||||||
if (i + num_handles > command_size) {
|
if (i + num_handles > command_size) {
|
||||||
return ResultCode(ErrCodes::CommandTooLarge, ErrorModule::OS,
|
return Result(ErrCodes::CommandTooLarge, ErrorModule::OS,
|
||||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,8 +87,8 @@ ResultCode TranslateCommandBuffer(Kernel::KernelSystem& kernel, Memory::MemorySy
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = dst_process->handle_table.Create(std::move(object));
|
R_ASSERT(dst_process->handle_table.Create(std::addressof(cmd_buf[i++]),
|
||||||
cmd_buf[i++] = result.ValueOr(0);
|
std::move(object)));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -180,10 +179,10 @@ ResultCode TranslateCommandBuffer(Kernel::KernelSystem& kernel, Memory::MemorySy
|
|||||||
next_vma.meminfo_state == MemoryState::Reserved);
|
next_vma.meminfo_state == MemoryState::Reserved);
|
||||||
|
|
||||||
// Unmap the buffer and guard pages from the source process
|
// Unmap the buffer and guard pages from the source process
|
||||||
ResultCode result =
|
Result result =
|
||||||
src_process->vm_manager.UnmapRange(page_start - Memory::CITRA_PAGE_SIZE,
|
src_process->vm_manager.UnmapRange(page_start - Memory::CITRA_PAGE_SIZE,
|
||||||
(num_pages + 2) * Memory::CITRA_PAGE_SIZE);
|
(num_pages + 2) * Memory::CITRA_PAGE_SIZE);
|
||||||
ASSERT(result == RESULT_SUCCESS);
|
ASSERT(result == ResultSuccess);
|
||||||
|
|
||||||
mapped_buffer_context.erase(found);
|
mapped_buffer_context.erase(found);
|
||||||
|
|
||||||
@ -216,11 +215,11 @@ ResultCode TranslateCommandBuffer(Kernel::KernelSystem& kernel, Memory::MemorySy
|
|||||||
ASSERT(dst_process->vm_manager.ChangeMemoryState(
|
ASSERT(dst_process->vm_manager.ChangeMemoryState(
|
||||||
low_guard_address, Memory::CITRA_PAGE_SIZE, Kernel::MemoryState::Shared,
|
low_guard_address, Memory::CITRA_PAGE_SIZE, Kernel::MemoryState::Shared,
|
||||||
Kernel::VMAPermission::ReadWrite, Kernel::MemoryState::Reserved,
|
Kernel::VMAPermission::ReadWrite, Kernel::MemoryState::Reserved,
|
||||||
Kernel::VMAPermission::None) == RESULT_SUCCESS);
|
Kernel::VMAPermission::None) == ResultSuccess);
|
||||||
ASSERT(dst_process->vm_manager.ChangeMemoryState(
|
ASSERT(dst_process->vm_manager.ChangeMemoryState(
|
||||||
high_guard_address, Memory::CITRA_PAGE_SIZE, Kernel::MemoryState::Shared,
|
high_guard_address, Memory::CITRA_PAGE_SIZE, Kernel::MemoryState::Shared,
|
||||||
Kernel::VMAPermission::ReadWrite, Kernel::MemoryState::Reserved,
|
Kernel::VMAPermission::ReadWrite, Kernel::MemoryState::Reserved,
|
||||||
Kernel::VMAPermission::None) == RESULT_SUCCESS);
|
Kernel::VMAPermission::None) == ResultSuccess);
|
||||||
|
|
||||||
// Get proper mapped buffer address and store it in the cmd buffer.
|
// Get proper mapped buffer address and store it in the cmd buffer.
|
||||||
target_address += Memory::CITRA_PAGE_SIZE;
|
target_address += Memory::CITRA_PAGE_SIZE;
|
||||||
@ -249,6 +248,6 @@ ResultCode TranslateCommandBuffer(Kernel::KernelSystem& kernel, Memory::MemorySy
|
|||||||
|
|
||||||
memory.WriteBlock(*dst_process, dst_address, cmd_buf.data(), command_size * sizeof(u32));
|
memory.WriteBlock(*dst_process, dst_address, cmd_buf.data(), command_size * sizeof(u32));
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -40,10 +40,9 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Performs IPC command buffer translation from one process to another.
|
/// Performs IPC command buffer translation from one process to another.
|
||||||
ResultCode TranslateCommandBuffer(KernelSystem& system, Memory::MemorySystem& memory,
|
Result TranslateCommandBuffer(KernelSystem& system, Memory::MemorySystem& memory,
|
||||||
std::shared_ptr<Thread> src_thread,
|
std::shared_ptr<Thread> src_thread,
|
||||||
std::shared_ptr<Thread> dst_thread, VAddr src_address,
|
std::shared_ptr<Thread> dst_thread, VAddr src_address,
|
||||||
VAddr dst_address,
|
VAddr dst_address,
|
||||||
std::vector<MappedBufferContext>& mapped_buffer_context,
|
std::vector<MappedBufferContext>& mapped_buffer_context, bool reply);
|
||||||
bool reply);
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -66,7 +66,7 @@ void Mutex::Acquire(Thread* thread) {
|
|||||||
lock_count++;
|
lock_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode Mutex::Release(Thread* thread) {
|
Result Mutex::Release(Thread* thread) {
|
||||||
// We can only release the mutex if it's held by the calling thread.
|
// We can only release the mutex if it's held by the calling thread.
|
||||||
if (thread != holding_thread.get()) {
|
if (thread != holding_thread.get()) {
|
||||||
if (holding_thread) {
|
if (holding_thread) {
|
||||||
@ -75,14 +75,14 @@ ResultCode Mutex::Release(Thread* thread) {
|
|||||||
"Tried to release a mutex (owned by thread id {}) from a different thread id {}",
|
"Tried to release a mutex (owned by thread id {}) from a different thread id {}",
|
||||||
holding_thread->thread_id, thread->thread_id);
|
holding_thread->thread_id, thread->thread_id);
|
||||||
}
|
}
|
||||||
return ResultCode(ErrCodes::WrongLockingThread, ErrorModule::Kernel,
|
return Result(ErrCodes::WrongLockingThread, ErrorModule::Kernel,
|
||||||
ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
|
ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: It should not be possible for the situation where the mutex has a holding thread with a
|
// Note: It should not be possible for the situation where the mutex has a holding thread with a
|
||||||
// zero lock count to occur. The real kernel still checks for this, so we do too.
|
// zero lock count to occur. The real kernel still checks for this, so we do too.
|
||||||
if (lock_count <= 0)
|
if (lock_count <= 0)
|
||||||
return ResultCode(ErrorDescription::InvalidResultValue, ErrorModule::Kernel,
|
return Result(ErrorDescription::InvalidResultValue, ErrorModule::Kernel,
|
||||||
ErrorSummary::InvalidState, ErrorLevel::Permanent);
|
ErrorSummary::InvalidState, ErrorLevel::Permanent);
|
||||||
|
|
||||||
lock_count--;
|
lock_count--;
|
||||||
@ -96,7 +96,7 @@ ResultCode Mutex::Release(Thread* thread) {
|
|||||||
kernel.PrepareReschedule();
|
kernel.PrepareReschedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mutex::AddWaitingThread(std::shared_ptr<Thread> thread) {
|
void Mutex::AddWaitingThread(std::shared_ptr<Thread> thread) {
|
||||||
|
@ -60,7 +60,7 @@ public:
|
|||||||
* @param thread Thread that wants to release the mutex.
|
* @param thread Thread that wants to release the mutex.
|
||||||
* @returns The result code of the operation.
|
* @returns The result code of the operation.
|
||||||
*/
|
*/
|
||||||
ResultCode Release(Thread* thread);
|
Result Release(Thread* thread);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KernelSystem& kernel;
|
KernelSystem& kernel;
|
||||||
|
@ -192,9 +192,12 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VAddr out_addr{};
|
||||||
|
|
||||||
auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions,
|
auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions,
|
||||||
MemoryState memory_state) {
|
MemoryState memory_state) {
|
||||||
HeapAllocate(segment.addr, segment.size, permissions, memory_state, true);
|
HeapAllocate(std::addressof(out_addr), segment.addr, segment.size, permissions,
|
||||||
|
memory_state, true);
|
||||||
kernel.memory.WriteBlock(*this, segment.addr, codeset->memory.data() + segment.offset,
|
kernel.memory.WriteBlock(*this, segment.addr, codeset->memory.data() + segment.offset,
|
||||||
segment.size);
|
segment.size);
|
||||||
};
|
};
|
||||||
@ -205,8 +208,8 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
|
|||||||
MapSegment(codeset->DataSegment(), VMAPermission::ReadWrite, MemoryState::Private);
|
MapSegment(codeset->DataSegment(), VMAPermission::ReadWrite, MemoryState::Private);
|
||||||
|
|
||||||
// Allocate and map stack
|
// Allocate and map stack
|
||||||
HeapAllocate(Memory::HEAP_VADDR_END - stack_size, stack_size, VMAPermission::ReadWrite,
|
HeapAllocate(std::addressof(out_addr), Memory::HEAP_VADDR_END - stack_size, stack_size,
|
||||||
MemoryState::Locked, true);
|
VMAPermission::ReadWrite, MemoryState::Locked, true);
|
||||||
|
|
||||||
// Map special address mappings
|
// Map special address mappings
|
||||||
kernel.MapSharedPages(vm_manager);
|
kernel.MapSharedPages(vm_manager);
|
||||||
@ -246,14 +249,14 @@ VAddr Process::GetLinearHeapLimit() const {
|
|||||||
return GetLinearHeapBase() + memory_region->size;
|
return GetLinearHeapBase() + memory_region->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<VAddr> Process::HeapAllocate(VAddr target, u32 size, VMAPermission perms,
|
Result Process::HeapAllocate(VAddr* out_addr, VAddr target, u32 size, VMAPermission perms,
|
||||||
MemoryState memory_state, bool skip_range_check) {
|
MemoryState memory_state, bool skip_range_check) {
|
||||||
LOG_DEBUG(Kernel, "Allocate heap target={:08X}, size={:08X}", target, size);
|
LOG_DEBUG(Kernel, "Allocate heap target={:08X}, size={:08X}", target, size);
|
||||||
if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END ||
|
if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END ||
|
||||||
target + size < target) {
|
target + size < target) {
|
||||||
if (!skip_range_check) {
|
if (!skip_range_check) {
|
||||||
LOG_ERROR(Kernel, "Invalid heap address");
|
LOG_ERROR(Kernel, "Invalid heap address");
|
||||||
return ERR_INVALID_ADDRESS;
|
return ResultInvalidAddress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -261,13 +264,13 @@ ResultVal<VAddr> Process::HeapAllocate(VAddr target, u32 size, VMAPermission per
|
|||||||
if (vma->second.type != VMAType::Free ||
|
if (vma->second.type != VMAType::Free ||
|
||||||
vma->second.base + vma->second.size < target + size) {
|
vma->second.base + vma->second.size < target + size) {
|
||||||
LOG_ERROR(Kernel, "Trying to allocate already allocated memory");
|
LOG_ERROR(Kernel, "Trying to allocate already allocated memory");
|
||||||
return ERR_INVALID_ADDRESS_STATE;
|
return ResultInvalidAddressState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto allocated_fcram = memory_region->HeapAllocate(size);
|
auto allocated_fcram = memory_region->HeapAllocate(size);
|
||||||
if (allocated_fcram.empty()) {
|
if (allocated_fcram.empty()) {
|
||||||
LOG_ERROR(Kernel, "Not enough space");
|
LOG_ERROR(Kernel, "Not enough space");
|
||||||
return ERR_OUT_OF_HEAP_MEMORY;
|
return ResultOutOfHeapMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maps heap block by block
|
// Maps heap block by block
|
||||||
@ -290,20 +293,19 @@ ResultVal<VAddr> Process::HeapAllocate(VAddr target, u32 size, VMAPermission per
|
|||||||
memory_used += size;
|
memory_used += size;
|
||||||
resource_limit->Reserve(ResourceLimitType::Commit, size);
|
resource_limit->Reserve(ResourceLimitType::Commit, size);
|
||||||
|
|
||||||
return target;
|
*out_addr = target;
|
||||||
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode Process::HeapFree(VAddr target, u32 size) {
|
Result Process::HeapFree(VAddr target, u32 size) {
|
||||||
LOG_DEBUG(Kernel, "Free heap target={:08X}, size={:08X}", target, size);
|
LOG_DEBUG(Kernel, "Free heap target={:08X}, size={:08X}", target, size);
|
||||||
if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END ||
|
if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END ||
|
||||||
target + size < target) {
|
target + size < target) {
|
||||||
LOG_ERROR(Kernel, "Invalid heap address");
|
LOG_ERROR(Kernel, "Invalid heap address");
|
||||||
return ERR_INVALID_ADDRESS;
|
return ResultInvalidAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 0) {
|
R_SUCCEED_IF(size == 0);
|
||||||
return RESULT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Free heaps block by block
|
// Free heaps block by block
|
||||||
CASCADE_RESULT(auto backing_blocks, vm_manager.GetBackingBlocksForRange(target, size));
|
CASCADE_RESULT(auto backing_blocks, vm_manager.GetBackingBlocksForRange(target, size));
|
||||||
@ -313,23 +315,23 @@ ResultCode Process::HeapFree(VAddr target, u32 size) {
|
|||||||
holding_memory -= MemoryRegionInfo::Interval(backing_offset, backing_offset + block_size);
|
holding_memory -= MemoryRegionInfo::Interval(backing_offset, backing_offset + block_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode result = vm_manager.UnmapRange(target, size);
|
Result result = vm_manager.UnmapRange(target, size);
|
||||||
ASSERT(result.IsSuccess());
|
ASSERT(result.IsSuccess());
|
||||||
|
|
||||||
memory_used -= size;
|
memory_used -= size;
|
||||||
resource_limit->Release(ResourceLimitType::Commit, size);
|
resource_limit->Release(ResourceLimitType::Commit, size);
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<VAddr> Process::LinearAllocate(VAddr target, u32 size, VMAPermission perms) {
|
Result Process::LinearAllocate(VAddr* out_addr, VAddr target, u32 size, VMAPermission perms) {
|
||||||
LOG_DEBUG(Kernel, "Allocate linear heap target={:08X}, size={:08X}", target, size);
|
LOG_DEBUG(Kernel, "Allocate linear heap target={:08X}, size={:08X}", target, size);
|
||||||
u32 physical_offset;
|
u32 physical_offset;
|
||||||
if (target == 0) {
|
if (target == 0) {
|
||||||
auto offset = memory_region->LinearAllocate(size);
|
auto offset = memory_region->LinearAllocate(size);
|
||||||
if (!offset) {
|
if (!offset) {
|
||||||
LOG_ERROR(Kernel, "Not enough space");
|
LOG_ERROR(Kernel, "Not enough space");
|
||||||
return ERR_OUT_OF_HEAP_MEMORY;
|
return ResultOutOfHeapMemory;
|
||||||
}
|
}
|
||||||
physical_offset = *offset;
|
physical_offset = *offset;
|
||||||
target = physical_offset + GetLinearHeapAreaAddress();
|
target = physical_offset + GetLinearHeapAreaAddress();
|
||||||
@ -337,7 +339,7 @@ ResultVal<VAddr> Process::LinearAllocate(VAddr target, u32 size, VMAPermission p
|
|||||||
if (target < GetLinearHeapBase() || target + size > GetLinearHeapLimit() ||
|
if (target < GetLinearHeapBase() || target + size > GetLinearHeapLimit() ||
|
||||||
target + size < target) {
|
target + size < target) {
|
||||||
LOG_ERROR(Kernel, "Invalid linear heap address");
|
LOG_ERROR(Kernel, "Invalid linear heap address");
|
||||||
return ERR_INVALID_ADDRESS;
|
return ResultInvalidAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kernel would crash/return error when target doesn't meet some requirement.
|
// Kernel would crash/return error when target doesn't meet some requirement.
|
||||||
@ -350,7 +352,7 @@ ResultVal<VAddr> Process::LinearAllocate(VAddr target, u32 size, VMAPermission p
|
|||||||
physical_offset = target - GetLinearHeapAreaAddress(); // relative to FCRAM
|
physical_offset = target - GetLinearHeapAreaAddress(); // relative to FCRAM
|
||||||
if (!memory_region->LinearAllocate(physical_offset, size)) {
|
if (!memory_region->LinearAllocate(physical_offset, size)) {
|
||||||
LOG_ERROR(Kernel, "Trying to allocate already allocated memory");
|
LOG_ERROR(Kernel, "Trying to allocate already allocated memory");
|
||||||
return ERR_INVALID_ADDRESS_STATE;
|
return ResultInvalidAddressState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,26 +368,20 @@ ResultVal<VAddr> Process::LinearAllocate(VAddr target, u32 size, VMAPermission p
|
|||||||
resource_limit->Reserve(ResourceLimitType::Commit, size);
|
resource_limit->Reserve(ResourceLimitType::Commit, size);
|
||||||
|
|
||||||
LOG_DEBUG(Kernel, "Allocated at target={:08X}", target);
|
LOG_DEBUG(Kernel, "Allocated at target={:08X}", target);
|
||||||
return target;
|
*out_addr = target;
|
||||||
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode Process::LinearFree(VAddr target, u32 size) {
|
Result Process::LinearFree(VAddr target, u32 size) {
|
||||||
LOG_DEBUG(Kernel, "Free linear heap target={:08X}, size={:08X}", target, size);
|
LOG_DEBUG(Kernel, "Free linear heap target={:08X}, size={:08X}", target, size);
|
||||||
if (target < GetLinearHeapBase() || target + size > GetLinearHeapLimit() ||
|
if (target < GetLinearHeapBase() || target + size > GetLinearHeapLimit() ||
|
||||||
target + size < target) {
|
target + size < target) {
|
||||||
LOG_ERROR(Kernel, "Invalid linear heap address");
|
LOG_ERROR(Kernel, "Invalid linear heap address");
|
||||||
return ERR_INVALID_ADDRESS;
|
return ResultInvalidAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 0) {
|
R_SUCCEED_IF(size == 0);
|
||||||
return RESULT_SUCCESS;
|
R_TRY(vm_manager.UnmapRange(target, size));
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode result = vm_manager.UnmapRange(target, size);
|
|
||||||
if (result.IsError()) {
|
|
||||||
LOG_ERROR(Kernel, "Trying to free already freed memory");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 physical_offset = target - GetLinearHeapAreaAddress(); // relative to FCRAM
|
u32 physical_offset = target - GetLinearHeapAreaAddress(); // relative to FCRAM
|
||||||
memory_region->Free(physical_offset, size);
|
memory_region->Free(physical_offset, size);
|
||||||
@ -394,7 +390,7 @@ ResultCode Process::LinearFree(VAddr target, u32 size) {
|
|||||||
memory_used -= size;
|
memory_used -= size;
|
||||||
resource_limit->Release(ResourceLimitType::Commit, size);
|
resource_limit->Release(ResourceLimitType::Commit, size);
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<VAddr> Process::AllocateThreadLocalStorage() {
|
ResultVal<VAddr> Process::AllocateThreadLocalStorage() {
|
||||||
@ -435,7 +431,7 @@ ResultVal<VAddr> Process::AllocateThreadLocalStorage() {
|
|||||||
if (!offset) {
|
if (!offset) {
|
||||||
LOG_ERROR(Kernel_SVC,
|
LOG_ERROR(Kernel_SVC,
|
||||||
"Not enough space in BASE linear region to allocate a new TLS page");
|
"Not enough space in BASE linear region to allocate a new TLS page");
|
||||||
return ERR_OUT_OF_MEMORY;
|
return ResultOutOfMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
holding_tls_memory +=
|
holding_tls_memory +=
|
||||||
@ -467,14 +463,13 @@ ResultVal<VAddr> Process::AllocateThreadLocalStorage() {
|
|||||||
return tls_address;
|
return tls_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode Process::Map(VAddr target, VAddr source, u32 size, VMAPermission perms,
|
Result Process::Map(VAddr target, VAddr source, u32 size, VMAPermission perms, bool privileged) {
|
||||||
bool privileged) {
|
|
||||||
LOG_DEBUG(Kernel, "Map memory target={:08X}, source={:08X}, size={:08X}, perms={:08X}", target,
|
LOG_DEBUG(Kernel, "Map memory target={:08X}, source={:08X}, size={:08X}, perms={:08X}", target,
|
||||||
source, size, perms);
|
source, size, perms);
|
||||||
if (!privileged && (source < Memory::HEAP_VADDR || source + size > Memory::HEAP_VADDR_END ||
|
if (!privileged && (source < Memory::HEAP_VADDR || source + size > Memory::HEAP_VADDR_END ||
|
||||||
source + size < source)) {
|
source + size < source)) {
|
||||||
LOG_ERROR(Kernel, "Invalid source address");
|
LOG_ERROR(Kernel, "Invalid source address");
|
||||||
return ERR_INVALID_ADDRESS;
|
return ResultInvalidAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(wwylele): check target address range. Is it also restricted to heap region?
|
// TODO(wwylele): check target address range. Is it also restricted to heap region?
|
||||||
@ -489,17 +484,17 @@ ResultCode Process::Map(VAddr target, VAddr source, u32 size, VMAPermission perm
|
|||||||
VMAPermission::ReadWrite,
|
VMAPermission::ReadWrite,
|
||||||
MemoryState::AliasCode, perms);
|
MemoryState::AliasCode, perms);
|
||||||
} else {
|
} else {
|
||||||
return ERR_INVALID_ADDRESS;
|
return ResultInvalidAddress;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return ERR_INVALID_ADDRESS_STATE;
|
return ResultInvalidAddressState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto vma = vm_manager.FindVMA(target);
|
auto vma = vm_manager.FindVMA(target);
|
||||||
if (vma->second.type != VMAType::Free || vma->second.base + vma->second.size < target + size) {
|
if (vma->second.type != VMAType::Free || vma->second.base + vma->second.size < target + size) {
|
||||||
LOG_ERROR(Kernel, "Trying to map to already allocated memory");
|
LOG_ERROR(Kernel, "Trying to map to already allocated memory");
|
||||||
return ERR_INVALID_ADDRESS_STATE;
|
return ResultInvalidAddressState;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryState source_state = privileged ? MemoryState::Locked : MemoryState::Aliased;
|
MemoryState source_state = privileged ? MemoryState::Locked : MemoryState::Aliased;
|
||||||
@ -507,8 +502,8 @@ ResultCode Process::Map(VAddr target, VAddr source, u32 size, VMAPermission perm
|
|||||||
VMAPermission source_perm = privileged ? VMAPermission::None : VMAPermission::ReadWrite;
|
VMAPermission source_perm = privileged ? VMAPermission::None : VMAPermission::ReadWrite;
|
||||||
|
|
||||||
// Mark source region as Aliased
|
// Mark source region as Aliased
|
||||||
CASCADE_CODE(vm_manager.ChangeMemoryState(source, size, MemoryState::Private,
|
R_TRY(vm_manager.ChangeMemoryState(source, size, MemoryState::Private, VMAPermission::ReadWrite,
|
||||||
VMAPermission::ReadWrite, source_state, source_perm));
|
source_state, source_perm));
|
||||||
|
|
||||||
CASCADE_RESULT(auto backing_blocks, vm_manager.GetBackingBlocksForRange(source, size));
|
CASCADE_RESULT(auto backing_blocks, vm_manager.GetBackingBlocksForRange(source, size));
|
||||||
VAddr interval_target = target;
|
VAddr interval_target = target;
|
||||||
@ -520,16 +515,15 @@ ResultCode Process::Map(VAddr target, VAddr source, u32 size, VMAPermission perm
|
|||||||
interval_target += block_size;
|
interval_target += block_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
ResultCode Process::Unmap(VAddr target, VAddr source, u32 size, VMAPermission perms,
|
Result Process::Unmap(VAddr target, VAddr source, u32 size, VMAPermission perms, bool privileged) {
|
||||||
bool privileged) {
|
|
||||||
LOG_DEBUG(Kernel, "Unmap memory target={:08X}, source={:08X}, size={:08X}, perms={:08X}",
|
LOG_DEBUG(Kernel, "Unmap memory target={:08X}, source={:08X}, size={:08X}, perms={:08X}",
|
||||||
target, source, size, perms);
|
target, source, size, perms);
|
||||||
if (!privileged && (source < Memory::HEAP_VADDR || source + size > Memory::HEAP_VADDR_END ||
|
if (!privileged && (source < Memory::HEAP_VADDR || source + size > Memory::HEAP_VADDR_END ||
|
||||||
source + size < source)) {
|
source + size < source)) {
|
||||||
LOG_ERROR(Kernel, "Invalid source address");
|
LOG_ERROR(Kernel, "Invalid source address");
|
||||||
return ERR_INVALID_ADDRESS;
|
return ResultInvalidAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(wwylele): check target address range. Is it also restricted to heap region?
|
// TODO(wwylele): check target address range. Is it also restricted to heap region?
|
||||||
@ -543,10 +537,10 @@ ResultCode Process::Unmap(VAddr target, VAddr source, u32 size, VMAPermission pe
|
|||||||
VMAPermission::None, MemoryState::Private,
|
VMAPermission::None, MemoryState::Private,
|
||||||
perms);
|
perms);
|
||||||
} else {
|
} else {
|
||||||
return ERR_INVALID_ADDRESS;
|
return ResultInvalidAddress;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return ERR_INVALID_ADDRESS_STATE;
|
return ResultInvalidAddressState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,13 +549,13 @@ ResultCode Process::Unmap(VAddr target, VAddr source, u32 size, VMAPermission pe
|
|||||||
|
|
||||||
MemoryState source_state = privileged ? MemoryState::Locked : MemoryState::Aliased;
|
MemoryState source_state = privileged ? MemoryState::Locked : MemoryState::Aliased;
|
||||||
|
|
||||||
CASCADE_CODE(vm_manager.UnmapRange(target, size));
|
R_TRY(vm_manager.UnmapRange(target, size));
|
||||||
|
|
||||||
// Change back source region state. Note that the permission is reprotected according to param
|
// Change back source region state. Note that the permission is reprotected according to param
|
||||||
CASCADE_CODE(vm_manager.ChangeMemoryState(source, size, source_state, VMAPermission::None,
|
R_TRY(vm_manager.ChangeMemoryState(source, size, source_state, VMAPermission::None,
|
||||||
MemoryState::Private, perms));
|
MemoryState::Private, perms));
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::FreeAllMemory() {
|
void Process::FreeAllMemory() {
|
||||||
|
@ -231,19 +231,18 @@ public:
|
|||||||
VAddr GetLinearHeapBase() const;
|
VAddr GetLinearHeapBase() const;
|
||||||
VAddr GetLinearHeapLimit() const;
|
VAddr GetLinearHeapLimit() const;
|
||||||
|
|
||||||
ResultVal<VAddr> HeapAllocate(VAddr target, u32 size, VMAPermission perms,
|
Result HeapAllocate(VAddr* out_addr, VAddr target, u32 size, VMAPermission perms,
|
||||||
MemoryState memory_state = MemoryState::Private,
|
MemoryState memory_state = MemoryState::Private,
|
||||||
bool skip_range_check = false);
|
bool skip_range_check = false);
|
||||||
ResultCode HeapFree(VAddr target, u32 size);
|
Result HeapFree(VAddr target, u32 size);
|
||||||
|
|
||||||
ResultVal<VAddr> LinearAllocate(VAddr target, u32 size, VMAPermission perms);
|
Result LinearAllocate(VAddr* out_addr, VAddr target, u32 size, VMAPermission perms);
|
||||||
ResultCode LinearFree(VAddr target, u32 size);
|
Result LinearFree(VAddr target, u32 size);
|
||||||
|
|
||||||
ResultVal<VAddr> AllocateThreadLocalStorage();
|
ResultVal<VAddr> AllocateThreadLocalStorage();
|
||||||
|
|
||||||
ResultCode Map(VAddr target, VAddr source, u32 size, VMAPermission perms,
|
Result Map(VAddr target, VAddr source, u32 size, VMAPermission perms, bool privileged = false);
|
||||||
bool privileged = false);
|
Result Unmap(VAddr target, VAddr source, u32 size, VMAPermission perms,
|
||||||
ResultCode Unmap(VAddr target, VAddr source, u32 size, VMAPermission perms,
|
|
||||||
bool privileged = false);
|
bool privileged = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -26,9 +26,7 @@ ResultVal<std::shared_ptr<Semaphore>> KernelSystem::CreateSemaphore(s32 initial_
|
|||||||
s32 max_count,
|
s32 max_count,
|
||||||
std::string name) {
|
std::string name) {
|
||||||
|
|
||||||
if (initial_count > max_count) {
|
R_UNLESS(initial_count <= max_count, ResultInvalidCombinationKernel);
|
||||||
return ERR_INVALID_COMBINATION_KERNEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the semaphore is created, some slots are reserved for other threads,
|
// When the semaphore is created, some slots are reserved for other threads,
|
||||||
// and the rest is reserved for the caller thread
|
// and the rest is reserved for the caller thread
|
||||||
@ -44,21 +42,20 @@ bool Semaphore::ShouldWait(const Thread* thread) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Semaphore::Acquire(Thread* thread) {
|
void Semaphore::Acquire(Thread* thread) {
|
||||||
if (available_count <= 0)
|
if (available_count <= 0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
--available_count;
|
--available_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<s32> Semaphore::Release(s32 release_count) {
|
Result Semaphore::Release(s32* out_count, s32 release_count) {
|
||||||
if (max_count - available_count < release_count)
|
R_UNLESS(max_count >= release_count + available_count, ResultOutOfRangeKernel);
|
||||||
return ERR_OUT_OF_RANGE_KERNEL;
|
|
||||||
|
|
||||||
s32 previous_count = available_count;
|
*out_count = available_count;
|
||||||
available_count += release_count;
|
available_count += release_count;
|
||||||
|
|
||||||
WakeupAllWaitingThreads();
|
WakeupAllWaitingThreads();
|
||||||
|
|
||||||
return previous_count;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
* @param release_count The number of slots to release
|
* @param release_count The number of slots to release
|
||||||
* @return The number of free slots the semaphore had before this call
|
* @return The number of free slots the semaphore had before this call
|
||||||
*/
|
*/
|
||||||
ResultVal<s32> Release(s32 release_count);
|
Result Release(s32* out_count, s32 release_count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
|
@ -24,14 +24,12 @@ namespace Kernel {
|
|||||||
ServerPort::ServerPort(KernelSystem& kernel) : WaitObject(kernel) {}
|
ServerPort::ServerPort(KernelSystem& kernel) : WaitObject(kernel) {}
|
||||||
ServerPort::~ServerPort() {}
|
ServerPort::~ServerPort() {}
|
||||||
|
|
||||||
ResultVal<std::shared_ptr<ServerSession>> ServerPort::Accept() {
|
Result ServerPort::Accept(std::shared_ptr<ServerSession>* out_server_session) {
|
||||||
if (pending_sessions.empty()) {
|
R_UNLESS(!pending_sessions.empty(), ResultNoPendingSessions);
|
||||||
return ERR_NO_PENDING_SESSIONS;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto session = std::move(pending_sessions.back());
|
*out_server_session = std::move(pending_sessions.back());
|
||||||
pending_sessions.pop_back();
|
pending_sessions.pop_back();
|
||||||
return session;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerPort::ShouldWait(const Thread* thread) const {
|
bool ServerPort::ShouldWait(const Thread* thread) const {
|
||||||
|
@ -39,9 +39,9 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts a pending incoming connection on this port. If there are no pending sessions, will
|
* Accepts a pending incoming connection on this port. If there are no pending sessions, will
|
||||||
* return ERR_NO_PENDING_SESSIONS.
|
* return ResultNoPendingSessions.
|
||||||
*/
|
*/
|
||||||
ResultVal<std::shared_ptr<ServerSession>> Accept();
|
Result Accept(std::shared_ptr<ServerSession>* out_server_session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the HLE handler template for the port. ServerSessions crated by connecting to this port
|
* Sets the HLE handler template for the port. ServerSessions crated by connecting to this port
|
||||||
|
@ -77,7 +77,7 @@ void ServerSession::Acquire(Thread* thread) {
|
|||||||
pending_requesting_threads.pop_back();
|
pending_requesting_threads.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ServerSession::HandleSyncRequest(std::shared_ptr<Thread> thread) {
|
Result ServerSession::HandleSyncRequest(std::shared_ptr<Thread> thread) {
|
||||||
// The ServerSession received a sync request, this means that there's new data available
|
// The ServerSession received a sync request, this means that there's new data available
|
||||||
// from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or
|
// from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or
|
||||||
// similar.
|
// similar.
|
||||||
@ -136,7 +136,7 @@ ResultCode ServerSession::HandleSyncRequest(std::shared_ptr<Thread> thread) {
|
|||||||
// If this ServerSession does not have an HLE implementation, just wake up the threads waiting
|
// If this ServerSession does not have an HLE implementation, just wake up the threads waiting
|
||||||
// on it.
|
// on it.
|
||||||
WakeupAllWaitingThreads();
|
WakeupAllWaitingThreads();
|
||||||
return RESULT_SUCCESS;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
KernelSystem::SessionPair KernelSystem::CreateSessionPair(const std::string& name,
|
KernelSystem::SessionPair KernelSystem::CreateSessionPair(const std::string& name,
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user