Esempio n. 1
0
void CDefaultTerminal::PreCreateThread()
{
	// Write to [HKCU\Software\Microsoft\Windows\CurrentVersion\Run]
	CheckRegisterOsStartup();

	// Write to [HKCU\Software\ConEmu]
	m_Opt.Serialize(true);
}
Esempio n. 2
0
void CDefaultTerminal::PostCreated(bool bWaitForReady /*= false*/, bool bShowErrors /*= false*/)
{
	if (!ghWnd)
	{
		// Main ConEmu window must be created
		// It is required for initialization of ConEmuHk.dll
		// wich will be injected into hooked processes
		_ASSERTE(ghWnd!=NULL);
		return;
	}

	mb_Initialized = true;

	if (!isDefaultTerminalAllowed())
	{
		_ASSERTE(bWaitForReady == false);
		if (bShowErrors && gpConEmu->DisableSetDefTerm)
		{
			DisplayLastError(L"Default terminal feature was blocked\n"
				L"with '/NoDefTerm' ConEmu command line argument!", -1);
		}
		return;
	}

	if (mb_PostCreatedThread)
	{
		if (!bShowErrors)
			return;
		ClearThreads(false);
		if (m_Threads.size() > 0)
		{
			Icon.ShowTrayIcon(L"Previous Default Terminal setup cycle was not finished yet", tsa_Default_Term);
			return;
		}
	}

	CheckRegisterOsStartup();

	mb_ReadyToHook = TRUE;

	// Этот процесс занимает некоторое время, чтобы не блокировать основной поток - запускаем фоновый
	mb_PostCreatedThread = true;
	DWORD  nWait = WAIT_FAILED;
	HANDLE hPostThread = CreateThread(NULL, 0, PostCreatedThread, this, 0, &mn_PostThreadId);
	
	if (hPostThread)
	{
		if (bWaitForReady)
		{
			// Wait for 30 seconds
			DWORD nStart = GetTickCount();
			SetCursor(LoadCursor(NULL, IDC_WAIT));
			nWait = WaitForSingleObject(hPostThread, 30000);
			SetCursor(LoadCursor(NULL, IDC_ARROW));
			DWORD nDuration = GetTickCount() - nStart;
			if (nWait == WAIT_OBJECT_0)
			{
				CloseHandle(hPostThread);
				return;
			}
			else
			{
				//_ASSERTE(nWait == WAIT_OBJECT_0);
				DisplayLastError(L"PostCreatedThread was not finished in 30 seconds");
				UNREFERENCED_PARAMETER(nDuration);
			}
		}

		m_Threads.push_back(hPostThread);
	}
	else
	{
		if (bShowErrors)
		{
			DisplayLastError(L"Failed to start PostCreatedThread");
		}
		_ASSERTE(hPostThread!=NULL);
		mb_PostCreatedThread = false;
	}
}