MsiFlags.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace AppSecInc {
4 namespace Msi {
5 namespace Flags {
6 
7 typedef struct
8 {
9  LPCWSTR name;
10  WORD value;
12 
13 typedef struct
14 {
15  LPCWSTR name;
16  UINT value;
18 
19 typedef struct
20 {
21  LPCWSTR name;
22  DWORD value;
24 
26 template<typename T, typename R>
27 R GetFlagValue(const std::wstring& name, const T& flagmap)
28 {
29  for (int i = 0; i < ARRAYSIZE(flagmap); i++)
30  {
31  if (flagmap[i].name == name)
32  {
33  return flagmap[i].value;
34  }
35  }
36 
37  std::stringstream error;
38  error << "invalid flag name: " << AppSecInc::StringUtils::wc2mb(name);
39  throw std::exception(error.str().c_str());
40 }
41 
43 template<typename T, typename R>
44 std::wstring GetFlagName(const R& value, const T& flagmap)
45 {
46  for (int i = 0; i < ARRAYSIZE(flagmap); i++)
47  {
48  if (flagmap[i].value == value)
49  {
50  return flagmap[i].name;
51  }
52  }
53 
54  std::stringstream error;
55  error << "invalid flag value: " << AppSecInc::StringUtils::toString(value);
56  throw std::exception(error.str().c_str());
57 }
58 
60 template<typename T, typename R>
61 R GetFlagsValue(const std::vector<std::wstring>& flags, const T& flagmap)
62 {
63  R result = 0;
64 
65  for each (const std::wstring& flag_entry in flags)
66  {
67  if (flag_entry.length() == 0)
68  continue;
69 
70  R item_result = GetFlagValue<T, R>(flag_entry, flagmap);
71  result |= item_result;
72  }
73 
74  return result;
75 }
76 
78 template <typename T, typename R>
79 R GetStringFlagsValue(const std::wstring& flags, const T& flagmap)
80 {
81  std::vector<std::wstring> flags_vector;
82  AppSecInc::StringUtils::tokenizeOnChar(flags, flags_vector, L"|,; \t\n");
83  return GetFlagsValue<T, R>(flags_vector, flagmap);
84 }
85 
87 template <typename T, typename R>
88 R GetPropertyValue(MsiInstall& msiInstall, const std::wstring& name, const T& flagmap)
89 {
90  std::wstring property_value = msiInstall.GetProperty(name);
91  return GetStringFlagsValue<T, R>(property_value, flagmap);
92 }
93 
95 template<typename T>
96 ULONG GetFlagValue(const std::wstring& name, const T& flagmap)
97 {
98  return GetFlagValue<T, ULONG>(name, flagmap);
99 }
100 
101 template<typename T>
102 ULONG GetFlagsValue(const std::vector<std::wstring>& flags, const T& flagmap)
103 {
104  return GetFlagsValue<T, ULONG>(flags, flagmap);
105 }
106 
108 template <typename T>
109 ULONG GetStringFlagsValue(const std::wstring& flags, const T& flagmap)
110 {
111  return GetStringFlagsValue<T, ULONG>(flags, flagmap);
112 }
113 
115 template <typename T>
116 ULONG GetPropertyValue(MsiInstall& msiInstall, const std::wstring& name, const T& flagmap)
117 {
118  return GetPropertyValue<T, ULONG>(msiInstall, name, flagmap);
119 }
120 
121 }}}
122 
struct AppSecInc::Msi::Flags::FlagMapEntryWORD FlagMapEntry
R GetStringFlagsValue(const std::wstring &flags, const T &flagmap)
convert a string of flags to the combined flag value
Definition: MsiFlags.h:79
void tokenizeOnChar(const std::string &ss, std::vector< std::string > &tokens, const std::string &delims)
Definition: StringUtils.cpp:54
Definition: MsiFlags.h:13
DWORD value
Definition: MsiFlags.h:22
R GetFlagsValue(const std::vector< std::wstring > &flags, const T &flagmap)
convert a vector of flags to the combined flag value
Definition: MsiFlags.h:61
Definition: MsiFlags.h:7
R GetPropertyValue(MsiInstall &msiInstall, const std::wstring &name, const T &flagmap)
retreive an MSI property and convert to a flag value
Definition: MsiFlags.h:88
A wrapper for an MSIHANDLE with MSI support functions.
Definition: MsiInstall.h:7
std::wstring GetFlagName(const R &value, const T &flagmap)
convert a single flag value to its flag name
Definition: MsiFlags.h:44
R GetFlagValue(const std::wstring &name, const T &flagmap)
convert a single flag to its flag value
Definition: MsiFlags.h:27
LPCWSTR name
Definition: MsiFlags.h:9
std::string toString(VARIANT from)
Definition: StringUtils.cpp:359
WORD value
Definition: MsiFlags.h:10
LPCWSTR name
Definition: MsiFlags.h:15
Definition: MsiFlags.h:19
std::string wc2mb(const std::wstring &from)
Definition: StringUtils.cpp:184
std::wstring GetProperty(const std::wstring &name)
get a property
Definition: MsiInstall.cpp:26
LPCWSTR name
Definition: MsiFlags.h:21
UINT value
Definition: MsiFlags.h:16


© Application Security Inc. - All Rights Reserved http://msiext.codeplex.com