chdir() -> -[OFFileManager changeCurrentDirectoryPath:]

This commit is contained in:
Inori 2019-12-15 20:51:55 -05:00
parent 4fb4f626f4
commit 572f6c43db
3 changed files with 40 additions and 66 deletions

View file

@ -127,13 +127,12 @@ void Config::read(int argc, char *argv[])
OFEnumerator* e = [confData keyEnumerator]; OFEnumerator* e = [confData keyEnumerator];
for (id key = [e nextObject]; key != nil; key = [e nextObject]) for (id key = [e nextObject]; key != nil; key = [e nextObject])
{ {
Debug() << [[key description] UTF8String] << [[key className] UTF8String];
opts[key] = confData[key]; opts[key] = confData[key];
} }
} }
@catch(OFException *e){ @catch(OFException *e){
Debug() << [[e description] UTF8String]; Debug() << "OBJC:" << [[e description] UTF8String];
} }
} }
#define SET_OPT_CUSTOMKEY(var, key, type) GUARD( var = [opts[@#key] type]; ) #define SET_OPT_CUSTOMKEY(var, key, type) GUARD( var = [opts[@#key] type]; )
@ -231,41 +230,6 @@ void Config::readGameINI()
} }
/*
std::string iniFilename = execName + ".ini";
SDLRWStream iniFile(iniFilename.c_str(), "r");
if (iniFile)
{
INIConfiguration ic;
if(ic.load(iniFile.stream()))
{
GUARD_ALL( game.title = ic.getStringProperty("Game", "Title"); );
GUARD_ALL( game.scripts = ic.getStringProperty("Game", "Scripts"); );
strReplace(game.scripts, '\\', '/');
if (game.title.empty())
{
Debug() << iniFilename + ": Could not find Game.Title property";
}
if (game.scripts.empty())
{
Debug() << iniFilename + ": Could not find Game.Scripts property";
}
}
else
{
Debug() << iniFilename + ": Failed to parse ini file";
}
}
else
{
Debug() << "FAILED to open" << iniFilename;
}
*/
if (game.title.empty()) if (game.title.empty())
{ {
game.title = "mkxp-z"; game.title = "mkxp-z";

View file

@ -19,33 +19,35 @@
** along with mkxp. If not, see <http://www.gnu.org/licenses/>. ** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <alc.h> #import <alc.h>
#include <SDL.h> #import <SDL.h>
#include <SDL_image.h> #import <SDL_image.h>
#include <SDL_ttf.h> #import <SDL_ttf.h>
#include <SDL_sound.h> #import <SDL_sound.h>
#include <unistd.h> #import <unistd.h>
#include <string.h> #import <string.h>
#include <assert.h> #import <assert.h>
#include <string> #import <string>
#include "sharedstate.h" #import "sharedstate.h"
#include "eventthread.h" #import "eventthread.h"
#include "gl-debug.h" #import "gl-debug.h"
#include "debugwriter.h" #import "debugwriter.h"
#include "exception.h" #import "exception.h"
#include "gl-fun.h" #import "gl-fun.h"
#include "binding.h" #import "binding.h"
#ifdef __WINDOWS__ #ifdef __WINDOWS__
#include "resource.h" #import "resource.h"
#include <Winsock2.h> #import <Winsock2.h>
#endif #endif
#include "icon.png.xxd" #import <ObjFW/ObjFW.h>
#import "icon.png.xxd"
#ifdef __APPLE__ #ifdef __APPLE__
#define GLINIT_SHOWERROR(s) showInitError(s) #define GLINIT_SHOWERROR(s) showInitError(s)
@ -112,8 +114,10 @@ int rgssThreadFun(void *userdata)
return 0; return 0;
} }
/* Start script execution */ @autoreleasepool{
scriptBinding->execute(); /* Start script execution */
scriptBinding->execute();
}
threadData->rqTermAck.set(); threadData->rqTermAck.set();
threadData->ethread->requestTerminate(); threadData->ethread->requestTerminate();
@ -161,7 +165,7 @@ static void setupWindowIcon(const Config &conf, SDL_Window *win)
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {@autoreleasepool{
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
@ -195,6 +199,8 @@ int main(int argc, char *argv[])
#endif #endif
#endif #endif
*/ */
OFFileManager* fm = [OFFileManager defaultManager];
#ifndef WORKDIR_CURRENT #ifndef WORKDIR_CURRENT
char dataDir[512]{}; char dataDir[512]{};
@ -215,7 +221,7 @@ int main(int argc, char *argv[])
SDL_free(tmp); SDL_free(tmp);
} }
} }
chdir(dataDir); @try{[fm changeCurrentDirectoryPath:[OFString stringWithUTF8String:dataDir]];}@catch(...){}
#endif #endif
/* now we load the config */ /* now we load the config */
@ -223,11 +229,15 @@ int main(int argc, char *argv[])
conf.read(argc, argv); conf.read(argc, argv);
if (!conf.gameFolder.empty()) if (!conf.gameFolder.empty())
if (chdir(conf.gameFolder.c_str()) != 0) {
{ @try{
[fm changeCurrentDirectoryPath:[OFString stringWithUTF8String:conf.gameFolder.c_str()]];
}
@catch(...){
showInitError(std::string("Unable to switch into gameFolder ") + conf.gameFolder); showInitError(std::string("Unable to switch into gameFolder ") + conf.gameFolder);
return 0; return 0;
} }
}
conf.readGameINI(); conf.readGameINI();
@ -399,7 +409,7 @@ int main(int argc, char *argv[])
SDL_Quit(); SDL_Quit();
return 0; return 0;
} }}
static SDL_GLContext initGL(SDL_Window* win, Config& conf, RGSSThreadData* threadData) static SDL_GLContext initGL(SDL_Window* win, Config& conf, RGSSThreadData* threadData)
{ {
@ -445,4 +455,4 @@ static SDL_GLContext initGL(SDL_Window* win, Config& conf, RGSSThreadData* threa
//GLDebugLogger dLogger; //GLDebugLogger dLogger;
return glCtx; return glCtx;
} }

View file

@ -38,7 +38,7 @@ if get_option('cjk_fallback_font') == true
endif endif
main_source = files( main_source = files(
'main.cpp', 'main.mm',
'audio.cpp', 'audio.cpp',
'bitmap.cpp', 'bitmap.cpp',
'eventthread.cpp', 'eventthread.cpp',