]> wimlib.net Git - wimlib/commitdiff
Add wimlib_get_image_property() and wimlib_set_image_property()
authorEric Biggers <ebiggers3@gmail.com>
Sat, 3 Oct 2015 17:42:35 +0000 (12:42 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 3 Oct 2015 20:02:55 +0000 (15:02 -0500)
include/wimlib.h
src/xml.c

index 09a427985469274526e3a80172aafcf4551dedc0..c95e7635db4f014062caf338ceac69ae9be6c431 100644 (file)
  *
  * wimlib_update_image() can add, delete, and rename files in a WIM image.
  *
  *
  * wimlib_update_image() can add, delete, and rename files in a WIM image.
  *
- * wimlib_set_image_name(), wimlib_set_image_descripton(), and
- * wimlib_set_image_flags() can change other image metadata.
+ * wimlib_set_image_name(), wimlib_set_image_descripton(),
+ * wimlib_set_image_flags(), and wimlib_set_image_property() can change other
+ * image metadata.
  *
  * wimlib_set_wim_info() can change information about the WIM file itself, such
  * as the boot index.
  *
  * wimlib_set_wim_info() can change information about the WIM file itself, such
  * as the boot index.
@@ -3133,6 +3134,33 @@ wimlib_get_image_description(const WIMStruct *wim, int image);
 extern const wimlib_tchar *
 wimlib_get_image_name(const WIMStruct *wim, int image);
 
 extern const wimlib_tchar *
 wimlib_get_image_name(const WIMStruct *wim, int image);
 
+/**
+ * @ingroup G_wim_information
+ *
+ * Get a per-image property from the WIM's XML document.  This is an alternative
+ * to wimlib_get_image_name() and wimlib_get_image_descripton() which allows
+ * getting any simple string property.
+ *
+ * @param wim
+ *     Pointer to the ::WIMStruct for the WIM.
+ * @param image
+ *     The 1-based index of the image for which to get the property.
+ * @param property_name
+ *     The name of the image property, for example "NAME", "DESCRIPTION", or
+ *     "TOTALBYTES".  The name can contain forward slashes to indicate a nested
+ *     XML element; for example, "WINDOWS/VERSION/BUILD" indicates the BUILD
+ *     element nested within the VERSION element nested within the WINDOWS
+ *     element.  The <tt>[</tt> character is reserved for future use.
+ *
+ * @return
+ *     The property's value as a wimlib_tchar string, or @c NULL if there is no
+ *     such property.  The string may not remain valid after later library
+ *     calls, so the caller should duplicate it if needed.
+ */
+extern const wimlib_tchar *
+wimlib_get_image_property(const WIMStruct *wim, int image,
+                         const wimlib_tchar *property_name);
+
 /**
  * @ingroup G_general
  *
 /**
  * @ingroup G_general
  *
@@ -3960,6 +3988,37 @@ wimlib_set_image_flags(WIMStruct *wim, int image, const wimlib_tchar *flags);
 extern int
 wimlib_set_image_name(WIMStruct *wim, int image, const wimlib_tchar *name);
 
 extern int
 wimlib_set_image_name(WIMStruct *wim, int image, const wimlib_tchar *name);
 
+/**
+ * @ingroup G_modifying_wims
+ *
+ * Add, modify, or remove a per-image property from the WIM's XML document.
+ * This is an alternative to wimlib_set_image_name(),
+ * wimlib_set_image_descripton(), and wimlib_set_image_flags() which allows
+ * manipulating any simple string property.
+ *
+ * @param wim
+ *     Pointer to the ::WIMStruct for the WIM.
+ * @param image
+ *     The 1-based index of the image for which to set the property.
+ * @param property_name
+ *     The name of the image property in the same format documented for
+ *     wimlib_get_image_property().
+ * @param property_value
+ *     If not NULL and not empty, the property is set to this value.
+ *     Otherwise, the property is removed from the XML document.
+ *
+ * @return 0 on success; a ::wimlib_error_code value on failure.
+ *
+ * @retval ::WIMLIB_ERR_INVALID_IMAGE
+ *     @p image does not exist in @p wim.
+ * @retval ::WIMLIB_ERR_INVALID_PARAM
+ *     @p property_name has an unsupported format.
+ */
+extern int
+wimlib_set_image_property(WIMStruct *wim, int image,
+                         const wimlib_tchar *property_name,
+                         const wimlib_tchar *property_value);
+
 /**
  * @ingroup G_general
  *
 /**
  * @ingroup G_general
  *
index 60643756ac7f1dde86c559bb20ee2af5455f3585..fdc3ed2ff07259a0d98eef3a61d32de97f92a6c0 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -1380,6 +1380,20 @@ wimlib_get_image_description(const WIMStruct *wim, int image)
        return get_image_property(wim, image, "DESCRIPTION", NULL);
 }
 
        return get_image_property(wim, image, "DESCRIPTION", NULL);
 }
 
+WIMLIBAPI const tchar *
+wimlib_get_image_property(const WIMStruct *wim, int image,
+                         const tchar *property_name)
+{
+       const xmlChar *name;
+       const tchar *value;
+
+       if (tstr_get_utf8(property_name, &name))
+               return NULL;
+       value = get_image_property(wim, image, name, NULL);
+       tstr_put_utf8(name);
+       return value;
+}
+
 WIMLIBAPI int
 wimlib_set_image_name(WIMStruct *wim, int image, const tchar *name)
 {
 WIMLIBAPI int
 wimlib_set_image_name(WIMStruct *wim, int image, const tchar *name)
 {
@@ -1400,3 +1414,18 @@ wimlib_set_image_flags(WIMStruct *wim, int image, const tchar *flags)
 {
        return set_image_property(wim, image, "FLAGS", flags);
 }
 {
        return set_image_property(wim, image, "FLAGS", flags);
 }
+
+WIMLIBAPI int
+wimlib_set_image_property(WIMStruct *wim, int image, const tchar *property_name,
+                         const tchar *property_value)
+{
+       const xmlChar *name;
+       int ret;
+
+       ret = tstr_get_utf8(property_name, &name);
+       if (ret)
+               return ret;
+       ret = set_image_property(wim, image, name, property_value);
+       tstr_put_utf8(name);
+       return ret;
+}