summaryrefslogtreecommitdiff
path: root/setup_native/source/win32/customactions/reg4msdoc/registryvalueimpl.cxx
blob: 813d62db1c64abb05d74333b5db18b8c5eb965e1 (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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// RegistryValueImpl.cpp: Implementierung der Klasse RegistryValueImpl.
//
//////////////////////////////////////////////////////////////////////

#ifndef _REGISTRYVALUEIMPL_HXX_
#include "registryvalueimpl.hxx"
#endif

#include <malloc.h>
#include <windows.h>
#include <assert.h>

#include "stringconverter.hxx"

//#################################
// Creation/Destruction
//#################################

//--------------------------------------------
/**
*/
RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, int Value) :
    m_Name(Name),
    m_Type(REG_DWORD),
    m_IntData(Value)
{
}

//--------------------------------------------
/**
*/
RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, const std::wstring& Value) :
    m_Name(Name),
    m_Type(REG_SZ),
    m_StringData(Value),
    m_IntData(0)
{
}

//--------------------------------------------
/**
*/
RegistryValueImpl::RegistryValueImpl(const std::wstring& Name, const std::string& Value) :
    m_Name(Name),
    m_Type(REG_SZ),
    m_IntData(0)
{
    m_StringData = AnsiToUnicodeString(Value);
}

#if (_MSC_VER >= 1300)
RegistryValueImpl::RegistryValueImpl(const RegistryValueImpl& s) :
    m_Name(s.m_Name),
    m_Type(s.m_Type),
    m_StringData(s.m_StringData),
    m_IntData(s.m_IntData)
    {
}
#endif
//--------------------------------------------
/**
*/
RegistryValueImpl::~RegistryValueImpl()
{
}

//#################################
// Query
//#################################

//--------------------------------------------
/** Returns the name of the value
*/
std::wstring RegistryValueImpl::GetName() const
{
    return m_Name;
}

//--------------------------------------------
/** Return the size of data held
*/
size_t RegistryValueImpl::GetDataSize() const
{
    size_t size = 0;

    if (REG_DWORD == m_Type)
        size = sizeof(m_IntData);
    else if (REG_SZ == m_Type)
        size = m_StringData.length() ? ((m_StringData.length() + 1) * sizeof(wchar_t)) : 0;

    return size;
}

//--------------------------------------------
/** Get a pointer to the data buffer
    in order to copy the data
*/
const void* RegistryValueImpl::GetDataBuffer() const
{
    const void* pData = 0;

    if (REG_DWORD == m_Type)
        pData = reinterpret_cast<const void*>(&m_IntData);
    else if (REG_SZ == m_Type)
        pData = reinterpret_cast<const void*>(m_StringData.c_str());

    return pData;
}

//--------------------------------------------
/** Returns the data as string
*/
std::wstring RegistryValueImpl::GetDataAsUniString() const
{
    assert(REG_SZ == m_Type);
    return m_StringData;
}

//--------------------------------------------
/** Returns the data as string
*/
std::string RegistryValueImpl::GetDataAsAnsiString() const
{
    assert(REG_SZ == m_Type);
    return UnicodeToAnsiString(m_StringData);
}

//--------------------------------------------
/** Returns the data as number
*/
int RegistryValueImpl::GetDataAsInt() const
{
    assert(REG_DWORD == m_Type);
    return m_IntData;
}

//--------------------------------------------
/** Returns the type of the data
*/
int RegistryValueImpl::GetType() const
{
    return m_Type;
}


//#################################
// Command
//#################################


//--------------------------------------------
/** Set a new name
*/
void RegistryValueImpl::SetName(const std::wstring& NewName)
{
    m_Name = NewName;
}

//--------------------------------------------
/**
*/
void RegistryValueImpl::SetValue(const std::wstring& NewValue)
{
    m_Type = REG_SZ;
    m_StringData = NewValue;
}

//--------------------------------------------
/**
*/
void RegistryValueImpl::SetValue(const std::string& NewValue)
{
    m_Type = REG_SZ;
    m_StringData = AnsiToUnicodeString(NewValue);
}

//--------------------------------------------
/**
*/
void RegistryValueImpl::SetValue(int NewValue)
{
    m_Type = REG_DWORD;
    m_IntData = NewValue;
}