initconf.cpp
Code: Select all
#include <pspkernel.h>
#include <stdio.h>
#include <libconfig.hh>
#include <libconfig.h>
#include <iostream>
#include <fstream>
#include <sys/unistd.h>
#include <cstdlib>
#include <oslib/oslib.h> //use nothing from here except values
using namespace std;
using namespace libconfig;
#include "../main/global.h"
#include "initconf.h"
PSP_MODULE_INFO("initconf", 0x0006, 1, 1);
PSP_HEAP_SIZE_KB(1500);
Config cfg;
bool loaded = false;
bool finished = false;
bool created = false;
void check_finished()
{
while(!finished)
{
//just wait till main is finished loading config
}
}
bool file_exist(string src)
{
bool r = false;
ifstream file;
file.open(src.c_str());
if(file.is_open())
r = true;
else
r = false;
file.close();
return r;
}
int main(int argc, char * argv[])
{
if(argc < 2)
{
loaded = false;
finished = true;
return 0;
}
try
{
if(file_exist(argv[1]))
{
cfg.readFile(argv[1]);
loaded = true;
}
}
catch(FileIOException &e)
{
loaded = false;
debugerr("FileIOException",__LINE__,__FILE__,__FUNCTION__);
if(file_exist(argv[1]))
{
string renamed = "~";
renamed += argv[1];
if(file_exist(renamed))
remove(renamed.c_str());
rename(argv[1],renamed.c_str());
cfg.writeFile(argv[1]);
}
}
catch(ParseException &e)
{
loaded = false;
char err[1000];
sprintf(err,"ParseException: what = %s, error = %s, line = %d",e.what(),e.getError(),e.getLine());
debugerr(err,__LINE__,__FILE__,__FUNCTION__);
if(file_exist(argv[1]))
{
string renamed = "~";
renamed += argv[1];
if(file_exist(renamed))
remove(renamed.c_str());
rename(argv[1],renamed.c_str());
cfg.writeFile(argv[1]);
}
}
finished = true;
return 0;
}
bool initconf_enableHome()
{
check_finished();
bool enableHome = false;
if(!cfg.lookupValue("enableHome",enableHome))
enableHome = true;
return enableHome;
}
int initconf_getPixelFormat()
{
check_finished();
int bpp = 0;
if(!cfg.lookupValue("bits_per_pixel",bpp))
bpp = 16;
switch(bpp)
{
case 32: return OSL_PF_8888;
case 16: return OSL_PF_5650;
case 15: return OSL_PF_5551;
default: return OSL_PF_4444;
}
return OSL_PF_4444;
}
Code: Select all
PSPSDK=$(shell psp-config --pspsdk-path)
TARGET = initconf
OBJS = main.o ../main/main_exp.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fexceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LDFLAGS =
#-mno-crt0 -nostartfiles
INCS = -I/usr/local/pspdev/include \
-I/usr/local/pspdev/psp/include \
-I/usr/local/pspdev/psp/sdk/include
CFLAGS := $(INCS)
INCDIR =
LIBDIR =
STDLIBS = -losl -mp3 -lmikmod -lpng -lz
STDLIBS += -lpspctrl -lpspumd -lpsprtc -lpsppower
STDLIBS += -lpspgu -lpspgum -lpsphprm -lpspaudiolib -lpspaudio
STDLIBS += -lmikmod -lm -lc -lstdc++ -lpspmpeg -lpsprtc
STDLIBS += -lpspaudiocodec -lpspatrac3
YOURLIBS = -lconfig++ -lconfig
LIBS = $(YOURLIBS) $(STDLIBS)
BUILD_PRX = 1
PRX_EXPORTS = exports.exp
include ../locations.mak
include $(PSPSDK)/lib/build.mak
s_file: $(shell psp-build-exports -s exports.exp)
install:
mkdir -p $(INITCONF_DIR)
cp -f initconf.prx $(INITCONF_DIR)