+static int setting_set_priority(const TCHAR *service_name, void *param, const TCHAR *name, void *default_value, value_t *value, const TCHAR *additional) {
+ HKEY key = (HKEY) param;
+ if (! param) return -1;
+
+ TCHAR *priority_string;
+ int i;
+ long error;
+
+ if (value && value->string) priority_string = value->string;
+ else if (default_value) priority_string = (TCHAR *) default_value;
+ else {
+ error = RegDeleteValue(key, name);
+ if (error == ERROR_SUCCESS || error == ERROR_FILE_NOT_FOUND) return 0;
+ print_message(stderr, NSSM_MESSAGE_REGDELETEVALUE_FAILED, name, service_name, error_string(error));
+ return -1;
+ }
+
+ for (i = 0; priority_strings[i]; i++) {
+ if (! str_equiv(priority_strings[i], priority_string)) continue;
+
+ if (default_value && str_equiv(priority_string, (TCHAR *) default_value)) {
+ error = RegDeleteValue(key, name);
+ if (error == ERROR_SUCCESS || error == ERROR_FILE_NOT_FOUND) return 0;
+ print_message(stderr, NSSM_MESSAGE_REGDELETEVALUE_FAILED, name, service_name, error_string(error));
+ return -1;
+ }
+
+ if (set_number(key, (TCHAR *) name, priority_index_to_constant(i))) return -1;
+ return 1;
+ }
+
+ print_message(stderr, NSSM_MESSAGE_INVALID_PRIORITY, priority_string);
+ for (i = 0; priority_strings[i]; i++) _ftprintf(stderr, _T("%s\n"), priority_strings[i]);
+
+ return -1;
+}
+
+static int setting_get_priority(const TCHAR *service_name, void *param, const TCHAR *name, void *default_value, value_t *value, const TCHAR *additional) {
+ HKEY key = (HKEY) param;
+ if (! param) return -1;
+
+ unsigned long constant;
+ switch (get_number(key, (TCHAR *) name, &constant, false)) {
+ case 0: return value_from_string(name, value, (const TCHAR *) default_value);
+ case -1: return -1;
+ }
+
+ return value_from_string(name, value, priority_strings[priority_constant_to_index(constant)]);
+}
+