From db4a1876424db4f2b28283b63179fd221d0b7baa Mon Sep 17 00:00:00 2001 From: Eric Heien Date: Fri, 6 Dec 2002 19:44:31 +0000 Subject: [PATCH] add/change/quit project svn path=/trunk/boinc/; revision=698 --- client/account.C | 99 +++++++++++++++++++++++++++++++++++++++++++ client/client_state.h | 3 ++ 2 files changed, 102 insertions(+) diff --git a/client/account.C b/client/account.C index dc78e10c00..89ce0b03ca 100644 --- a/client/account.C +++ b/client/account.C @@ -68,3 +68,102 @@ int CLIENT_STATE::parse_account_files() { return 0; } +int CLIENT_STATE::add_project(char* master_url, char* authenticator) +{ + char path[256]; + PROJECT* project; + FILE* f; + int retval; + + // check if this project is already running + if(lookup_project(master_url)) return -1; + + // create project state + write_account_file(master_url, authenticator); + get_account_filename(master_url, path); + f = fopen(path, "r"); + if (!f) return ERR_FOPEN; + project = new PROJECT; + retval = project->parse_account(f); + fclose(f); + if(retval) { + return retval; + } + + // remove any old files + retval = remove_project_dir(*project); + + retval = make_project_dir(*project); + if(retval) { + return retval; + } + projects.push_back(project); + return 0; +} + +int CLIENT_STATE::change_project(int index, char* master_url, char* authenticator) +{ + char path[256]; + PROJECT* project; + FILE* f; + int retval; + + // check if this project is already running + if(lookup_project(master_url)) return -1; + + // delete old file + project = projects[index]; + get_account_filename(project->master_url, path); + retval = file_delete(path); + + // create project state + write_account_file(master_url, authenticator); + get_account_filename(master_url, path); + f = fopen(path, "r"); + if (!f) return ERR_FOPEN; + retval = project->parse_account(f); + fclose(f); + if(retval) { + return retval; + } + + // remove any old files + retval = remove_project_dir(*project); + + retval = make_project_dir(*project); + if(retval) { + return retval; + } + return 0; +} + +int CLIENT_STATE::quit_project(int index) +{ + PROJECT* project = NULL; + vector ::iterator iter; + int curindex = 0; + + // find project and remove it from the vector + for(iter = projects.begin(); iter != projects.end(); iter ++) { + if(curindex == index) { + project = *iter; + projects.erase(iter); + break; + } + curindex ++; + } + if(project == NULL) return -1; + + // delete file + char path[256]; + int retval; + get_account_filename(project->master_url, path); + retval = file_delete(path); + +// delete project; //also somewhere else? + +#ifdef _WIN32 + AfxMessageBox("Please restart the client to complete the quit.", MB_OK, 0); +#endif + return 0; +} diff --git a/client/client_state.h b/client/client_state.h index 4051e37141..7ddb29257c 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -124,6 +124,9 @@ public: void handle_scheduler_reply(PROJECT*, char* scheduler_url); void set_client_state_dirty(char*); int report_project_error( RESULT &res, int err_num, char *err_msg ); + int add_project(char* master_url, char* authenticator); + int change_project(int index, char* master_url, char* authenticator); + int quit_project(int index); private: PROJECT* find_project_with_overdue_results(); bool some_project_rpc_ok();