Exemplo n.º 1
0
	Image* loadLibrary(const char* path) {
		bool al;
		Image* im;
		
		im = loadLibraryEx(path, &al);
		
		return im;
	}
Exemplo n.º 2
0
// ----------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
	ctkCommandLineParser commandLine;
	commandLine.setArgumentPrefix("--", "-");

	commandLine.beginGroup(QString("Option"));
	commandLine.addArgument("help", "h", QVariant::Bool,
		"Display available command line arguments.");
	commandLine.addArgument("list-resources", "l", QVariant::String,
		"List all resources of an executable or library.");
	commandLine.addArgument("add-resource-bitmap", "", QVariant::StringList,
		"Add resource using the provided <path/to/exec/or/lib> <resourceName> and <path/to/resource>");
	commandLine.addArgument("update-resource-ico", "", QVariant::StringList,
		"Add resource using the provided <path/to/exec/or/lib> <resourceName> and <path/to/resource>");
	commandLine.addArgument("delete-resource", "", QVariant::StringList,
		"Delete resource using the provided <path/to/exec/or/lib> <resourceType> <resourceName>");
	commandLine.endGroup();

	bool ok;
	QHash<QString, QVariant> parsedArgs = commandLine.parseArguments(argc, argv, &ok);
	if (!ok)
		{
		QTextStream(stdout, QIODevice::WriteOnly) << "Error parsing arguments : " << commandLine.errorString() << "\n";
		return EXIT_FAILURE;
		}

	if(parsedArgs.contains("help") || parsedArgs.contains("h"))
		{
		QTextStream(stdout, QIODevice::WriteOnly) << commandLine.helpText() << "\n";
		return EXIT_SUCCESS;
		}

	char* exePath;
	HMODULE hExe;       // handle to existing .EXE file

	if(parsedArgs.contains("list-resources") || parsedArgs.contains("l"))
		{
		// Load the .EXE file that contains the dialog box you want to copy.
		exePath =
			(char*) malloc(strlen(parsedArgs.value("list-resources").toString().toStdString().c_str()) * sizeof(char));
		strcpy(exePath, parsedArgs.value("list-resources").toString().toStdString().c_str());
		hExe = loadLibraryEx(TEXT(exePath), NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE);

		// List all resources
		EnumResourceTypes(hExe, (ENUMRESTYPEPROC)EnumTypesFunc, 0);

		for (int i = 0; i < resources::Resources.size() ; ++i)
			{
			QTextStream(stdout, QIODevice::WriteOnly) << "Type : " << resources::Resources.at(i).Type <<  " -- " << resources::types[resources::Resources.at(i).Type.toInt()] << "\n";
			QTextStream(stdout, QIODevice::WriteOnly) << "\tName : " << resources::Resources.at(i).Name << "\n";
			QTextStream(stdout, QIODevice::WriteOnly) << "\t\tLang : " << resources::Resources.at(i).Lang << "\n";
			}

		// Clean up.
		if (!FreeLibrary(hExe))
			{
			QTextStream(stdout, QIODevice::WriteOnly) << "Could not free executable : " << exePath << "\n";
			return EXIT_FAILURE;
			}
		}

	else if(parsedArgs.contains("delete-resource"))
		{
		QStringList arguments = parsedArgs.value("delete-resource").toStringList();
		exePath = (char*) malloc(strlen(arguments.at(0).toStdString().c_str()) * sizeof(char));
		strcpy(exePath, arguments.at(0).toStdString().c_str());
		hExe = loadLibraryEx(TEXT(exePath), NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE);

		// List all resources
		EnumResourceTypes(hExe, (ENUMRESTYPEPROC)EnumTypesFunc, 0);
		FreeLibrary(hExe);

		bool resultat = removeResource(arguments.at(0), arguments.at(1), arguments.at(2));
		if(!resultat)
			{
			return EXIT_FAILURE;
			}
		}

	else if(parsedArgs.contains("add-resource-bitmap"))
		{
		QStringList arguments = parsedArgs.value("add-resource-bitmap").toStringList();

		bool result = addResourceBITMAP(arguments.at(0), arguments.at(1), arguments.at(2));
		if(!result)
			{
			QTextStream(stdout, QIODevice::WriteOnly) << "Resource bitmap couldn't be added.\n";
			return EXIT_FAILURE;
			}
		QTextStream(stdout, QIODevice::WriteOnly) << "Resource bitmap added.\n";
		return EXIT_SUCCESS;
		}

	else if(parsedArgs.contains("update-resource-ico"))
		{
		QStringList arguments = parsedArgs.value("update-resource-ico").toStringList();

		bool result = updateResourceICO(arguments.at(0), arguments.at(1), arguments.at(2));
		if(!result)
			{
			QTextStream(stdout, QIODevice::WriteOnly) << "Resource ico couldn't be updated.\n";
			return EXIT_FAILURE;
			}
		QTextStream(stdout, QIODevice::WriteOnly) << "Resource ico updated.\n";
		return EXIT_SUCCESS;
		}

  return EXIT_SUCCESS;
}