RequestOut<TGetLabDataReplyData> LabService::getLabData(const RequestIn<TGetLabDataRequestData> &in) { typedef RequestOut<TGetLabDataReplyData> Out; Translator t(in.locale()); QString error; if (!commonCheck(t, &error)) return Out(error); QDateTime dt = QDateTime::currentDateTime(); bool ok = false; if (in.cachingEnabled() && in.lastRequestDateTime().isValid()) { QDateTime lastModDT = LabRepo->findLastModificationDateTime(in.data().labId(), &ok); if (!ok) return Out(t.translate("LabService", "Failed to get lab last modification date time (internal)", "error")); if (in.lastRequestDateTime() >= lastModDT) return Out(dt); } Lab entity = LabRepo->findOne(in.data().labId(), &ok); if (!ok) return Out(t.translate("LabService", "Failed to get lab (internal)", "error")); ok = false; foreach (const TLabDataInfo &ldi, entity.labDataInfos()) { if (int(ldi.type()) != TLabType::DesktopApplication || ldi.os() == in.data().os()) { ok = true; break; } } if (!ok) return Out(t.translate("LabService", "No application for your platform", "error")); TGetLabDataReplyData replyData; replyData.setData(entity.labData(in.data().os())); return Out(replyData, dt); }
ResourceLoader::ResourceLoader() { int lab_counter = 0; _cacheDirty = false; _cacheMemorySize = 0; Lab *l; Common::ArchiveMemberList files; SearchMan.listMatchingMembers(files, "*.lab"); SearchMan.listMatchingMembers(files, "*.m4b"); if (files.empty()) error("Cannot find game data - check configuration file"); for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) { const Common::String filename = (*x)->getName(); l = new Lab(); if (l->open(filename)) { if (filename.equalsIgnoreCase("data005.lab")) _labs.push_front(l); else _labs.push_back(l); lab_counter++; } else { delete l; } } files.clear(); if (g_grim->getGameFlags() & GF_DEMO) { SearchMan.listMatchingMembers(files, "*.mus"); for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) { const Common::String filename = (*x)->getName(); l = new Lab(); if (l->open(filename)) { _labs.push_back(l); lab_counter++; } else { delete l; } } } }
RequestOut<TGetLabExtraFileReplyData> LabService::getLabExtraFile(const RequestIn<TGetLabExtraFileRequestData> &in) { typedef RequestOut<TGetLabExtraFileReplyData> Out; Translator t(in.locale()); QString error; if (!commonCheck(t, &error)) return Out(error); QDateTime dt = QDateTime::currentDateTime(); bool ok = false; if (in.cachingEnabled() && in.lastRequestDateTime().isValid()) { QDateTime lastModDT = LabRepo->findLastModificationDateTime(in.data().labId(), &ok); if (!ok) return Out(t.translate("LabService", "Failed to get lab last modification date time (internal)", "error")); if (in.lastRequestDateTime() >= lastModDT) return Out(dt); } Lab entity = LabRepo->findOne(in.data().labId(), &ok); if (!ok) return Out(t.translate("LabService", "Failed to get lab (internal)", "error")); TGetLabExtraFileReplyData replyData; replyData.setFile(entity.extraFile(in.data().fileName())); return Out(replyData, dt); }
RequestOut<TDeleteLabReplyData> LabService::deleteLab(const RequestIn<TDeleteLabRequestData> &in) { typedef RequestOut<TDeleteLabReplyData> Out; Translator t(in.locale()); QString error; if (!commonCheck(t, in.data(), &error)) return Out(error); bool ok = false; const TDeleteLabRequestData &requestData = in.data(); Lab entity = LabRepo->findOne(requestData.id(), &ok); if (!ok) return Out(t.translate("LabService", "Failed to get lab (internal)", "error")); if (!entity.isValid()) return Out(t.translate("LabService", "No such lab", "error")); TransactionHolder holder(Source); QDateTime dt = LabRepo->deleteOne(requestData.id(), &ok); if (!ok) return Out(t.translate("LabService", "Failed to delete lab (internal)", "error")); TDeleteLabReplyData replyData; if (!commit(t, holder, &error)) return Out(error); return Out(replyData, dt); }
int main(int argc, char **argv){ Lab jsk; Professor *p1 = new Professor(); Student *s1 = new Student(); p1->SetName("yamada"); s1->SetName("suzuki"); p1->SetRoom(123); s1->SetGrade(4); jsk.AddMember(p1); jsk.AddMember(s1); printf("jsk member\n"); jsk.PrintMember(); delete p1; delete s1; Lab gsk; Professor *p2 = new Professor(); Student *s2 = new Student(); p2->SetName("sato"); s2->SetName("kato"); p2->SetRoom(125); s2->SetGrade(6); gsk.AddMember(p2); gsk.AddMember(s2); printf("gsk member\n"); gsk.PrintMember(); delete p2; delete s2; return 0; }
ResourceLoader::ResourceLoader() { _cacheDirty = false; _cacheMemorySize = 0; Lab *l; Common::ArchiveMemberList files, updFiles; if (g_grim->getGameType() == GType_GRIM) { if (g_grim->getGameFlags() & ADGF_DEMO) { SearchMan.listMatchingMembers(files, "gfdemo01.lab"); SearchMan.listMatchingMembers(files, "grimdemo.mus"); SearchMan.listMatchingMembers(files, "sound001.lab"); SearchMan.listMatchingMembers(files, "voice001.lab"); } else { //Load the update from the executable Common::File *updStream = new Common::File(); if (updStream && updStream->open("gfupd101.exe")) { Common::Archive *update = loadUpdateArchive(updStream); if (update) SearchMan.add("update", update, 1); } else delete updStream; if (!SearchMan.hasFile("residualvm-grim-patch.lab")) error("residualvm-grim-patch.lab not found"); SearchMan.listMatchingMembers(files, "residualvm-grim-patch.lab"); SearchMan.listMatchingMembers(files, "data???.lab"); SearchMan.listMatchingMembers(files, "movie??.lab"); SearchMan.listMatchingMembers(files, "vox????.lab"); SearchMan.listMatchingMembers(files, "year?mus.lab"); SearchMan.listMatchingMembers(files, "local.lab"); SearchMan.listMatchingMembers(files, "credits.lab"); //Sort the archives in order to ensure that they are loaded with the correct order Common::sort(files.begin(), files.end(), LabListComperator()); //Check the presence of datausr.lab and ask the user if he wants to load it. //In this case put it in the top of the list Common::ArchiveMemberList::iterator datausr_it = Common::find_if(files.begin(), files.end(), LabListComperator("datausr.lab")); if (datausr_it != files.end()) { Grim::InputDialog d("User-patch detected, the ResidualVM-team\n provides no support for using such patches.\n Click OK to load, or Cancel\n to skip the patch.", "OK", false); int res = d.runModal(); if (res == GUI::kMessageOK) files.push_front(*datausr_it); files.erase(datausr_it); } } } else if (g_grim->getGameType() == GType_MONKEY4) { if (g_grim->getGameFlags() == ADGF_DEMO) { SearchMan.listMatchingMembers(files, "i9n.lab"); SearchMan.listMatchingMembers(files, "lip.lab"); SearchMan.listMatchingMembers(files, "MagDemo.lab"); SearchMan.listMatchingMembers(files, "tile.lab"); SearchMan.listMatchingMembers(files, "voice.lab"); } else { if (g_grim->getGamePlatform() == Common::kPlatformWindows) { //Load the update from the executable SearchMan.listMatchingMembers(updFiles, "MonkeyUpdate.exe"); SearchMan.listMatchingMembers(updFiles, "MonkeyUpdate_???.exe"); for (Common::ArchiveMemberList::const_iterator x = updFiles.begin(); x != updFiles.end(); ++x) { Common::SeekableReadStream *updStream; updStream = (*x)->createReadStream(); Common::Archive *update = loadUpdateArchive(updStream); if (update) SearchMan.add("update", update, 1); } } SearchMan.listMatchingMembers(files, "patch.m4b"); SearchMan.listMatchingMembers(files, "i9n.m4b"); SearchMan.listMatchingMembers(files, "art???.m4b"); SearchMan.listMatchingMembers(files, "lip.m4b"); SearchMan.listMatchingMembers(files, "local.m4b"); SearchMan.listMatchingMembers(files, "sfx.m4b"); SearchMan.listMatchingMembers(files, "voice???.m4b"); SearchMan.listMatchingMembers(files, "music?.m4b"); } } if (files.empty()) error("Cannot find game data - check configuration file"); //load labs int priority = files.size(); for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) { Common::String filename = (*x)->getName(); filename.toLowercase(); //Avoid duplicates if (_files.hasArchive(filename)) continue; l = new Lab(); if (l->open(filename)) _files.add(filename, l, priority--, true); else delete l; } files.clear(); }
ResourceLoader::ResourceLoader() { _cacheDirty = false; _cacheMemorySize = 0; Lab *l; Common::ArchiveMemberList files, updFiles; if (g_grim->getGameType() == GType_GRIM) { if (g_grim->getGameFlags() & ADGF_DEMO) { SearchMan.listMatchingMembers(files, "gfdemo01.lab"); SearchMan.listMatchingMembers(files, "grimdemo.mus"); SearchMan.listMatchingMembers(files, "sound001.lab"); SearchMan.listMatchingMembers(files, "voice001.lab"); } else { //Load the update from the executable Common::File *updStream = new Common::File(); if (updStream && updStream->open("gfupd101.exe")) { Common::Archive *update = loadUpdateArchive(updStream); if (update) SearchMan.add("update", update, 1); } else delete updStream; if (!SearchMan.hasFile("residualvm-grim-patch.lab")) error("residualvm-grim-patch.lab not found"); SearchMan.listMatchingMembers(files, "residualvm-grim-patch.lab"); SearchMan.listMatchingMembers(files, "data005.lab"); SearchMan.listMatchingMembers(files, "data004.lab"); SearchMan.listMatchingMembers(files, "data003.lab"); SearchMan.listMatchingMembers(files, "data002.lab"); SearchMan.listMatchingMembers(files, "data001.lab"); SearchMan.listMatchingMembers(files, "data000.lab"); SearchMan.listMatchingMembers(files, "movie??.lab"); SearchMan.listMatchingMembers(files, "vox????.lab"); SearchMan.listMatchingMembers(files, "year?mus.lab"); SearchMan.listMatchingMembers(files, "local.lab"); SearchMan.listMatchingMembers(files, "credits.lab"); //Sort the archives in order to ensure that they are loaded with the correct order Common::sort(files.begin(), files.end(), LabListComperator()); //Check the presence of datausr.lab and if the user wants to load it. //In this case put it in the top of the list const char *datausr_name = "datausr.lab"; if (SearchMan.hasFile(datausr_name) && ConfMan.getBool("datausr_load")) { warning("Loading datausr.lab. Please note that the ResidualVM-team doesn't provide support for using such patches"); files.push_front(SearchMan.getMember(datausr_name)); } } } else if (g_grim->getGameType() == GType_MONKEY4) { if (g_grim->getGameFlags() & ADGF_DEMO) { SearchMan.listMatchingMembers(files, "i9n.lab"); SearchMan.listMatchingMembers(files, "lip.lab"); SearchMan.listMatchingMembers(files, "MagDemo.lab"); SearchMan.listMatchingMembers(files, "tile.lab"); SearchMan.listMatchingMembers(files, "voice.lab"); } else { if (g_grim->getGamePlatform() == Common::kPlatformWindows) { //Load the update from the executable SearchMan.listMatchingMembers(updFiles, "MonkeyUpdate.exe"); SearchMan.listMatchingMembers(updFiles, "MonkeyUpdate_???.exe"); for (Common::ArchiveMemberList::const_iterator x = updFiles.begin(); x != updFiles.end(); ++x) { Common::SeekableReadStream *updStream; updStream = (*x)->createReadStream(); Common::Archive *update = loadUpdateArchive(updStream); if (update) SearchMan.add("update", update, 1); } } SearchMan.listMatchingMembers(files, "patch.m4b"); SearchMan.listMatchingMembers(files, "i9n.m4b"); SearchMan.listMatchingMembers(files, "art???.m4b"); SearchMan.listMatchingMembers(files, "lip.m4b"); SearchMan.listMatchingMembers(files, "local.m4b"); SearchMan.listMatchingMembers(files, "sfx.m4b"); SearchMan.listMatchingMembers(files, "voice???.m4b"); SearchMan.listMatchingMembers(files, "music?.m4b"); if (g_grim->getGamePlatform() == Common::kPlatformPS2) { SearchMan.listMatchingMembers(files, "???.m4b"); } //Check the presence of datausr.m4b and if the user wants to load it. //In this case put it in the top of the list const char *datausr_name = "datausr.m4b"; if (SearchMan.hasFile(datausr_name) && ConfMan.getBool("datausr_load")) { warning("Loading datausr.m4b. Please note that the ResidualVM-team doesn't provide support for using such patches"); files.push_front(SearchMan.getMember(datausr_name)); } } } // Check if the update has correctly loaded if (!(g_grim->getGameFlags() & ADGF_DEMO || SearchMan.hasArchive("update"))) { const char *errorMessage = 0; if (g_grim->getGameType() == GType_GRIM) { errorMessage = "Unsupported version of Grim Fandango.\n" "Please download the original patch from\n" "http://www.residualvm.org/downloads/\n" "and put it in the game data files directory"; GUI::displayErrorDialog(errorMessage); error("gfupd101.exe not found"); } //Don't force the update for MI4 for now /*else if (g_grim->getGameType() == GType_MONKEY4) errorMessage = "Unsupported version of Escape from Monkey Island.\n" "Please download the original patch from\n" "http://www.residualvm.org/downloads/\n" "and put it in the game data files directory.\n" "Pay attention to download the correct version according to the game's language"; */ } if (files.empty()) error("Cannot find game data - check configuration file"); //load labs int priority = files.size(); for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) { Common::String filename = (*x)->getName(); filename.toLowercase(); //Avoid duplicates if (SearchMan.hasArchive(filename)) continue; l = new Lab(); if (l->open(filename)) SearchMan.add(filename, l, priority--, true); else delete l; } files.clear(); }
RequestOut<TAddLabReplyData> LabService::addLab(const RequestIn<TAddLabRequestData> &in, quint64 userId) { typedef RequestOut<TAddLabReplyData> Out; Translator t(in.locale()); QString error; const TAddLabRequestData &requestData = in.data(); if (!commonCheck(t, requestData, &error)) return Out(error); if (!checkUserId(t, userId, &error)) return Out(error); bool ok = false; Lab entity; entity.setAuthors(requestData.authors()); entity.setDataList(requestData.dataList()); entity.setDescription(requestData.description()); entity.setExtraFiles(requestData.extraFiles()); entity.setGroups(requestData.groups()); entity.setSenderId(userId); entity.setTags(requestData.tags()); entity.setTitle(requestData.title()); entity.setType(requestData.dataList().first().type()); TransactionHolder holder(Source); quint64 id = LabRepo->add(entity, &ok); if (!ok || !id) return Out(t.translate("LabService", "Failed to add lab (internal)", "error")); entity = LabRepo->findOne(id, &ok); if (!ok || !entity.isValid()) return Out(t.translate("LabService", "Failed to get lab (internal)", "error")); TLabInfo info = labToLabInfo(entity, &ok); if (!ok) return Out(t.translate("LabService", "Failed to create lab info (internal)", "error")); if (!commit(t, holder, &error)) return Out(error); TAddLabReplyData replyData; replyData.setLabInfo(info); return Out(replyData, info.creationDateTime()); }
RequestOut<TEditLabReplyData> LabService::editLab(const RequestIn<TEditLabRequestData> &in) { typedef RequestOut<TEditLabReplyData> Out; Translator t(in.locale()); QString error; if (!commonCheck(t, in.data(), &error)) return Out(error); bool ok = false; const TEditLabRequestData &requestData = in.data(); Lab entity = LabRepo->findOne(requestData.id(), &ok); if (!ok) return Out(t.translate("LabService", "Failed to get lab (internal)", "error")); if (!entity.isValid()) return Out(t.translate("LabService", "No such lab", "error")); entity.convertToCreatedByUser(); entity.setAuthors(requestData.authors()); entity.setDeletedExtraFiles(requestData.deletedExtraFiles()); entity.setDescription(requestData.description()); entity.setExtraFiles(requestData.newExtraFiles()); entity.setGroups(requestData.groups()); entity.setSaveData(requestData.editData()); if (requestData.editData()) { entity.setDataList(requestData.dataList()); entity.setType(requestData.dataList().first().type()); } entity.setTags(requestData.tags()); entity.setTitle(requestData.title()); TransactionHolder holder(Source); LabRepo->edit(entity, &ok); if (!ok) return Out(t.translate("LabService", "Failed to edit lab (internal)", "error")); entity = LabRepo->findOne(entity.id(), &ok); if (!ok || !entity.isValid()) return Out(t.translate("LabService", "Failed to get lab (internal)", "error")); TEditLabReplyData replyData; TLabInfo info = labToLabInfo(entity, &ok); if (!ok) return Out(t.translate("LabService", "Failed to create lab info (internal)", "error")); if (!commit(t, holder, &error)) return Out(error); replyData.setLabInfo(info); return Out(replyData, entity.lastModificationDateTime()); }