move directories away from loader into new dirs namespace

This commit is contained in:
HJfod 2022-11-30 19:19:00 +02:00
parent 8126175eaa
commit f73d1042a3
17 changed files with 739 additions and 809 deletions

View file

@ -6,5 +6,6 @@
#include "loader/Mod.hpp"
#include "loader/Setting.hpp"
#include "loader/SettingEvent.hpp"
#include "loader/Dirs.hpp"
#include <Geode/DefaultInclude.hpp>

View file

@ -83,23 +83,5 @@ namespace geode {
static void closePlatfromConsole();
bool didLastLaunchCrash() const;
ghc::filesystem::path getCrashLogDirectory() const;
/**
* Directory where Geometry Dash is
*/
ghc::filesystem::path getGameDirectory() const;
/**
* Directory where GD saves its files
*/
ghc::filesystem::path getSaveDirectory() const;
/**
* Directory where Geode is
*/
ghc::filesystem::path getGeodeDirectory() const;
/**
* Directory where Geode saves its files
*/
ghc::filesystem::path getGeodeSaveDirectory() const;
};
}

View file

@ -129,9 +129,6 @@ namespace geode {
}
};
class Mod;
class Setting;
/**
* Represents if a mod has been loaded &
* its dependencies resolved
@ -151,16 +148,10 @@ namespace geode {
Disabled,
};
static constexpr std::string_view GEODE_DIRECTORY = "geode";
static constexpr std::string_view GEODE_MOD_DIRECTORY = "mods";
static constexpr std::string_view GEODE_LOG_DIRECTORY = "log";
static constexpr std::string_view GEODE_RESOURCE_DIRECTORY = "resources";
static constexpr std::string_view GEODE_CONFIG_DIRECTORY = "config";
static constexpr std::string_view GEODE_TEMP_DIRECTORY = "temp";
static constexpr std::string_view GEODE_MOD_EXTENSION = ".geode";
static constexpr std::string_view GEODE_INDEX_DIRECTORY = "index";
constexpr std::string_view GEODE_MOD_EXTENSION = ".geode";
class Mod;
class Setting;
class Loader;
class Hook;
struct ModInfo;

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,7 @@
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Log.hpp>
#include <Geode/loader/Dirs.hpp>
#include <Geode/utils/web.hpp>
#include <Geode/utils/file.hpp>
#include <fmt/format.h>
@ -94,9 +95,8 @@ void InternalLoader::loadInfoAlerts(nlohmann::json& json) {
void InternalLoader::downloadLoaderResources(IndexUpdateCallback callback) {
auto version = this->getVersion().toString();
auto tempResourcesZip = this->getGeodeDirectory() / GEODE_RESOURCE_DIRECTORY / "new.zip";
auto resourcesDir =
this->getGeodeDirectory() / GEODE_RESOURCE_DIRECTORY / InternalMod::get()->getID();
auto tempResourcesZip = dirs::getTempDir() / "new.zip";
auto resourcesDir = dirs::getGeodeResourcesDir() / InternalMod::get()->getID();
web::AsyncWebRequest()
.join("update-geode-loader-resources")
@ -142,8 +142,7 @@ bool InternalLoader::verifyLoaderResources(IndexUpdateCallback callback) {
}
// geode/resources/geode.loader
auto resourcesDir =
this->getGeodeDirectory() / GEODE_RESOURCE_DIRECTORY / InternalMod::get()->getID();
auto resourcesDir = dirs::getGeodeResourcesDir() / InternalMod::get()->getID();
// if the resources dir doesn't exist, then it's probably incorrect
if (!(ghc::filesystem::exists(resourcesDir) && ghc::filesystem::is_directory(resourcesDir))) {

View file

@ -1,5 +1,5 @@
#include "InternalMod.hpp"
#include <Geode/loader/Dirs.hpp>
#include "InternalLoader.hpp"
#include "about.hpp"
@ -41,7 +41,7 @@ static ModInfo getInternalModInfo() {
}
InternalMod::InternalMod() : Mod(getInternalModInfo()) {
m_saveDirPath = Loader::get()->getGeodeSaveDirectory() / GEODE_MOD_DIRECTORY / m_info.m_id;
m_saveDirPath = dirs::getModsSaveDir() / m_info.m_id;
ghc::filesystem::create_directories(m_saveDirPath);

View file

@ -1,6 +1,7 @@
#pragma once
#include <Geode/DefaultInclude.hpp>
#include <fs/filesystem.hpp>
#include <string>
/**
@ -22,5 +23,5 @@ namespace crashlog {
* @returns Path to the directory, or an empty string if the platform does
* not support crash logs
*/
std::string GEODE_DLL getCrashLogDirectory();
ghc::filesystem::path GEODE_DLL getCrashLogDirectory();
}

View file

@ -1,6 +1,7 @@
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Mod.hpp>
#include <Geode/loader/Dirs.hpp>
#include <InternalLoader.hpp>
#include <InternalMod.hpp>
#include <about.hpp>
@ -20,9 +21,8 @@ Loader::~Loader() {
}
m_mods.clear();
log::Logs::clear();
ghc::filesystem::remove_all(
this->getGeodeDirectory() / GEODE_TEMP_DIRECTORY
);
ghc::filesystem::remove_all(dirs::getModRuntimeDir());
ghc::filesystem::remove_all(dirs::getTempDir());
}
VersionInfo Loader::getVersion() {
@ -49,24 +49,19 @@ bool Loader::isModVersionSupported(VersionInfo const& version) {
}
void Loader::createDirectories() {
auto modDir = this->getGeodeDirectory() / GEODE_MOD_DIRECTORY;
auto logDir = this->getGeodeDirectory() / GEODE_LOG_DIRECTORY;
auto resDir = this->getGeodeDirectory() / GEODE_RESOURCE_DIRECTORY;
auto tempDir = this->getGeodeDirectory() / GEODE_TEMP_DIRECTORY;
auto confDir = this->getGeodeDirectory() / GEODE_CONFIG_DIRECTORY;
#ifdef GEODE_IS_MACOS
ghc::filesystem::create_directory(this->getSaveDirectory());
ghc::filesystem::create_directory(dirs::getSaveDir());
#endif
ghc::filesystem::create_directories(resDir);
ghc::filesystem::create_directory(confDir);
ghc::filesystem::create_directory(modDir);
ghc::filesystem::create_directory(logDir);
ghc::filesystem::create_directory(tempDir);
ghc::filesystem::create_directories(dirs::getGeodeResourcesDir());
ghc::filesystem::create_directory(dirs::getModConfigDir());
ghc::filesystem::create_directory(dirs::getModsDir());
ghc::filesystem::create_directory(dirs::getGeodeLogDir());
ghc::filesystem::create_directory(dirs::getTempDir());
ghc::filesystem::create_directory(dirs::getModRuntimeDir());
if (!ranges::contains(m_modSearchDirectories, modDir)) {
m_modSearchDirectories.push_back(modDir);
if (!ranges::contains(m_modSearchDirectories, dirs::getModsDir())) {
m_modSearchDirectories.push_back(dirs::getModsDir());
}
}
@ -146,8 +141,7 @@ Result<Mod*> Loader::loadModFromInfo(ModInfo const& info) {
// add mod resources
this->queueInGDThread([this, mod]() {
auto searchPath = this->getGeodeDirectory() /
GEODE_TEMP_DIRECTORY / mod->getID() / "resources";
auto searchPath = dirs::getModRuntimeDir() / mod->getID() / "resources";
CCFileUtils::get()->addSearchPath(searchPath.string().c_str());
this->updateModResources(mod);
@ -326,10 +320,6 @@ bool Loader::didLastLaunchCrash() const {
return crashlog::didLastLaunchCrash();
}
ghc::filesystem::path Loader::getCrashLogDirectory() const {
return crashlog::getCrashLogDirectory();
}
void Loader::openPlatformConsole() {
InternalLoader::get()->openPlatformConsole();
}
@ -343,7 +333,7 @@ void Loader::updateModResources(Mod* mod) {
return;
}
auto searchPath = this->getGeodeDirectory() / GEODE_TEMP_DIRECTORY / mod->getID() / "resources";
auto searchPath = dirs::getModRuntimeDir() / mod->getID() / "resources";
log::debug("Adding resources for {}", mod->getID());
@ -369,12 +359,8 @@ void Loader::updateModResources(Mod* mod) {
}
void Loader::addSearchPaths() {
CCFileUtils::get()->addPriorityPath(
(this->getGeodeDirectory() / GEODE_RESOURCE_DIRECTORY).string().c_str()
);
CCFileUtils::get()->addPriorityPath(
(this->getGeodeDirectory() / GEODE_TEMP_DIRECTORY).string().c_str()
);
CCFileUtils::get()->addPriorityPath(dirs::getGeodeResourcesDir().string().c_str());
CCFileUtils::get()->addPriorityPath(dirs::getModRuntimeDir().string().c_str());
}
void Loader::updateResources() {
@ -388,32 +374,3 @@ void Loader::updateResources() {
this->updateModResources(mod);
}
}
ghc::filesystem::path Loader::getGameDirectory() const {
return ghc::filesystem::path(CCFileUtils::sharedFileUtils()->getWritablePath2().c_str());
}
ghc::filesystem::path Loader::getSaveDirectory() const {
#ifdef GEODE_IS_MACOS
// not using ~/Library/Caches
return ghc::filesystem::path("/Users/Shared/Geode");
#elif defined(GEODE_IS_WINDOWS)
return ghc::filesystem::path(
ghc::filesystem::weakly_canonical(
CCFileUtils::sharedFileUtils()->getWritablePath().c_str()
).string()
);
#else
return ghc::filesystem::path(
CCFileUtils::sharedFileUtils()->getWritablePath().c_str()
);
#endif
}
ghc::filesystem::path Loader::getGeodeDirectory() const {
return this->getGameDirectory() / GEODE_DIRECTORY;
}
ghc::filesystem::path Loader::getGeodeSaveDirectory() const {
return this->getSaveDirectory() / GEODE_DIRECTORY;
}

View file

@ -1,4 +1,4 @@
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Dirs.hpp>
#include <Geode/loader/Log.hpp>
#include <Geode/loader/Mod.hpp>
#include <Geode/utils/casts.hpp>
@ -115,11 +115,7 @@ std::string Log::toString(bool logTime) const {
}
void Logs::setup() {
s_logStream = std::ofstream(
Loader::get()->getGeodeDirectory() /
GEODE_LOG_DIRECTORY /
log::generateLogName()
);
s_logStream = std::ofstream(dirs::getGeodeLogDir() / log::generateLogName());
}
void Logs::push(Log&& log) {

View file

@ -2,6 +2,7 @@
#include <Geode/cocos/support/zip_support/ZipUtils.h>
#include <Geode/loader/Hook.hpp>
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Dirs.hpp>
#include <Geode/loader/Log.hpp>
#include <Geode/loader/Mod.hpp>
#include <Geode/loader/Setting.hpp>
@ -17,8 +18,7 @@ USE_GEODE_NAMESPACE();
Mod::Mod(ModInfo const& info) {
m_info = info;
m_saveDirPath = Loader::get()->getGeodeSaveDirectory() /
GEODE_MOD_DIRECTORY / info.m_id;
m_saveDirPath = dirs::getModsSaveDir() / info.m_id;
ghc::filesystem::create_directories(m_saveDirPath);
}
@ -112,15 +112,15 @@ Result<> Mod::createTempDir() {
}
// Create geode/temp
auto tempDir = Loader::get()->getGeodeDirectory() / GEODE_TEMP_DIRECTORY;
auto tempDir = dirs::getModRuntimeDir();
if (!file::createDirectoryAll(tempDir)) {
return Err("Unable to create Geode temp directory");
return Err("Unable to create mods' runtime directory");
}
// Create geode/temp/mod.id
auto tempPath = tempDir / m_info.m_id;
if (!file::createDirectoryAll(tempPath)) {
return Err("Unable to create mod temp directory");
return Err("Unable to create mod runtime directory");
}
// Unzip .geode file into temp dir
@ -400,7 +400,7 @@ ghc::filesystem::path Mod::getPackagePath() const {
}
ghc::filesystem::path Mod::getConfigDir(bool create) const {
auto dir = Loader::get()->getGeodeDirectory() / GEODE_CONFIG_DIRECTORY / m_info.m_id;
auto dir = dirs::getModConfigDir() / m_info.m_id;
if (create && !ghc::filesystem::exists(dir)) {
ghc::filesystem::create_directories(dir);
}

View file

@ -4,6 +4,7 @@
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Log.hpp>
#include <Geode/loader/Dirs.hpp>
#include <iostream>
#include <InternalMod.hpp>
#include <pwd.h>
@ -17,7 +18,7 @@ void InternalLoader::platformMessageBox(char const* title, std::string const& in
void InternalLoader::openPlatformConsole() {
ghc::filesystem::path(getpwuid(getuid())->pw_dir);
freopen(
ghc::filesystem::path(Loader::get()->getGeodeDirectory() / "geode_log.txt").string().c_str(), "w",
ghc::filesystem::path(dirs::getGeodeDir() / "geode_log.txt").string().c_str(), "w",
stdout
);
InternalLoader::m_platformConsoleOpen = true;

View file

@ -10,7 +10,7 @@ bool crashlog::didLastLaunchCrash() {
return false;
}
std::string crashlog::getCrashLogDirectory() {
ghc::filesystem::path crashlog::getCrashLogDirectory() {
return "";
}

View file

@ -14,7 +14,7 @@ bool crashlog::didLastLaunchCrash() {
return false;
}
std::string crashlog::getCrashLogDirectory() {
ghc::filesystem::path crashlog::getCrashLogDirectory() {
std::array<char, 1024> path;
CFStringGetCString(
(CFStringRef)NSHomeDirectory(), path.data(), path.size(), kCFStringEncodingUTF8

View file

@ -5,7 +5,9 @@
#ifdef GEODE_IS_WINDOWS
#include <crashlog.hpp>
#include <Geode/loader/Dirs.hpp>
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Mod.hpp>
#include <DbgHelp.h>
#include <Geode/utils/casts.hpp>
#include <Geode/utils/file.hpp>
@ -224,7 +226,7 @@ static LONG WINAPI exceptionHandler(LPEXCEPTION_POINTERS info) {
// add a file to let Geode know on next launch that it crashed previously
// this could also be done by saving a loader setting or smth but eh.
(void)utils::file::writeBinary(crashlog::getCrashLogDirectory() + "/last-crashed", {});
(void)utils::file::writeBinary(crashlog::getCrashLogDirectory() / "last-crashed", {});
SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES);
@ -273,7 +275,7 @@ static LONG WINAPI exceptionHandler(LPEXCEPTION_POINTERS info) {
// save actual file
std::ofstream actualFile;
actualFile.open(
crashlog::getCrashLogDirectory() + "/" + getDateString(true) + ".log", std::ios::app
crashlog::getCrashLogDirectory() / (getDateString(true) + ".log"), std::ios::app
);
actualFile << file.rdbuf() << std::flush;
actualFile.close();
@ -283,7 +285,7 @@ static LONG WINAPI exceptionHandler(LPEXCEPTION_POINTERS info) {
bool crashlog::setupPlatformHandler() {
SetUnhandledExceptionFilter(exceptionHandler);
auto lastCrashedFile = crashlog::getCrashLogDirectory() + "/last-crashed";
auto lastCrashedFile = crashlog::getCrashLogDirectory() / "last-crashed";
if (ghc::filesystem::exists(lastCrashedFile)) {
g_lastLaunchCrashed = true;
try {
@ -299,9 +301,8 @@ bool crashlog::didLastLaunchCrash() {
return g_lastLaunchCrashed;
}
std::string crashlog::getCrashLogDirectory() {
static auto dir = (Loader::get()->getGeodeDirectory() / "crashlogs").string();
return dir;
ghc::filesystem::path crashlog::getCrashLogDirectory() {
return dirs::getGeodeDir() / "crashlogs";
}
#endif

View file

@ -5,6 +5,7 @@
#include "../settings/ModSettingsPopup.hpp"
#include "../settings/AdvancedSettingsPopup.hpp"
#include <InternalLoader.hpp>
#include <Geode/loader/Dirs.hpp>
#include <Geode/binding/ButtonSprite.hpp>
#include <Geode/binding/CCTextInputNode.hpp>
@ -264,9 +265,7 @@ bool ModInfoLayer::init(ModObject* obj, ModListView* list) {
// Check if a config directory for the mod exists
// Mod::getConfigDir auto-creates the directory for user convenience, so
// have to do it manually
if (ghc::filesystem::exists(
Loader::get()->getGeodeDirectory() / GEODE_CONFIG_DIRECTORY / m_mod->getID()
)) {
if (ghc::filesystem::exists(m_mod->getConfigDir(false))) {
auto configSpr = CircleButtonSprite::createWithSpriteFrameName(
"pencil.png"_spr, 1.f, CircleBaseColor::Green, CircleBaseSize::Medium2
);
@ -809,7 +808,7 @@ void ModInfoLayer::showIssueReportPopup(ModInfo const& info) {
"\n\n"
"If your issue relates to a <cr>game crash</c>, <cb>please include</c> the "
"latest crash log(s) from `" +
Loader::get()->getCrashLogDirectory().string() + "`",
dirs::getCrashlogsDir().string() + "`",
"OK", (info.m_issues.value().m_url ? "Open URL" : ""),
[info](bool btn2) {
if (btn2) {
@ -825,8 +824,7 @@ void ModInfoLayer::showIssueReportPopup(ModInfo const& info) {
"[#support](https://discord.com/channels/911701438269386882/979352389985390603) "
"channnel in the [Geode Discord Server](https://discord.gg/9e43WMKzhp)\n\n"
"If your issue relates to a <cr>game crash</c>, <cb>please include</c> the "
"latest crash log(s) from `" +
Loader::get()->getCrashLogDirectory().string() + "`",
"latest crash log(s) from `" + dirs::getCrashlogsDir().string() + "`",
"OK"
)
->show();

View file

@ -13,6 +13,7 @@
#include <Geode/ui/BasedButton.hpp>
#include <Geode/ui/Notification.hpp>
#include <Geode/utils/casts.hpp>
#include <Geode/loader/Dirs.hpp>
#include <optional>
static ModListType g_tab = ModListType::Installed;
@ -382,7 +383,7 @@ void ModListLayer::onFilters(CCObject*) {
}
void ModListLayer::onOpenFolder(CCObject*) {
file::openFolder(ghc::filesystem::canonical(Loader::get()->getGeodeDirectory() / "mods"));
file::openFolder(ghc::filesystem::canonical(dirs::getModsDir()));
}
void ModListLayer::onResetSearch(CCObject*) {

View file

@ -6,6 +6,7 @@
#include <Geode/binding/Slider.hpp>
#include <Geode/binding/CCMenuItemToggler.hpp>
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Dirs.hpp>
// BoolSettingNode
@ -122,7 +123,7 @@ void FileSettingNode::onPickFile(CCObject*) {
if (auto path = file::pickFile(
file::PickMode::OpenFile,
{
Loader::get()->getGameDirectory(),
dirs::getGameDir(),
setting->getFileFilters().value_or(std::vector<file::FilePickOptions::Filter>())
}
)) {