From 9c127b32a27e5077f4688f5241ef1890f0217038 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 24 Jan 2013 17:57:19 +0100 Subject: 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. --- tools/wixl/builder.vala | 42 ++++++++++++++++++++++++++++++++++-------- tools/wixl/msi-default.vala | 2 +- tools/wixl/util.vala | 4 ++-- 3 files changed, 37 insertions(+), 11 deletions(-) (limited to 'tools') 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 (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 (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 (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 (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 (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 (string str) throws GLib.Error { + var k = (EnumClass)typeof(G).class_ref (); var v = k.get_value_by_nick (str); if (v == null) -- cgit