From: Marc-Andre R. C. <kx...@us...> - 2002-06-06 02:13:33
|
Update of /cvsroot/planeshift/planeshift/src/updater/client In directory usw-pr-cvs1:/tmp/cvs-serv8432/src/updater/client Modified Files: main.cpp Makefile.am uclient.cpp uclient.h Removed Files: config.xml untgz.c Log Message: Fixed the updater to support the linux distribution. Changed compression to gz only instead of tgz. Index: main.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/client/main.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** main.cpp 30 May 2002 12:06:29 -0000 1.3 --- main.cpp 6 Jun 2002 02:13:29 -0000 1.4 *************** *** 19,22 **** --- 19,25 ---- #include <config.h> + #ifdef OS_UNIX + #include <unistd.h> + #endif #include <iostream.h> #include <fstream.h> *************** *** 29,32 **** --- 32,36 ---- bool LoadConfig(sConfig & config, char *filename); + void WriteConfig(int port=13330, csString addr="the-wing.com", char *md5="", int autorun=1); void Help(void); *************** *** 37,43 **** csCommandLineParser *clp; sConfig config; ! char * filename = "config.xml"; const char *val; ! uClient *uc; // display program info --- 41,47 ---- csCommandLineParser *clp; sConfig config; ! char * filename = "uclient.xml"; const char *val; ! uClient *uc = NULL; // display program info *************** *** 57,60 **** --- 61,66 ---- if((val = clp->GetOption("serv")) || (val = clp->GetOption("s"))) config.addr = csStrNew(val); else config.addr = ""; + if((val = clp->GetOption("auto")) || (val = clp->GetOption("a"))) config.autorun = atoi(csStrNew(val)); + else config.autorun = -1; // free the commandline parser delete clp; *************** *** 72,82 **** //if(getchar() == 'q') break; } - } ! // free the client class ! if(uc) ! { ! delete uc; ! uc = NULL; } --- 78,119 ---- //if(getchar() == 'q') break; } ! // free the client class ! if(uc) ! { ! delete uc; ! uc = NULL; ! } ! ! if(config.autorun) ! { ! cout << "Press -ENTER- to launch PlaneShift..." << endl; ! cin.get(); // ~pause ! ! int ret = 0; ! #if defined(OS_UNIX) ! if(getuid() == 0) ! { ! cout << "You are about to run the PlaneShift client as 'root'." << endl; ! cout << "Do you want to continue? [y/n] "; ! char c; ! while(1) ! { ! c = cin.get(); ! if(c == 'y' || c == 'Y') ! { ! ret = execl("./psclient", ""); ! break; ! } ! else if(c == 'n' || c == 'N') break; ! } ! } ! else ret = execl("./psclient", ""); ! #elif defined(OS_WIN32) ! ret = _execl("psclient.exe", ""); ! #endif ! if(ret == -1) cout << "Could not run PlaneShift client. " << strerror(errno) << endl; ! } ! } *************** *** 97,102 **** if(!is) { ! cout << "Error while trying to open file: " << filename << endl; ! return 1; } --- 134,151 ---- if(!is) { ! cout << "Config file <" << filename << "> does not exist." << endl; ! if(strcmp(filename, "uclient.xml") == 0) ! { ! cout << "Building uclient.xml with default values." << endl; ! WriteConfig(); ! is.open("uclient.xml", ios::in|ios::binary); ! if(!is) ! { ! cout << "Error while loading uclient.xml. " << strerror(errno) << endl; ! return 1; ! } ! } ! else ! return 1; } *************** *** 127,131 **** if(startTag != -1) config.port = atoi(tagString.GetData()); } - cout << "Port: " << config.port << endl; // get server addr if needed --- 176,179 ---- *************** *** 138,142 **** if(startTag != -1) config.addr.Append(buffer, strlen(buffer)); } ! printf("Address: %s\n", config.addr.GetData()); // get file_list.xml MD5 --- 186,190 ---- if(startTag != -1) config.addr.Append(buffer, strlen(buffer)); } ! cout << "Server: " << config.addr.GetData() << ":" << config.port << endl; // get file_list.xml MD5 *************** *** 145,157 **** buffer = tagString.GetData(); if(startTag != -1) strcpy(config.list_md5, buffer); ! printf("List MD5: %s\n", config.list_md5); // set platform type #if defined(OS_UNIX) config.platform = X86_LINUX; #elif defined(OS_WIN32) config.platform = X86_WIN; #else config.platform = UNKNOWN; #endif --- 193,238 ---- buffer = tagString.GetData(); if(startTag != -1) strcpy(config.list_md5, buffer); ! cout << "List MD5: " << config.list_md5 << endl; ! ! // get autorun value ! if(config.autorun == -1) ! { ! startTag = sectionString.FindTag("autorun"); ! sectionString.GetWithinTagSection(startTag, "autorun", tagString); ! if(startTag != -1) config.autorun = atoi(tagString.GetData()); ! } ! cout << "Autorun: " << ((config.autorun)?"Yes":"No") << endl; // set platform type #if defined(OS_UNIX) config.platform = X86_LINUX; + // get module paths + startTag = sectionString.FindTag("module"); + do + + { + psXMLTag tag(sectionString, startTag); + csString tmp; + tag.GetTagParm("name", tmp); + if(Str2Module(tmp.GetData()) == MODULE_CS) tag.GetTagParm("path", config.CSPath); + else if(Str2Module(tmp.GetData()) == MODULE_PS) tag.GetTagParm("path", config.PSPath); + startTag = sectionString.FindTag("module", startTag+1); + } while(startTag != -1); + + cout << "CrystalSpace path: " << config.CSPath.GetData() << endl; + cout << "PlaneShift path: " << config.PSPath.GetData() << endl; + if(config.CSPath == "" || config.PSPath == "") + { + cout << endl << "One or more module paths are not defined. Please verify uclient.xml." << endl; + return 1; + } #elif defined(OS_WIN32) config.platform = X86_WIN; + config.CSPath = ""; + config.PSPath = ""; #else config.platform = UNKNOWN; + config.CSPath = ""; + config.PSPath = ""; #endif *************** *** 163,170 **** cout << "Usage: uclient [options]" << endl << endl; cout << "Options:" << endl; ! cout << " -[c]onfig=<filename> Use alternate config file (default: config.xml)" << endl; cout << " -[p]ort=<number> Override config file port value" << endl; cout << " -[s]erv=<ip|name> Override config file server address" << endl; ! cout << " ** MD5 of last file list must be in config.xml, if not it will check everything." << endl << endl; cout << "Config file format:" << endl; cout << " <updater_config>" << endl; --- 244,253 ---- cout << "Usage: uclient [options]" << endl << endl; cout << "Options:" << endl; ! cout << " -[c]onfig=<filename> Use alternate config file (default: uclient.xml)" << endl; cout << " -[p]ort=<number> Override config file port value" << endl; cout << " -[s]erv=<ip|name> Override config file server address" << endl; ! cout << " -[a]uto=<1|0> Override config file autorun value" << endl; ! cout << " ** MD5 of last file list must be in uclient.xml, if not it will check everything." << endl; ! cout << " Under linux, modules must be defined in uclient.xml or the updater wont run." << endl << endl; cout << "Config file format:" << endl; cout << " <updater_config>" << endl; *************** *** 172,176 **** --- 255,305 ---- cout << " <server>1.1.1.1</server>" << endl; cout << " <list_md5>blah</list_md5>" << endl; + cout << " <autorun>1</autorun>" << endl; + cout << " <module name=\"MODULE_CS\" path=\"/usr/local/crystal\" /> /* linux only */" << endl; + cout << " <module name=\"MODULE_PS\" path=\"/usr/local/games/planeshift\" /> /* linux only */" << endl; cout << " </updater_config>" << endl << endl; cout << "Report bugs to <cou...@th...>" << endl; + } + + // ghetto function to write the config file + void WriteConfig(int port, csString addr, char *md5, int autorun) + { + ofstream os; + int ar; + char temp[512]; + + // autorun must be disabled by default in linux since the updater run as root + #if defined(OS_LINUX) + ar = 0; + #else + ar = autorun; + #endif + + os.open("uclient.xml", ios::out); + + sprintf(temp, "<updater_config>\n\r"); + os.write(temp, strlen(temp)); + + sprintf(temp, "\t<port>%i</port>\n\r", port); + os.write(temp, strlen(temp)); + + sprintf(temp, "\t<server>%s</server>\n\r", addr.GetData()); + os.write(temp, strlen(temp)); + + sprintf(temp, "\t<list_md5>%s</list_md5>\n\r", md5); + os.write(temp, strlen(temp)); + + sprintf(temp, "\t<autorun>%i</autorun>\n\r", ar); + os.write(temp, strlen(temp)); + + sprintf(temp, "\t<module name=\"MODULE_CS\" path=\"/usr/local/crystal\" /> /* linux only */\n\r"); + os.write(temp, strlen(temp)); + + sprintf(temp, "\t<module name=\"MODULE_PS\" path=\"/usr/local/games/planeshift\" /> /* linux only */\n\r"); + os.write(temp, strlen(temp)); + + sprintf(temp, "</updater_config>"); + os.write(temp, strlen(temp)); + + os.close(); } Index: Makefile.am =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/client/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.am 1 Jun 2002 09:22:07 -0000 1.3 --- Makefile.am 6 Jun 2002 02:13:29 -0000 1.4 *************** *** 9,13 **** # $LIB=zlib bin_PROGRAMS = uclient ! uclient_SOURCES = main.cpp uclient.h uclient.cpp untgz.c uclient_LDADD = $(COMMONSRC)/sal/libsal.la $(COMMONSRC)/util/libpsutil.la \ --- 9,13 ---- # $LIB=zlib bin_PROGRAMS = uclient ! uclient_SOURCES = main.cpp uclient.h uclient.cpp zstream.h uclient_LDADD = $(COMMONSRC)/sal/libsal.la $(COMMONSRC)/util/libpsutil.la \ Index: uclient.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/client/uclient.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** uclient.cpp 1 Jun 2002 09:22:07 -0000 1.4 --- uclient.cpp 6 Jun 2002 02:13:29 -0000 1.5 *************** *** 19,22 **** --- 19,27 ---- #include <config.h> + #if defined(OS_UNIX) + #include <unistd.h> + #include <sys/stat.h> + #include <sys/types.h> + #endif #include <csutil/csstring.h> #include <csutil/csmd5.h> *************** *** 24,27 **** --- 29,33 ---- #include <fstream.h> #include <iostream.h> + #include <errno.h> #include <zlib.h> #include "../common/release.h" *************** *** 33,42 **** extern bool bRunning; - extern "C" { - int tar OF((gzFile, int, int, int, char **)); - } - static void printHash(const unsigned long amount, const unsigned long total, unsigned long progressCurrent, const unsigned long progressTotal); static int hashesPrinted = 0; --- 39,45 ---- extern bool bRunning; static void printHash(const unsigned long amount, const unsigned long total, unsigned long progressCurrent, const unsigned long progressTotal); + int makedir (char *newdir); static int hashesPrinted = 0; *************** *** 56,60 **** if(!tptr) { ! cout << "Error while creating client thread." << endl; bRunning = false; } --- 59,63 ---- if(!tptr) { ! cout << "Error while creating client thread. " << strerror(errno) << endl; bRunning = false; } *************** *** 89,93 **** { // Error, cleanup and return error number ! cout << "Error while loading socket library." << endl; return 1; } --- 92,96 ---- { // Error, cleanup and return error number ! cout << "Error while loading socket library. " << strerror(errno) << endl; return 1; } *************** *** 109,113 **** if(lpHostEntry == NULL) { ! cout << "Error getting host <" << _config->addr.GetData() << ">" << endl; return 1; } --- 112,116 ---- if(lpHostEntry == NULL) { ! cout << "Error getting host <" << _config->addr.GetData() << ">:" << strerror(errno) << endl; return 1; } *************** *** 121,125 **** } ! bool uClient::open(packet & p, eRequest r, csString filename) { // Create ip stream socket to listen --- 124,128 ---- } ! bool uClient::open(packet & p, eRequest r, eModule module, csString filename) { // Create ip stream socket to listen *************** *** 142,146 **** p.login_request.request = r; p.login_request.platform = _config->platform; ! strcpy(p.login_request.param, filename.GetData()); if(U_DEBUG) cout << "Out: " << Packet2Str(p).GetData() << endl; sendall(_sock, (char*)(void*)&p, PACKET_SIZE); --- 145,150 ---- p.login_request.request = r; p.login_request.platform = _config->platform; ! p.login_request.module = module; ! strcpy(p.login_request.param, filename.GetData()); if(U_DEBUG) cout << "Out: " << Packet2Str(p).GetData() << endl; sendall(_sock, (char*)(void*)&p, PACKET_SIZE); *************** *** 205,209 **** char buffer[4096]; ! if(open(p, LIST_REQUEST, "")) return 1; // prepare to get file_list.xml --- 209,213 ---- char buffer[4096]; ! if(open(p, LIST_REQUEST, MODULE_NULL, "")) return 1; // prepare to get file_list.xml *************** *** 219,223 **** unsigned long left = filesize; ! cout << "Receiving file list (" << filesize << ")\n" << "\tProgress -[ "; cout.flush(); --- 223,227 ---- unsigned long left = filesize; ! cout << "Receiving file list (" << filesize << ")" << endl << "\tProgress -[ "; cout.flush(); *************** *** 255,272 **** } ! bool uClient::request_file(csString filename) { packet p; unsigned long filesize; ofstream os; char buffer[4096]; ! if(open(p, FILE_REQUEST, filename)) return 1; // prepare to get file filesize = atol(p.login_reply.param); // open the file ! os.open("temp.tar.gz", ios::out|ios::binary); // tell server we're ready for the file --- 259,297 ---- } ! bool uClient::request_file(eModule module, csString filename) { packet p; unsigned long filesize; ofstream os; + csString realpath; char buffer[4096]; ! // open the request ! if(open(p, FILE_REQUEST, module, filename.GetData())) return 1; // prepare to get file filesize = atol(p.login_reply.param); + // get real path with module path + if(module == MODULE_CS) realpath.Append((*_config).CSPath); + else if(module == MODULE_PS) realpath.Append((*_config).PSPath); + realpath.Append("/"); + realpath.Append(filename); + realpath.Append(".gz"); + + // create the directories if needed + // ***** STRIPE FILENAME FIRST TNX + csString dironly; + int i=realpath.Length(); + while(i > 0) + { + if(realpath[i-1] == '/' || realpath[i-1] == '\\') break; + i--; + } + dironly.Append(realpath, i-1); + makedir(dironly.GetData()); + // open the file ! os.open(realpath.GetData(), ios::out|ios::binary); // tell server we're ready for the file *************** *** 280,284 **** unsigned long left = filesize; ! cout << "Receiving: " << filename << " (" << filesize << ")\n" << "\tProgress -[ "; cout.flush(); --- 305,309 ---- unsigned long left = filesize; ! cout << "Receiving: " << filename << " (" << filesize << ")" << endl << "\tProgress -[ "; cout.flush(); *************** *** 315,328 **** // install the file ! gzFile f; ! f = gzopen("temp.tar.gz", "rb"); ! if(f != NULL) ! { ! tar(f, 0, 0, 0, NULL); ! } ! if(remove("temp.tar.gz") == -1) ! { ! cout << "Error while deleting temp.tar.gz." << endl; ! } cout << endl; --- 340,344 ---- // install the file ! ungzip(realpath); cout << endl; *************** *** 331,334 **** --- 347,351 ---- } + // thread of the client void task_proc uClient::thread_main(void *arg) { *************** *** 344,348 **** { ParseFileList(list_buffer, fil); ! total_size = CompareFiles(fil); if(fil.Length() > 0) --- 361,365 ---- { ParseFileList(list_buffer, fil); ! total_size = CompareFiles(fil, This->_config); if(fil.Length() > 0) *************** *** 352,356 **** for(int i=0;i<fil.Length();i++) ! This->request_file(fil[i].name); } else --- 369,375 ---- for(int i=0;i<fil.Length();i++) ! { ! This->request_file(fil[i].module, fil[i].name); ! } } else *************** *** 362,365 **** --- 381,385 ---- } + // get md5 value of buffer char * GetMD5(void * buffer, int len) { *************** *** 398,405 **** --- 418,434 ---- psXMLTag tag(sectionString, startTag); csString tmp; + // get file module + tag.GetTagParm("module", tmp); + if(Str2Module(tmp.GetData()) == MODULE_CS) fi.module = MODULE_CS; + else if(Str2Module(tmp.GetData()) == MODULE_CEL) fi.module = MODULE_CEL; + else if(Str2Module(tmp.GetData()) == MODULE_PS) fi.module = MODULE_PS; + else fi.module = MODULE_NULL; + // get file path tag.GetTagParm("path", tmp); strcpy(fi.name, tmp.GetData()); + // get patch file size tag.GetTagParm("size", tmp); fi.size = atol(tmp.GetData()); + // get file md5 tag.GetTagParm("md5", tmp); strcpy(fi.md5, tmp.GetData()); *************** *** 411,427 **** } ! unsigned long CompareFiles(FileList & fil) { ifstream is; unsigned long filesize; unsigned long total_size = 0; char *buffer; csString abs_path = "./"; //list<sFileInfo>::iterator i = fil.begin(); ! cout << "Comparing local files with server file list... please wait." << endl; ! for(int i=0;i<fil.Length();i++) { abs_path.Append(fil[i].name); if(U_DEBUG) cout << "Checking " << abs_path.GetData() << ": "; --- 440,466 ---- } ! // compare file list to local files ! unsigned long CompareFiles(FileList & fil, sConfig *config) { ifstream is; unsigned long filesize; unsigned long total_size = 0; + int list_length = fil.Length(); char *buffer; csString abs_path = "./"; //list<sFileInfo>::iterator i = fil.begin(); ! cout << "Comparing local files with server file list..." << endl ! << "\tProgress -[ "; ! hashesPrinted = 0; ! int i,j=1; ! for(i=0;i<list_length;i++,j++) { + #if defined(OS_LINUX) + if(fil[i].module == MODULE_CS) abs_path.Append(config->CSPath); + else if(fil[i].module == MODULE_PS) abs_path.Append(config->PSPath); + abs_path.Append("/"); + #endif abs_path.Append(fil[i].name); if(U_DEBUG) cout << "Checking " << abs_path.GetData() << ": "; *************** *** 461,469 **** --- 500,515 ---- abs_path.Clear(); abs_path += "./"; + + // show progress + printHash(((j*100)/list_length)/4, 25, i, list_length); } + printHash(25, 25, list_length, list_length); + + cout << endl; return total_size; } + // adapted from rpm sources (commented tty related code for win32 compatibility) static void printHash(const unsigned long amount, const unsigned long total, unsigned long progressCurrent, const unsigned long progressTotal) *************** *** 522,524 **** --- 568,648 ---- (void) fflush(stdout); } + } + + // unzip filename + void ungzip(csString filename) + { + csString realname; + gzFile gzf; + ofstream os; + unsigned long len = 4096; + char buffer[4096]; + + realname.Append(filename, filename.Length() - 3); + gzf = gzopen(filename.GetData(), "rb"); + os.open(realname.GetData(), ios::out|ios::binary); + + while(len == 4096) + { + len = gzread(gzf, &buffer, 4096); + os.write(buffer, len); + } + + gzclose(gzf); + os.close(); + + // do stuff + if(remove(filename.GetData()) == -1) + { + cout << "Error while deleting " << filename.GetData() << ". " << strerror(errno) << endl; + } + } + + // make directories + int makedir (char *newdir) + { + char *buffer = strdup(newdir); + char *p; + int len = strlen(buffer); + + if (len <= 0) + { + free(buffer); + return 0; + } + if (buffer[len-1] == '/') + { + buffer[len-1] = '\0'; + } + if (mkdir(buffer, 0775) == 0) + { + free(buffer); + return 1; + } + + p = buffer+1; + while (1) + { + char hold; + + while(*p && *p != '\\' && *p != '/') + p++; + + hold = *p; + *p = 0; + if ((mkdir(buffer, 0775) == -1) && (errno == ENOENT)) + { + cout << "Couldn't create directory " << buffer << ": " << strerror(errno) << endl; + free(buffer); + return 0; + } + + if (hold == 0) + break; + *p++ = hold; + } + + free(buffer); + + return 1; } Index: uclient.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/client/uclient.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** uclient.h 1 Jun 2002 09:22:07 -0000 1.4 --- uclient.h 6 Jun 2002 02:13:29 -0000 1.5 *************** *** 38,41 **** --- 38,44 ---- char list_md5[33]; ePlatform platform; + int autorun; + csString CSPath; // path to Crystal Space install.. used in linux only + csString PSPath; // path to PlaneShift install.. used in linux only }; *************** *** 50,54 **** ~uClient(); bool request_list(csString & file_buffer); ! bool request_file(csString filename); private: --- 53,57 ---- ~uClient(); bool request_list(csString & file_buffer); ! bool request_file(eModule module, csString filename); private: *************** *** 56,60 **** static void task_proc thread_main(void *arg); void end(void); ! bool open(packet & p, eRequest r, csString filename); private: --- 59,63 ---- static void task_proc thread_main(void *arg); void end(void); ! bool open(packet & p, eRequest r, eModule module, csString filename); private: *************** *** 67,71 **** char * GetMD5(void * buffer, int len); void ParseFileList(csString & buffer, FileList & fil); ! unsigned long CompareFiles(FileList & fil); #define __UCLIENT_H__ --- 70,75 ---- char * GetMD5(void * buffer, int len); void ParseFileList(csString & buffer, FileList & fil); ! unsigned long CompareFiles(FileList & fil, sConfig *config); ! void ungzip(csString filename); #define __UCLIENT_H__ --- config.xml DELETED --- --- untgz.c DELETED --- |