From dd0b5df304b489465b4123a27438e660378b8e29 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 3 Aug 2010 23:05:05 +0200 Subject: [PATCH] Changed: #1051 Create a console-based working patcher --- code/ryzom/client/client.sln | 19 +- code/ryzom/client/src/CMakeLists.txt | 2 +- code/ryzom/client/src/attached_fx.h | 1 + code/ryzom/client/src/login_patch.cpp | 169 +++++--- code/ryzom/client/src/login_patch.h | 8 +- code/ryzom/tools/CMakeLists.txt | 1 + code/ryzom/tools/client/CMakeLists.txt | 1 + .../client/client_patcher/CMakeLists.txt | 33 ++ .../client_patcher/client_patcher.vcproj | 391 ++++++++++++++++++ .../tools/client/client_patcher/main.cpp | 191 +++++++++ 10 files changed, 763 insertions(+), 53 deletions(-) create mode 100644 code/ryzom/tools/client/CMakeLists.txt create mode 100644 code/ryzom/tools/client/client_patcher/CMakeLists.txt create mode 100644 code/ryzom/tools/client/client_patcher/client_patcher.vcproj create mode 100644 code/ryzom/tools/client/client_patcher/main.cpp diff --git a/code/ryzom/client/client.sln b/code/ryzom/client/client.sln index 6095d8cb4..0636576a8 100644 --- a/code/ryzom/client/client.sln +++ b/code/ryzom/client/client.sln @@ -3,9 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 10.00 # Visual C++ Express 2008 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "src\client.vcproj", "{0B58874C-AFD1-4A30-9C43-135D36A0A8C7}" ProjectSection(ProjectDependencies) = postProject - {263C0F2E-112D-437F-A6AB-DEA151A7A1F0} = {263C0F2E-112D-437F-A6AB-DEA151A7A1F0} {44B21233-EFCC-4825-B5E5-3A3BD6CC5516} = {44B21233-EFCC-4825-B5E5-3A3BD6CC5516} - {9440443B-97BA-43C2-A762-31EEC8958BEE} = {9440443B-97BA-43C2-A762-31EEC8958BEE} {F74C0046-00DA-4A77-9B4D-D9FE5831E705} = {F74C0046-00DA-4A77-9B4D-D9FE5831E705} {4B320F68-0B9B-4065-A2ED-AF5D4B163006} = {4B320F68-0B9B-4065-A2ED-AF5D4B163006} {9D284C6B-BE12-4549-87E5-2337D64F31BE} = {9D284C6B-BE12-4549-87E5-2337D64F31BE} @@ -16,7 +14,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "src\client.vcproj {4AF7ADB2-DAF8-4F04-9793-F92010001470} = {4AF7ADB2-DAF8-4F04-9793-F92010001470} {296D8FB5-DB32-48DD-A6AF-10A77A5DEE70} = {296D8FB5-DB32-48DD-A6AF-10A77A5DEE70} {1DDC11C7-AF79-40F3-A6D4-F84BA8644B5C} = {1DDC11C7-AF79-40F3-A6D4-F84BA8644B5C} - {1D9576F6-3321-4036-8C86-B5361CCCD4FB} = {1D9576F6-3321-4036-8C86-B5361CCCD4FB} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game_share", "..\common\src\game_share\game_share.vcproj", "{4B320F68-0B9B-4065-A2ED-AF5D4B163006}" @@ -97,6 +94,13 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "driver_dsound", "..\..\nel\ {4AF7ADB2-DAF8-4F04-9793-F92010001470} = {4AF7ADB2-DAF8-4F04-9793-F92010001470} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client_patcher", "..\tools\client\client_patcher\client_patcher.vcproj", "{B0323569-5F46-4E7D-A045-56697BEFBF03}" + ProjectSection(ProjectDependencies) = postProject + {44B21233-EFCC-4825-B5E5-3A3BD6CC5516} = {44B21233-EFCC-4825-B5E5-3A3BD6CC5516} + {F74C0046-00DA-4A77-9B4D-D9FE5831E705} = {F74C0046-00DA-4A77-9B4D-D9FE5831E705} + {4B320F68-0B9B-4065-A2ED-AF5D4B163006} = {4B320F68-0B9B-4065-A2ED-AF5D4B163006} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -232,7 +236,6 @@ Global {739618D3-04B6-4EB1-BAED-53D3217F5A86}.Release|Win32.ActiveCfg = Release|Win32 {739618D3-04B6-4EB1-BAED-53D3217F5A86}.Release|Win32.Build.0 = Release|Win32 {739618D3-04B6-4EB1-BAED-53D3217F5A86}.Release|x64.ActiveCfg = Release|x64 - {739618D3-04B6-4EB1-BAED-53D3217F5A86}.Release|x64.Build.0 = Release|x64 {079E2366-3714-4B09-B553-41A44D290F04}.Debug|Win32.ActiveCfg = Debug|Win32 {079E2366-3714-4B09-B553-41A44D290F04}.Debug|Win32.Build.0 = Debug|Win32 {079E2366-3714-4B09-B553-41A44D290F04}.Debug|x64.ActiveCfg = Debug|x64 @@ -265,6 +268,14 @@ Global {309F8A55-BFBA-433B-8C3E-CB2223F799C3}.Release|Win32.Build.0 = Release|Win32 {309F8A55-BFBA-433B-8C3E-CB2223F799C3}.Release|x64.ActiveCfg = Release|x64 {309F8A55-BFBA-433B-8C3E-CB2223F799C3}.Release|x64.Build.0 = Release|x64 + {B0323569-5F46-4E7D-A045-56697BEFBF03}.Debug|Win32.ActiveCfg = Debug|Win32 + {B0323569-5F46-4E7D-A045-56697BEFBF03}.Debug|Win32.Build.0 = Debug|Win32 + {B0323569-5F46-4E7D-A045-56697BEFBF03}.Debug|x64.ActiveCfg = Debug|x64 + {B0323569-5F46-4E7D-A045-56697BEFBF03}.Debug|x64.Build.0 = Debug|x64 + {B0323569-5F46-4E7D-A045-56697BEFBF03}.Release|Win32.ActiveCfg = Release|Win32 + {B0323569-5F46-4E7D-A045-56697BEFBF03}.Release|Win32.Build.0 = Release|Win32 + {B0323569-5F46-4E7D-A045-56697BEFBF03}.Release|x64.ActiveCfg = Release|x64 + {B0323569-5F46-4E7D-A045-56697BEFBF03}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/code/ryzom/client/src/CMakeLists.txt b/code/ryzom/client/src/CMakeLists.txt index a82b2214c..8d3d236de 100644 --- a/code/ryzom/client/src/CMakeLists.txt +++ b/code/ryzom/client/src/CMakeLists.txt @@ -1,11 +1,11 @@ # These are Windows/MFC apps IF(WIN32) - ADD_SUBDIRECTORY(seven_zip) ADD_SUBDIRECTORY(bug_report) SET(SEVENZIP_LIBRARY "ryzom_sevenzip") ENDIF(WIN32) ADD_SUBDIRECTORY(client_sheets) +ADD_SUBDIRECTORY(seven_zip) FILE(GLOB SRC *.cpp *.h motion/*.cpp motion/*.h motion/modes/*.cpp motion/modes/*.h r2/*.h r2/*.cpp r2/dmc/*.h r2/dmc/*.cpp interface_v3/*.h interface_v3/*.cpp) diff --git a/code/ryzom/client/src/attached_fx.h b/code/ryzom/client/src/attached_fx.h index 24b97f281..c58a9e92c 100644 --- a/code/ryzom/client/src/attached_fx.h +++ b/code/ryzom/client/src/attached_fx.h @@ -23,6 +23,7 @@ #include "client_sheets/fx_stick_mode.h" #include "nel/misc/smart_ptr.h" #include "nel/misc/vector.h" +#include "nel/3d/animation_time.h" namespace NL3D { diff --git a/code/ryzom/client/src/login_patch.cpp b/code/ryzom/client/src/login_patch.cpp index b33ae6811..677eda675 100644 --- a/code/ryzom/client/src/login_patch.cpp +++ b/code/ryzom/client/src/login_patch.cpp @@ -79,7 +79,6 @@ static std::vector ForceRemovePatchCategories; // the actual file is updated void tmpFlagMainlandPatchCategories(NLMISC::CConfigFile &cf) { -#ifdef NL_DEBUG NLMISC::CConfigFile::CVar *catList = cf.getVarPtr("ForceMainlandPatchCategories"); if (catList) { @@ -88,14 +87,12 @@ void tmpFlagMainlandPatchCategories(NLMISC::CConfigFile &cf) ForceMainlandPatchCategories.push_back(catList->asString(k)); } } -#endif } // TMP for debug : force some category in the patch to be flagged as 'mainland' until // the actual file is updated void tmpFlagRemovedPatchCategories(NLMISC::CConfigFile &cf) { -#ifdef NL_DEBUG NLMISC::CConfigFile::CVar *catList = cf.getVarPtr("RemovePatchCategories"); if (catList) { @@ -104,7 +101,6 @@ void tmpFlagRemovedPatchCategories(NLMISC::CConfigFile &cf) ForceRemovePatchCategories.push_back(catList->asString(k)); } } -#endif } @@ -191,6 +187,7 @@ public: }; #endif +static std::string ClientRootPath; // **************************************************************************** CPatchManager::CPatchManager() : State("t_state"), DataScanState("t_data_scan_state") @@ -199,8 +196,8 @@ CPatchManager::CPatchManager() : State("t_state"), DataScanState("t_data_scan_st UpdateBatchFilename = "updt_nl.bat"; - ClientPatchPath = "./unpack/"; - ClientDataPath = "./data/"; + // use current directory by default + setClientRootPath("./"); VerboseLog = true; @@ -221,6 +218,14 @@ CPatchManager::CPatchManager() : State("t_state"), DataScanState("t_data_scan_st _StartRyzomAtEnd = true; } +// **************************************************************************** +void CPatchManager::setClientRootPath(const std::string& clientRootPath) +{ + ClientRootPath = clientRootPath; + ClientPatchPath = ClientRootPath + "unpack/"; + ClientDataPath = ClientRootPath + "data/"; +} + // **************************************************************************** void CPatchManager::setErrorMessage(const ucstring &message) { @@ -734,17 +739,23 @@ void CPatchManager::deleteBatchFile() } // **************************************************************************** -void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool wantRyzomRestart) +void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool wantRyzomRestart, bool useBatchFile) { uint nblab = 0; - deleteBatchFile(); - FILE *fp = fopen (UpdateBatchFilename.c_str(), "wt"); - if (fp == 0) + + FILE *fp = NULL; + + if (useBatchFile) { - string err = toString("Can't open file '%s' for writing: code=%d %s (error code 29)", UpdateBatchFilename.c_str(), errno, strerror(errno)); - throw Exception (err); + deleteBatchFile(); + fp = fopen (UpdateBatchFilename.c_str(), "wt"); + if (fp == 0) + { + string err = toString("Can't open file '%s' for writing: code=%d %s (error code 29)", UpdateBatchFilename.c_str(), errno, strerror(errno)); + throw Exception (err); + } + fprintf(fp, "@echo off\n"); } - fprintf(fp, "@echo off\n"); // Unpack files with category ExtractPath non empty const CBNPCategorySet &rDescCats = descFile.getCategories(); @@ -768,32 +779,57 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool } catch(...) { - fclose(fp); + if (useBatchFile) + { + fclose(fp); + } + throw; } if (!result) { //:TODO: handle exception? string err = toString("Error unpacking %s", rFilename.c_str()); - fclose(fp); + + if (useBatchFile) + { + fclose(fp); + } + throw Exception (err); } else { for (uint32 fff = 0; fff < vFilenames.size (); fff++) { - string SrcPath = CPath::standardizeDosPath(ClientPatchPath); - string SrcName = SrcPath + vFilenames[fff]; - string DstPath = CPath::standardizeDosPath(rCat.getUnpackTo()); - string DstName = DstPath + vFilenames[fff]; - NLMISC::CFile::createDirectoryTree(rCat.getUnpackTo()); + string SrcPath = ClientPatchPath; + string DstPath = rCat.getUnpackTo(); + NLMISC::CFile::createDirectoryTree(DstPath); // this file must be moved - fprintf(fp, ":loop%u\n", nblab); - fprintf(fp, "attrib -r -a -s -h %s\n", DstName.c_str()); - fprintf(fp, "del %s\n", DstName.c_str()); - fprintf(fp, "if exist %s goto loop%u\n", DstName.c_str(), nblab); - fprintf(fp, "move %s %s\n", SrcName.c_str(), DstPath.c_str()); + if (useBatchFile) + { + SrcPath = CPath::standardizeDosPath(SrcPath); + DstPath = CPath::standardizeDosPath(DstPath); + } + + std::string SrcName = SrcPath + vFilenames[fff]; + std::string DstName = DstPath + vFilenames[fff]; + + if (useBatchFile) + { + fprintf(fp, ":loop%u\n", nblab); + fprintf(fp, "attrib -r -a -s -h %s\n", DstName.c_str()); + fprintf(fp, "del %s\n", DstName.c_str()); + fprintf(fp, "if exist %s goto loop%u\n", DstName.c_str(), nblab); + fprintf(fp, "move %s %s\n", SrcName.c_str(), DstPath.c_str()); + } + else + { + deleteFile(DstName); + CFile::moveFile(DstName.c_str(), SrcName.c_str()); + } + nblab++; } } @@ -803,31 +839,54 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool // Finalize batch file if (NLMISC::CFile::isExists("patch") && NLMISC::CFile::isDirectory("patch")) { - fprintf(fp, ":looppatch\n"); + if (useBatchFile) + { + fprintf(fp, ":looppatch\n"); + } vector vFileList; CPath::getPathContent ("patch", false, false, true, vFileList, NULL, false); for(uint32 i = 0; i < vFileList.size(); ++i) - fprintf(fp, "del %s\n", CPath::standardizeDosPath(vFileList[i]).c_str()); + { + if (useBatchFile) + { + fprintf(fp, "del %s\n", CPath::standardizeDosPath(vFileList[i]).c_str()); + } + else + { + CFile::deleteFile(vFileList[i]); + } + } - fprintf(fp, "rd /Q /S patch\n"); - fprintf(fp, "if exist patch goto looppatch\n"); + if (useBatchFile) + { + fprintf(fp, "rd /Q /S patch\n"); + fprintf(fp, "if exist patch goto looppatch\n"); + } + else + { + CFile::deleteDirectory("patch"); + } } - if (wantRyzomRestart) + if (useBatchFile) { - fprintf(fp, "start %s %%1 %%2 %%3\n", RyzomFilename.c_str()); - } - bool writeError = ferror(fp) != 0; - bool diskFull = ferror(fp) && errno == 28 /* ENOSPC */; - fclose(fp); - if (diskFull) - { - throw NLMISC::EDiskFullError(UpdateBatchFilename.c_str()); - } - if (writeError) - { - throw NLMISC::EWriteError(UpdateBatchFilename.c_str()); + if (wantRyzomRestart) + { + fprintf(fp, "start %s %%1 %%2 %%3\n", RyzomFilename.c_str()); + } + + bool writeError = ferror(fp) != 0; + bool diskFull = ferror(fp) && errno == 28 /* ENOSPC */; + fclose(fp); + if (diskFull) + { + throw NLMISC::EDiskFullError(UpdateBatchFilename.c_str()); + } + if (writeError) + { + throw NLMISC::EWriteError(UpdateBatchFilename.c_str()); + } } } @@ -1046,6 +1105,24 @@ void CPatchManager::readDescFile(sint32 nVersion) throw Exception ("Can't open file '%s'", srcName.c_str ()); uint cat; + + if (ClientRootPath != "./") + { + // fix relative paths + for (cat = 0; cat < DescFile.getCategories().categoryCount(); ++cat) + { + CBNPCategory &category = const_cast(DescFile.getCategories().getCategory(cat)); + + std::string unpackTo = category.getUnpackTo(); + + if (unpackTo.substr(0, 2) == "./") + { + unpackTo = ClientRootPath + unpackTo.substr(2); + category.setUnpackTo(unpackTo); + } + } + } + // tmp for debug : flag some categories as 'Mainland' for (cat = 0; cat < DescFile.getCategories().categoryCount(); ++cat) { @@ -1664,7 +1741,7 @@ bool CPatchManager::bnpUnpack(const string &srcBigfile, const string &dstPath, v // SourceName = ClientPatchPath + srcBigfile; if (dstPath.empty()) - DestPath = "./"; + DestPath = ClientRootPath; else DestPath = CPath::standardizePath (dstPath); @@ -3315,7 +3392,7 @@ void CDownloadThread::run() { CPatchManager *pPM = CPatchManager::getInstance(); - std::string patchPath = CPath::standardizePath (std::string("./")+TheTmpInstallDirectory)+std::string("patch/"); + std::string patchPath = CPath::standardizePath (ClientRootPath+TheTmpInstallDirectory)+"patch/"; static bool _FirstTime = true; @@ -3418,7 +3495,7 @@ void CDownloadThread::run() void CInstallThread::run() { - std::string patchPath = CPath::standardizePath (std::string("./")+TheTmpInstallDirectory)+std::string("patch/"); + std::string patchPath = CPath::standardizePath (ClientRootPath+TheTmpInstallDirectory)+"patch/"; CPatchManager *pPM = CPatchManager::getInstance(); std::set allowed; @@ -3535,7 +3612,7 @@ void CInstallThread::run() { // remove date from tmp directory (because install is finished) - std::string install = CPath::standardizePath (std::string("./")+TheTmpInstallDirectory); + std::string install = CPath::standardizePath (ClientRootPath+TheTmpInstallDirectory); std::vector vFiles; // Delete all classic file from tmp directory diff --git a/code/ryzom/client/src/login_patch.h b/code/ryzom/client/src/login_patch.h index 02b341fa6..162765fc9 100644 --- a/code/ryzom/client/src/login_patch.h +++ b/code/ryzom/client/src/login_patch.h @@ -206,7 +206,7 @@ public: void forceStopPatchThread(); bool mustLaunchBatFile() const { return MustLaunchBatFile; } - void createBatchFile(CProductDescriptionForClient &descFile, bool wantRyzomRestart = true); + void createBatchFile(CProductDescriptionForClient &descFile, bool wantRyzomRestart = true, bool useBatchFile = true); void executeBatchFile(); void deleteBatchFile(); void reboot(); @@ -257,7 +257,11 @@ public: // By default the name used is the name of the current executable. // But for external torrent downloader we must set "client_ryzom_rd.exe" void setRyzomFilename(const std::string& ryzomFilename) { RyzomFilename = ryzomFilename; } - // Use by installation software to download a file only if necessary + + // Used when client data is not located in current directory + void setClientRootPath(const std::string& clientRootPath); + + // Used by installation software to download a file only if necessary static bool download(const std::string& patchPath, const std::string& sourcePath, const std::string& tmpDirectory, uint32 timestamp); // Used by installation software to create install.bat file (not used) diff --git a/code/ryzom/tools/CMakeLists.txt b/code/ryzom/tools/CMakeLists.txt index 695c59518..d6d267841 100644 --- a/code/ryzom/tools/CMakeLists.txt +++ b/code/ryzom/tools/CMakeLists.txt @@ -11,6 +11,7 @@ ADD_SUBDIRECTORY(pdr_util) ADD_SUBDIRECTORY(stats_scan) ADD_SUBDIRECTORY(sheets_packer) +ADD_SUBDIRECTORY(client) ADD_SUBDIRECTORY(server) # Old stuff that doesn't compile anymore. diff --git a/code/ryzom/tools/client/CMakeLists.txt b/code/ryzom/tools/client/CMakeLists.txt new file mode 100644 index 000000000..0ca38fdfc --- /dev/null +++ b/code/ryzom/tools/client/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(client_patcher) diff --git a/code/ryzom/tools/client/client_patcher/CMakeLists.txt b/code/ryzom/tools/client/client_patcher/CMakeLists.txt new file mode 100644 index 000000000..29ce59b88 --- /dev/null +++ b/code/ryzom/tools/client/client_patcher/CMakeLists.txt @@ -0,0 +1,33 @@ +FILE(GLOB SRC *.cpp *.h + ${CMAKE_SOURCE_DIR}/client/src/client_cfg.cpp + ${CMAKE_SOURCE_DIR}/client/src/login_patch.cpp + ${CMAKE_SOURCE_DIR}/client/src/login_xdelta.cpp +) + +SET(SEVENZIP_LIBRARY "ryzom_sevenzip") + +ADD_EXECUTABLE(ryzom_client_patcher ${SRC}) + +INCLUDE_DIRECTORIES( + ${CMAKE_BINARY_DIR} + ${LIBXML2_INCLUDE_DIR} + ${NEL_INCLUDE_DIR} + ${CURL_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/client/src +) + +TARGET_LINK_LIBRARIES(ryzom_client_patcher ${PLATFORM_LINKFLAGS} + ${NELMISC_LIBRARY} + ryzom_gameshare + ${NELNET_LIBRARY} + ${CURL_LIBRARIES} + ${SEVENZIP_LIBRARY}) + +ADD_DEFINITIONS(-DRZ_NO_CLIENT -DNL_USE_SEVENZIP) + +IF(WITH_PCH) + ADD_NATIVE_PRECOMPILED_HEADER(ryzom_client_patcher ${CMAKE_SOURCE_DIR}/client/src/stdpch.h ${CMAKE_SOURCE_DIR}/client/src/stdpch.cpp) +ENDIF(WITH_PCH) + +INSTALL(TARGETS ryzom_client_patcher RUNTIME DESTINATION ${RYZOM_BIN_PREFIX} COMPONENT client BUNDLE DESTINATION /Applications) diff --git a/code/ryzom/tools/client/client_patcher/client_patcher.vcproj b/code/ryzom/tools/client/client_patcher/client_patcher.vcproj new file mode 100644 index 000000000..659003ace --- /dev/null +++ b/code/ryzom/tools/client/client_patcher/client_patcher.vcproj @@ -0,0 +1,391 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/code/ryzom/tools/client/client_patcher/main.cpp b/code/ryzom/tools/client/client_patcher/main.cpp new file mode 100644 index 000000000..d4de6fa2b --- /dev/null +++ b/code/ryzom/tools/client/client_patcher/main.cpp @@ -0,0 +1,191 @@ +#include "stdpch.h" +#include "login_patch.h" +#include "client_cfg.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +using namespace NLMISC; +using namespace std; + +// stuff which is defined as extern in other .cpp files +void quitCrashReport() +{ +} + +/// domain server version for patch +string R2ServerVersion; +/// name of the version (used to alias many version under the same name), +/// the value is used to get the release not if not empty +string VersionName; + +string LoginLogin, LoginPassword; +uint32 LoginShardId = 0xFFFFFFFF; + +// stuff which is defined in other .cpp files +extern void tmpFlagRemovedPatchCategories(NLMISC::CConfigFile &cf); + +int main(int argc, char *argv[]) +{ + // init the Nel context + CApplicationContext *appContext = new CApplicationContext; + + createDebug(); + + // disable log display on stdout + INelContext::getInstance().getDebugLog()->removeDisplayer("DEFAULT_SD"); + INelContext::getInstance().getInfoLog()->removeDisplayer("DEFAULT_SD"); + INelContext::getInstance().getWarningLog()->removeDisplayer("DEFAULT_SD"); + + // if client_default.cfg is not in current directory, use application default directory + if (!CFile::isExists("client_default.cfg")) + { + std::string currentPath = CFile::getApplicationDirectory("Ryzom"); + + if (!CFile::isExists(currentPath)) CFile::createDirectory(currentPath); + + CPath::setCurrentPath(currentPath); + } + + ClientCfg.init("client.cfg"); + + std::string dataPath = "./data/"; + std::string rootPath = "./"; + + if (!ClientCfg.DataPath.empty()) + { + dataPath = CPath::standardizePath(ClientCfg.DataPath[0]); + string::size_type pos = dataPath.rfind('/', dataPath.length()-2); + if (pos != string::npos) + rootPath = dataPath.substr(0, pos+1); + } + + // add .bnp containing translations + CPath::addSearchBigFile(dataPath + "gamedev.bnp", true, false); + + // load translation + CI18N::load(ClientCfg.LanguageCode); + +#ifdef NL_OS_UNIX + // don't use cfg, exe and dll from Windows version + CConfigFile::CVar var; + var.Type = CConfigFile::CVar::T_STRING; + std::vector cats; + cats.push_back("main_exedll"); + cats.push_back("main_cfg"); + var.setAsString(cats); + ClientCfg.ConfigFile.insertVar("RemovePatchCategories", var); + + // add categories to remove + tmpFlagRemovedPatchCategories(ClientCfg.ConfigFile); +#endif + + // initialize patch manager and set the ryzom full path, before it's used + CPatchManager *pPM = CPatchManager::getInstance(); + + pPM->setClientRootPath(rootPath); + + vector patchURLs; + pPM->init(patchURLs, ClientCfg.PatchServer, ClientCfg.PatchVersion); + pPM->startCheckThread(true /* include background patchs */); + + ucstring state; + vector log; + bool res = false; + bool finished = false; + + while (!finished) + { + nlSleep(100); + + finished = pPM->isCheckThreadEnded(res); + + if (pPM->getThreadState(state, log)) + { + for(uint i = 0; i < log.size(); ++i) + { + printf("%s\n", log[i].toUtf8().c_str()); + } + } + + if (!res) + { + ucstring errMsg = CI18N::get("uiErrChecking"); + if (!pPM->getLastErrorMessage().empty()) + { + ucstring errMsg = pPM->getLastErrorMessage(); + printf("Error: %s\n", errMsg.toUtf8().c_str()); + } + } + } + + CPatchManager::SPatchInfo InfoOnPatch; + + // Check is good now ask the player if he wants to apply the patch + pPM->getInfoToDisp(InfoOnPatch); + + uint AvailablePatchs = InfoOnPatch.getAvailablePatchsBitfield(); + + // Get the list of optional categories to patch + vector vCategories; + + for(uint i = 0; i < InfoOnPatch.OptCat.size(); i++) + { + // Ok for the moment all optional categories must be patched even if the player + // does not want it. Because we cant detect that a continent have to be patched ingame. + vCategories.push_back(InfoOnPatch.OptCat[i].Name); + } + + pPM->startPatchThread(vCategories, true); + + res = false; + finished = false; + + while (!finished) + { + nlSleep(100); + + finished = pPM->isPatchThreadEnded(res); + + if (pPM->getThreadState(state, log)) + { + printf("%s\n", state.toUtf8().c_str()); + + for(uint i = 0; i < log.size(); ++i) + { + printf("%s\n", log[i].toUtf8().c_str()); + } + } + + if (!res) + { + ucstring errMsg = CI18N::get("uiErrChecking"); + if (!pPM->getLastErrorMessage().empty()) + { + ucstring errMsg = pPM->getLastErrorMessage(); + printf("Error: %s\n", errMsg.toUtf8().c_str()); + } + } + } + + if (CPatchManager::getInstance()->mustLaunchBatFile()) + { + // move downloaded files to final location + pPM->createBatchFile(pPM->getDescFile(), false, false); + CFile::createEmptyFile("show_eula"); + } + +/* + // Start Scanning + pPM->startScanDataThread(); + + // request to stop the thread + pPM->askForStopScanDataThread(); +*/ + + delete appContext; + + return 0; +} +