Ejemplo n.º 1
0
int Resource::data(lua_State * L) // const : const uchar
{
	QResource* lhs = ValueInstaller2<QResource>::check( L, 1 );
	Util::push( L, lhs->data() );
	return 1; 
}
Ejemplo n.º 2
0
void InitializationThread::initTranslations(void)
{
	//Search for language files
	const QDir qmDirectory(":/localization");
	const QStringList qmFiles = qmDirectory.entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name);

	//Make sure we found at least one translation
	if(qmFiles.count() < 1)
	{
		qFatal("Could not find any translation files!");
		return;
	}

	//Initialize variables
	const QString langResTemplate(":/localization/%1.txt");
	QRegExp langIdExp("^LameXP_(\\w\\w)\\.qm$", Qt::CaseInsensitive);

	//Add all available translations
	for(QStringList::ConstIterator iter = qmFiles.constBegin(); iter != qmFiles.constEnd(); iter++)
	{
		const QString langFile = qmDirectory.absoluteFilePath(*iter);
		QString langId, langName;
		unsigned int systemId = 0, country = 0;
		
		if(QFileInfo(langFile).isFile() && (langIdExp.indexIn(*iter) >= 0))
		{
			langId = langIdExp.cap(1).toLower();
			QResource langRes = QResource(langResTemplate.arg(*iter));
			if(langRes.isValid() && langRes.size() > 0)
			{
				QByteArray data = QByteArray::fromRawData(reinterpret_cast<const char*>(langRes.data()), langRes.size());
				QTextStream stream(&data, QIODevice::ReadOnly);
				stream.setAutoDetectUnicode(false); stream.setCodec("UTF-8");

				while(!(stream.atEnd() || (stream.status() != QTextStream::Ok)))
				{
					QStringList langInfo = stream.readLine().simplified().split(",", QString::SkipEmptyParts);
					if(langInfo.count() >= 3)
					{
						systemId = langInfo.at(0).trimmed().toUInt();
						country  = langInfo.at(1).trimmed().toUInt();
						langName = langInfo.at(2).trimmed();
						break;
					}
				}
			}
		}

		if(!(langId.isEmpty() || langName.isEmpty() || (systemId == 0)))
		{
			if(MUtils::Translation::insert(langId, langFile, langName, systemId, country))
			{
				qDebug("Registering translation: %s = %s (%u) [%u]", MUTILS_UTF8(*iter), MUTILS_UTF8(langName), systemId, country);
			}
			else
			{
				qWarning("Failed to register: %s", langFile.toLatin1().constData());
			}
		}
	}

	qDebug("All registered.\n");
}
Ejemplo n.º 3
0
statswinimpl::statswinimpl(Hero *h) 
: QWidget(0,0)
{
	setupUi(this);
	hero = h;
	hwin = new herowinimpl(hero);
	diary = new diarywinimpl();
	
	stayontopToggle(false);
	connect(hero, SIGNAL(done(QString)), this, SLOT(loginDone(QString)));
	
	//трей

#ifdef Q_WS_WIN
        QResource res = QResource("bin/icon.bmp");
#else
        QResource res = QResource("src/icon_128.png");
#endif
	QPixmap pix;
        pix.loadFromData(res.data(), res.size());
	QIcon ico = QIcon(pix);
	tray = new QSystemTrayIcon(ico);
	tray->setVisible(true);
	connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
	
	//меню
	QMenu *menu = new QMenu();
	QAction *hideshow = menu->addAction(tr("Скрыть/Показать"));
	connect(hideshow, SIGNAL(triggered()), this, SLOT(hideshow()));
	menu->addSeparator();
	showmess = menu->addAction(tr("Показывать сообщения"));
	showmess->setCheckable(true);
	showmess->setChecked(true);
	QAction *stayontop = menu->addAction(tr("Поверх всех окон"));
	stayontop->setCheckable(true);
	stayontop->setChecked(false);
	connect(stayontop, SIGNAL(toggled(bool)), this, SLOT(stayontopToggle(bool)));
	menu->addSeparator();
	
	QAction *herotrbt = menu->addAction(tr("Герой"));
	connect(herotrbt, SIGNAL(triggered()), this, SLOT(on_btInfo_pressed()));
	QAction *diarytrbt = menu->addAction(tr("Дневник"));
	connect(diarytrbt, SIGNAL(triggered()), this, SLOT(on_btDiary_pressed()));
	menu->addSeparator();

        settingsDialog = new Dialog(this);
        connect(settingsDialog,SIGNAL(accepted()),this,SLOT(updateSettings()));
        QAction *settingstrbt = menu->addAction(tr("Настройки"));
        connect(settingstrbt,SIGNAL(triggered()),this,SLOT(settings()));
        menu->addSeparator();
        //settingstrbt->setEnabled(false);
	
	QAction *exit = menu->addAction(tr("Выход"));
	connect(exit, SIGNAL(triggered()), qApp, SLOT(quit()));
	connect(exit, SIGNAL(triggered()), tray, SLOT(hide()));
	
	tray->setContextMenu(menu);
	
	//таймер
	timer = new QTimer(this);
	timer->start(15000);
	connect(timer, SIGNAL(timeout()), this, SLOT(update()));
	
        mess = new HeroMessager();

        QSettings settings("godville.net", "godvilleQT");
        restoreGeometry(settings.value("statWinGeometry").toByteArray());
        this->setWindowOpacity(settings.value("statWinOp",100).toInt()/100);
}
Ejemplo n.º 4
0
double InitializationThread::doInit(const size_t threadCount)
{
	m_bSuccess = false;
	delay();

	//CPU type selection
	unsigned int cpuSupport = 0;
	if((m_cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE) && (m_cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE2) && m_cpuFeatures.intel)
	{
		cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_SSE : CPU_TYPE_X86_SSE;
	}
	else
	{
		cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_GEN : CPU_TYPE_X86_GEN;
	}

	//Hack to disable x64 on Wine, as x64 binaries won't run under Wine (tested with Wine 1.4 under Ubuntu 12.04 x64)
	if(cpuSupport & CPU_TYPE_X64_ALL)
	{
		if(MUtils::OS::running_on_wine())
		{
			qWarning("Running under Wine on a 64-Bit system. Going to disable all x64 support!\n");
			cpuSupport = (cpuSupport == CPU_TYPE_X64_SSE) ? CPU_TYPE_X86_SSE : CPU_TYPE_X86_GEN;
		}
	}

	//Print selected CPU type
	switch(cpuSupport)
	{
		PRINT_CPU_TYPE(CPU_TYPE_X86_GEN); break;
		PRINT_CPU_TYPE(CPU_TYPE_X86_SSE); break;
		PRINT_CPU_TYPE(CPU_TYPE_X64_GEN); break;
		PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break;
		default: MUTILS_THROW("CPU support undefined!");
	}

	//Allocate queues
	QQueue<QString> queueToolName;
	QQueue<QString> queueChecksum;
	QQueue<QString> queueVersInfo;
	QQueue<unsigned int> queueVersions;
	QQueue<unsigned int> queueCpuTypes;

	//Init properties
	for(int i = 0; true; i++)
	{
		if(!(g_lamexp_tools[i].pcName || g_lamexp_tools[i].pcHash  || g_lamexp_tools[i].uiVersion))
		{
			break;
		}
		else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion)
		{
			queueToolName.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcName));
			queueChecksum.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcHash));
			queueVersInfo.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcVersTag));
			queueCpuTypes.enqueue(g_lamexp_tools[i].uiCpuType);
			queueVersions.enqueue(g_lamexp_tools[i].uiVersion);
		}
		else
		{
			qFatal("Inconsistent checksum data detected. Take care!");
		}
	}

	QDir appDir = QDir(QCoreApplication::applicationDirPath()).canonicalPath();

	QScopedPointer<QThreadPool> pool(new QThreadPool());
	pool->setMaxThreadCount((threadCount > 0) ? threadCount : qBound(2U, cores2threads(m_cpuFeatures.count), EXPECTED_TOOL_COUNT));
	/* qWarning("Using %u threads for extraction.", pool->maxThreadCount()); */

	LockedFile::selfTest();
	ExtractorTask::clearFlags();

	//Start the timer
	QElapsedTimer timeExtractStart;
	timeExtractStart.start();
	
	//Extract all files
	while(!(queueToolName.isEmpty() || queueChecksum.isEmpty() || queueVersInfo.isEmpty() || queueCpuTypes.isEmpty() || queueVersions.isEmpty()))
	{
		const QString toolName = queueToolName.dequeue();
		const QString checksum = queueChecksum.dequeue();
		const QString versInfo = queueVersInfo.dequeue();
		const unsigned int cpuType = queueCpuTypes.dequeue();
		const unsigned int version = queueVersions.dequeue();
			
		const QByteArray toolHash(checksum.toLatin1());
		if(toolHash.size() != 96)
		{
			qFatal("The checksum for \"%s\" has an invalid size!", MUTILS_UTF8(toolName));
			return -1.0;
		}
			
		QResource *resource = new QResource(QString(":/tools/%1").arg(toolName));
		if(!(resource->isValid() && resource->data()))
		{
			MUTILS_DELETE(resource);
			qFatal("The resource for \"%s\" could not be found!", MUTILS_UTF8(toolName));
			return -1.0;
		}
			
		if(cpuType & cpuSupport)
		{
			pool->start(new ExtractorTask(resource, appDir, toolName, toolHash, version, versInfo));
			continue;
		}

		MUTILS_DELETE(resource);
	}

	//Sanity Check
	if(!(queueToolName.isEmpty() && queueChecksum.isEmpty() && queueVersInfo.isEmpty() && queueCpuTypes.isEmpty() && queueVersions.isEmpty()))
	{
		qFatal("Checksum queues *not* empty fater verification completed. Take care!");
	}

	//Wait for extrator threads to finish
	pool->waitForDone();

	//Performance measure
	const double delayExtract = double(timeExtractStart.elapsed()) / 1000.0;
	timeExtractStart.invalidate();

	//Make sure all files were extracted correctly
	if(ExtractorTask::getExcept())
	{
		char errorMsg[BUFF_SIZE];
		if(ExtractorTask::getErrMsg(errorMsg, BUFF_SIZE))
		{
			qFatal("At least one of the required tools could not be initialized:\n%s", errorMsg);
			return -1.0;
		}
		qFatal("At least one of the required tools could not be initialized!");
		return -1.0;
	}

	qDebug("All extracted.\n");

	//Using any custom tools?
	if(ExtractorTask::getCustom())
	{
		qWarning("Warning: Using custom tools, you might encounter unexpected problems!\n");
	}

	//Check delay
	if(delayExtract > g_allowedExtractDelay)
	{
		m_slowIndicator = true;
		qWarning("Extracting tools took %.3f seconds -> probably slow realtime virus scanner.", delayExtract);
		qWarning("Please report performance problems to your anti-virus developer !!!\n");
	}
	else
	{
		qDebug("Extracting the tools took %.3f seconds (OK).\n", delayExtract);
	}

	//Register all translations
	initTranslations();

	//Look for AAC encoders
	InitAacEncTask::clearFlags();
	for(size_t i = 0; g_lamexp_aacenc[i].toolName; i++)
	{
		pool->start(new InitAacEncTask(&(g_lamexp_aacenc[i])));
	}
	pool->waitForDone();

	//Make sure initialization finished correctly
	if(InitAacEncTask::getExcept())
	{
		char errorMsg[BUFF_SIZE];
		if(InitAacEncTask::getErrMsg(errorMsg, BUFF_SIZE))
		{
			qFatal("At least one optional component failed to initialize:\n%s", errorMsg);
			return -1.0;
		}
		qFatal("At least one optional component failed to initialize!");
		return -1.0;
	}

	m_bSuccess = true;
	delay();

	return delayExtract;
}