Skip to content

Commit a9502a0

Browse files
committed
why tf was the gdpsmain changes not in the previous commit what the hell
1 parent 304eb87 commit a9502a0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/utils/GDPSMain.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,46 @@ geode::Result<> GDPSMain::modifyRegisteredServer(GDPSTypes::Server& server) {
8787
return geode::Ok();
8888
}
8989

90+
geode::Result<> GDPSMain::deleteServer(GDPSTypes::Server& server) {
91+
m_shouldSaveGameData = false;
92+
93+
std::filesystem::path serverPath = geode::dirs::getSaveDir() / "gdpses" / server.saveDir;
94+
std::filesystem::path gdpsesDir = geode::dirs::getSaveDir() / "gdpses";
95+
std::error_code err;
96+
97+
if (!std::filesystem::exists(serverPath, err) && err) {
98+
return geode::Err("Failed to check existence of path: {}\n\nnerd shit: std::error_code message: {}", serverPath, err.message());
99+
}
100+
101+
err.clear();
102+
std::filesystem::path canonicalServerPath;
103+
canonicalServerPath.clear();
104+
canonicalServerPath = std::filesystem::canonical(serverPath, err);
105+
if (err) {
106+
return geode::Err("Failed to get canonical path for {}: {}", serverPath, err.message());
107+
}
108+
109+
if (!canonicalServerPath.string().starts_with(gdpsesDir.string()) || serverPath != gdpsesDir) {
110+
return geode::Err(
111+
"Attempted to delete a path outside or equal to the gdpses directory: {}\n\n"
112+
"To prevent unintentional extra data loss, your save was not deleted - "
113+
"only saves within {} will be deleted. If you want to delete this data, do it manually.",
114+
serverPath, gdpsesDir
115+
);
116+
}
117+
118+
log::debug("Deleting {}", serverPath);
119+
std::filesystem::remove_all(serverPath, err);
120+
if (err) {
121+
return geode::Err("Failed to delete save data for {}: {}", server.name, err.message());
122+
}
123+
124+
m_servers.erase(server.id);
125+
this->save();
126+
127+
return geode::Ok();
128+
}
129+
90130
GDPSMain *GDPSMain::m_instance = nullptr;
91131

92132
void GDPSMain::init() {

src/utils/GDPSMain.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class GDPSMain {
1717
bool isBase() const;
1818
geode::Result<> registerServer(GDPSTypes::Server& server);
1919
geode::Result<> modifyRegisteredServer(GDPSTypes::Server& server);
20+
geode::Result<> deleteServer(GDPSTypes::Server& server);
2021
static bool isBase(std::string url);
2122

2223
void save() const;

0 commit comments

Comments
 (0)