~aleteoryx/muditaos

ref: 3887c43ca51732e2c32b2ce35215e2bba11645d4 muditaos/module-utils/bootconfig/include/boot/bootconfig.hpp -rw-r--r-- 2.2 KiB
3887c43c — Lefucjusz [CP-1734] Create factory reset reboot UI 3 years ago
                                                                                
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once
#include <json11.hpp>
#include <string>
#include <filesystem>

namespace boot
{
    namespace json
    {
        inline constexpr auto main            = "main";
        inline constexpr auto os_type         = "ostype";
        inline constexpr auto os_image        = "imagename";
        inline constexpr auto os_version      = "version";
        inline constexpr auto timestamp       = "timestamp";
        inline constexpr auto misc            = "misc";
        inline constexpr auto git_info        = "git";
        inline constexpr auto os_git_revision = "git_commit";
        inline constexpr auto os_git_branch   = "git_branch";
        inline constexpr auto bootloader      = "bootloader";
    } // namespace json

    class BootConfig
    {
      public:
        BootConfig();
        static int version_compare(const std::string &v1, const std::string &v2);
        [[nodiscard]] json11::Json to_json() const;
        int load();
        int save();
        auto os_image() -> const std::string &
        {
            return m_os_image;
        }
        auto os_type() -> const std::string &
        {
            return m_os_type;
        }
        auto os_version() -> const std::string &
        {
            return m_os_version;
        }
        auto bootloader_version() -> const std::string &
        {
            return m_bootloader_version;
        }
        auto timestamp() -> const std::string &
        {
            return m_timestamp;
        }
        auto os_root_path() -> const std::filesystem::path &
        {
            return m_os_root_path;
        }

      private:
        bool loadBootConfig(const std::filesystem::path &bootJsonPath);
        std::filesystem::path getCurrentBootJSON();

      private:
        std::string m_os_image{"boot.bin"};
        std::string m_os_type{"current"};
        std::string m_os_version;
        std::string m_bootloader_version;
        std::string m_timestamp;
        json11::Json m_boot_json_parsed;
        std::filesystem::path m_os_root_path;
        std::filesystem::path m_boot_json;
    };
} // namespace boot