Exemple #1
0
void ExtensionsWizard::OnWizardFinished(wxWizardEvent &e)
{
	String extensionName = conversions::to_utf16(m_pageGeneral->getExtensionName());
	String extensionDescription = conversions::to_utf16(m_pageGeneral->getExtensionDescription());
	String extensionAuthor = conversions::to_utf16(m_pageGeneral->getExtensionAuthor());
	shared_ptr<ExtensionsWizardPageTemplate::TemplateDetails> extensionTemplate = m_pageTemplate->getTemplate();
	const ExtensionsWizardPageTemplate::TemplateDetails::Files &extensionFiles = extensionTemplate->getFiles();

	ExtensionID extensionID = ExtensionID::generate();

	String rootPath = ExtensionsSystem::instance()->getDataPath();
	String extensionPath = utils::makeFolderPath(rootPath, extensionID.toUTF16());

	shared_ptr<XMLDocument> document(OS_NEW XMLDocument());
	shared_ptr<XMLNode> nodeRoot = document->create(OS_EXTENSION_XML_NODE_ROOT);
	nodeRoot->setAttributeString(OS_EXTENSION_XML_NODE_ROOT_ID, extensionID.getString());
	nodeRoot->setAttributeString(OS_EXTENSION_XML_NODE_ROOT_NAME, extensionName);
	nodeRoot->setAttributeString(OS_EXTENSION_XML_NODE_ROOT_DESCRIPTION, extensionDescription);
	nodeRoot->setAttributeString(OS_EXTENSION_XML_NODE_ROOT_AUTHOR, extensionAuthor);
	nodeRoot->setAttributeString(OS_EXTENSION_XML_NODE_ROOT_VERSION_CODE, _S("1"));
	nodeRoot->setAttributeString(OS_EXTENSION_XML_NODE_ROOT_VERSION_NAME, _S("0.1"));
	nodeRoot->setAttributeString(OS_EXTENSION_XML_NODE_ROOT_ICON, _S("icon.png"));
	nodeRoot->setAttributeString(OS_EXTENSION_XML_NODE_ROOT_LOGO, _S("logo.png"));

	shared_ptr<XMLNode> nodeScripts;
	ExtensionsWizardPageTemplate::TemplateDetails::Files::const_iterator i;
	for(i = extensionFiles.begin(); i != extensionFiles.end(); ++i)
	{
		if((*i).script)
		{
			if(nodeScripts == nullptr)
				nodeScripts = nodeRoot->addChild(OS_EXTENSION_XML_NODE_SCRIPTS);

			shared_ptr<XMLNode> nodeScript = nodeScripts->addChild(OS_EXTENSION_XML_NODE_SCRIPT);
			nodeScript->setAttributeString(OS_EXTENSION_XML_NODE_SCRIPT_PATH, (*i).target);
			// TODO: temp
			nodeScript->setAttributeString(OS_EXTENSION_XML_NODE_SCRIPT_LANGUAGE, "python");
		}
	}

	String documentString;
	if(document->writeString(documentString) == false)
	{
		OS_ASSERTFALSE();
		Application::instance()->reportError("Internal error generating extension's xml, please report it", true);
		return;
	}

	if(XMLManager::instance()->validateString(documentString, XMLSchema::fromFile(utils::makeFilePath(utils::makeFolderPath(Options::instance()->getSharePath(), OS_SCHEMAS_PATH), OS_EXTENSIONS_EXTENSION_SCHEMA))) == false)
	{
		OS_ASSERTFALSE();
		Application::instance()->reportError("Internal error validating extension's xml, please report it", true);
		return;
	}

	if(FileSystem::instance()->ensureDirectory(extensionPath) == false)
	{
		Application::instance()->reportError("Cannot create directory '" + extensionPath + "'", true);
		return;
	}

	for(i = extensionFiles.begin(); i != extensionFiles.end(); ++i)
	{
		String targetFile = utils::makeFilePath(extensionPath, (*i).target);
		String sourceFile = utils::makeFilePath(extensionTemplate->getFolder(), (*i).source);

		String targetPath = FileSystem::instance()->getFilePath(targetFile);
		if(FileSystem::instance()->ensureDirectory(targetPath) == false)
		{
			Application::instance()->reportError("Cannot create directory '" + targetPath + "'", true);
			return;
		}

		if(FileSystem::instance()->copyFile(sourceFile, targetFile) == false)
		{
			Application::instance()->reportError("Cannot copy file '" + sourceFile + "' to '" + targetFile + "'", true);
			return;
		}

		if((*i).macro)
		{
			// Open file, do replaces and save.
			String data;
			TextFile::readFile(targetFile, data);

			data = data.replace_all("{extension_id}", extensionID.getString());
			data = data.replace_all("{extension_name}", extensionName);
			data = data.replace_all("{extension_description}", extensionDescription);
			data = data.replace_all("{extension_author}", extensionAuthor);
			UniqueID uniqueID = UniqueID::generate();
			data = data.replace_all("{unique_id}", uniqueID.getString());

			TextFile file;
			file.open(targetFile, TextFile::ofWrite);
			file.writeLine(data);
			file.close();
		}
	}

	String documentFile = utils::makeFilePath(extensionPath, OS_MANIFESTXML);
	if(document->writeFile(documentFile) == false)
	{
		Application::instance()->reportError("Error writing file '" + documentFile + "'", true);
		return;
	}

	OS_ASSERT(XMLManager::instance()->validateFile(documentFile, XMLSchema::fromFile(utils::makeFilePath(utils::makeFolderPath(Options::instance()->getSharePath(), OS_SCHEMAS_PATH), OS_EXTENSIONS_EXTENSION_SCHEMA))));

	if(m_pageFinish->getOpenFolder())
		Application::instance()->shell(extensionPath);

	Application::instance()->reloadExtensions();
}
Exemple #2
0
void SymbolData::writeNocashSym()
{
    if (nocashSymFileName.empty())
        return;

    std::vector<NocashSymEntry> entries;
    for (size_t k = 0; k < modules.size(); k++)
    {
        SymDataModule& module = modules[k];
        for (size_t i = 0; i < module.symbols.size(); i++)
        {
            SymDataSymbol& sym = module.symbols[i];

            NocashSymEntry entry;
            entry.address = sym.address;
            entry.text = sym.name;
            entries.push_back(entry);
        }

        for (size_t i = 0; i < module.data.size(); i++)
        {
            SymDataData& data = module.data[i];
            NocashSymEntry entry;
            entry.address = data.address;

            switch (data.type)
            {
            case Data8:
                entry.text = formatString(".byt:%04X",data.size);
                break;
            case Data16:
                entry.text = formatString(".wrd:%04X",data.size);
                break;
            case Data32:
                entry.text = formatString(".dbl:%04X",data.size);
                break;
            case DataAscii:
                entry.text = formatString(".asc:%04X",data.size);
                break;
            }

            entries.push_back(entry);
        }
    }

    std::sort(entries.begin(),entries.end());

    TextFile file;
    if (file.open(nocashSymFileName,TextFile::Write,TextFile::ASCII) == false)
    {
        Logger::printError(Logger::Error,L"Could not open sym file %s.",file.getFileName().c_str());
        return;
    }
    file.writeLine(L"00000000 0");

    for (size_t i = 0; i < entries.size(); i++)
    {
        file.writeFormat(L"%08X %S\n",entries[i].address,entries[i].text.c_str());
    }

    file.write("\x1A");
    file.close();
}