static void writeNFCResource(ostream& stream, const SETTINGS& s) { if (!s.nfc || !existsFile(s.nfc)) { printf("If NFC permissions are set, then\n" "1.the --nfc parameter must be set, and\n" "2. that file must exist."); exit(1); } NfcInfo* nfcInfo = NfcInfo::parse(string(s.nfc)); vector<TechList*> techLists = nfcInfo->getTechLists(); stream << "<resources xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">\n"; for (size_t i = 0; i < techLists.size(); i++) { TechList* techList = techLists.at(i); vector<string> technologies = techList->technologies; stream << "\t<tech-list>\n"; for (size_t j = 0; j < technologies.size(); j++) { stream << "\t\t<tech>"; // Simple for now :) string tech = technologies.at(j); stream << "android.nfc.tech." << tech; stream << "</tech>\n"; } stream << "\t</tech-list>\n"; } stream << "</resources>"; //TODO: delete nfcInfo; }
static void fromTemplate(const char* templateFile, const char* filename, const SETTINGS& s, const RuntimeInfo& ri) { string packageName = string(s.androidPackage); string versionCode = string(s.androidVersionCode); string version = string(s.version); string installLocation = string(s.androidInstallLocation ? s.androidInstallLocation : "internalOnly"); string largeHeap = string(s.androidHeap ? s.androidHeap : ""); MustacheParser parser(true); AndroidContext root(NULL, ri.androidVersion); root.setParameter("debug", s.debug ? "debug" : ""); root.setParameter("package-name", packageName); root.setParameter("version-code", versionCode); root.setParameter("version", version); root.setParameter("install-location", installLocation); root.setParameter("heap", largeHeap); char androidVersionStr[8]; sprintf(androidVersionStr, "%d", ri.androidVersion); root.setParameter("sdk-version", androidVersionStr); PermissionContext permissions(&root, s.permissions); root.addChild("permissions", &permissions); vector<AndroidContext*> deleteUs; if (s.nfc) { NfcInfo* nfcInfo = NfcInfo::parse(string(s.nfc)); vector<TechList*> techLists = nfcInfo->getTechLists(); for (size_t i = 0; i < techLists.size(); i++) { TechList* techList = techLists.at(i); AndroidContext* techListContext = new AndroidContext(&root, ri.androidVersion); deleteUs.push_back(techListContext); root.addChild("tech-list", techListContext); vector<string> technologies = techList->technologies; for (size_t j = 0; j < technologies.size(); j++) { AndroidContext* techContext = new AndroidContext(techListContext, ri.androidVersion); deleteUs.push_back(techContext); techListContext->addChild("tech", techContext); string techName = technologies.at(j); techContext->setParameter("name", techName); } } } ofstream output(filename); if (output.good()) { DefaultParserCallback cb(&root, output); string templateFileStr = string(templateFile); string result = parser.parseFile(templateFileStr, &cb); output.flush(); output.close(); if (!result.empty()) { printf("Error creating android manifest: %s\n", result.c_str()); exit(1); } } else { printf("Could not write android manifest!\n"); exit(1); } for (size_t i = 0; i < deleteUs.size(); i++) { delete deleteUs[(int) i]; } }