summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2013-01-24 17:57:19 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2013-01-24 18:30:12 +0100
commit9c127b32a27e5077f4688f5241ef1890f0217038 (patch)
tree7f85187f67a554e33f3775487cd5914e19c7b632 /tools
parent252a23c3b0ec1794e36eed77c130f848100b9512 (diff)
downloadmsitools-9c127b32a27e5077f4688f5241ef1890f0217038.tar.gz
msitools-9c127b32a27e5077f4688f5241ef1890f0217038.tar.xz
msitools-9c127b32a27e5077f4688f5241ef1890f0217038.zip
wixl: do not use enum_from_string directly, make it generic
The right spelling is multiString, not multi-string as defined by vala, so we cannot use enum_from_string. Thus do not make it public and use it internally from a (possibly more complex) from_string static method of the enum. I haven't checked the usage in msi-default.vala.
Diffstat (limited to 'tools')
-rw-r--r--tools/wixl/builder.vala42
-rw-r--r--tools/wixl/msi-default.vala2
-rw-r--r--tools/wixl/util.vala4
3 files changed, 37 insertions, 11 deletions
diff --git a/tools/wixl/builder.vala b/tools/wixl/builder.vala
index 231ae9a..dd4d646 100644
--- a/tools/wixl/builder.vala
+++ b/tools/wixl/builder.vala
@@ -354,7 +354,11 @@ namespace Wixl {
enum FeatureDisplay {
HIDDEN = 0,
EXPAND,
- COLLAPSE
+ COLLAPSE;
+
+ public static FeatureDisplay from_string(string s) throws GLib.Error {
+ return enum_from_string<FeatureDisplay> (s);
+ }
}
WixFeature? feature_root;
int feature_display;
@@ -373,7 +377,7 @@ namespace Wixl {
int display = FeatureDisplay.COLLAPSE;
if (feature.Display != null) {
try {
- display = enum_from_string (typeof (FeatureDisplay), feature.Display);
+ display = FeatureDisplay.from_string (feature.Display);
} catch (GLib.Error error) {
display = int.parse (feature.Display);
if (display != 0)
@@ -440,11 +444,15 @@ namespace Wixl {
enum InstallMode {
INSTALL = 1,
UNINSTALL,
- BOTH
+ BOTH;
+
+ public static InstallMode from_string(string s) throws GLib.Error {
+ return enum_from_string<InstallMode> (s);
+ }
}
public override void visit_remove_folder (WixRemoveFolder rm) throws GLib.Error {
- var on = enum_from_string (typeof (InstallMode), rm.On);
+ var on = InstallMode.from_string (rm.On);
var comp = rm.parent as WixComponent;
var dir = resolve<WixDirectory> (comp.parent);
@@ -466,7 +474,21 @@ namespace Wixl {
INTEGER,
BINARY,
EXPANDABLE,
- MULTI_STRING
+ MULTI_STRING;
+
+ public static RegistryValueType from_string(string s) throws GLib.Error {
+ if (s == "string")
+ return STRING;
+ if (s == "integer")
+ return INTEGER;
+ if (s == "binary")
+ return BINARY;
+ if (s == "expandable")
+ return EXPANDABLE;
+ if (s == "multistring")
+ return MULTI_STRING;
+ throw new Wixl.Error.FAILED ("Can't convert string to enum");
+ }
}
enum RegistryRoot {
@@ -474,7 +496,11 @@ namespace Wixl {
HKCU,
HKLM,
HKU,
- HKMU
+ HKMU;
+
+ public static RegistryRoot from_string(string s) throws GLib.Error {
+ return enum_from_string<RegistryRoot> (s);
+ }
}
public override void visit_registry_value (WixRegistryValue reg) throws GLib.Error {
@@ -499,8 +525,8 @@ namespace Wixl {
reg_root = reg.Root;
var value = reg.Value;
- var t = enum_from_string (typeof (RegistryValueType), reg.Type);
- var r = enum_from_string (typeof (RegistryRoot), reg_root.down ());
+ var t = RegistryValueType.from_string (reg.Type);
+ var r = RegistryRoot.from_string (reg_root.down ());
if (reg.Id == null) {
reg.Id = generate_id ("reg", 4,
comp.Id,
diff --git a/tools/wixl/msi-default.vala b/tools/wixl/msi-default.vala
index e800b72..6d536b0 100644
--- a/tools/wixl/msi-default.vala
+++ b/tools/wixl/msi-default.vala
@@ -173,7 +173,7 @@ namespace Wixl {
ActionInfo? action = null;
try {
- action = actions[enum_from_string (typeof (Action), name.down ())];
+ action = actions[enum_from_string<Action> (name.down ())];
} catch (GLib.Error error) {
}
diff --git a/tools/wixl/util.vala b/tools/wixl/util.vala
index 13269c7..1b201ec 100644
--- a/tools/wixl/util.vala
+++ b/tools/wixl/util.vala
@@ -23,8 +23,8 @@ namespace Wixl {
return (string) udn;
}
- public int enum_from_string (Type t, string str) throws GLib.Error {
- var k = (EnumClass)t.class_ref ();
+ public G enum_from_string<G> (string str) throws GLib.Error {
+ var k = (EnumClass)typeof(G).class_ref ();
var v = k.get_value_by_nick (str);
if (v == null)