38 #if defined(__native_client__) || (defined(ANDROID) && defined(USE_SDL2))
50 #include "render/graphics.h"
55 #include <CoreFoundation/CFBundle.h>
60 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
61 #include <SDL_syswm.h>
63 #include "fs/specialfolder.h"
73 #if defined __native_client__
74 #define _nacl_dir std::string("/persistent/manaplus")
80 int loadingProgressCounter = 1;
82 static void updateProgress(
int cnt)
84 const int progress = cnt + loadingProgressCounter;
88 const int width = maxSize * progress / 50;
93 void Dirs::setProgress()
95 loadingProgressCounter++;
96 updateProgress(loadingProgressCounter);
99 static void resetProgress()
101 loadingProgressCounter = 0;
102 updateProgress(loadingProgressCounter);
107 if (!getenv(
"APPDIR"))
109 logger->
log(
"error: APPDIR is not set!");
115 uint8_t *buf =
new uint8_t[1000000];
117 FILE *
const file = fopen(
fileName.c_str(),
"w");
118 for (
int f = 0; f < 100; f ++)
120 std::string part =
strprintf(
"manaplus-data.zip%u%u",
124 SDL_RWops *
const rw = SDL_RWFromFile(part.c_str(),
"r");
127 const int size = SDL_RWsize(rw);
128 int size2 = SDL_RWread(rw, buf, 1,
size);
130 fwrite(buf, 1, size2, file);
141 const std::string fileName2 =
pathJoin(getenv(
"APPDIR"),
143 FILE *
const file2 = fopen(fileName2.c_str(),
"w");
144 SDL_RWops *
const rw = SDL_RWFromFile(
"manaplus-locale.zip",
"r");
147 const int size = SDL_RWsize(rw);
148 int size2 = SDL_RWread(rw, buf, 1,
size);
149 fwrite(buf, 1, size2, file2);
181 #if defined(ANDROID) && defined(USE_SDL2)
182 Files::setCopyCallBack(&updateProgress);
186 const std::string zipName =
pathJoin(getenv(
"APPDIR"),
"data.zip");
187 const std::string dirName =
pathJoin(getenv(
"APPDIR"),
"data");
192 "data/perserver/default",
194 Files::extractLocale();
205 #if defined __APPLE__
206 CFBundleRef mainBundle = CFBundleGetMainBundle();
207 CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
209 if (!CFURLGetFileSystemRepresentation(resourcesURL,
211 reinterpret_cast<uint8_t*
>(path),
214 fprintf(stderr,
"Can't find Resources directory\n");
216 CFRelease(resourcesURL);
217 std::string path2 =
pathJoin(path,
"data");
230 if (getenv(
"APPDIR"))
232 const std::string appDir = getenv(
"APPDIR");
240 #if defined __native_client__
254 const int loc =
CAST_S32(path.find_last_of(
'/'));
259 0, loc + 1).append(
"data"),
272 if (stat(portableName.c_str(), &statbuf) == 0 &&
273 S_ISREG(statbuf.st_mode))
277 portable.
init(portableName,
289 logger->
log(
"Portable file: %s", portableName.c_str());
293 dir = portable.
getValue(
"dataDir",
"");
304 dir = portable.
getValue(
"configDir",
"");
315 dir = portable.
getValue(
"screenshotDir",
"");
319 logger->
log(
"Portable screenshot dir: %s",
346 "Library/Application Support",
348 #elif defined __HAIKU__
350 "config/cache/Mana");
357 #elif defined __ANDROID__
361 #elif defined __native_client__
363 #elif defined __SWITCH__
368 ".local/share/mana");
405 #elif defined __HAIKU__
407 "config/settings/Mana",
421 #elif defined __ANDROID__
425 #elif defined __native_client__
427 #elif defined __SWITCH__
453 std::stringstream updates;
476 if (pos != std::string::npos)
486 logger->
log(
"Error: Invalid update host: %s",
496 logger->
log1(
"Warning: no protocol was specified for the update host");
516 if (!CreateDirectory(newDir.c_str(),
nullptr) &&
517 GetLastError() != ERROR_ALREADY_EXISTS)
519 logger->
log(
"Error: %s can't be made, but doesn't exist!",
527 logger->
log(
"Error: %s/%s can't be made, but doesn't exist!",
536 const std::string updateLocal =
pathJoin(updateDir,
"local");
537 const std::string updateFix =
pathJoin(updateDir,
"fix");
553 _(
"Error: %s doesn't exist and can't be created! "
559 #ifdef __native_client__
568 + std::string(
"/images");
574 _(
"Error: %s doesn't exist and can't be created! "
582 const std::string configScreenshotSuffix =
585 if (!configScreenshotSuffix.empty())
588 configScreenshotSuffix);
std::string decodeBase64String(std::string value)
std::string encodeBase64String(std::string value)
void setState(const StateT state)
std::string getValue(const std::string &key, const std::string &deflt) const
bool getBoolValue(const std::string &key) const
std::string getStringValue(const std::string &key) const
void setValue(const std::string &key, const std::string &value)
void init(const std::string &filename, const UseVirtFs useResManager, const SkipError skipError)
std::string getDirectory() const
static void initRootDir()
static void initTempDir()
static void initConfigDir()
static void initUpdatesDir()
static void initHomeDir()
static void initLocalDataDir()
static void initUsersDir()
static void initScreenshotDir()
static void extractDataDir()
static void mountDataDir()
static void updateDataPath()
virtual void updateScreen()=0
virtual void fillRectangle(const Rect &rectangle)=0
virtual void setColor(const Color &color)
void log(const char *const log_text,...)
void log1(const char *const log_text)
void error(const std::string &error_text) __attribute__((noreturn))
std::string screenshotDir
std::string serverConfigDir
void setBrandingDefaults(Configuration &cfg)
int mkdir_r(const char *const pathname)
Create a directory, making leading components first if necessary.
bool mkdir(const std::string &dirname)
const char * getBaseDir()
bool mountZip(std::string newDir, const Append append)
bool isDirectory(std::string name)
const char * getUserDir()
bool mountDir(std::string newDir, const Append append)
bool mountDirSilent(std::string newDir, const Append append)
bool mountZip2(std::string newDir, std::string subDir, const Append append)
std::string getPicturesDir()
bool checkPath(const std::string &path)
void setPackageDir(const std::string &dir)
bool isRealPath(const std::string &str)
const bool SkipError_false
std::string & replaceAll(std::string &context, const std::string &from, const std::string &to)
std::string strprintf(const char *const format,...)
std::string pathJoin(std::string str1, const std::string &str2)
std::string screenshotDir
const bool UseVirtFs_false