Beispiel #1
0
std::string GetWinVersionString(
	DWORD dwPlatformId  ,
	DWORD dwMinorVersion,
	DWORD dwMajorVersion,
	DWORD dwBuildNumber
	)
{
	std::string strVersion = WUNKNOWNSTR;

	int nVersion = GetWinVersion(dwPlatformId,dwMinorVersion,dwMajorVersion,dwBuildNumber);

	switch (nVersion)
	{
	default:
	case WUNKNOWN:								break;
	case W95:		strVersion = W95STR;		break;
	case W95SP1:	strVersion = W95SP1STR;		break;
	case W95OSR2:	strVersion = W95OSR2STR;	break;
	case W98:		strVersion = W98STR;		break;
	case W98SP1:	strVersion = W98SP1STR;		break;
	case W98SE:		strVersion = W98SESTR;		break;
	case WME:		strVersion = WMESTR;		break;
	case WNT351:	strVersion = WNT351STR;		break;
	case WNT4:		strVersion = WNT4STR;		break;
	case W2K:		strVersion = W2KSTR;		break;
	case WXP:		strVersion = WXPSTR;		break;
	case W2003:		strVersion = W2003STR;		break;
	case WVISTA:	strVersion = "Windows Vista/Windows Server 2008";	break;
	case WIN7:		strVersion = "Windows7/Windows Server 2008 R2";		break;
	case WIN8:		strVersion = "Windows8/Windows Server 2012";			break;
	case WCE:		strVersion = WCESTR;		break;
	}
	//SYSTEM_INFO	sysinfo;
	//GetNativeSystemInfo(&sysinfo);
	//switch(sysinfo.wProcessorArchitecture){
	//case PROCESSOR_ARCHITECTURE_INTEL        :{}break;
	//case PROCESSOR_ARCHITECTURE_MIPS         :{}break;
	//case PROCESSOR_ARCHITECTURE_ALPHA        :{}break;
	//case PROCESSOR_ARCHITECTURE_PPC          :{}break;
	//case PROCESSOR_ARCHITECTURE_SHX          :{}break;
	//case PROCESSOR_ARCHITECTURE_ARM          :{}break;
	//case PROCESSOR_ARCHITECTURE_IA64         :{}break;
	//case PROCESSOR_ARCHITECTURE_ALPHA64      :{}break;
	//case PROCESSOR_ARCHITECTURE_MSIL         :{}break;
	//case PROCESSOR_ARCHITECTURE_AMD64        :{}break;
	//}
	//if(IsX64()){
	//	strVersion	+=	"	64bit";
	//}else{
	//	strVersion	+=	"	32bit";
	//}
	return strVersion;
}
Beispiel #2
0
void PaintSur::PolygonImage(const std::vector<RenderVertex> &rgv, HBITMAP hbm, const float left, const float top, const float right, const float bottom, const int bitmapwidth, const int bitmapheight)
{
   const int ix = SCALEXf(left);
   const int iy = SCALEYf(top);
   const int ix2 = SCALEXf(right);
   const int iy2 = SCALEYf(bottom);

   const HDC hdcNew = CreateCompatibleDC(m_hdc);
   const HBITMAP hbmOld = (HBITMAP)SelectObject(hdcNew, hbm);

   std::vector<POINT> rgpt(rgv.size());
   for (size_t i = 0; i < rgv.size(); i++)
   {
      rgpt[i].x = SCALEXf(rgv[i].x);
      rgpt[i].y = SCALEYf(rgv[i].y);
   }

   if (GetWinVersion() >= 2600) // For everything newer than Windows XP: use the alpha in the bitmap (RGB needs to be premultiplied with alpha, too, then! see CopyTo_ConvertAlpha())
   {
      const HRGN hrgn = CreatePolygonRgn(rgpt.data(), (int)rgv.size(), WINDING);
      SelectClipRgn(m_hdc, hrgn);

      const BLENDFUNCTION blendf = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
      AlphaBlend(m_hdc, ix, iy, ix2 - ix, iy2 - iy, hdcNew, 0, 0, bitmapwidth, bitmapheight, blendf);

      SelectClipRgn(m_hdc, NULL);
      DeleteObject(hrgn);
   }
   else // do XOR trick for masking (draw image, draw black polygon, draw image again, and the XOR will do an implicit mask op)
   {
      SetStretchBltMode(m_hdc, HALFTONE); // somehow enables filtering
      StretchBlt(m_hdc, ix, iy, ix2 - ix, iy2 - iy, hdcNew, 0, 0, bitmapwidth, bitmapheight, SRCINVERT);

      SelectObject(m_hdc, GetStockObject(BLACK_BRUSH));
      SelectObject(m_hdc, GetStockObject(NULL_PEN));

      ::Polygon(m_hdc, rgpt.data(), (int)rgv.size());

      SetStretchBltMode(m_hdc, HALFTONE); // somehow enables filtering
      StretchBlt(m_hdc, ix, iy, ix2 - ix, iy2 - iy, hdcNew, 0, 0, bitmapwidth, bitmapheight, SRCINVERT);
   }

   SelectObject(hdcNew, hbmOld);
   DeleteDC(hdcNew);
}
    bool PathProvider(int key, FilePath* result)
    {
        // 需要进行值的计算. 支持长于MAX_PATH的路径会更好, 但是系统函数设计的时候
        // 除了GetTempPath以外都不支持.
        wchar_t system_buffer[MAX_PATH] = { 0 };
        system_buffer[0] = 0;

        FilePath cur;
        switch(key)
        {
        case DIR_CURRENT:
            if(!FilePath::GetCurrentDirectory(cur))
            {
                return false;
            }
            break;
        case DIR_EXE:
            GetModuleFileNameW(NULL, system_buffer, MAX_PATH);
            cur = FilePath(system_buffer);
            cur.RemoveFileSpec();
            break;
        case DIR_MODULE:
            {
                // 代码调用的模块都有资源, 无论dll或exe.
                HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
                ::GetModuleFileNameW(this_module, system_buffer, MAX_PATH);
                cur = FilePath(system_buffer);
                cur.RemoveFileSpec();
                break;
            }
        case DIR_TEMP:
            if(!FilePath::GetTempDir(cur))
            {
                return false;
            }
            break;
        case FILE_EXE:
            GetModuleFileNameW(NULL, system_buffer, MAX_PATH);
            cur = FilePath(system_buffer);
            break;
        case FILE_MODULE:
            {
                // 代码调用的模块都有资源, 无论dll或exe.
                HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
                GetModuleFileNameW(this_module, system_buffer, MAX_PATH);
                cur = FilePath(system_buffer);
                break;
            }
        case DIR_WINDOWS:
            GetWindowsDirectoryW(system_buffer, MAX_PATH);
            cur = FilePath(system_buffer);
            break;
        case DIR_SYSTEM:
            GetSystemDirectoryW(system_buffer, MAX_PATH);
            cur = FilePath(system_buffer);
            break;
        case DIR_PROGRAM_FILES:
            if(FAILED(SHGetFolderPathW(NULL, CSIDL_PROGRAM_FILES, NULL,
                SHGFP_TYPE_CURRENT, system_buffer)))
            {
                return false;
            }
            cur = FilePath(system_buffer);
            break;
        case DIR_IE_INTERNET_CACHE:
            if(FAILED(SHGetFolderPathW(NULL, CSIDL_INTERNET_CACHE, NULL,
                SHGFP_TYPE_CURRENT, system_buffer)))
            {
                return false;
            }
            cur = FilePath(system_buffer);
            break;
        case DIR_COMMON_START_MENU:
            if(FAILED(SHGetFolderPathW(NULL, CSIDL_COMMON_PROGRAMS, NULL,
                SHGFP_TYPE_CURRENT, system_buffer)))
            {
                return false;
            }
            cur = FilePath(system_buffer);
            break;
        case DIR_START_MENU:
            if(FAILED(SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL,
                SHGFP_TYPE_CURRENT, system_buffer)))
            {
                return false;
            }
            cur = FilePath(system_buffer);
            break;
        case DIR_COMMON_APP_DATA:
            if(FAILED(SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL,
                SHGFP_TYPE_CURRENT, system_buffer)))
            {
                return false;
            }
            cur = FilePath(system_buffer);
            break;
        case DIR_APP_DATA:
            if(FAILED(SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL,
                SHGFP_TYPE_CURRENT, system_buffer)))
            {
                return false;
            }
            cur = FilePath(system_buffer);
            break;
        case DIR_PROFILE:
            if(FAILED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL,
                SHGFP_TYPE_CURRENT, system_buffer)))
            {
                return false;
            }
            cur = FilePath(system_buffer);
            break;
        case DIR_LOCAL_APP_DATA_LOW:
            if(GetWinVersion() < WINVERSION_VISTA)
            {
                return false;
            }
            // TODO: 应该使用SHGetKnownFolderPath替换. Bug 1281128.
            if(FAILED(SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL,
                SHGFP_TYPE_CURRENT, system_buffer)))
            {
                return false;
            }
            cur = FilePath(system_buffer);
            cur.RemoveFileSpec();
            cur.Append(L"LocalLow");
            break;
        case DIR_LOCAL_APP_DATA:
            if(FAILED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL,
                SHGFP_TYPE_CURRENT, system_buffer)))
            {
                return false;
            }
            cur = FilePath(system_buffer);
            break;
        default:
            return false;
        }

        *result = cur;
        return true;
    }
int __cdecl _tmain(int argc, _TCHAR *argv[])
{
	HDEVINFO h = NULL;
	SP_DEVINFO_DATA dev_info_data;
	ULONG status = 0, problem = 0;
	BOOL bDevice = FALSE;

	if (IsWow64()) {
		logPrint("Your are runing 32bit VirtualMonitor on 64bit windows\n");
		logPrint("Please Download 64bit version of VirtualMonitor\n");
		return -1;
	}
	if (argc < 2 || !strcmp(argv[1], "-h")) {
		usage(argv);
		goto out;
	}

	GetWinVersion();
	if (!isSupport) {
		logPrint("Unsupported Windows system\n");
		goto out;
	}
	if (isVista || isWin7) {
		if (!IsUserAnAdmin()) {
			logPrint("Access Denied. Administrator permissions are needed to use the selected options.");
			logPrint("Use an administrator command prompt to complete these tasks.");
			goto out;
		}
	}

	if (!strcmp(argv[1], "-i")) {
		FixInfFile(INF);
	}
	h = GetDevInfoFromDeviceId(&dev_info_data, DRIVER_NAME);
	if (!strcmp(argv[1], "-i")) {
		if (h) {
			logPrint("Driver already installed\n");
			goto out;
		}
		if (!logInit()) {
			goto out;
		}
		logPrint("Installing driver, It may take few minutes. please wait\n");
		RegClean();
		InstallInf(INF);
		if (isVista || isWin7) {
			DisableMirror();
		}
		h = GetDevInfoFromDeviceId(&dev_info_data, DRIVER_NAME);
		if (!h) {
			logError("GetDevInfo Failed After Driver Installed\n");
		}
		GetDevStatus(h, &dev_info_data, &status, &problem);
		bDevice = DetectVirtualMonitor(FALSE);
		logInfo("Driver Status: %x, problem: %x\n", status, problem);
		if (!bDevice) {
			DetectVirtualMonitor(TRUE);
			logPrint("Driver installed Status: %x, problem: %x\n", status, problem);
			logPrint("Please reboot your system\n");
		} else {
			logPrint("Driver installed successful\n");
		}
		if (isVista || isWin7) {
			logPrint("Please reboot your system\n");
		}
	} else if (!strcmp(argv[1], "-u")) {
		if (!h) {
			logPrint("Driver not found\n");
		} else {
			if (!logInit()) {
				goto out;
			}
			UnInstallDriver(h, &dev_info_data);
			if (isVista || isWin7) {
				CleanOemInf();
			}
			RegClean();
			logPrint("Driver Uninstalled sucessful, Please Reboot System\n");
		}
	} else {
		usage(argv);
		goto out;
	}
out:
	if (g_logf)
		fclose(g_logf);
	if (h) {
			DestroyDevInfo(h);
	}
	exit(0);
}
static LRESULT CALLBACK WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData )
{
	if (uMsg==WM_WINDOWPOSCHANGING)
	{
		WINDOWPOS *pos=(WINDOWPOS*)lParam;
		if (pos->flags&SWP_SHOWWINDOW)
		{
			wchar_t title[256];
			GetWindowText(hWnd,title,_countof(title));

			if (_wcsicmp(title,g_TitleMove)==0 || _wcsicmp(title,g_TitleCopy)==0)
			{
				// file UI
				if (GetSettingBool(L"ReplaceFileUI"))
				{
					CString log;
					bool bLog=GetSettingInt(L"LogLevel")>0;
					CComPtr<IAccessible> pAcc;
					HRESULT h=AccessibleObjectFromWindow(hWnd,OBJID_WINDOW,IID_IAccessible,(void**)&pAcc);
					if (SUCCEEDED(h) && pAcc)
					{
						CClassicCopyFile copy;
						if (copy.Run(hWnd,pAcc,bLog?&log:NULL))
						{
							pos->x=pos->y=-20000;
							pos->flags&=~(SWP_SHOWWINDOW|SWP_NOMOVE);
						}
					}
					else if (bLog)
						LogPrint(&log,L"AccessibleObjectFromWindow: error=0x%X, hWnd=0x%X",h,(DWORD)hWnd);

					if (bLog)
					{
						wchar_t fname[_MAX_PATH]=L"%LOCALAPPDATA%\\ExplorerLog.txt";
						DoEnvironmentSubst(fname,_countof(fname));
						if (!log.IsEmpty())
						{
							FILE *f;
							if (_wfopen_s(&f,fname,L"wb")==0)
							{
								fwprintf(f,L"\xFEFF");

								OSVERSIONINFOEX ver={sizeof(ver)};
								GetVersionEx((OSVERSIONINFO*)&ver);
								fwprintf(f,L"version = %d.%d.%d - %d.%d\r\n\r\n",ver.dwMajorVersion,ver.dwMinorVersion,ver.dwBuildNumber,ver.wServicePackMajor,ver.wServicePackMinor);

								wchar_t languages[100]={0};
								ULONG size=4; // up to 4 languages
								ULONG len=_countof(languages);
								GetThreadPreferredUILanguages(MUI_LANGUAGE_NAME,&size,languages,&len);
								for (const wchar_t *lang=languages;*lang;lang+=wcslen(lang)+1)
									fwprintf(f,L"language = %s\r\n",lang);

								fwprintf(f,L"\r\n");
								fwprintf(f,L"g_ButtonMove = '%s'\r\n",g_ButtonMove);
								fwprintf(f,L"g_ButtonDontMove = '%s'\r\n",g_ButtonDontMove);
								fwprintf(f,L"g_ButtonCopy = '%s'\r\n",g_ButtonCopy);
								fwprintf(f,L"g_ButtonDontCopy = '%s'\r\n",g_ButtonDontCopy);
								fwprintf(f,L"g_ButtonCancel = '%s'\r\n",g_ButtonCancel);
								fwprintf(f,L"\r\n");

								fwrite((const wchar_t*)log,log.GetLength(),2,f);
								fclose(f);
							}
						}
						else
							DeleteFile(fname);
					}
				}
			}
			else if (_wcsicmp(title,g_TitleFolder)==0)
			{
				// folder UI
				if (GetSettingBool(L"ReplaceFolderUI"))
				{
					CClassicCopyFolder copy;
					if (copy.Run(hWnd))
					{
						pos->x=pos->y=-20000;
						pos->flags&=~(SWP_SHOWWINDOW|SWP_NOMOVE);
					}
				}
			}
			else
			{
				// look for progress bar
				if (GetSettingBool(L"EnableMore"))
				{
					HWND progress=FindChildWindow(hWnd,PROGRESS_CLASS);
					if (progress)
					{
						bool bDef;
						int delay=GetSettingInt(L"MoreProgressDelay",bDef);
						if (bDef)
						{
							delay=0;
							if (GetWinVersion()>=WIN_VER_WIN7)
							{
								BOOL comp;
								if (SUCCEEDED(DwmIsCompositionEnabled(&comp)) && comp)
									delay=500;
							}
						}
						SetTimer(hWnd,'CLEX',delay,NULL);
						return DefSubclassProc(hWnd,uMsg,wParam,lParam);
					}
				}
			}
			LRESULT res=DefSubclassProc(hWnd,uMsg,wParam,lParam);
			RemoveWindowSubclass(hWnd,WindowProc,uIdSubclass);
			return res;
		}
	}
	if (uMsg==WM_TIMER && wParam=='CLEX')
	{
		KillTimer(hWnd,wParam);

		CComPtr<IAccessible> pAcc;
		HRESULT h=AccessibleObjectFromWindow(hWnd,OBJID_WINDOW,IID_IAccessible,(void**)&pAcc);
		if (SUCCEEDED(h) && pAcc)
		{
			CComPtr<IAccessible> pMore=FindMoreButton(pAcc);
			if (pMore) pMore->accDoDefaultAction(CComVariant(CHILDID_SELF));
		}

		LRESULT res=DefSubclassProc(hWnd,uMsg,wParam,lParam);
		RemoveWindowSubclass(hWnd,WindowProc,uIdSubclass);
		return res;
	}
	return DefSubclassProc(hWnd,uMsg,wParam,lParam);
}
Beispiel #6
0
// DLL Entry Point
extern "C" BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )
{
	if (dwReason==DLL_PROCESS_ATTACH)
	{
		InitSettings();
		g_TlsIndex=TlsAlloc();
		if (g_TlsIndex==TLS_OUT_OF_INDEXES) 
			return FALSE; // TLS failure

		wchar_t path[_MAX_PATH];
		GetModuleFileName(NULL,path,_countof(path));
		const wchar_t *exe=PathFindFileName(path);
		g_bExplorerExe=(_wcsicmp(exe,L"explorer.exe")==0 || _wcsicmp(exe,L"verclsid.exe")==0);
		bool bReplaceUI=GetWinVersion()<WIN_VER_WIN8 && (GetSettingBool(L"ReplaceFileUI") || GetSettingBool(L"ReplaceFolderUI") || GetSettingBool(L"EnableMore"));
		if (_wcsicmp(exe,L"regsvr32.exe")!=0 && _wcsicmp(exe,L"msiexec.exe")!=0 && _wcsicmp(exe,L"ClassicExplorerSettings.exe")!=0 && !g_bExplorerExe)
		{
			// some arbitrary app
			if ((!GetSettingBool(L"ShareOverlay") || GetSettingBool(L"ShareExplorer")) && (!bReplaceUI || GetSettingBool(L"FileExplorer")))
				return FALSE;
			CString whiteList=GetSettingString(L"ProcessWhiteList");
			if (!whiteList.IsEmpty())
			{
				// check for whitelisted process names
				const wchar_t *str=whiteList;
				bool bFound=false;
				while (*str)
				{
					wchar_t token[_MAX_PATH];
					str=GetToken(str,token,_countof(token),L",;");
					wchar_t *start=token;
					while (*start==' ')
						start++;
					wchar_t *end=start+Strlen(start);
					while (end>start && end[-1]==' ')
						end--;
					*end=0;
					if (_wcsicmp(exe,start)==0)
					{
						bFound=true;
						break;
					}
				}
				if (!bFound)
					return FALSE;
			}
			else
			{
				// check for blacklisted process names
				CString blackList=GetSettingString(L"ProcessBlackList");
				const wchar_t *str=blackList;
				while (*str)
				{
					wchar_t token[_MAX_PATH];
					str=GetToken(str,token,_countof(token),L",;");
					wchar_t *start=token;
					while (*start==' ')
						start++;
					wchar_t *end=start+Strlen(start);
					while (end>start && end[-1]==' ')
						end--;
					*end=0;
					if (_wcsicmp(exe,start)==0)
						return FALSE;
				}
			}
		}

		g_Instance=hInstance;
		g_LoadedSettingsAtom=(LPCWSTR)GlobalAddAtom(L"ClassicExplorer.LoadedSettings");

		GetModuleFileName(hInstance,path,_countof(path));
		*PathFindFileName(path)=0;
		wchar_t fname[_MAX_PATH];
		Sprintf(fname,_countof(fname),L"%s" INI_PATH L"ExplorerL10N.ini",path);
		CString language=GetSettingString(L"Language");
		ParseTranslations(fname,language);

		HINSTANCE resInstance=NULL;
		if (!language.IsEmpty())
		{
			wchar_t fname[_MAX_PATH];
			Sprintf(fname,_countof(fname),L"%s" INI_PATH L"%s.dll",path,language);
			resInstance=LoadLibraryEx(fname,NULL,LOAD_LIBRARY_AS_DATAFILE|LOAD_LIBRARY_AS_IMAGE_RESOURCE);
		}
		else
		{
			wchar_t languages[100]={0};
			ULONG size=4; // up to 4 languages
			ULONG len=_countof(languages);
			GetThreadPreferredUILanguages(MUI_LANGUAGE_NAME,&size,languages,&len);

			for (const wchar_t *language=languages;*language;language+=Strlen(language)+1)
			{
				wchar_t fname[_MAX_PATH];
				Sprintf(fname,_countof(fname),L"%s" INI_PATH L"%s.dll",path,language);
				resInstance=LoadLibraryEx(fname,NULL,LOAD_LIBRARY_AS_DATAFILE|LOAD_LIBRARY_AS_IMAGE_RESOURCE);
				if (resInstance)
					break;
			}
		}

		if (resInstance && GetVersionEx(resInstance)!=GetVersionEx(g_Instance))
		{
			FreeLibrary(resInstance);
			resInstance=NULL;
		}
		LoadTranslationResources(g_Instance,resInstance,g_LoadDialogs);

		if (resInstance)
			FreeLibrary(resInstance);

		g_bHookCopyThreads=(bReplaceUI && (g_bExplorerExe || !GetSettingBool(L"FileExplorer")));
		if (g_bHookCopyThreads)
		{
			InitClassicCopyProcess();
			InitClassicCopyThread();
		}

		if (GetSettingBool(L"ShareOverlay") && (g_bExplorerExe || !GetSettingBool(L"ShareExplorer")))
			CShareOverlay::InitOverlay(GetSettingString(L"ShareOverlayIcon"));
	}

	if (dwReason==DLL_THREAD_ATTACH)
	{
		if (g_bHookCopyThreads)
			InitClassicCopyThread();
	}

	if (dwReason==DLL_THREAD_DETACH)
	{
		void *pData=TlsGetValue(g_TlsIndex);
		if (pData)
			LocalFree((HLOCAL)pData);
		TlsSetValue(g_TlsIndex,NULL);
		if (g_bHookCopyThreads)
			FreeClassicCopyThread();
	}

	if (dwReason==DLL_PROCESS_DETACH)
	{
		void *pData=TlsGetValue(g_TlsIndex);
		if (pData)
			LocalFree((HLOCAL)pData);
		TlsSetValue(g_TlsIndex,NULL);
		TlsFree(g_TlsIndex);
		GlobalDeleteAtom((ATOM)g_LoadedSettingsAtom);
	}

	return _AtlModule.DllMain(dwReason, lpReserved);
}
Beispiel #7
0
//----------------------------------------------------------------------------------------------------------
BOOL IsWinXP()         { return GetWinVersion()>=PACKVERSION(5,1)?TRUE:FALSE; }