-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwslregistry.h
97 lines (77 loc) · 3.18 KB
/
wslregistry.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* This file is part of wslman.
*
* wslman is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* wslman is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with wslman. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "wslwrap.h"
#include <string>
#include <vector>
class WslDistribution
{
public:
WslDistribution();
bool isValid() const { return !m_uuid.empty(); }
const std::wstring &name() const { return m_name; }
std::wstring uuid() const { return m_uuid; }
WslApi::Version version() const { return m_version; }
uint32_t defaultUID() const { return m_defaultUID; }
WslApi::DistributionFlags flags() const { return m_flags; }
const std::vector<std::wstring> &defaultEnvironment() const { return m_defaultEnvironment; }
uint32_t state() const { return m_state; }
const std::wstring &path() const { return m_path; }
const std::wstring &kernelCmdLine() const { return m_kernelCmdLine; }
const std::wstring &packageFamilyName() const { return m_packageFamilyName; }
std::wstring rootfsPath() const;
void setName(const std::wstring &name);
void setVersion(WslApi::Version version);
void setDefaultUID(uint32_t uid);
void setFlags(WslApi::DistributionFlags flags);
void setState(uint32_t state);
void setPath(const std::wstring &path);
void setKernelCmdLine(const std::wstring &cmdline);
void setPackageFamilyName(const std::wstring &packageFamilyName);
void addEnvironment(const std::wstring &key, const std::wstring &value);
void delEnvironment(const std::wstring &key);
void setEnvironment(const std::vector<std::wstring> &env);
static WslDistribution loadFromRegistry(const std::wstring &path);
static WslDistribution create();
private:
// Available in WSL API
std::wstring m_name;
WslApi::Version m_version;
uint32_t m_defaultUID;
WslApi::DistributionFlags m_flags;
std::vector<std::wstring> m_defaultEnvironment;
// Available only in the Registry
std::wstring m_uuid;
uint32_t m_state;
std::wstring m_path;
std::wstring m_kernelCmdLine;
std::wstring m_packageFamilyName;
};
class WslRegistry
{
public:
WslRegistry();
~WslRegistry();
std::vector<WslDistribution> getDistributions() const;
WslDistribution defaultDistribution() const;
void setDefaultDistribution(const std::wstring &uuid);
WslDistribution findDistByName(const std::wstring &name) const;
static WslDistribution findDistByUuid(const std::wstring &uuid);
WslDistribution registerDistribution(const std::wstring &name,
const std::wstring &path);
private:
HKEY m_lxssKey;
};