update runtime

This commit is contained in:
chuanweizhang2013 2014-03-31 11:18:41 +08:00
parent 2649c5b971
commit 93c424071e
1 changed files with 75 additions and 39 deletions

View File

@ -373,20 +373,8 @@ bool CreateDir(const char *sPathName)
return true; return true;
} }
void updateResFileInfo(string filename,string filetime) bool updateResFileInfo()
{ {
if (g_filecfgjson.HasMember(filename.c_str())) {
g_filecfgjson.RemoveMember(filename.c_str());
}
rapidjson::Value filetimeValue(rapidjson::kStringType);
filetimeValue.SetString(filetime.c_str(),g_filecfgjson.GetAllocator());
rapidjson::Value filenameValue(rapidjson::kStringType);
filenameValue.SetString(filename.c_str(),g_filecfgjson.GetAllocator());
g_filecfgjson.AddMember(filenameValue.GetString(),filetimeValue,g_filecfgjson.GetAllocator());
//g_filecfgjson[filename.c_str()] = filetime.c_str();
rapidjson::StringBuffer buffer; rapidjson::StringBuffer buffer;
rapidjson::Writer< rapidjson::StringBuffer > writer(buffer); rapidjson::Writer< rapidjson::StringBuffer > writer(buffer);
g_filecfgjson.Accept(writer); g_filecfgjson.Accept(writer);
@ -396,11 +384,16 @@ void updateResFileInfo(string filename,string filetime)
filecfg.append("/"); filecfg.append("/");
filecfg.append("fileinfo_debug.json"); filecfg.append("fileinfo_debug.json");
FILE * pFile = fopen (filecfg.c_str() , "w"); FILE * pFile = fopen (filecfg.c_str() , "w");
if (!pFile)
return false;
fwrite(str,sizeof(char),strlen(str),pFile); fwrite(str,sizeof(char),strlen(str),pFile);
fclose(pFile); fclose(pFile);
return true;
} }
void readResFile() void readResFileFinfo()
{ {
string filecfg = g_resourcePath; string filecfg = g_resourcePath;
filecfg.append("/"); filecfg.append("/");
@ -420,22 +413,24 @@ void readResFile()
bool FileServer::recv_file(int fd) bool FileServer::recv_file(int fd)
{ {
char filename[1024]={0};
char headlen[5]={0}; char headlen[5]={0};
if (recv(fd, headlen, 4,0)<=0) { if (recv(fd, headlen, 4,0)<=0) {
return false; return false;
} }
if (recv(fd, filename, atoi(headlen),0)<=0) { char *headSeg = new char[atoi(headlen)+1];
if (!headSeg)
{
return false; return false;
} }
char filetimeinfo[1024]={0}; if (recv(fd, headSeg, atoi(headlen),0)<=0) {
if (recv(fd, headlen, 4,0)<=0) {
return false;
}
if (recv(fd, filetimeinfo, atoi(headlen),0)<=0) {
return false; return false;
} }
rapidjson::Document headjson;
headjson.Parse<0>(headSeg);
if (headjson.HasMember("filename"))
{
string filename = headjson["filename"].GetString();
char fullfilename[1024]={0}; char fullfilename[1024]={0};
sprintf(fullfilename,"%s%s",g_resourcePath.c_str(),filename); sprintf(fullfilename,"%s%s",g_resourcePath.c_str(),filename);
string file(fullfilename); string file(fullfilename);
@ -449,9 +444,31 @@ bool FileServer::recv_file(int fd)
fwrite(fullfilename, sizeof(char), length,fp); fwrite(fullfilename, sizeof(char), length,fp);
} }
fclose(fp); fclose(fp);
if (headjson.HasMember("lastmodifytime"))
{
string filemodifytime = headjson["lastmodifytime"].GetString();
if (g_filecfgjson.HasMember(filename.c_str()))
{
g_filecfgjson.RemoveMember(filename.c_str());
}
rapidjson::Value filetimeValue(rapidjson::kStringType);
filetimeValue.SetString(filemodifytime.c_str(),g_filecfgjson.GetAllocator());
rapidjson::Value filenameValue(rapidjson::kStringType);
filenameValue.SetString(filename.c_str(),g_filecfgjson.GetAllocator());
g_filecfgjson.AddMember(filenameValue.GetString(),filetimeValue,g_filecfgjson.GetAllocator());
updateResFileInfo();
}
}
if (headSeg)
{
delete [] headSeg;
headSeg =nullptr;
}
string finish("finish\n"); string finish("finish\n");
send(fd, finish.c_str(), finish.size(),0); send(fd, finish.c_str(), finish.size(),0);
updateResFileInfo(filename,filetimeinfo);
return true; return true;
} }
@ -631,7 +648,7 @@ public:
rapidjson::Value bodyvalue(rapidjson::kObjectType); rapidjson::Value bodyvalue(rapidjson::kObjectType);
for (auto it=g_filecfgjson.MemberonBegin();it!=g_filecfgjson.MemberonEnd();++it) for (auto it=g_filecfgjson.MemberonBegin();it!=g_filecfgjson.MemberonEnd();++it)
{ {
bodyvalue.AddMember(it->name.GetString(),it->value,dReplyParse.GetAllocator()); bodyvalue.AddMember(it->name.GetString(),it->value.GetString(),dReplyParse.GetAllocator());
} }
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator()); dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator()); dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
@ -645,6 +662,16 @@ public:
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator()); dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator()); dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
}else if(strcmp(strcmd.c_str(),"updatefileinfo")==0)
{
if(updateResFileInfo())
{
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
}else
{
dReplyParse.AddMember("code",1,dReplyParse.GetAllocator());
}
}else if(strcmp(strcmd.c_str(),"remove")==0) }else if(strcmp(strcmd.c_str(),"remove")==0)
{ {
if (dArgParse.HasMember("files")) if (dArgParse.HasMember("files"))
@ -657,8 +684,16 @@ public:
filename.append("/"); filename.append("/");
filename.append(objectfiles[i].GetString()); filename.append(objectfiles[i].GetString());
if (FileUtils::getInstance()->isFileExist(filename)) { if (FileUtils::getInstance()->isFileExist(filename)) {
if(remove(filename.c_str())!=0) if(remove(filename.c_str())==0)
{
if (g_filecfgjson.HasMember(objectfiles[i].GetString())) {
g_filecfgjson.RemoveMember(objectfiles[i].GetString());
}
}
else
{
bodyvalue.AddMember(objectfiles[i].GetString(),2,dReplyParse.GetAllocator()); bodyvalue.AddMember(objectfiles[i].GetString(),2,dReplyParse.GetAllocator());
}
}else }else
{ {
bodyvalue.AddMember(objectfiles[i].GetString(),1,dReplyParse.GetAllocator()); bodyvalue.AddMember(objectfiles[i].GetString(),1,dReplyParse.GetAllocator());
@ -666,6 +701,7 @@ public:
} }
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator()); dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
updateResFileInfo();
} }
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator()); dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
@ -726,7 +762,7 @@ void startRuntime()
ScriptEngineManager::getInstance()->setScriptEngine(engine); ScriptEngineManager::getInstance()->setScriptEngine(engine);
luaopen_debugger(engine->getLuaStack()->getLuaState()); luaopen_debugger(engine->getLuaStack()->getLuaState());
readResFile(); readResFileFinfo();
auto scene = Scene::create(); auto scene = Scene::create();
auto layer = new ConnectWaitLayer(); auto layer = new ConnectWaitLayer();
layer->autorelease(); layer->autorelease();