Exemplo n.º 1
0
QStringList ComponentInstaller::install()
{
    if (m_componentsToInstall.isEmpty()) {
        Log.w("Nothing to install - empty collection.");
        return QStringList();
    }

    Log.i(QString("Install %1 components...").arg(m_componentsToInstall.size()));
    loadComponents(m_componentsToInstall);

    QStringList copiedDefinitions;
    for (IComponent *comp : m_componentsToInstall) {
        QString componentPath = createComponentDirectory(comp->name());

        QString definitionFileName = componentPath + QDir::separator() + comp->name() + ".definition";
        definitionFileName = QDir::toNativeSeparators(definitionFileName);
        QFile::copy(comp->definition()->definitionLocation(), definitionFileName);

        QFileInfo library(comp->definition()->componentLocation());
        QString libraryFileName = componentPath + QDir::separator() + library.fileName();
        QFile::copy(comp->definition()->componentLocation(), libraryFileName);

        Log.i(QString("Component \"%1\" has been installed to the \"%2\" directory.")
              .arg(comp->name())
              .arg(componentPath));

        copiedDefinitions.push_back(definitionFileName);
    }

    Log.i("Installation finished.");

    return copiedDefinitions;
}
Exemplo n.º 2
0
Component CRewardInfo::getDisplayedComponent(const CGHeroInstance * h) const
{
	std::vector<Component> comps;
	loadComponents(comps, h);
	assert(!comps.empty());
	return comps.front();
}
Exemplo n.º 3
0
 void Backend::load()
 {
     if (is_directory(directory)) {
         loadComponents(directory);
     } else {
         std::stringstream s;
         s << "Unable to open directory: " << directory;
         throw s.str();
     }
 }
Exemplo n.º 4
0
static void loadCapitalShipDef(char *filename)
{
	cJSON *root;
	char *text;
	Entity *e;

	SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);

	text = readFile(filename);

	root = cJSON_Parse(text);

	if (root)
	{
		e = malloc(sizeof(Entity));
		memset(e, 0, sizeof(Entity));
		defTail->next = e;
		defTail = e;

		e->type = ET_CAPITAL_SHIP;
		e->active = 1;

		STRNCPY(e->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
		STRNCPY(e->defName, e->name, MAX_NAME_LENGTH);
		e->shield = e->maxShield = cJSON_GetObjectItem(root, "shield")->valueint;
		e->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint;
		e->texture = getTexture(cJSON_GetObjectItem(root, "texture")->valuestring);
		e->speed = 1;
		e->systemPower = 3;
		e->flags = EF_NO_HEALTH_BAR;

		e->action = think;
		e->die = die;

		SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);

		e->separationRadius = MAX(e->w, e->h);

		loadComponents(e, cJSON_GetObjectItem(root, "components"));

		loadGuns(e, cJSON_GetObjectItem(root, "guns"));

		loadEngines(e, cJSON_GetObjectItem(root, "engines"));

		cJSON_Delete(root);
	}
	else
	{
		SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to load '%s'", filename);
	}

	free(text);
}
Exemplo n.º 5
0
    void Backend::loadComponents(std::string dir)
    {
        auto listing = get_directory_listing(dir);

        for (auto entry : listing) {
            std::string fullPath = dir+"/"+entry;
            if (is_directory(fullPath)) {
                loadComponents(fullPath);
            } else {
                if (endswith(fullPath, ".scad") && !endswith(fullPath, ".metabot.scad")) {
                    parse(fullPath);
                }
            }
        }
    }
Exemplo n.º 6
0
CArtifact * CArtHandler::loadFromJson(const JsonNode & node, const std::string & identifier)
{
	CArtifact * art;

	if (!VLC->modh->modules.COMMANDERS || node["growing"].isNull())
		art = new CArtifact();
	else
	{
		auto  growing = new CGrowingArtifact();
		loadGrowingArt(growing, node);
		art = growing;
	}
	art->identifier = identifier;
	const JsonNode & text = node["text"];
	art->name        = text["name"].String();
	art->description = text["description"].String();
	art->eventText   = text["event"].String();

	const JsonNode & graphics = node["graphics"];
	art->image = graphics["image"].String();

	if (!graphics["large"].isNull())
		art->large = graphics["large"].String();
	else
		art->large = art->image;

	art->advMapDef = graphics["map"].String();

	art->price = node["value"].Float();

	loadSlots(art, node);
	loadClass(art, node);
	loadType(art, node);
	loadComponents(art, node);

	for (auto b : node["bonuses"].Vector())
	{
		auto bonus = JsonUtils::parseBonus(b);
		art->addNewBonus(bonus);
	}
	return art;
}
Exemplo n.º 7
0
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Init(void){
    char    loadPath[PATH_MAX];
    OMX_U32 num;

    if (gOmxCore != NULL){
        AGILE_LOGW("MagOMX IL Core has been initialized!");
        return OMX_ErrorNone;
    }

    gOmxCore = (MagOMX_IL_Core_t *)mag_mallocz(sizeof(MagOMX_IL_Core_t));
    if (NULL != gOmxCore){
        INIT_LIST(&gOmxCore->LoadedCompListHead);
        Mag_CreateMutex(&gOmxCore->lock);
        gOmxCore->roleToComponentTable = createMagStrHashTable(128);
        if (NULL == gOmxCore->roleToComponentTable){
            AGILE_LOGE("failed to create hastable: roleToComponentTable!");
            mag_freep((void **)&gOmxCore);
            return OMX_ErrorInsufficientResources;
        }
        gOmxCore->componentToRoleTable = createMagStrHashTable(128);
        if (NULL == gOmxCore->componentToRoleTable){
            AGILE_LOGE("failed to create hastable: componentToRoleTable!");
            mag_freep((void **)&gOmxCore);
            return OMX_ErrorInsufficientResources;
        }
    }else{
        AGILE_LOGE("failed to malloc the MagOMX_IL_Core_t!");
        return OMX_ErrorInsufficientResources;
    }

    sprintf(loadPath, "%s", getenv("OMX_LOAD_PATH") ? getenv("OMX_LOAD_PATH") : DEFAULT_OMX_COMP_LOAD_PATH);
    AGILE_LOGD("try to load the omx il components from %s", loadPath);

    num = loadComponents(loadPath);

    gOmxCore->LoadedCompNumber = num;
    Mag_CreateMutex(&gOmxCore->lock);
    
    return OMX_ErrorNone;
}
Exemplo n.º 8
0
// Loads JSON from file and parses it and assigns to LibraryFile class properties
bool LibraryFile::loadJson(QString filepath)
{
    // Try to open file and read it
    QFile file(filepath);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;

    // Copy library file to root directory
    QDir rootDir(libraryDirPath);
    if(!rootDir.exists())
        rootDir.mkdir(libraryDirPath);

    QFileInfo loadedInfo(file);
    QFileInfo info(libraryDirPath, loadedInfo.fileName());
    if(info.exists())
    {
        QFile newFile(info.absoluteFilePath());
        if(newFile.remove())
        {
            //QString s = file.readAll();
            file.copy(loadedInfo.absoluteFilePath(), info.absoluteFilePath());

        }
    }
    else
    {
        file.copy(loadedInfo.absoluteFilePath(), info.absoluteFilePath());
    }

    QFile libFile(info.absoluteFilePath());
    // Parse json file
    if(!libFile.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;

    libraryFileName = info.fileName();
    QString data = libFile.readAll();
    QJsonDocument doc(QJsonDocument::fromJson(data.toUtf8()));

    // Get JSON root object
    QJsonObject root = doc.object();

    // Load basic information
    libraryTitle = root["libraryTitle"].toString();
    libraryInfo = root["libraryInfo"].toString();
    comdelDirectory = root["comdelDirectory"].toString();
    loadComdelHeader(root["comdelHeader"].toArray());

    // Load list of address spaces
    loadAddressSpaceList(root["addressSpaceList"].toArray());

    // Load messages
    loadMessages(root["messages"].toObject());

    // Load all components and its children
    loadComponents(root["componentList"].toArray());

    // Load automatic and regular buses
    loadBuses(root["regularBusList"].toArray(), true);
    loadBuses(root["automaticBusList"].toArray());

    // Load connection rules
    loadRegularBusConnectionRules(root["regularBusConnectionRules"].toArray());
    loadAutomaticBusConnectionRules(root["automaticBusConnectionRules"].toArray());

    return true;
}
Exemplo n.º 9
0
ATOM_Components::ATOM_Components (const char *filename, int loadPriority, unsigned flags, ATOM_LoadingRequestCallback callback, void *userData, long group, ATOM_LoadInterface *owner): _internalData (0)
{
	ATOM_STACK_TRACE(ATOM_Components::ATOM_Components);
	loadComponents (filename, loadPriority, flags, callback, userData, group, owner);
}