diff --git a/client/client_state.h b/client/client_state.h index bd2e6b42b7..74ff594c74 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -77,6 +77,7 @@ using std::vector; struct CLIENT_STATE { vector platforms; vector projects; + // in alphabetical order, to improve display vector apps; vector file_infos; vector app_versions; @@ -456,6 +457,7 @@ struct CLIENT_STATE { int write_file_transfers_gui(MIOFILE&); int write_tasks_gui(MIOFILE&, bool); void sort_results(); + void sort_projects(); // --------------- cs_trickle.cpp: int read_trickle_files(PROJECT*, FILE*); diff --git a/client/cs_account.cpp b/client/cs_account.cpp index 15ed20e6ce..bd86d04749 100644 --- a/client/cs_account.cpp +++ b/client/cs_account.cpp @@ -353,6 +353,7 @@ int CLIENT_STATE::parse_account_files() { } } } + sort_projects(); return 0; } @@ -574,6 +575,7 @@ int CLIENT_STATE::add_project( retval = make_project_dir(*project); if (retval) return retval; projects.push_back(project); + sort_projects(); project->sched_rpc_pending = RPC_REASON_INIT; set_client_state_dirty("Add project"); return 0; diff --git a/client/cs_statefile.cpp b/client/cs_statefile.cpp index 10c4c74219..dbf80da189 100644 --- a/client/cs_statefile.cpp +++ b/client/cs_statefile.cpp @@ -568,6 +568,18 @@ void CLIENT_STATE::sort_results() { } } +static inline bool project_name_compare(PROJECT* p0, PROJECT* p1) { + return strcasecmp(p0->project_name, p1->project_name) < 0; +} + +void CLIENT_STATE::sort_projects() { + std::sort( + projects.begin(), + projects.end(), + project_name_compare + ); +} + #ifndef SIM // Write the client_state.xml file diff --git a/client/work_fetch.cpp b/client/work_fetch.cpp index 7f73875a86..eb98c5f486 100644 --- a/client/work_fetch.cpp +++ b/client/work_fetch.cpp @@ -517,8 +517,8 @@ void WORK_FETCH::piggyback_work_request(PROJECT* p) { } if (check_higher_priority_projects) { PROJECT* p2 = NULL; - for (unsigned int j=0; jsched_priority == p->sched_priority) continue; if (p2->pwf.project_reason) { @@ -627,9 +627,10 @@ void WORK_FETCH::setup() { } } + projects_sorted = gstate.projects; std::sort( - gstate.projects.begin(), - gstate.projects.end(), + projects_sorted.begin(), + projects_sorted.end(), higher_priority ); if (log_flags.work_fetch_debug) { @@ -657,8 +658,8 @@ PROJECT* WORK_FETCH::choose_project() { // scan projects in order of decreasing priority // bool found = false; - for (unsigned int j=0; jpwf.project_reason) { WF_DEBUG(msg_printf(p, MSG_INFO, "skip: cfwr %d", p->pwf.project_reason);) diff --git a/client/work_fetch.h b/client/work_fetch.h index 6c0ece63dc..ea231365e9 100644 --- a/client/work_fetch.h +++ b/client/work_fetch.h @@ -299,6 +299,8 @@ struct PROJECT_WORK_FETCH { // global work fetch state // struct WORK_FETCH { + std::vector projects_sorted; + // projects in decreasing priority order void setup(); PROJECT* choose_project(); // Find a project to ask for work.