chdir() -> -[OFFileManager changeCurrentDirectoryPath:]

This commit is contained in:
Inori 2019-12-15 20:51:55 -05:00 committed by Inori
parent bc92516cff
commit 3554e2b72f
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];
for (id key = [e nextObject]; key != nil; key = [e nextObject])
{
Debug() << [[key description] UTF8String] << [[key className] UTF8String];
{
opts[key] = confData[key];
}
}
@catch(OFException *e){
Debug() << [[e description] UTF8String];
Debug() << "OBJC:" << [[e description] UTF8String];
}
}
#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())
{
game.title = "mkxp-z";

View file

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

View file

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