示例#1
0
// Sets an option
void Installer::setOption(const std::string& name,
                          const std::string& value)
{
    BOOST_ASSERT(name.empty() == false);
    BOOST_ASSERT(value.empty() == false);

    // before set any new config file option
    // reread config file
    m_factory->getConfig()->load();

    // look for the option
    OptionList options = m_factory->getConfig()->getOptions();
    OptionList::iterator i = std::find_if(
        options.begin(), options.end(),
        boost::bind(
            std::equal_to<std::string>(),
            name,
            boost::bind(&IOption::getName, _1)));
    if (i == options.end())
    {
        throw Exception(__FILE__, __LINE__,
                        "Cannot find option with name: " + name);
    }

    (*i)->setValue(value);

    // save result
    m_factory->getConfig()->save();

}
示例#2
0
	//------------------------------------------------------------------------
	void OptimiseTool::doInvoke(const OptionList& toolOptions,
		const Ogre::StringVector& inFileNames, const Ogre::StringVector& outFileNamesArg)
	{
		// Name count has to match, else we have no way to figure out how to apply output
		// names to input files.
		if (!(outFileNamesArg.empty() || inFileNames.size() == outFileNamesArg.size()))
		{
			fail("number of output files must match number of input files.");
		}

		mPosTolerance = mNormTolerance = mUVTolerance = 1e-06f;
		mKeepIdentityTracks = OptionsUtil::isOptionSet(toolOptions, "keep-identity-tracks");
		for (OptionList::const_iterator it = toolOptions.begin(); it != toolOptions.end(); ++it)
		{
			if (it->first == "tolerance")
			{
				mPosTolerance = mNormTolerance = mUVTolerance = static_cast<float>(any_cast<Real>(it->second));
			}
			else if (it->first == "pos_tolerance")
			{
				mPosTolerance = static_cast<float>(any_cast<Real>(it->second));
			}
			else if (it->first == "norm_tolerance")
			{
				mNormTolerance = static_cast<float>(any_cast<Real>(it->second));
			}
			else if (it->first == "uv_tolerance")
			{
				mUVTolerance = static_cast<float>(any_cast<Real>(it->second));
			}
		}


		StringVector outFileNames = outFileNamesArg.empty() ? inFileNames : outFileNamesArg;

		// Process the meshes
		for (size_t i = 0, end = inFileNames.size(); i < end; ++i)
		{
			if (StringUtil::endsWith(inFileNames[i], ".mesh", true))
			{
				processMeshFile(inFileNames[i], outFileNames[i]);
			}
			else if (StringUtil::endsWith(inFileNames[i], ".skeleton", true))
			{
				processSkeletonFile(inFileNames[i], outFileNames[i]);
			}
			else
			{
				warn("unrecognised name ending for file " + inFileNames[i]);
				warn("file skipped.");
			}
		}
	}
示例#3
0
文件: main.cpp 项目: t0suj4/minetest
static void print_allowed_options(const OptionList &allowed_options)
{
	for (OptionList::const_iterator i = allowed_options.begin();
			i != allowed_options.end(); ++i) {
		std::ostringstream os1(std::ios::binary);
		os1 << "  --" << i->first;
		if (i->second.type != VALUETYPE_FLAG)
			os1 << _(" <value>");

		dstream << padStringRight(os1.str(), 24);

		if (i->second.help != NULL)
			dstream << i->second.help;

		dstream << std::endl;
	}
}
示例#4
0
// Processes interactive option
void Installer::processInteractive()
{
    // process all options
    IConfig* config = m_factory->getConfig();
    // before set any new config file option
    // reread config file
    config->load();

    // look for the option
    OptionList options = config->getOptions();
    for (OptionList::iterator i = options.begin();
         i != options.end(); i++)
    {
        const std::string name = (*i)->getName();
        const std::string oldval = (*i)->getValue();

        std::cout << "Option '" << name << "' has the following value: "
                  << oldval << std::endl;

        if (ask("Do you want to change it [N/y]: "))
        {
            std::string value = get("New value: ");
            setOption((*i)->getName(), value);
        }
    }

    if (ask("Do you want to recreate DB [N/y]: "))
    {
        recreateDB();
    }

    // resources detection
    if (ask("Do you want to detect resources [N/y]: "))
    {
        detectResources();
    }
}
示例#5
0
int main(int argc, const char** argv)
{
    if (argc < 2)
    {
        printHelp();
        return -1;
    }

    ToolManager manager;
    manager.registerToolFactory(new TransformToolFactory());
    manager.registerToolFactory(new InfoToolFactory());
    manager.registerToolFactory(new MeshMergeToolFactory());
    manager.registerToolFactory(new RenameToolFactory());
	manager.registerToolFactory(new OptimiseToolFactory());

    OgreEnvironment* ogreEnv = new OgreEnvironment();
	ogreEnv->initialize();

    CommandLine cmdLine = parseCommandLine(argc, argv);

    // Define allowed global arguments
    OptionDefinitionSet globalOptionDefs = OptionDefinitionSet();
    globalOptionDefs.insert(OptionDefinition("help", OT_STRING, false, false, Any(String())));
    globalOptionDefs.insert(OptionDefinition("list"));
    globalOptionDefs.insert(OptionDefinition("no-follow-skeleton"));
    globalOptionDefs.insert(OptionDefinition("version"));
    globalOptionDefs.insert(OptionDefinition("quiet"));
    globalOptionDefs.insert(OptionDefinition("verbose"));

	OptionList globalOptions;
	try
	{
        globalOptions = OptionsParser::parseOptions(
            cmdLine.globalArgc, cmdLine.globalArgv, globalOptionDefs);
	}
    catch (std::exception& se)
    {
		std::cout << "Parsing global options failed:" << std::endl;
        std::cout << se.what() << std::endl;
        return -1;
    }
    catch (...)
    {
		std::cout << "Parsing global options failed." << std::endl;
        return -1;
    }

    // Evaluate global options (as far as they are of interest here...)
    for (OptionList::const_iterator it = globalOptions.begin(); it != globalOptions.end(); ++it)
    {
        if (it->first == "version")
        {
			std::cout << "MeshMagick version "
                << MESHMAGICK_VERSION_MAJOR << "."
                << MESHMAGICK_VERSION_MINOR << "."
                << MESHMAGICK_VERSION_PATCH << std::endl;
			std::cout << "using Ogre version "
                << OGRE_VERSION_MAJOR << "."
                << OGRE_VERSION_MINOR << "."
                << OGRE_VERSION_PATCH
                << " (" << OGRE_VERSION_NAME ")"
                << std::endl;
            return 0;
        }
        else if (it->first == "help")
        {
            String toolName = any_cast<String>(it->second);
            if (!toolName.empty())
            {
                // toolhelp
				try
				{
	                manager.printToolHelp(toolName, std::cout);
				}
				catch (std::exception& se)
				{
					std::cout << se.what() << std::endl << std::endl;
					// global help
					printHelp();
				}
                return 0;
            }
            else
            {
                // global help
                printHelp();
                return 0;
            }
        }
        else if (it->first == "list")
        {
            manager.printToolList(std::cout);
            return 0;
        }
    }

    if (cmdLine.toolName.empty())
    {
        std::cout << "No tool given." << std::endl << "call \""
            << argv[0] << "\" -h for help" << std::endl;
        return -1;
    }

    // create and invoke tool
    try
    {
        manager.invokeTool(cmdLine.toolName, globalOptions, cmdLine.toolArgc, cmdLine.toolArgv,
            cmdLine.inFileNames, cmdLine.outFileNames);
    }
    catch (std::exception& se)
    {
        std::cout << "Invocation of tool " << cmdLine.toolName << " failed:" << std::endl;
        std::cout << se.what() << std::endl;
        return -1;
    }
    catch (...)
    {
        std::cout << "Invocation of tool " << cmdLine.toolName << " failed." << std::endl;
        return -1;
    }

    return 0;
}