summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar wwylele2016-06-01 10:42:37 +0300
committerGravatar wwylele2016-07-03 08:23:59 +0300
commitab2eef396ad6633f67419daa1b473898bef1c43a (patch)
tree00a23ca7b18a992b958a8ce058e719c470460610 /src
parentService::CFG: move known block ID to an enum (diff)
downloadyuzu-ab2eef396ad6633f67419daa1b473898bef1c43a.tar.gz
yuzu-ab2eef396ad6633f67419daa1b473898bef1c43a.tar.xz
yuzu-ab2eef396ad6633f67419daa1b473898bef1c43a.zip
Service::CFG/FS: add and refactor out utilities for front-end
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/cfg/cfg.cpp71
-rw-r--r--src/core/hle/service/cfg/cfg.h60
-rw-r--r--src/core/hle/service/fs/archive.cpp24
-rw-r--r--src/core/hle/service/fs/archive.h6
4 files changed, 146 insertions, 15 deletions
diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp
index 0f95464e6..a5dc47322 100644
--- a/src/core/hle/service/cfg/cfg.cpp
+++ b/src/core/hle/service/cfg/cfg.cpp
@@ -449,11 +449,7 @@ ResultCode FormatConfig() {
449 return RESULT_SUCCESS; 449 return RESULT_SUCCESS;
450} 450}
451 451
452void Init() { 452ResultCode LoadConfigNANDSaveFile() {
453 AddService(new CFG_I_Interface);
454 AddService(new CFG_S_Interface);
455 AddService(new CFG_U_Interface);
456
457 // Open the SystemSaveData archive 0x00010017 453 // Open the SystemSaveData archive 0x00010017
458 FileSys::Path archive_path(cfg_system_savedata_id); 454 FileSys::Path archive_path(cfg_system_savedata_id);
459 auto archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); 455 auto archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path);
@@ -481,14 +477,75 @@ void Init() {
481 if (config_result.Succeeded()) { 477 if (config_result.Succeeded()) {
482 auto config = config_result.MoveFrom(); 478 auto config = config_result.MoveFrom();
483 config->backend->Read(0, CONFIG_SAVEFILE_SIZE, cfg_config_file_buffer.data()); 479 config->backend->Read(0, CONFIG_SAVEFILE_SIZE, cfg_config_file_buffer.data());
484 return; 480 return RESULT_SUCCESS;
485 } 481 }
486 482
487 FormatConfig(); 483 return FormatConfig();
484}
485
486void Init() {
487 AddService(new CFG_I_Interface);
488 AddService(new CFG_S_Interface);
489 AddService(new CFG_U_Interface);
490
491 LoadConfigNANDSaveFile();
488} 492}
489 493
490void Shutdown() { 494void Shutdown() {
491} 495}
492 496
497void SetUsername(const std::u16string& name) {
498 ASSERT(name.size() <= 10);
499 UsernameBlock block{};
500 name.copy(block.username, name.size());
501 SetConfigInfoBlock(UsernameBlockID, sizeof(block), 4, &block);
502}
503
504std::u16string GetUsername() {
505 UsernameBlock block;
506 GetConfigInfoBlock(UsernameBlockID, sizeof(block), 8, &block);
507
508 // the username string in the block isn't null-terminated,
509 // so we need to find the end manually.
510 std::u16string username(block.username, ARRAY_SIZE(block.username));
511 const size_t pos = username.find(u'\0');
512 if (pos != std::u16string::npos)
513 username.erase(pos);
514 return username;
515}
516
517void SetBirthday(u8 month, u8 day) {
518 BirthdayBlock block = { month, day };
519 SetConfigInfoBlock(BirthdayBlockID, sizeof(block), 4, &block);
520}
521
522std::tuple<u8, u8> GetBirthday() {
523 BirthdayBlock block;
524 GetConfigInfoBlock(BirthdayBlockID, sizeof(block), 8, &block);
525 return std::make_tuple(block.month, block.day);
526}
527
528void SetSystemLanguage(SystemLanguage language) {
529 u8 block = language;
530 SetConfigInfoBlock(LanguageBlockID, sizeof(block), 4, &block);
531}
532
533SystemLanguage GetSystemLanguage() {
534 u8 block;
535 GetConfigInfoBlock(LanguageBlockID, sizeof(block), 8, &block);
536 return static_cast<SystemLanguage>(block);
537}
538
539void SetSoundOutputMode(SoundOutputMode mode) {
540 u8 block = mode;
541 SetConfigInfoBlock(SoundOutputModeBlockID, sizeof(block), 4, &block);
542}
543
544SoundOutputMode GetSoundOutputMode() {
545 u8 block;
546 GetConfigInfoBlock(SoundOutputModeBlockID, sizeof(block), 8, &block);
547 return static_cast<SoundOutputMode>(block);
548}
549
493} // namespace CFG 550} // namespace CFG
494} // namespace Service 551} // namespace Service
diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h
index 4822433cf..18f60f4ca 100644
--- a/src/core/hle/service/cfg/cfg.h
+++ b/src/core/hle/service/cfg/cfg.h
@@ -5,6 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <string>
8 9
9#include "common/common_types.h" 10#include "common/common_types.h"
10 11
@@ -271,11 +272,70 @@ ResultCode UpdateConfigNANDSavegame();
271 */ 272 */
272ResultCode FormatConfig(); 273ResultCode FormatConfig();
273 274
275/**
276 * Open the config savegame file and load it to the memory buffer
277 * @returns ResultCode indicating the result of the operation, 0 on success
278 */
279ResultCode LoadConfigNANDSaveFile();
280
274/// Initialize the config service 281/// Initialize the config service
275void Init(); 282void Init();
276 283
277/// Shutdown the config service 284/// Shutdown the config service
278void Shutdown(); 285void Shutdown();
279 286
287// Utilities for frontend to set config data.
288// Note: before calling these functions, LoadConfigNANDSaveFile should be called,
289// and UpdateConfigNANDSavegame should be called after making changes to config data.
290
291/**
292 * Sets the username in config savegame.
293 * @param name the username to set. The maximum size is 10 in char16_t.
294 */
295void SetUsername(const std::u16string& name);
296
297/**
298 * Gets the username from config savegame.
299 * @returns the username
300 */
301std::u16string GetUsername();
302
303/**
304 * Sets the profile birthday in config savegame.
305 * @param month the month of birthday.
306 * @param day the day of the birthday.
307 */
308void SetBirthday(u8 month, u8 day);
309
310/**
311 * Gets the profile birthday from the config savegame.
312 * @returns a tuple of (month, day) of birthday
313 */
314std::tuple<u8, u8> GetBirthday();
315
316/**
317 * Sets the system language in config savegame.
318 * @param language the system language to set.
319 */
320void SetSystemLanguage(SystemLanguage language);
321
322/**
323 * Gets the system language from config savegame.
324 * @returns the system language
325 */
326SystemLanguage GetSystemLanguage();
327
328/**
329 * Sets the sound output mode in config savegame.
330 * @param mode the sound output mode to set
331 */
332void SetSoundOutputMode(SoundOutputMode mode);
333
334/**
335 * Gets the sound output mode from config savegame.
336 * @returns the sound output mode
337 */
338SoundOutputMode GetSoundOutputMode();
339
280} // namespace CFG 340} // namespace CFG
281} // namespace Service 341} // namespace Service
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index 81b9abe4c..cc7af7218 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -255,7 +255,7 @@ using FileSys::ArchiveFactory;
255 255
256/** 256/**
257 * Map of registered archives, identified by id code. Once an archive is registered here, it is 257 * Map of registered archives, identified by id code. Once an archive is registered here, it is
258 * never removed until the FS service is shut down. 258 * never removed until UnregisterArchiveTypes is called.
259 */ 259 */
260static boost::container::flat_map<ArchiveIdCode, std::unique_ptr<ArchiveFactory>> id_code_map; 260static boost::container::flat_map<ArchiveIdCode, std::unique_ptr<ArchiveFactory>> id_code_map;
261 261
@@ -516,12 +516,7 @@ ResultCode CreateSystemSaveData(u32 high, u32 low) {
516 return RESULT_SUCCESS; 516 return RESULT_SUCCESS;
517} 517}
518 518
519/// Initialize archives 519void RegisterArchiveTypes() {
520void ArchiveInit() {
521 next_handle = 1;
522
523 AddService(new FS::Interface);
524
525 // TODO(Subv): Add the other archive types (see here for the known types: 520 // TODO(Subv): Add the other archive types (see here for the known types:
526 // http://3dbrew.org/wiki/FS:OpenArchive#Archive_idcodes). 521 // http://3dbrew.org/wiki/FS:OpenArchive#Archive_idcodes).
527 522
@@ -558,10 +553,23 @@ void ArchiveInit() {
558 RegisterArchiveType(std::move(systemsavedata_factory), ArchiveIdCode::SystemSaveData); 553 RegisterArchiveType(std::move(systemsavedata_factory), ArchiveIdCode::SystemSaveData);
559} 554}
560 555
556void UnregisterArchiveTypes() {
557 id_code_map.clear();
558}
559
560/// Initialize archives
561void ArchiveInit() {
562 next_handle = 1;
563
564 AddService(new FS::Interface);
565
566 RegisterArchiveTypes();
567}
568
561/// Shutdown archives 569/// Shutdown archives
562void ArchiveShutdown() { 570void ArchiveShutdown() {
563 handle_map.clear(); 571 handle_map.clear();
564 id_code_map.clear(); 572 UnregisterArchiveTypes();
565} 573}
566 574
567} // namespace FS 575} // namespace FS
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h
index 006606740..f7a50a3a7 100644
--- a/src/core/hle/service/fs/archive.h
+++ b/src/core/hle/service/fs/archive.h
@@ -235,5 +235,11 @@ void ArchiveInit();
235/// Shutdown archives 235/// Shutdown archives
236void ArchiveShutdown(); 236void ArchiveShutdown();
237 237
238/// Register all archive types
239void RegisterArchiveTypes();
240
241/// Unregister all archive types
242void UnregisterArchiveTypes();
243
238} // namespace FS 244} // namespace FS
239} // namespace Service 245} // namespace Service