bool LockDirectory(char* directory, LockTypes type)
{
	dirlockdebug("DirLocking: Locking directory '%s' for %ss.\n", directory, LockTypesToString[(unsigned int)type]);
	// A different directory is already locked, since we will no longer need to hang on to that directory, we'll just Unlock it.
	if(locks.find(type) != locks.end()) 
	{
		dirlockdebug("DirLocking: Found existing lock when locking directory for %s\n.", LockTypesToString[(unsigned int)type]);
		UnlockDirectory(type);
	}

	char name[MAX_PATH+1];
	strcpy(name, directory);
	strcat(name, "hourglass.lock\0");
	// FILE_FLAG_DELETE_ON_CLOSE is really handy here as it means we don't have to manage the deletion process for the lock-files ourselves.
	HANDLE rv = CreateFile(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, (FILE_ATTRIBUTE_HIDDEN | FILE_FLAG_DELETE_ON_CLOSE), NULL);
	if(rv == INVALID_HANDLE_VALUE)
	{
		DirLockPrintLastError("DirLocking: CreateFile", GetLastError());
		// Locking directory failed, issue an error-message and stop.
		char str[1024];
		sprintf(str, "Locking the directory '%s' for %ss failed\nPlease make sure that Hourglass has rights to create files in this directory or choose another directory", directory, LockTypesToString[(unsigned int)type]);
		CustomMessageBox(str, "Error!", (MB_OK | MB_ICONERROR));
		return false;
	}
	locks[type] = rv;
	return true; // Locking directory succeeded
}
Beispiel #2
0
void MediumModeWindow::checkTableAvailable()
{
    if(!DataFileMgr::hasNoErrorTrue("Multifacile.xml", "MediumMode", _multiple))
    {
        _chronometre->stop();
        CustomMessageBox(CannotDoThisTable, this, _multiple).exec();
        emit wasClosed();
    }
}
// MAIN ENTRY
BOOL __stdcall DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
{
	(void)lpvReserved;
	(void)hinstDll;

	//Read the config file
	g_reader = new configReader;

	switch (fdwReason)
	{
	case DLL_PROCESS_ATTACH:
		DisableThreadLibraryCalls(hOriginalDll);

		// Splash Screen enabled?
		if (g_reader->GetEnableSplashScreen())
		{
			char info[255];
			sprintf_s(info, "OpenGL3DVision Wrapper v.%s", OGL3DVISION_VERSION_STR);
			// SDK Message box
			CustomMessageBox(NULL, _T("  \t\t\t\t\t\t               \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"),
				_T(info), MB_OK);
		}
		// Init the wrapper
		LoadFPSInject();
		Init();
		break;

	case DLL_PROCESS_DETACH:
		if (hOriginalDll != NULL)
		{
			// Stop the threads
			StopResizeThread();
			StoptNVAPIThread();
			Sleep(500);

			NV3DVisionBuffers_destroy(gl_d3d_buffers);
			add_log("\nDisabling 3D Vision... Cleaning up and freeing the resources...");
			// Removing the FPS inject
			if (FPSDestroy)
			{
				(FPSDestroy)(m_FPSInjector);
			}
			FreeLibrary(FPSHandle);
			add_log("Application closed successfully !\nEND\n");
			// The the openGL32.dll lib
			FreeLibrary(hOriginalDll);
			hOriginalDll = NULL;
			
		}
		break;
	}
	return TRUE;
}
void DlgffDPjrProperties::ExportThumb() {
    QString OutputFileName=QFileInfo(ffdProject->ProjectFileName).absolutePath();
    if (!OutputFileName.endsWith(QDir::separator())) OutputFileName=OutputFileName+QDir::separator();
    OutputFileName=OutputFileName+"folder.jpg";
    QString Filter="JPG (*.jpg)";
    OutputFileName=QFileDialog::getSaveFileName(this,QApplication::translate("MainWindow","Select destination file"),OutputFileName,"JPG (*.jpg)",&Filter);
    if (OutputFileName!="") {
        int Index=ApplicationConfig->ThumbnailModels->SearchModel(ffdProject->ThumbnailName);
        if (Index>=0) {
            QSize  ForcedThumbnailSize(THUMBWITH,THUMBHEIGHT);
            QImage Image=ApplicationConfig->ThumbnailModels->List[Index]->PrepareImage(0,ffdProject,ffdProject->ProjectThumbnail,&ForcedThumbnailSize);
            if (Image.save(OutputFileName,0,100))
                CustomMessageBox(this,QMessageBox::Information,QApplication::translate("DlgffDPjrProperties","Export thumbnail"),
                                 QApplication::translate("DlgffDPjrProperties","Thumbnail successfully exported","Information message"),QMessageBox::Close);
        }
    }
}
bool DlgFileExplorer::DoAccept() {
    QList<cBaseMediaFile*> MediaList;
    ui->Browser->GetCurrentSelectedMediaFile(&MediaList);
    bool HaveFolder=false;
    bool Ret=true;
    for (int i=0;i<MediaList.count();i++) if (MediaList[i]->ObjectType==OBJECTTYPE_FOLDER) HaveFolder=true;
    if (MediaList.count()==0) Ret=false; else if (HaveFolder) {
        if (MediaList.count()==1) {
            ui->Browser->OpenFolder();
            Ret=false;
        } else {
            CustomMessageBox(this,QMessageBox::Information,windowTitle(),QApplication::translate("wgt_QMultimediaBrowser","The selection can't include folders."),QMessageBox::Ok,QMessageBox::Ok);
            Ret=false;
        }
    }
    while (!MediaList.isEmpty()) delete MediaList.takeLast();
    return Ret;
}
DWORD WINAPI InjectDLLThreadFunc(LPVOID lpParam) 
{
	InjectDLLThreadFuncInfo* info = (InjectDLLThreadFuncInfo*)lpParam;
	HANDLE hProcess = info->hInjectProcess;
	DWORD dwInjectProcessID = info->dwInjectProcessID;
	HANDLE hInjectThread = info->hInjectThread;
	DWORD dwInjectThreadID = info->dwInjectThreadID;
	TCHAR* dllPath = info->injectDllPath;
	bool runDllLast = info->runDllLast;
	DWORD dwThread = 0;
	size_t dwPathLength = 1024;
	StringCchLength(dllPath, dwPathLength, &dwPathLength);

	dwPathLength *= sizeof(WCHAR);

	if (hProcess == NULL)
	{
		PrintLastError("CreateProcess", GetLastError());
		terminateRequest = true;
	}


	// modify the IDT (import directory table) (though the IAT is more commonly referred to)
	// so that Windows thinks the game needs to load our DLL first
	bool injected = InjectDLLIntoIDT(dwInjectProcessID, hProcess, hInjectThread, dllPath, !runDllLast);

	if(injected)
	{
		debugprintf("Injecting \"%s\" by IAT (method %d) apparently succeeded.\n", dllPath, runDllLast?2:1);
		info->injectIsAsyncReady = TRUE;
		goto done;
	} 

	DWORD exitCode = 0;

	if(exitCode == 0)
	{
		terminateRequest = true;
		if(hProcess != NULL)
		{
			debugprintf("Injection failed...\n");
			CustomMessageBox("Injection failed...\nYou can (hopefully) find more information in the debug log .txt file.", "Error", MB_OK | MB_ICONERROR);
		}
		else
		{
			CustomMessageBox("The game could not be launched...\nYou can (hopefully) find more information in the debug log .txt file.", "Error", MB_OK | MB_ICONERROR);
		}
	}
	else // Why is this here??
	{
		debugprintf("Injection probably succeeded (0x%X)...\n", exitCode);
	}

done:
	while(!info->injectAllowedToFinish)
	{
		Sleep(5);
	}
	delete info;

	return 0;
}