static int s_open(const char *pathname, int flags) { int drive = gpath_getPathDrive(pathname); if (drive != GPATH_ABSOLUTE) { if ((gpath_getDriveFlags(drive) & GPATH_RO) == GPATH_RO && (flags & O_ACCMODE) != O_RDONLY) { errno = EACCES; return -1; } } int fd = -1; FileInfo fi = {-1, (size_t)-1, (size_t)-1, 0}; if ( drive != 0 || s_zipFile.empty() ) fd=::open(gpath_transform(pathname), flags, 0755); else { pathname = gpath_normalizeArchivePath(pathname); glog_d("Looking for %s in archive %s",pathname,s_zipFile.c_str()); std::map<std::string, FileInfo>::iterator iter; iter = s_files.find(pathname); if (iter == s_files.end()) { glog_d("%s Not found in archive",pathname); errno = ENOENT; return -1; } fd = ::open(s_zipFile.c_str(), flags, 0755); glog_d("%s: fd is %d",pathname,fd); ::lseek(fd, iter->second.startOffset, SEEK_SET); fi = iter->second; } if (fd < 0) return fd; if (drive == 0) { const char *ext = strrchr(pathname, '.'); if (ext) { ext++; if (!strcasecmp(ext, "lua")) { fi.encrypt = 1; } else if (!strcasecmp(ext, "jpeg") || !strcasecmp(ext, "jpg") || !strcasecmp(ext, "png") || !strcasecmp(ext, "wav")) { fi.encrypt = 2; } } } s_fileInfos[fd] = fi; return fd; }
void ApplicationManager::play(const char *gapp) { FILE *fd=fopen(gapp,"rb"); if (!fd) return; //No file/not openable fseek(fd,0,SEEK_END); long pksz=ftell(fd); if (pksz < 16) return; //Invalid file size struct { uint32_t flistOffset; uint32_t version; char signature[8]; } PACKED tlr; fseek(fd,pksz - 16,SEEK_SET); fread(&tlr,1,16,fd); tlr.version = BIGENDIAN4(tlr.version); tlr.flistOffset = BIGENDIAN4(tlr.flistOffset); if ((!strncmp(tlr.signature, "GiDeRoS", 7)) && (tlr.version == 0)) { glog_v("GAPP-ARCH: %s", gapp); gvfs_setZipFile(gapp); char *buffer = (char *) malloc(pksz - tlr.flistOffset); fseek(fd,tlr.flistOffset,SEEK_SET); fread(buffer, 1,pksz - tlr.flistOffset,fd); int offset = 0; while (offset < (pksz - tlr.flistOffset)) { int plen = strlen(buffer + offset); if (!plen) break; //End of list uint32_t foffset=PBULONG(buffer + offset + plen + 1); uint32_t fsize=PBULONG(buffer + offset + plen + 1+sizeof(uint32_t)); const char *norm = gpath_normalizeArchivePath(buffer + offset); gvfs_addFile(norm, 0, foffset, fsize); //glog_d("GAPP-FILE: %s,%d,%d", norm, foffset, fsize); offset += (plen + 1 + 2 * sizeof(uint32_t)); } free(buffer); } else glog_w("GAPP: Invalid signature/version"); fclose(fd); if (running_ == true) { Event event(Event::APPLICATION_EXIT); GStatus status; application_->broadcastEvent(&event, &status); running_ = false; } std::string gappfile=gapp; std::string projectName=gappfile.substr(0,gappfile.find_last_of('.')-1); const char* documentsDirectory; const char* temporaryDirectory; std::string dir = "/"; std::string documents = dir + "documents"+appPath; std::string temporary = dir + "temporary"; _mkdir(documents.c_str()); _mkdir(temporary.c_str()); glog_v("documents: %s", documents.c_str()); glog_v("temporary: %s", temporary.c_str()); mkdir(documents.c_str(), 0755); mkdir(temporary.c_str(), 0755); setDocumentsDirectory(documents.c_str()); setTemporaryDirectory(temporary.c_str()); setResourceDirectory(""); loadProperties(); loadLuaFiles(); }