Fix for tessesframework migration

This commit is contained in:
2025-07-03 16:18:29 -05:00
parent 7797b0b387
commit f5e17217dd
23 changed files with 789 additions and 273625 deletions

View File

@@ -1,138 +1,43 @@
#include "CrossLang.hpp"
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
#include "../sago/platform_folders.h"
#endif
#if defined(_WIN32)
#include <windows.h>
#endif
namespace Tesses::CrossLang
{
using namespace Tesses::Framework::Platform::Environment;
#if defined(_WIN32)
static char EnvPathSeperator=';';
#else
static char EnvPathSeperator=':';
#endif
static std::string GetHomeFolder()
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getHomeDir();
#elif defined(__EMSCRIPTEN__)
return "/home/web_user";
#else
return "/CrossLangProfile";
#endif
}
Tesses::Framework::Filesystem::VFSPath GetCrossLangConfigDir()
{
#if defined(CROSSLANG_ENABLE_CONFIG_ENVVAR)
char* conf = std::getenv("CROSSLANG_CONFIG");
if(conf != NULL)
{
return std::string(conf);
}
#endif
Tesses::Framework::Filesystem::VFSPath p;
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
p=sago::getConfigHome();
#else
p = GetHomeFolder() + "/Config";
#endif
return p / "Tesses" / "CrossLang";
}
Tesses::Framework::Filesystem::VFSPath GetRealExecutablePath(Tesses::Framework::Filesystem::VFSPath realPath)
{
using namespace Tesses::Framework::Filesystem;
using namespace Tesses::Framework::Http;
LocalFilesystem lfs;
if(!realPath.relative) return realPath.MakeAbsolute();
if(lfs.FileExists(realPath)) return realPath.MakeAbsolute();
const char* path = std::getenv("PATH");
#if defined(_WIN32)
const char* pathext = std::getenv("PATHEXT");
auto pext = HttpUtils::SplitString(pathext,";");
pext.push_back({});
auto pathParts = HttpUtils::SplitString(path,";");
for(auto item : pathParts)
{
for(auto item2 : pext)
{
auto newPath = (lfs.SystemToVFSPath(item) / realPath) + item2;
if(lfs.FileExists(newPath)) return newPath;
}
}
return realPath;
#else
auto pathParts = HttpUtils::SplitString(path,":");
for(auto item : pathParts)
{
auto newPath = lfs.SystemToVFSPath(item) / realPath;
if(lfs.FileExists(newPath)) return newPath;
}
return realPath.MakeAbsolute();
#endif
return SpecialFolders::GetConfig() / "Tesses" / "CrossLang";
}
static TObject Env_getCrossLangConfig(GCList& ls, std::vector<TObject> args)
{
return GetCrossLangConfigDir();
}
static TObject Env_getPlatform(GCList& ls, std::vector<TObject> args)
{
#if defined(__SWITCH__)
return "Nintendo Switch";
#endif
#if defined(GEKKO)
#if defined(HW_RVL)
return "Nintendo Wii";
#endif
return "Nintendo Gamecube";
#endif
#if defined(WIN32) || defined(_WIN32)
return "Windows";
#endif
#if defined(linux)
return "Linux";
#endif
#ifdef __APPLE__
#include "TargetConditionals.h"
#if TARGET_OS_MAC
return "MacOS";
#endif
#if TARGET_OS_IOS
return "iOS";
#endif
#if TARGET_OS_TV
return "Apple TV";
#endif
#if TARGET_OS_WATCH
return "Apple Watch";
#endif
#if __EMSCRIPTEN__
return "WebAssembly";
#endif
return "Unknown Apple Device";
#endif
return "Unknown";
return Tesses::Framework::Platform::Environment::GetPlatform();
}
static TObject Env_GetAt(GCList& ls, std::vector<TObject> args)
{
std::string key;
if(GetArgument(args,0,key))
{
auto res = std::getenv(key.c_str());
if(res == nullptr) return nullptr;
std::string value = res;
return value;
auto v = GetVariable(key);
if(v) return v.value();
}
return nullptr;
}
@@ -143,108 +48,62 @@ namespace Tesses::CrossLang
if(GetArgument(args,0,key))
{
if(GetArgument(args,1,value))
#if defined(_WIN32)
SetEnvironmentVariable(key.c_str(),value.c_str());
#else
setenv(key.c_str(), value.c_str(),1);
#endif
else
#if defined(_WIN32)
{
SetVariable(key,value);
return value;
}
else
{
SetVariable(key,std::nullopt);
}
#else
unsetenv(key.c_str());
#endif
return value;
}
return nullptr;
}
static TObject Env_getDownloads(GCList& ls, std::vector<TObject> args)
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getDownloadFolder();
#else
return GetHomeFolder() + "/Downloads";
#endif
return SpecialFolders::GetDownloads();
}
static TObject Env_getMusic(GCList& ls, std::vector<TObject> args)
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getMusicFolder();
#else
return GetHomeFolder() + "/Music";
#endif
return SpecialFolders::GetMusic();
}
static TObject Env_getPictures(GCList& ls, std::vector<TObject> args)
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getPicturesFolder();
#else
return GetHomeFolder() + "/Pictures";
#endif
return SpecialFolders::GetPictures();
}
static TObject Env_getVideos(GCList& ls, std::vector<TObject> args)
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getVideoFolder();
#else
return GetHomeFolder() + "/Videos";
#endif
return SpecialFolders::GetVideos();
}
static TObject Env_getDocuments(GCList& ls, std::vector<TObject> args)
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getDocumentsFolder();
#else
return GetHomeFolder() + "/Documents";
#endif
return SpecialFolders::GetDocuments();
}
static TObject Env_getConfig(GCList& ls, std::vector<TObject> args)
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getConfigHome();
#else
return GetHomeFolder() + "/Config";
#endif
return SpecialFolders::GetConfig();
}
static TObject Env_getDesktop(GCList& ls, std::vector<TObject> args)
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getDesktopFolder();
#else
return GetHomeFolder() + "/Desktop";
#endif
return SpecialFolders::GetDesktop();
}
static TObject Env_getState(GCList& ls, std::vector<TObject> args)
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getStateDir();
#else
return GetHomeFolder() + "/State";
#endif
return SpecialFolders::GetState();
}
static TObject Env_getCache(GCList& ls, std::vector<TObject> args)
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getCacheDir();
#else
return GetHomeFolder() + "/Cache";
#endif
return SpecialFolders::GetCache();
}
static TObject Env_getData(GCList& ls, std::vector<TObject> args)
{
#if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
return sago::getDataHome();
#else
return GetHomeFolder() + "/Data";
#endif
return SpecialFolders::GetData();
}
static TObject Env_getUser(GCList& ls, std::vector<TObject> args)
{
return GetHomeFolder();
return SpecialFolders::GetHomeFolder();
}
static TObject Env_GetRealExecutablePath(GCList& ls, std::vector<TObject> args)
{