Esempio n. 1
0
unsigned long long TDEStorageDevice::deviceSize() {
	TQString bsnodename = systemPath();
	bsnodename.append("/queue/physical_block_size");
	TQFile bsfile( bsnodename );
	TQString blocksize;
	if ( bsfile.open( IO_ReadOnly ) ) {
		TQTextStream stream( &bsfile );
		blocksize = stream.readLine();
		bsfile.close();
	}
	else {
		// Drat, I can't get a guaranteed block size.  Assume a block size of 512, as everything I have read indicates that /sys/block/<dev>/size is given in terms of a 512 byte block...
		blocksize = "512";
	}

	TQString dsnodename = systemPath();
	dsnodename.append("/size");
	TQFile dsfile( dsnodename );
	TQString devicesize;
	if ( dsfile.open( IO_ReadOnly ) ) {
		TQTextStream stream( &dsfile );
		devicesize = stream.readLine();
		dsfile.close();
	}

	return ((unsigned long long)blocksize.toULong()*(unsigned long long)devicesize.toULong());
}
Esempio n. 2
0
/**
* Constructor 
*/
KttsFilterConf::KttsFilterConf( QWidget *parent, const char *name) : QWidget(parent, name){
    // kdDebug() << "KttsFilterConf::KttsFilterConf: Running" << endl;
    QString systemPath(getenv("PATH"));
    // kdDebug() << "Path is " << systemPath << endl;
    KGlobal::locale()->insertCatalogue("kttsd");
    m_path = QStringList::split(":", systemPath);
}
Esempio n. 3
0
TQString TDEStorageDevice::mountPath() {
	// See if this device node is mounted
	// This requires parsing /proc/mounts, looking for deviceNode()

	// The Device Mapper throws a monkey wrench into this
	// It likes to advertise mounts as /dev/mapper/<something>,
	// where <something> is listed in <system path>/dm/name

	// First, ensure that all device information (mainly holders/slaves) is accurate
	TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);

	TQString dmnodename = systemPath();
	dmnodename.append("/dm/name");
	TQFile namefile( dmnodename );
	TQString dmaltname;
	if ( namefile.open( IO_ReadOnly ) ) {
		TQTextStream stream( &namefile );
		dmaltname = stream.readLine();
		namefile.close();
	}
	if (!dmaltname.isNull()) {
		dmaltname.prepend("/dev/mapper/");
	}

	TQStringList lines;
	TQFile file( "/proc/mounts" );
	if ( file.open( IO_ReadOnly ) ) {
		TQTextStream stream( &file );
		TQString line;
		while ( !stream.atEnd() ) {
			line = stream.readLine();
			TQStringList mountInfo = TQStringList::split(" ", line, true);
			TQString testNode = *mountInfo.at(0);
			// Check for match
			if ((testNode == deviceNode()) || (testNode == dmaltname) || (testNode == ("/dev/disk/by-uuid/" + diskUUID()))) {
				TQString ret = *mountInfo.at(1);
				ret.replace("\\040", " ");
				return ret;
			}
			lines += line;
		}
		file.close();
	}

	// While this device is not directly mounted, it could concievably be mounted via the Device Mapper
	// If so, try to retrieve the mount path...
	TQStringList slaveDeviceList = holdingDevices();
	for ( TQStringList::Iterator slavedevit = slaveDeviceList.begin(); slavedevit != slaveDeviceList.end(); ++slavedevit ) {
		// Try to locate this device path in the TDE device tree
		TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
		TDEGenericDevice *hwdevice = hwdevices->findBySystemPath(*slavedevit);
		if ((hwdevice) && (hwdevice->type() == TDEGenericDeviceType::Disk)) {
			TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
			return sdevice->mountPath();
		}
	}

	return TQString::null;
}
	/*static*/
	HBITMAP Win32UIBinding::LoadPNGAsBitmap(std::string& path, int sizeX, int sizeY)
	{
		std::string systemPath(UTF8ToSystem(path));
		cairo_surface_t* pngSurface =
			cairo_image_surface_create_from_png(systemPath.c_str());
		
		cairo_t* pngcr = cairo_create(pngSurface);
		if (cairo_status(pngcr) != CAIRO_STATUS_SUCCESS)
			return 0;

		BITMAPINFO bitmapInfo;
		memset(&bitmapInfo, 0, sizeof(bitmapInfo));
		bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
		bitmapInfo.bmiHeader.biWidth = sizeX;
		bitmapInfo.bmiHeader.biHeight = -sizeY; // Bottom-up
		bitmapInfo.bmiHeader.biPlanes = 1;
		bitmapInfo.bmiHeader.biBitCount = 32;
		bitmapInfo.bmiHeader.biCompression = BI_RGB;
		bitmapInfo.bmiHeader.biSizeImage = 0;
		bitmapInfo.bmiHeader.biXPelsPerMeter = 1000;
		bitmapInfo.bmiHeader.biYPelsPerMeter = bitmapInfo.bmiHeader.biXPelsPerMeter;
		bitmapInfo.bmiHeader.biClrUsed = 0;
		bitmapInfo.bmiHeader.biClrImportant = 0;

		void* pixels = NULL;
		HDC hdc = ::GetDC(NULL);
		HBITMAP out = CreateDIBSection(hdc, &bitmapInfo,
			 DIB_RGB_COLORS, &pixels, NULL, 0);
		::ReleaseDC(NULL, hdc);

		BITMAP info;
		::GetObjectW(out, sizeof(info), &info);
		cairo_surface_t* outSurface = cairo_image_surface_create_for_data(
			(unsigned char*) pixels, CAIRO_FORMAT_ARGB32,
			sizeX, sizeY, info.bmWidthBytes);
		cairo_surface_t* scaledSurface = ScaleCairoSurface(pngSurface, sizeX, sizeY);

		cairo_t *cr = cairo_create(outSurface);

		cairo_save(cr);
		cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
		cairo_paint(cr);
		cairo_restore(cr);

		cairo_set_source_surface(cr, scaledSurface, 0, 0);
		cairo_rectangle(cr, 0, 0, sizeX, sizeY);
		cairo_fill(cr);

		cairo_destroy(cr);
		cairo_surface_destroy(outSurface);
		cairo_surface_destroy(scaledSurface);
		cairo_destroy(pngcr);
		cairo_surface_destroy(pngSurface);

		return out;
	}
Esempio n. 5
0
void GameCore::ParseXMLDoc(UString XMLFilename)
{
	TRACE_FN_ARGS1("XMLFilename", XMLFilename);
	tinyxml2::XMLDocument doc;
	tinyxml2::XMLElement *node;
	auto file = fw().data->fs.open(XMLFilename);
	if (!file)
	{
		LogError("Failed to open XML file \"%s\"", XMLFilename.c_str());
	}

	LogInfo("Loading XML file \"%s\" - found at \"%s\"", XMLFilename.c_str(),
	        file.systemPath().c_str());

	auto xmlText = file.readAll();
	if (!xmlText)
	{
		LogError("Failed to read in XML file \"%s\"", XMLFilename.c_str());
	}

	auto err = doc.Parse(xmlText.get(), file.size());

	if (err != tinyxml2::XML_SUCCESS)
	{
		LogError("Failed to parse XML file \"%s\" - \"%s\" \"%s\"", XMLFilename.c_str(),
		         doc.GetErrorStr1(), doc.GetErrorStr2());
		return;
	}

	node = doc.RootElement();

	if (!node)
	{
		LogError("Failed to parse XML file \"%s\" - no root element", XMLFilename.c_str());
		return;
	}

	UString nodename = node->Name();

	if (nodename == "openapoc")
	{
		for (node = node->FirstChildElement(); node != nullptr; node = node->NextSiblingElement())
		{
			ApplyAliases(node);
			nodename = node->Name();
			if (nodename == "game")
			{
				ParseGameXML(node);
			}
			else if (nodename == "form")
			{
				ParseFormXML(node);
			}
			else if (nodename == "apocfont")
			{
				UString fontName = node->Attribute("name");
				if (fontName == "")
				{
					LogError("apocfont element with no name");
					continue;
				}
				auto font = ApocalypseFont::loadFont(node);
				if (!font)
				{
					LogError("apocfont element \"%s\" failed to load", fontName.c_str());
					continue;
				}

				if (this->fonts.find(fontName) != this->fonts.end())
				{
					LogError("multiple fonts with name \"%s\"", fontName.c_str());
					continue;
				}
				this->fonts[fontName] = font;
			}
			else if (nodename == "alias")
			{
				aliases[UString(node->Attribute("id"))] = UString(node->GetText());
			}
			else if (nodename == "ufopaedia")
			{
				tinyxml2::XMLElement *nodeufo;
				for (nodeufo = node->FirstChildElement(); nodeufo != nullptr;
				     nodeufo = nodeufo->NextSiblingElement())
				{
					nodename = nodeufo->Name();
					if (nodename == "category")
					{
						Ufopaedia::UfopaediaDB.push_back(mksp<UfopaediaCategory>(nodeufo));
					}
				}
			}
			else
			{
				LogError("Unknown XML element \"%s\"", nodename.c_str());
			}
		}
	}
}
Esempio n. 6
0
void GameCore::ParseXMLDoc(UString XMLFilename)
{
	tinyxml2::XMLDocument doc;
	tinyxml2::XMLElement *node;
	UString systemPath;
	{
		auto file = fw.data->load_file(XMLFilename);
		if (!file)
		{
			LogError("Failed to open XML file \"%s\"", XMLFilename.c_str());
		}
		systemPath = file.systemPath();
	}

	if (systemPath == "")
	{
		LogError("Failed to read XML file \"%s\"", XMLFilename.c_str());
		return;
	}
	LogInfo("Loading XML file \"%s\" - found at \"%s\"", XMLFilename.c_str(), systemPath.c_str());

	doc.LoadFile(systemPath.c_str());
	node = doc.RootElement();

	if (!node)
	{
		LogError("Failed to parse XML file \"%s\"", systemPath.c_str());
		return;
	}

	UString nodename = node->Name();

	if (nodename == "openapoc")
	{
		for (node = node->FirstChildElement(); node != nullptr; node = node->NextSiblingElement())
		{
			ApplyAliases(node);
			nodename = node->Name();
			if (nodename == "game")
			{
				ParseGameXML(node);
			}
			else if (nodename == "string")
			{
				ParseStringXML(node);
			}
			else if (nodename == "form")
			{
				ParseFormXML(node);
			}
			else if (nodename == "apocfont")
			{
				UString fontName = node->Attribute("name");
				if (fontName == "")
				{
					LogError("apocfont element with no name");
					continue;
				}
				auto font = ApocalypseFont::loadFont(fw, node);
				if (!font)
				{
					LogError("apocfont element \"%s\" failed to load", fontName.c_str());
					continue;
				}

				if (this->fonts.find(fontName) != this->fonts.end())
				{
					LogError("multiple fonts with name \"%s\"", fontName.c_str());
					continue;
				}
				this->fonts[fontName] = font;
			}
			else if (nodename == "language")
			{
				supportedlanguages[node->Attribute("id")] = node->GetText();
			}
			else if (nodename == "alias")
			{
				aliases[UString(node->Attribute("id"))] = UString(node->GetText());
			}
			else if (nodename == "ufopaedia")
			{
				tinyxml2::XMLElement *nodeufo;
				for (nodeufo = node->FirstChildElement(); nodeufo != nullptr;
				     nodeufo = nodeufo->NextSiblingElement())
				{
					nodename = nodeufo->Name();
					if (nodename == "category")
					{
						Ufopaedia::UfopaediaDB.push_back(
						    std::make_shared<UfopaediaCategory>(fw, nodeufo));
					}
				}
			}
			else
			{
				LogError("Unknown XML element \"%s\"", nodename.c_str());
			}
		}
	}
}