|
@@ -11,7 +11,7 @@
|
|
|
|
|
|
namespace Keyboard {
|
|
|
|
|
|
-Optional<CharacterMapData> CharacterMapFile::load_from_file(const String& filename)
|
|
|
+ErrorOr<CharacterMapData> CharacterMapFile::load_from_file(const String& filename)
|
|
|
{
|
|
|
auto path = filename;
|
|
|
if (!path.ends_with(".json")) {
|
|
@@ -22,20 +22,10 @@ Optional<CharacterMapData> CharacterMapFile::load_from_file(const String& filena
|
|
|
path = full_path.to_string();
|
|
|
}
|
|
|
|
|
|
- auto file = Core::File::construct(path);
|
|
|
- file->open(Core::OpenMode::ReadOnly);
|
|
|
- if (!file->is_open()) {
|
|
|
- dbgln("Failed to open {}: {}", path, file->error_string());
|
|
|
- return {};
|
|
|
- }
|
|
|
-
|
|
|
+ auto file = TRY(Core::File::open(path, Core::OpenMode::ReadOnly));
|
|
|
auto file_contents = file->read_all();
|
|
|
- auto json_result = JsonValue::from_string(file_contents);
|
|
|
- if (json_result.is_error()) {
|
|
|
- dbgln("Failed to load character map from file {}", path);
|
|
|
- return {};
|
|
|
- }
|
|
|
- auto json = json_result.value().as_object();
|
|
|
+ auto json_result = TRY(JsonValue::from_string(file_contents));
|
|
|
+ const auto& json = json_result.as_object();
|
|
|
|
|
|
Vector<u32> map = read_map(json, "map");
|
|
|
Vector<u32> shift_map = read_map(json, "shift_map");
|