2002-04-30 22:22:54 +00:00
|
|
|
// 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):
|
|
|
|
//
|
|
|
|
|
2002-06-06 18:50:12 +00:00
|
|
|
#include "windows_cpp.h"
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2002-06-01 20:26:21 +00:00
|
|
|
#include <stdlib.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "parse.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "error_numbers.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "file_names.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "prefs.h"
|
|
|
|
|
|
|
|
PREFS::PREFS() {
|
2002-06-21 06:52:47 +00:00
|
|
|
mod_time = 0;
|
|
|
|
dont_run_on_batteries = false;
|
|
|
|
dont_run_if_user_active = false;
|
|
|
|
confirm_before_connecting = false;
|
2002-08-22 22:28:51 +00:00
|
|
|
high_water_days = 3;
|
|
|
|
low_water_days = 1;
|
|
|
|
disk_max_used_gb = 1;
|
|
|
|
disk_max_used_pct = 0.5;
|
|
|
|
disk_min_free_gb = 0.1;
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Parse XML based prefs, usually from prefs.xml
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int PREFS::parse(FILE* in) {
|
|
|
|
char buf[256];
|
2002-06-21 06:52:47 +00:00
|
|
|
PROJECT* project;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
while (fgets(buf, 256, in)) {
|
2002-09-26 05:57:10 +00:00
|
|
|
if (match_tag(buf, "</preferences>")) {
|
|
|
|
return 0;
|
2002-06-21 06:52:47 +00:00
|
|
|
} else if (match_tag(buf, "<dont_run_on_batteries/>")) {
|
2002-06-01 20:26:21 +00:00
|
|
|
dont_run_on_batteries = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
continue;
|
2002-06-01 20:26:21 +00:00
|
|
|
} 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)) {
|
2002-04-30 22:22:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Parse prefs.xml for user preferences
|
|
|
|
//
|
2002-06-21 06:52:47 +00:00
|
|
|
int PREFS::parse_file() {
|
|
|
|
FILE* f;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
f = fopen(PREFS_FILE_NAME, "r");
|
|
|
|
if (!f) return ERR_FOPEN;
|
|
|
|
retval = parse(f);
|
|
|
|
fclose(f);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
// Write the default preferences
|
2002-07-15 23:21:20 +00:00
|
|
|
// TODO: should mod_time really be 1?
|
2002-09-26 05:57:10 +00:00
|
|
|
//
|
|
|
|
int write_initial_prefs() {
|
2002-06-21 06:52:47 +00:00
|
|
|
FILE* f = fopen(PREFS_FILE_NAME, "w");
|
|
|
|
if (!f) return ERR_FOPEN;
|
|
|
|
fprintf(f,
|
|
|
|
"<preferences>\n"
|
|
|
|
" <mod_time>1</mod_time>\n"
|
|
|
|
" <high_water_days>2</high_water_days>\n"
|
|
|
|
" <low_water_days>1</low_water_days>\n"
|
2002-09-26 05:57:10 +00:00
|
|
|
"</preferences>\n"
|
2002-06-21 06:52:47 +00:00
|
|
|
);
|
|
|
|
fclose(f);
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|