summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-03-09 10:54:58 +0000
committerRichard Hughes <richard@hughsie.com>2015-03-09 11:03:26 +0000
commit057353cc1ca2cb36361c6661b7671a2cc26cac31 (patch)
treeeda7e3f23f352c9c332a8fe1baa9f90ba19dd2d3
parent5f76175e80ab1af9c9869036a0908e1c07de8650 (diff)
downloadappstream-glib-057353cc1ca2cb36361c6661b7671a2cc26cac31.tar.gz
Support Dirids in .inf files
A Dirid is a number that maps to a location in Windows, e.g. '%12%' corresponds to '%SystemRoot%\system32\drivers'
-rw-r--r--libappstream-glib/as-inf.c21
-rw-r--r--libappstream-glib/as-self-test.c8
2 files changed, 29 insertions, 0 deletions
diff --git a/libappstream-glib/as-inf.c b/libappstream-glib/as-inf.c
index 3390307..d1b50ff 100644
--- a/libappstream-glib/as-inf.c
+++ b/libappstream-glib/as-inf.c
@@ -79,6 +79,20 @@ as_inf_make_case_insensitive (AsInfHelper *helper, const gchar *text)
}
/**
+ * as_inf_string_isdigits:
+ */
+static gboolean
+as_inf_string_isdigits (const gchar *str)
+{
+ guint i;
+ for (i = 0; str[i] != '\0'; i++) {
+ if (!g_ascii_isdigit (str[i]))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
* as_inf_replace_variable:
*
* Replaces any instance of %val% with the 'val' key value found in @dict.
@@ -99,10 +113,17 @@ as_inf_replace_variable (AsInfHelper *helper, const gchar *line, GError **error)
/* the text between the substitutions */
if (i % 2 == 0) {
+ g_strdelimit (split[i], "\\", '/');
g_string_append (new, split[i]);
continue;
}
+ /* a Dirid */
+ if (as_inf_string_isdigits (split[i])) {
+ g_string_append (new, "/tmp");
+ continue;
+ }
+
/* replace or ignore things not (yet) in the dictionary */
lower = as_inf_make_case_insensitive (helper, split[i]);
tmp = g_hash_table_lookup (helper->dict, lower);
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 6e8718e..33f3b96 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -3385,6 +3385,14 @@ as_test_inf_func (void)
g_assert_cmpstr (tmp, ==, "SomeRandomValue=1");
g_free (tmp);
+ /* Dirids */
+ ret = as_inf_load_data (kf, "[DriverServiceInst]\nServiceBinary=%12%\\service.exe", 0, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+ tmp = g_key_file_get_string (kf, "DriverServiceInst", "ServiceBinary", NULL);
+ g_assert_cmpstr (tmp, ==, "/tmp/service.exe");
+ g_free (tmp);
+
/* comments */
data = "; group priority\n"
"[Metadata] ; similar to [Version]\n"