Fix File class' delimeter and homepath detection

meow :3
deleted Minecraft::OS enum because we have #ifdef
mrrrp
changed save directory name to not mess with minecraft java
This commit is contained in:
Acemany 2026-03-13 06:10:44 +03:00
parent 807af92321
commit 3cbd496186
No known key found for this signature in database
GPG key ID: E9F20EA337223AF4
3 changed files with 31 additions and 42 deletions

View file

@ -485,49 +485,41 @@ void Minecraft::blit(int x, int y, int sx, int sy, int w, int h)
File Minecraft::getWorkingDirectory() File Minecraft::getWorkingDirectory()
{ {
if (workDir.getPath().empty()) workDir = getWorkingDirectory(L"minecraft"); if (workDir.getPath().empty()) workDir = getWorkingDirectory(L"4jcraft");
return workDir; return workDir;
} }
File Minecraft::getWorkingDirectory(const std::wstring& applicationName) File Minecraft::getWorkingDirectory(const std::wstring& applicationName)
{ {
#if 0
// 4J - original version // 4J - original version
final String userHome = System.getProperty("user.home", "."); // 4jcraft: ported to C++
final File workingDirectory; std::wstring userHome = convStringToWstring(getenv("HOME"));
switch (getPlatform()) { File *workingDirectory;
case linux: #if defined(__linux__)
case solaris: workingDirectory = new File(userHome, L'.' + applicationName + L'/');
workingDirectory = new File(userHome, '.' + applicationName + '/'); #elif defined(_WINDOWS64)
break; std::string applicationData = getenv("APPDATA");
case windows: if (!applicationData.empty())
final String applicationData = System.getenv("APPDATA"); {
if (applicationData != null) workingDirectory = new File(applicationData, "." + applicationName + '/'); workingDirectory = new File(convStringToWstring(applicationData), L'.' + applicationName + L'/');
else workingDirectory = new File(userHome, '.' + applicationName + '/');
break;
case macos:
workingDirectory = new File(userHome, "Library/Application Support/" + applicationName);
break;
default:
workingDirectory = new File(userHome, applicationName + '/');
} }
if (!workingDirectory.exists()) if (!workingDirectory.mkdirs()) throw new RuntimeException("The working directory could not be created: " + workingDirectory); else
return workingDirectory; {
workingDirectory = new File(userHome, L'.' + applicationName + L'/');
}
//#elif defined(_MACOS)
// workingDirectory = new File(userHome, "Library/Application Support/" + applicationName);
#else #else
std::wstring userHome = L"home"; // 4J - TODO workingDirectory = new File(userHome, applicationName + L'/');
File workingDirectory(userHome, applicationName);
// 4J Removed
//if (!workingDirectory.exists())
//{
// workingDirectory.mkdirs();
//}
return workingDirectory;
#endif #endif
} if (!workingDirectory->exists()){
if (!workingDirectory->mkdirs()) {
Minecraft::OS Minecraft::getPlatform() app.DebugPrintf("The working directory could not be created");
{ assert(0);
return xbox; //throw new RuntimeException(L"The working directory could not be created: " + workingDirectory);
}
}
return *workingDirectory;
} }
LevelStorageSource *Minecraft::getLevelSource() LevelStorageSource *Minecraft::getLevelSource()
@ -4907,4 +4899,3 @@ int Minecraft::MustSignInReturnedPSN(void *pParam, int iPad, C4JStorage::EMessag
return 0; return 0;
} }
#endif #endif

View file

@ -50,11 +50,6 @@ class PsPlusUpsellWrapper;
class Minecraft class Minecraft
{ {
private:
enum OS{
linux, solaris, windows, macos, unknown, xbox
};
public: public:
static const std::wstring VERSION_STRING; static const std::wstring VERSION_STRING;
Minecraft(Component *mouseComponent, Canvas *parent, MinecraftApplet *minecraftApplet, int width, int height, bool fullscreen); Minecraft(Component *mouseComponent, Canvas *parent, MinecraftApplet *minecraftApplet, int width, int height, bool fullscreen);
@ -200,8 +195,6 @@ private:
public: public:
static File getWorkingDirectory(); static File getWorkingDirectory();
static File getWorkingDirectory(const std::wstring& applicationName); static File getWorkingDirectory(const std::wstring& applicationName);
private:
static OS getPlatform();
public: public:
LevelStorageSource *getLevelSource(); LevelStorageSource *getLevelSource();
void setScreen(Screen *screen); void setScreen(Screen *screen);

View file

@ -10,7 +10,12 @@
#include <fios2.h> #include <fios2.h>
#endif #endif
#ifdef __linux__
const wchar_t File::pathSeparator = L'/';
#else
const wchar_t File::pathSeparator = L'\\'; const wchar_t File::pathSeparator = L'\\';
#endif
#ifdef _XBOX #ifdef _XBOX
const std::wstring File::pathRoot = L"GAME:"; // Path root after pathSeparator has been removed const std::wstring File::pathRoot = L"GAME:"; // Path root after pathSeparator has been removed
#else #else