client: bug fixes to sorting projects alphabetically

There were two problems:
1) we were sorting before parsing the client state file
   (which is where we get project names from)
2) the Win implementation of strcasecmp() wasn't right;
   it returned difference but not order.
This commit is contained in:
David Anderson 2015-04-10 13:20:19 -05:00
parent fd13d09dd4
commit af97b5f9be
5 changed files with 11 additions and 6 deletions

View File

@ -511,6 +511,10 @@ int CLIENT_STATE::init() {
set_ncpus();
show_host_info();
// this follows parse_state_file() because that's where we read project names
//
sort_projects_by_name();
// check for app_config.xml files in project dirs
//
check_app_config();

View File

@ -457,7 +457,7 @@ struct CLIENT_STATE {
int write_file_transfers_gui(MIOFILE&);
int write_tasks_gui(MIOFILE&, bool);
void sort_results();
void sort_projects();
void sort_projects_by_name();
// --------------- cs_trickle.cpp:
int read_trickle_files(PROJECT*, FILE*);

View File

@ -353,7 +353,6 @@ int CLIENT_STATE::parse_account_files() {
}
}
}
sort_projects();
return 0;
}
@ -575,7 +574,7 @@ int CLIENT_STATE::add_project(
retval = make_project_dir(*project);
if (retval) return retval;
projects.push_back(project);
sort_projects();
sort_projects_by_name();
project->sched_rpc_pending = RPC_REASON_INIT;
set_client_state_dirty("Add project");
return 0;

View File

@ -572,7 +572,7 @@ static inline bool project_name_compare(PROJECT* p0, PROJECT* p1) {
return strcasecmp(p0->project_name, p1->project_name) < 0;
}
void CLIENT_STATE::sort_projects() {
void CLIENT_STATE::sort_projects_by_name() {
std::sort(
projects.begin(),
projects.end(),

View File

@ -46,9 +46,11 @@ inline int strcasecmp(const char* s1, const char* s2) {
while (*s1 && *s2) {
char c1 = tolower(*s1++);
char c2 = tolower(*s2++);
if (c1 != c2) return 1; // don't worry about +/-
if (c1 < c2) return -1;
if (c1 > c2) return 1;
}
if (*s1 || *s2) return 1;
if (*s1) return 1;
if (*s2) return -1;
return 0;
}
#endif