From 1f81d423052617741fd9531d622859a1e1024dc1 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Wed, 1 Jan 2025 21:05:12 +0100 Subject: [PATCH 1/2] unitmain.cpp: Remove confusing error message Now that the game ships without any driver by default, it is very likely that simplix.xml does not exist on fresh installations. In fact, the game already did not consider this as an error, so this was a leftover. --- src/drivers/simplix/src/unitmain.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/drivers/simplix/src/unitmain.cpp b/src/drivers/simplix/src/unitmain.cpp index f1fdfceac..6787d0d20 100644 --- a/src/drivers/simplix/src/unitmain.cpp +++ b/src/drivers/simplix/src/unitmain.cpp @@ -341,11 +341,7 @@ int moduleWelcomeV1_00 welcomeIn->itfVerMajor,welcomeIn->itfVerMinor); if (!RobotSettings) - { - LogSimplix.error("#Robot XML-Path not found: (%s) or (%s) %s\n\n", - GetLocalDir(), GetDataDir(), RobPathXMLRel); goto end; - } LogSimplix.debug("#Robot name: %s\n", RobName); LogSimplix.debug("#Robot directory: %s\n", RobPathDirRel); From 7e72f12a480d38076597d9e32b7f5ad6517ba379 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Wed, 1 Jan 2025 21:54:29 +0100 Subject: [PATCH 2/2] filesetup.cpp: Ensure destination dir before copy When GfFileSetup is called on a fresh installation, none of the destination directories might exist. On the other hand, robustness has been slightly improved by adding calls to good() and is_open(). --- src/libs/tgf/filesetup.cpp | 47 ++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/libs/tgf/filesetup.cpp b/src/libs/tgf/filesetup.cpp index 7de9bc6ec..fed2c228a 100644 --- a/src/libs/tgf/filesetup.cpp +++ b/src/libs/tgf/filesetup.cpp @@ -55,24 +55,51 @@ static bool needs_update(const struct version &src, const struct version &dst) static int update(const std::string &file) { - const char *datadir = GfDataDir(), *localdir = GfLocalDir(); + int ret = -1; + char *dstdir = nullptr; + std::string srcpath = std::string(GfDataDir()) + file, + dstpath = std::string(GfLocalDir()) + file; + const char *sp = srcpath.c_str(), *dp = dstpath.c_str(); + std::ifstream src(srcpath, std::ios::binary); + std::ofstream dst; - if (!datadir) + if (!src.is_open()) { - GfLogError("GfDataDir failed\n"); - return -1; + GfLogError("Failed to open file for reading: %s\n", sp); + goto end; } - else if (!localdir) + else if (!(dstdir = GfFileGetDirName(dp))) { - GfLogError("GfLocalDir failed\n"); - return -1; + GfLogError("GfFileGetDirName %s failed\n", dp); + goto end; + } + else if (GfDirCreate(dstdir) != GF_DIR_CREATED) + { + GfLogError("Failed to created directory: %s\n", dstdir); + goto end; } - std::ifstream src(std::string(datadir) + file, std::ios::binary); - std::ofstream dst(std::string(localdir) + file, std::ios::binary); + dst.open(dstpath, std::ios::binary); + + if (!dst.is_open()) + { + GfLogError("Failed to open file for writing: %s\n", dp); + goto end; + } dst << src.rdbuf(); - return 0; + + if (!dst.good()) + { + GfLogError("Failed to write from %s to %s\n", sp, dp); + goto end; + } + + ret = 0; + +end: + free(dstdir); + return ret; } static int process(const std::string &file)