storage: only use relative paths if installed in a desired way

graph:  drop support  for cs-ebot ewp files
This commit is contained in:
jeefo 2025-08-21 21:43:21 +03:00
commit 9b8c41edea
No known key found for this signature in database
GPG key ID: D696786B81B667C8
6 changed files with 32 additions and 13 deletions

@ -1 +1 @@
Subproject commit 89cfcf74cc870844d6e5029c296f6c4a6b2b6070 Subproject commit b5f7ccc23dec2d018048b40085f78255cc232e52

View file

@ -67,7 +67,7 @@ public:
CTS_BUILD_STR train { "train" }; CTS_BUILD_STR train { "train" };
CTS_BUILD_STR graph { "graph" }; CTS_BUILD_STR graph { "graph" };
CTS_BUILD_STR podbot { "pwf" }; CTS_BUILD_STR podbot { "pwf" };
CTS_BUILD_STR ebot { "ewp" }; CTS_BUILD_STR bin { "bin" };
} folders {}; } folders {};
#undef CTS_BUILD_STR #undef CTS_BUILD_STR

View file

@ -40,8 +40,7 @@ CR_DECLARE_SCOPED_ENUM_TYPE (BotFile, uint32_t,
Practice = 2, Practice = 2,
Graph = 3, Graph = 3,
Pathmatrix = 4, Pathmatrix = 4,
PodbotPWF = 5, PodbotPWF = 5
EbotEWP = 6
) )
class BotStorage final : public Singleton <BotStorage> { class BotStorage final : public Singleton <BotStorage> {
@ -58,6 +57,7 @@ private:
private: private:
int m_retries {}; int m_retries {};
ULZ *m_ulz {}; ULZ *m_ulz {};
bool m_useNonRelativePaths {};
public: public:
BotStorage () = default; BotStorage () = default;
@ -91,6 +91,9 @@ public:
// remove all bot related files from disk // remove all bot related files from disk
void unlinkFromDisk (bool onlyTrainingData, bool silenceMessages); void unlinkFromDisk (bool onlyTrainingData, bool silenceMessages);
// is correctly installed and running from correct folder?
void checkInstallLocation ();
public: public:
// loading the graph may attempt to recurse loading, with converting or download, reset retry counter // loading the graph may attempt to recurse loading, with converting or download, reset retry counter
void resetRetries () { void resetRetries () {

View file

@ -959,6 +959,7 @@ bool Game::loadCSBinary () {
} }
bool Game::postload () { bool Game::postload () {
bstor.checkInstallLocation (); // check if installed just as in manual
// register logger // register logger
logger.initialize (bstor.buildPath (BotFile::LogFile), [] (const char *msg) { logger.initialize (bstor.buildPath (BotFile::LogFile), [] (const char *msg) {

View file

@ -1702,10 +1702,8 @@ bool BotGraph::convertOldFormat () {
MemFile fp (bstor.buildPath (BotFile::PodbotPWF, true)); MemFile fp (bstor.buildPath (BotFile::PodbotPWF, true));
if (!fp) { if (!fp) {
if (!fp.open (bstor.buildPath (BotFile::EbotEWP, true))) {
return false; return false;
} }
}
PODGraphHeader header {}; PODGraphHeader header {};
plat.bzero (&header, sizeof (header)); plat.bzero (&header, sizeof (header));

View file

@ -6,6 +6,7 @@
// //
#include <yapb.h> #include <yapb.h>
#include "storage.h"
#if defined(BOT_STORAGE_EXPLICIT_INSTANTIATIONS) #if defined(BOT_STORAGE_EXPLICIT_INSTANTIATIONS)
@ -347,8 +348,7 @@ String BotStorage::buildPath (int32_t file, bool isMemoryLoad, bool withoutMapNa
{ BotFile::Pathmatrix, FilePath (folders.train, "pmx")}, { BotFile::Pathmatrix, FilePath (folders.train, "pmx")},
{ BotFile::LogFile, FilePath (folders.logs, "txt")}, { BotFile::LogFile, FilePath (folders.logs, "txt")},
{ BotFile::Graph, FilePath (folders.graph, "graph")}, { BotFile::Graph, FilePath (folders.graph, "graph")},
{ BotFile::PodbotPWF, FilePath (folders.podbot, "pwf")}, { BotFile::PodbotPWF, FilePath (folders.podbot, "pwf")}
{ BotFile::EbotEWP, FilePath (folders.ebot, "ewp")},
}; };
static StringArray path {}; static StringArray path {};
@ -447,8 +447,8 @@ StringRef BotStorage::getRunningPath () {
static String path {}; static String path {};
// we're do not do relative (against bot's library) paths on android // we're do not do relative (against bot's library) paths on specific cases
if (plat.android || plat.emscripten) { if (m_useNonRelativePaths) {
if (path.empty ()) { if (path.empty ()) {
path = strings.joinPath (game.getRunningModName (), folders.addons, folders.bot); path = strings.joinPath (game.getRunningModName (), folders.addons, folders.bot);
} }
@ -459,7 +459,7 @@ StringRef BotStorage::getRunningPath () {
if (path.empty ()) { if (path.empty ()) {
path = SharedLibrary::path (&bstor); path = SharedLibrary::path (&bstor);
if (path.startsWith ("<unk")) { if (path.empty ()) {
logger.fatal ("Unable to detect library path. Giving up..."); logger.fatal ("Unable to detect library path. Giving up...");
} }
@ -481,7 +481,7 @@ StringRef BotStorage::getRunningPathVFS () {
static String path {}; static String path {};
// we're do not do relative (against bot's library) paths on android // we're do not do relative (against bot's library) paths on android
if (plat.android) { if (m_useNonRelativePaths) {
if (path.empty ()) { if (path.empty ()) {
path = strings.joinPath (folders.addons, folders.bot); path = strings.joinPath (folders.addons, folders.bot);
} }
@ -497,5 +497,22 @@ StringRef BotStorage::getRunningPathVFS () {
return path; return path;
} }
void BotStorage::checkInstallLocation () {
if (plat.android || plat.emscripten) {
m_useNonRelativePaths = true;
return;
}
String path = SharedLibrary::path (&bstor);
if (path.empty ()) {
m_useNonRelativePaths = true;
return;
}
String dpath = strings.joinPath (folders.addons, folders.bot, folders.bin);
path = path.substr (0, path.rfind (kPathSeparator));
m_useNonRelativePaths = !path.lowercase ().endsWith (dpath.lowercase ());
}
#endif // BOT_STORAGE_EXPLICIT_INSTANTIATIONS #endif // BOT_STORAGE_EXPLICIT_INSTANTIATIONS