sieelf/AkkuD/conf_loader.cpp
loquat520@qq.com ce704cfd87 +vcmd
+SndDemon
+LogSms
+ElfsInHotKeys
+ELFLoader_lg8/drawhook 用于使65机型支持半透明颜色,主程序部分未获源码
+DynIDLE
+DisplayShooter v2.0里面貌似Balls文件夹有些共享的很好的代码
+Cpumon更新
+ChanBanner & GUI
+alarm2
+AkkuD
+7zlib
2010-05-11 02:34:33 +00:00

54 lines
1.2 KiB
C++

#include "..\inc\swilib.h"
#include "..\inc\cfg_items.h"
#include "conf_loader.h"
#include "akkusrc.h"
const char *successed_config_filename="";
#pragma segment="CONFIG_C"
int LoadConfigData(const char *fname)
{
int f;
unsigned int ul;
char *buf;
int result=0;
void *cfg;
unsigned int rlen, end;
cfg=(char *)__segment_begin("CONFIG_C");
unsigned int len=(char *)__segment_end("CONFIG_C")-(char *)__segment_begin("CONFIG_C");
if (!(buf=(char*)malloc(len))) return -1;
if ((f=fopen(fname,A_ReadOnly+A_BIN,P_READ,&ul))!=-1)
{
rlen=fread(f,buf,len,&ul);
end=lseek(f,0,S_END,&ul,&ul);
fclose(f,&ul);
if (rlen!=end || rlen!=len) goto L_SAVENEWCFG;
memcpy(cfg,buf,len);
}
else
{
L_SAVENEWCFG:
if ((f=fopen(fname,A_ReadWrite+A_Create+A_Truncate,P_READ+P_WRITE,&ul))!=-1)
{
if (fwrite(f,cfg,len,&ul)!=len) result=-1;
fclose(f,&ul);
}
else
result=-1;
}
mfree(buf);
if (result>=0) successed_config_filename=fname;
return(result);
}
void InitConfig()
{
if (LoadConfigData("4:\\ZBin\\etc\\akkud2.bcfg")<0)
{
LoadConfigData("0:\\ZBin\\etc\\akkud2.bcfg");
}
LoadATAB();
}