boinc/client/prefs.C

75 lines
2.4 KiB
C++
Raw Normal View History

// The contents of this file are subject to the Mozilla Public License
// Version 1.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
//
// The Initial Developer of the Original Code is the SETI@home project.
// Portions created by the SETI@home project are Copyright (C) 2002
// University of California at Berkeley. All Rights Reserved.
//
// Contributor(s):
//
#include "windows_cpp.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "parse.h"
#include "error_numbers.h"
#include "prefs.h"
PREFS::PREFS() {
memset(this, 0, sizeof(PREFS));
};
int PREFS::parse(FILE* in) {
char buf[256];
memset(this, 0, sizeof(PREFS));
prefs_xml = strdup("<preferences>\n");
while (fgets(buf, 256, in)) {
prefs_xml = (char*) realloc(
prefs_xml, strlen(prefs_xml) + strlen(buf) + 1
);
strcat(prefs_xml, buf);
if (match_tag(buf, "</preferences>")) return 0;
else if (match_tag(buf, "<dont_run_on_batteries/>")) {
dont_run_on_batteries = true;
continue;
} else if (match_tag(buf, "<dont_run_if_user_active/>")) {
dont_run_if_user_active = true;
continue;
} else if (match_tag(buf, "<confirm_before_connecting/>")) {
confirm_before_connecting = true;
continue;
} else if (parse_double(buf, "<high_water_days>", high_water_days)) {
continue;
} else if (parse_double(buf, "<low_water_days>", low_water_days)) {
continue;
} else if (parse_double(buf, "<disk_max_used_gb>", disk_max_used_gb)) {
continue;
} else if (parse_double(buf, "<disk_max_used_pct>", disk_max_used_pct)) {
continue;
} else if (parse_double(buf, "<disk_min_free_gb>", disk_min_free_gb)) {
continue;
}
}
return ERR_XML_PARSE;
}
int PREFS::write(FILE* out) {
if (prefs_xml) fputs(prefs_xml, out);
return 0;
}