📄 main.cpp
字号:
//--------------------------------------------------------------------------------//// Filename : main.cpp// Written By : Reiot////--------------------------------------------------------------------------------// include files#include "Types.h"#include "Exception.h"#include "UpdateServer.h"#include "Properties.h"// 诀单捞飘 叼泛配府 胶牡 包访#include <stdio.h>#include <unistd.h>#include <dirent.h>#include <sys/stat.h>#include <sys/resource.h>#include <iostream.h>#include <stdlib.h>#include <list>#include <algorithm>#include "UpdateManager.h"#include "Update.h"#include "StringStream.h"// scandir// readdir// seekdir// getcwd//// // 巩磊凯 厚背// strcasecmp( "LISt" , "LIST" ) == 0class SourceInfo {public : string getName() { return m_Name; } void setName( string Name ) { m_Name = Name; } string getDirectory() { return m_Directory; } void setDirectory( string Directory ) { m_Directory = Directory; }private : string m_Name; string m_Directory;};class VersionInfo {public : string getName() { return m_Name; } void setName( string Name ) { m_Name = Name; } string getDirectory() { return m_Directory; } void setDirectory( string Directory ) { m_Directory = Directory; } int getVersion() { return m_Version; } void setVersion( int Version ) { m_Version = Version; } int getSize() { return m_Size; } void setSize( int Size ) { m_Size = Size; }private : string m_Name; string m_Directory; int m_Size; int m_Version;};list<SourceInfo *> SourceInfoList;list<VersionInfo*> VersionInfoList;class isSameName {public : // constructor isSameName ( string Name ) : m_Name(Name) {} bool operator () ( VersionInfo * pVersionInfo ) throw () { // 捞抚捞 鞍促. if( strcasecmp( m_Name.c_str(), pVersionInfo->getName().c_str() ) == 0 ) { return true; } else { return false; } }private : // Name identifier string m_Name;};class isSource {public : // constructor isSource ( string Name ) : m_Name(Name) {} bool operator () ( SourceInfo * pSourceInfo ) throw () { // 捞抚捞 鞍促. if( strcasecmp( m_Name.c_str(), pSourceInfo->getName().c_str() ) == 0 ) { return true; } else { return false; } }private : // Name identifier string m_Name;};/*void main(void) { struct dirent * Testdir; int count = 0; readdir( 0, Testdir, count ); scandir //cout << " DirName : " << TestDir->d_Name << endl;}*//* // 菩摹 叼泛配府甫 坷锹茄促. DIR * pDIR = opendir( patchDir.c_str() ); // 菩摹 叼泛配府啊 绝栏搁 富炉 炔! Assert( pDIR != NULL ); // 菩摹 叼泛配府狼 窍困 叼泛配府(滚傈 叼泛配府)甸阑 佬绢甸牢促. bool sameVersionFound = false; struct dirent * versionDir; while ( ( versionDir = readdir( pDIR ) ) != NULL ) { // 后 浇儿(inode==0)篮 公矫茄促... if ( versionDir->d_ino != 0 ) { // // 滚傈 叼泛配府绰 v + 0栏肺 盲况柳 5磊府 沥荐 巩磊凯肺 登绢 乐促. // ex> v00001/ v00002/ v00003/ ... // string dir = versionDir->d_name; // v 肺 矫累窍瘤 臼绰 窍困 叼泛配府肺绰 "." 苞 ".." 捞 乐促. -_-; if ( dir[0] == 'v' ) { // 滚傈阑 厚背窍扁 困秦辑绰 // 箭磊 何盒阑 胶飘傅栏肺 函券秦辑 促矫 沥荐肺 函券茄促. Version_t version = atoi( dir.substr( 1 , 5 ).c_str() ); if ( version == pPacket->getVersion() ) sameVersionFound = true; if ( version > pPacket->getVersion() ) directories.push_back( dir ); } else //cout << endl; } } closedir( pDIR );*/#include <dirent.h>int myselect( const struct dirent *entry ) { const char * filename = entry->d_name; if( *filename == '.' ) { return 0; } else { return 1; }}void scan_Source( const string & Directory ) {// struct dirent **namelist; DIR * pDIR = opendir( Directory.c_str() ); struct dirent * versionDir;// //cout << "Open Dir : " << Directory << endl; while ( ( versionDir = readdir( pDIR ) ) != NULL ) { string vName = versionDir->d_name; if ( versionDir->d_ino != 0 && vName[0] != '.' ) {// //cout << "versionDir : " << versionDir->d_name<< endl; string DirectoryName = Directory + "/"; string SubDirectory = DirectoryName + versionDir->d_name; struct stat List; stat( SubDirectory.c_str(), &List );// //cout << versionDir->d_name << " " << List.st_size << endl; replace ( DirectoryName.begin(), DirectoryName.end(), '/', '\\' );// //cout << "Path : " << array << " Path Size : " << size << endl; if( S_ISDIR( List.st_mode ) ) {// //cout << versionDir->d_name << " is Directory " << endl;// string SubDirectory = DirectoryName + "/" + namelist[n]->d_name;// //cout << "SubDirectory : " << SubDirectory << endl; scan_Source( SubDirectory );// //cout << get_current_dir_name() << endl; } else { SourceInfo * pSourceInfo = new SourceInfo(); pSourceInfo->setName( versionDir->d_name ); pSourceInfo->setDirectory( DirectoryName.substr( g_pConfig->getProperty("SourceDirectory").size() + 1, DirectoryName.size()-1 ) ); SourceInfoList.push_back( pSourceInfo ); /* // 老窜 鞍篮 捞抚捞 乐绰瘤 茫绰促. list<SourceInfo*>::iterator itr = find_if( SourceInfoList.begin(), SourceInfoList.end(), isSameName(pSourceInfo->getName()) ); // 度鞍篮 捞抚捞 乐促搁 弥脚 滚怜栏肺 持绢 拎具零. if ( itr != SourceInfoList.end() ) { //cout << "盔夯 颇老俊辑 鞍篮 捞抚狼 颇老捞 惯斑 登菌促!" << endl; //cout << "盔贰 乐带 颇老狼 叼泛篮 : " << (*itr)->getDirectory() << ", 颇老 捞抚篮 : " << (*itr)->getName() << endl; //cout << "弥脚 颇老狼 滚怜篮 : " << pSourceInfo->getDirectory() << ", 颇老 捞抚篮 : " << pSourceInfo->getName() << endl; // 鞍篮 颇老捞 绝促. } else { SourceInfoList.push_back( pSourceInfo ); } */ } } } closedir( pDIR );}void scan_Version( const string & Directory, int version ) {// struct dirent **namelist; DIR * pDIR = opendir( Directory.c_str() ); struct dirent * versionDir;// //cout << "Open Dir : " << Directory << endl; while ( ( versionDir = readdir( pDIR ) ) != NULL ) { string vName = versionDir->d_name; if( vName == "index.dat" ) { string removeName = Directory + "/" + "index.dat"; //cout << "Remove index.dat Directory : " << removeName << endl; remove( removeName.c_str() ); } if ( versionDir->d_ino != 0 && vName[0] != '.' && vName != "index.dat" ) {// //cout << "versionDir : " << versionDir->d_name<< endl; string DirectoryName = Directory; string SubDirectory = DirectoryName + "/" + versionDir->d_name; /* replace ( DirectoryName.begin(), DirectoryName.end(), '/', '\\' );// //cout << "ChangeName : " << DirectoryName << endl; */ struct stat List; stat( SubDirectory.c_str(), &List );// //cout << versionDir->d_name << " " << List.st_size << endl;// //cout << "Path : " << array << " Path Size : " << size << endl; if( S_ISDIR( List.st_mode ) ) { int version = atoi( vName.substr( 1 , 5 ).c_str() );// //cout << versionDir->d_name << " is Directory " << endl;// string SubDirectory = DirectoryName + "/" + namelist[n]->d_name;// //cout << "SubDirectory : " << SubDirectory << endl; scan_Version( SubDirectory, version );// //cout << get_current_dir_name() << endl; } else { VersionInfo * pVersionInfo = new VersionInfo(); pVersionInfo->setName( versionDir->d_name ); list<SourceInfo*>::iterator itr2 = find_if( SourceInfoList.begin(), SourceInfoList.end(), isSource( pVersionInfo->getName() ) ); pVersionInfo->setDirectory( (*itr2)->getDirectory() ); pVersionInfo->setSize( List.st_size ); pVersionInfo->setVersion( version ); // 老窜 鞍篮 捞抚捞 乐绰瘤 茫绰促. list<VersionInfo*>::iterator itr = find_if( VersionInfoList.begin(), VersionInfoList.end(), isSameName( pVersionInfo->getName() ) ); // 度鞍篮 捞抚捞 乐促搁 弥脚 滚怜栏肺 持绢 拎具零. if ( itr != VersionInfoList.end() ) { //cout << "鞍篮 颇老捞 惯斑 登菌促 弥脚 滚怜栏肺 绊摹磊" << endl; //cout << "盔贰 乐带 颇老狼 滚怜篮 : " << (*itr)->getVersion() << ", 颇老 捞抚篮 : " << (*itr)->getName() << endl; //cout << "弥脚 颇老狼 滚怜篮 : " << pVersionInfo->getVersion() << ", 颇老 捞抚篮 : " << pVersionInfo->getName() << endl; if( (*itr)->getVersion() < pVersionInfo->getVersion() ) { VersionInfo * pTempVersionInfo = (*itr); VersionInfoList.erase( itr ); //cout << "扁粮狼 颇老阑 昏力茄促." << endl; delete pTempVersionInfo; VersionInfoList.push_back(pVersionInfo); //cout << "货 颇老阑 府胶飘俊 眠啊茄促." << endl; } else { } // 鞍篮 颇老捞 绝促. } else { VersionInfoList.push_back(pVersionInfo); } } } } closedir( pDIR );}void create_Index() { list<VersionInfo*>::const_iterator itr = VersionInfoList.begin(); int beforeVersion = 0; int version = 0; // 滚怜牢器俊辑 颇老阑 窍唱究 波郴搁辑 颇老捞 甸绢哎 困摹甫 惶酒辰促. for( ; itr != VersionInfoList.end(); itr++ ) { StringStream msg1; StringStream msg2; StringStream msg3; StringStream msg4; UpdateManager updatemanager; Update * pUpdate = new Update(); msg1 << (*itr)->getName() << " " << (*itr)->getSize(); msg2 << (*itr)->getDirectory() << (*itr)->getName(); version = (*itr)->getVersion(); char filename[256]; sprintf(filename,"%s/v%05d/index.dat", g_pConfig->getProperty("PatchDirectory").c_str() , version); ofstream ofile( filename , ios::out | ios::app ); // 诀单捞飘 肮荐甫 舅酒郴辑 敬促. if( beforeVersion != version ) { int Count = 0; list<VersionInfo*>::const_iterator itr2 = VersionInfoList.begin(); for(; itr2 != VersionInfoList.end(); itr2++ ) { if( (*itr2)->getVersion() == version ) { Count++; } } //cout << "Version : " << version << ", Count: " << Count << endl; ofile.write( (const char *)&Count , szWORD ); beforeVersion = version; } //cout << "create Index msg1 : " << msg1.toString() << endl; //cout << "create Index msg2 : " << msg2.toString() << endl; pUpdate = new Update(); pUpdate->setVersion(version); pUpdate->setUpdateType(UPDATETYPE_CREATE_FILE); pUpdate->setParam(0,msg1.toString()); pUpdate->setParam(1,msg2.toString()); pUpdate->save(ofile); ofile.close(); } // 后 牢郸胶甫 积己茄促. for( int i = 0; i <= version ; i++ ) { char filename[256]; sprintf(filename,"%s/v%05d/index.dat", g_pConfig->getProperty("PatchDirectory").c_str() , i ); ifstream ifile( filename, ios::in | ios::binary | ios::nocreate ); // 颇老捞 绝栏搁 后 牢郸胶甫 积己茄促. if ( !ifile ) { int Count = 0; char filename[256]; sprintf(filename,"%s/v%05d/index.dat", g_pConfig->getProperty("PatchDirectory").c_str() , i ); ofstream ofile( filename , ios::out | ios::app ); ofile.write( (const char *)&Count , szWORD ); } ifile.close(); }}//--------------------------------------------------------------------------------//// main()//// UpdateServer狼 皋牢 风橇////--------------------------------------------------------------------------------int main ( int argc , char * argv[] ){ if ( argc < 3 ) { //cout << "Usage : updateserver -f 券版颇老" << endl; exit(1); } // command-line parameter甫 string 栏肺 函券茄促. ^^; string * Argv; Argv = new string[argc]; for ( int i = 0 ; i < argc ; i ++ ) Argv[i] = argv[i]; // 券版 颇老阑 佬绢甸牢促. // 窜 角青 颇老篮 $VSHOME/bin俊, 券版 颇老篮 $VSHOME/conf 俊 粮犁秦具 茄促.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -