// We don't track every file. This function filters potential files. static bool checkInWhitelist(utString path) { // Note the platform-specific version of our whitelisted folders. static utString assetPath = "./assets"; platform_normalizePath(const_cast<char*>(assetPath.c_str())); static utString binPath = "./bin"; platform_normalizePath(const_cast<char*>(binPath.c_str())); static utString srcPath = "./src"; platform_normalizePath(const_cast<char*>(srcPath.c_str())); // Just prefix match against assets for now - ignore things in other folders. lmLogDebug(gAssetAgentLogGroup, "Whitelisting path %s prefix %s\n", path.c_str(), path.substr(0, 6).c_str()); platform_normalizePath(const_cast<char*>(path.c_str())); if (path.substr(path.length() - 3, 3) == "tmp") { return false; } if (path.substr(0, 8) == assetPath) { return true; } if (path.substr(0, 5) == srcPath) { return true; } if (path.substr(0, 5) == binPath) { return true; } return false; }
void send() { if (url == "") { _OnFailureDelegate.pushArgument("Error: Empty URL"); _OnFailureDelegate.invoke(); } else { if (bodyBytes != NULL) { // Send with body as byte array. platform_HTTPSend((const char *)url.c_str(), (const char *)method.c_str(), &HTTPRequest::respond, (void *)this, (const char *)bodyBytes->getInternalArray()->ptr(), bodyBytes->getSize(), header, (const char *)responseCacheFile.c_str(), base64EncodeResponseData, followRedirects); } else { // Send with body as string. platform_HTTPSend((const char *)url.c_str(), (const char *)method.c_str(), &HTTPRequest::respond, (void *)this, (const char *)body.c_str(), body.length(), header, (const char *)responseCacheFile.c_str(), base64EncodeResponseData, followRedirects); } } }
// Helper to recognize an asset's type from its path/name. static int loom_asset_recognizeAssetTypeFromPath(utString& path) { // Easy out - empty strings are no good! if (path.length() == 0) { return 0; } // Walk backwards to first dot. size_t firstDotPos = path.size() - 1; for (size_t pos = path.size() - 1; pos > 0; pos--) { if (path.at(pos) != '.') { continue; } firstDotPos = pos; break; } // Split out the extension. utString pathExt = path.substr(firstDotPos + 1); // See if we can get a type out of any of the recognizers. int type = 0; for (UTsize i = 0; i < gRecognizerList.size(); i++) { type = gRecognizerList[i](pathExt.c_str()); if (type) { break; } } // No match, so let's use text. if (type == 0) { lmLogInfo(gAssetLogGroup, "Couldn't recognize '%s', defaulting to LATText...", path.c_str()); type = LATText; } return type; }
// this will always be in assets/loom.config (unless we decide to move it) void LoomApplicationConfig::parseApplicationConfig(const utString& jsonString) { configJSON = jsonString; // verify config is valid JSON json_error_t jerror; json_t *json = json_loadb(jsonString.c_str(), jsonString.length(), 0, &jerror); lmAssert(json, "LoomApplicationConfig::parseApplicationConfig() error parsing application config %s\n %s %i\n", jerror.source, jerror.text, jerror.line); if (json_t *wfaa = json_object_get(json, "waitForAssetAgent")) { _waitForAssetAgent = _jsonParseInt("waitForAssetAgent", wfaa); } if (json_t *ah = json_object_get(json, "assetAgentHost")) { if (!json_is_string(ah)) { lmLog(gLoomApplicationConfigLogGroup, "assetAgentHost was specified but is not a string!"); } else { assetHost = json_string_value(ah); } } if (json_t *ap = json_object_get(json, "assetAgentPort")) { assetPort = _jsonParseInt("assetAgentPort", ap); } const char *v = json_string_value(json_object_get(json, "version")); if (v != NULL) { _version = v; } const char *app_id = json_string_value(json_object_get(json, "app_id")); if (app_id != NULL) { _applicationId = app_id; } // Parse log block. if (json_t *logBlock = json_object_get(json, "log")) { // Walk the children. const char *key; json_t *value; json_object_foreach(logBlock, key, value) { // Key is the prefix for the rule. // Maybe we have level or enabled data? int enabledRule = -1; int filterRule = -1; if (json_t *enabledBlock = json_object_get(value, "enabled")) { enabledRule = _jsonParseBool("log.enabled", value); } // TODO: Allow info, warn, error as parameters here. if (json_t *levelBlock = json_object_get(value, "level")) { filterRule = (int)json_integer_value(levelBlock); } loom_log_addRule(key, enabledRule, filterRule); } }
void LSCompiler::linkRootAssembly(const utString& sjson) { json_error_t jerror; json_t *json = json_loadb((const char *)sjson.c_str(), sjson.length(), 0, &jerror); lmAssert(json, "Error linking assembly"); json_t *ref_array = json_object_get(json, "references"); lmAssert(json, "Error linking assembly, can't get executable references"); for (UTsize i = 0; i < rootBuildDependencies.size(); i++) { BuildInfo *buildInfo = rootBuildDependencies.at(i); utString assemblySource = buildInfo->getOutputDir() + platform_getFolderDelimiter() + buildInfo->getAssemblyName() + ".loomlib"; utArray<unsigned char> rarray; lmAssert(utFileStream::tryReadToArray(assemblySource, rarray), "Unable to load library assembly %s", assemblySource.c_str()); utBase64 base64 = utBase64::encode64(rarray); for (size_t j = 0; j < json_array_size(ref_array); j++) { json_t *jref = json_array_get(ref_array, j); utString jname = json_string_value(json_object_get(jref, "name")); if (buildInfo->getAssemblyName() == jname) { logVerbose("Linking: %s", jname.c_str()); json_object_set(jref, "binary", json_string(base64.getBase64().c_str())); json_object_set(jref, "uid", json_string(readAssemblyUID(rarray))); break; } } } // filter the reference array by the import assemblies utStack<int> filter; for (size_t j = 0; j < json_array_size(ref_array); j++) { json_t *jref = json_array_get(ref_array, j); utString jname = json_string_value(json_object_get(jref, "name")); bool found = false; // always find the System assembly, so we don't have to explicitly import from it if (jname == "System") { found = true; } for (UTsize k = 0; k < importedAssemblies.size() && !found; k++) { if (importedAssemblies.at(k)->getName() == jname) { found = true; break; } } if (!found) { filter.push((int)j); } } while (filter.size()) { json_array_remove(ref_array, filter.pop()); } for (UTsize i = 0; i < rootLibDependencies.size(); i++) { utString libName = rootLibDependencies.at(i); for (size_t j = 0; j < json_array_size(ref_array); j++) { json_t *jref = json_array_get(ref_array, j); utString jname = json_string_value(json_object_get(jref, "name")); if (libName != jname) { continue; } log("Linking: %s", libName.c_str()); utString delim = platform_getFolderDelimiter(); utString libPath = sdkPath + delim + "libs" + delim + libName + ".loomlib"; utArray<unsigned char> rarray; if (libName == "System" && embeddedSystemAssembly) { size_t embeddedSystemAssemblyLength = strlen(embeddedSystemAssembly); rarray.resize((int)(embeddedSystemAssemblyLength + 1)); memcpy(&rarray[0], embeddedSystemAssembly, embeddedSystemAssemblyLength + 1); } else { lmAssert(utFileStream::tryReadToArray(libPath, rarray), "Unable to load library assembly %s at %s", libName.c_str(), libPath.c_str()); } utBase64 base64 = utBase64::encode64(rarray); json_object_set(jref, "binary", json_string(base64.getBase64().c_str())); json_object_set(jref, "uid", json_string(readAssemblyUID(rarray))); break; } } json_object_set(json, "executable", json_true()); utString execSource = rootBuildInfo->getOutputDir() + utString(platform_getFolderDelimiter()) + rootBuildInfo->getAssemblyName() + ".loom"; // generate binary assembly for executable BinWriter::writeExecutable(execSource.c_str(), json); log("Compile Successful: %s\n", execSource.c_str()); }