static int upload(lua_State *L) { GFacebook *facebook = getInstance(L, 1); const char *path = luaL_checkstring(L, 2); facebook->upload(g_pathForFile(path), path); return 0; }
static std::map<std::string, std::string> tableToMap(lua_State *L, int index) { luaL_checktype(L, index, LUA_TTABLE); std::map<std::string, std::string> result; int t = abs_index(L, index); lua_pushnil(L); while (lua_next(L, t) != 0) { lua_pushvalue(L, -2); std::string key = luaL_checkstring(L, -1); lua_pop(L, 1); std::string value = luaL_checkstring(L, -1); if(key == "path") value = g_pathForFile(value.c_str()); result[key] = value; lua_pop(L, 1); } return result; }
void NetworkManager::createFile(const std::vector<char>& data) { std::string fileName = &data[1]; const char* absfilename = g_pathForFile(fileName.c_str()); FILE* fos = fopen(absfilename, "wb"); int pos = 1 + fileName.size() + 1; if (data.size() > pos) fwrite(&data[pos], data.size() - pos, 1, fos); fclose(fos); calculateMD5(fileName.c_str()); saveMD5(); }
jstring transformPath(jstring jpath) { JNIEnv *env = g_getJNIEnv(); const char *path = env->GetStringUTFChars(jpath, NULL); const char *gpath = g_pathForFile(path); env->ReleaseStringUTFChars(jpath, path); jstring jgpath = env->NewStringUTF(gpath); return jgpath; }
static int postPhoto(lua_State *L){ //graphRequest(L, "me/photos", HTTP_POST); GFacebook *facebook = getInstance(L, 1); const char *graphPath = g_pathForFile(luaL_checkstring(L, 2)); if (lua_isnoneornil(L, 3)) { std::vector<gfacebook_Parameter> params2; gfacebook_Parameter parama = {"path", graphPath}; params2.push_back(parama); gfacebook_Parameter param = {NULL, NULL}; params2.push_back(param); facebook->request("me/photos", ¶ms2[0], HTTP_POST); } else { std::map<std::string, std::string> params = lua_isnoneornil(L, 3) ? std::map<std::string, std::string>() : tableToMap(L, 3); std::vector<gfacebook_Parameter> params2; std::map<std::string, std::string>::iterator iter, e = params.end(); for (iter = params.begin(); iter != e; ++iter) { gfacebook_Parameter param = {iter->first.c_str(), iter->second.c_str()}; params2.push_back(param); } gfacebook_Parameter parama = {"path", graphPath}; params2.push_back(parama); gfacebook_Parameter param = {NULL, NULL}; params2.push_back(param); facebook->request("me/photos", ¶ms2[0], HTTP_POST); } return 0; }
void NetworkManager::deleteFile(const std::vector<char> &data) { ByteBuffer buffer(&data[0], data.size()); char chr; buffer >> chr; std::string fileName; buffer >> fileName; remove(g_pathForFile(fileName.c_str())); { std::map<std::string, std::vector<unsigned char> >::iterator iter = md5_.find(fileName); if (iter != md5_.end()) { md5_.erase(iter); saveMD5(); } } }
void NetworkManager::calculateMD5(const char* file) { std::vector<unsigned char> md5(16); if (md5_fromfile(g_pathForFile(file), &md5[0])) md5_[file] = md5; }
void NetworkManager::createFolder(const std::vector<char>& data) { std::string folderName = &data[1]; mkdir(g_pathForFile(folderName.c_str()), 0755); }
void NetworkManager::tick() { int dataTotal = 0; while (true) { if(!openProject_.empty()){ application_->openProject(openProject_.c_str()); openProject_.clear(); } int dataSent0 = serverDataSent(); int dataReceived0 = serverDataReceived(); NetworkEvent event; serverTick(&event); int dataSent1 = serverDataSent(); int dataReceived1 = serverDataReceived(); if (event.eventCode == eDataReceived) { const std::vector<char>& data = event.data; LuaDebugging::studioCommand(data); switch (data[0]) { case gptMakeDir: createFolder(data); break; case gptWriteFile: createFile(data); break; case gptPlay:{ const char* absfilename = g_pathForFile("../luafiles.txt"); FILE* fos = fopen(absfilename, "wb"); fwrite(&data[0], data.size(), 1, fos); fclose(fos); play(data); } break; case gptStop: stop(); break; case gptGetFileList: sendFileList(); break; case gptSetProjectName: setProjectName(data); break; case gptDeleteFile: deleteFile(data); break; case gptSetProperties:{ const char* absfilename = g_pathForFile("../properties.bin"); FILE* fos = fopen(absfilename, "wb"); fwrite(&data[0], data.size(), 1, fos); fclose(fos); setProperties(data); } break; } } int dataDelta = (dataSent1 - dataSent0) + (dataReceived1 - dataReceived0); dataTotal += dataDelta; if (dataDelta == 0 || dataTotal > 1024) break; } }
const char* LuaApplication::fileNameFunc(const char* filename) { return g_pathForFile(filename); }
void ApplicationManager::playFiles(const char* pfile,const char *lfile) { //setting properties const char* propfilename = g_pathForFile(pfile); FILE* fis_prop = fopen(propfilename, "rb"); const char* luafilename = g_pathForFile(lfile); FILE* fis_lua = fopen(luafilename, "rb"); if (fis_prop != NULL && fis_lua != NULL) { fseek(fis_prop, 0, SEEK_END); int len = ftell(fis_prop); fseek(fis_prop, 0, SEEK_SET); std::vector<char> buf_prop(len); fread(&buf_prop[0], 1, len, fis_prop); fclose(fis_prop); ProjectProperties properties; ByteBuffer buffer(&buf_prop[0], buf_prop.size()); char chr; buffer >> chr; buffer >> properties.scaleMode; buffer >> properties.logicalWidth; buffer >> properties.logicalHeight; int scaleCount; buffer >> scaleCount; properties.imageScales.resize(scaleCount); for (int i = 0; i < scaleCount; ++i) { buffer >> properties.imageScales[i].first; buffer >> properties.imageScales[i].second; } buffer >> properties.orientation; buffer >> properties.fps; buffer >> properties.retinaDisplay; buffer >> properties.autorotation; buffer >> properties.mouseToTouch; buffer >> properties.touchToMouse; buffer >> properties.mouseTouchOrder; setProjectProperties(properties); //loading lua files std::vector<std::string> luafiles; const char* luafilename = g_pathForFile(lfile); FILE* fis_lua = fopen(luafilename, "rb"); fseek(fis_lua, 0, SEEK_END); len = ftell(fis_lua); fseek(fis_lua, 0, SEEK_SET); std::vector<char> buf_lua(len); fread(&buf_lua[0], 1, len, fis_lua); fclose(fis_lua); ByteBuffer buffer2(&buf_lua[0], buf_lua.size()); buffer2 >> chr; while (buffer2.eob() == false) { std::string str; buffer2 >> str; luafiles.push_back(str); } play(luafiles); }