blob: 9687e36daff33ee628c87519bfd2ec137db14e50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
/*
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ProjectConfig.h"
#include <AK/NonnullOwnPtr.h>
#include <LibCore/File.h>
namespace HackStudio {
ProjectConfig::ProjectConfig(JsonObject config)
: m_config(move(config))
{
}
ErrorOr<NonnullOwnPtr<ProjectConfig>> ProjectConfig::try_load_project_config(DeprecatedString path)
{
auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
auto file_contents = TRY(file->read_until_eof());
auto json = TRY(JsonValue::from_string(file_contents));
if (!json.is_object())
return Error::from_string_literal("The topmost JSON element is not an object");
return try_make<ProjectConfig>(json.as_object());
}
NonnullOwnPtr<ProjectConfig> ProjectConfig::create_empty()
{
JsonObject empty {};
return adopt_own(*new ProjectConfig(empty));
}
Optional<DeprecatedString> ProjectConfig::read_key(DeprecatedString key_name) const
{
return m_config.get_deprecated_string(key_name);
}
}
|