//================================================================================================ // // LoadFile() // // - Called by Configuration::Load() // /// <summary> /// Attempts to load the specified config-file. Returns true if successful, false if not /// </summary> // bool Configuration::LoadFile(const TCHAR *file, HANDLE *fp, HANDLE *map, const void **view) { TCHAR chBuf[256]; _stprintf_s(chBuf, _countof(chBuf), _T("[Configuration] [LoadFile] loading file:[%s]"), file); g_tlog.LogMessage(chBuf, TRACELOG_LEVEL_INFO); *fp=CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if(*fp==INVALID_HANDLE_VALUE) { TRACEERR("[Configuration] [LoadFile]", L"Can't open file", GetLastError()); return false; } // Attempting to access a 0-byte file causes "The volume for a file has been externally // altered so that the opened file is no longer valid." errors, both here and when trying // to save the .conf file later on. DWORD size=0; size=GetFileSize(*fp, NULL); if (size == 0) { TRACEW("[Configuration] [LoadFile] 0 byte conf file"); CloseHandle(*fp); *fp = 0; return false; } else if (size == INVALID_FILE_SIZE) { TRACEERR("[Configuration] [LoadFile]", L"Can't get file size", GetLastError()); CloseHandle(*fp); *fp = 0; return false; } else { tstring strBuf = boost::str(tformat(_T("[Configuration] [LoadFile] about to memory-map file - size: [%1%]")) % size ); TRACEBUFI(strBuf); } *map=CreateFileMapping(*fp, NULL, PAGE_READONLY, 0, 0, NULL); if(*map==NULL) { TRACEERR("[Configuration] [LoadFile]", L"Can't create file map", GetLastError()); return false; } *view=MapViewOfFile(*map, FILE_MAP_READ, 0, 0, 0); if(*view==NULL) { TRACEERR("[Configuration] [LoadFile]", L"Can't map view of file", GetLastError()); return false; } _stprintf_s(chBuf, _countof(chBuf), _T("[Configuration] [LoadFile] Successfully loaded file:[%s]"), file); g_tlog.LogMessage(chBuf, TRACELOG_LEVEL_SUCCESS); return true; }; // End of LoadFile()
void pbfilter_base::start_thread() { TRACEV("[pbfilter_base] [start_thread] > Entering routine."); m_runthread = true; m_exitevt = CreateEvent(0, TRUE, FALSE, 0); if(!m_exitevt) throw win32_error("CreateEvent", 0); TRACEI("[pbfilter_base] [start_thread] creating thread_thunk"); m_thread = CreateThread(0, 0, thread_thunk, this, 0, 0); if(!m_thread) { DWORD err = GetLastError(); CloseHandle(m_exitevt); TRACEE("[pbfilter_base] [start_thread] ERROR creating thread_thunk!!"); throw win32_error("CreateThread", err); } TCHAR chBuf[256]; _stprintf_s(chBuf, sizeof(chBuf)/2, _T("[pbfilter_base] [start_thread] thread_thunk created with handle:[%p]"), m_thread); g_tlog.LogMessage(chBuf, TRACELOG_LEVEL_VERBOSE); TRACEV("[pbfilter_base] [start_thread] < Leaving routine."); } // End of start_thread()
//================================================================================================ // // CheckOS() // // - Called by _tWinMain at app start // /// <summary> /// Simply gets/logs the OS Version, doesn't actually do anything permanent with it. /// </summary> // static bool CheckOS() { OSVERSIONINFOEX osv = {0}; osv.dwOSVersionInfoSize = sizeof(osv); if(!GetVersionEx((OSVERSIONINFO *)&osv)) return false; SYSTEM_INFO si; GetSystemInfo(&si); //TODO: save version info tstring strOsName; if ( osv.dwMajorVersion == 6 && osv.dwMinorVersion == 3 && osv.wProductType == VER_NT_WORKSTATION ) strOsName = _T("Windows 8.1"); else if ( osv.dwMajorVersion == 6 && osv.dwMinorVersion == 2 && osv.wProductType == VER_NT_WORKSTATION ) strOsName = _T("Windows 8"); else if ( osv.dwMajorVersion == 6 && osv.dwMinorVersion == 2 && osv.wProductType != VER_NT_WORKSTATION ) strOsName = _T("Windows 8 Server"); else if ( osv.dwMajorVersion == 6 && osv.dwMinorVersion == 1 && osv.wProductType == VER_NT_WORKSTATION ) strOsName = _T("Windows 7"); else if ( osv.dwMajorVersion == 6 && osv.dwMinorVersion == 1 && osv.wProductType != VER_NT_WORKSTATION ) strOsName = _T("Windows Server 2008 R2"); else if ( osv.dwMajorVersion == 6 && osv.dwMinorVersion == 0 && osv.wProductType == VER_NT_WORKSTATION ) strOsName = _T("Windows Vista"); else if ( osv.dwMajorVersion == 6 && osv.dwMinorVersion == 0 && osv.wProductType != VER_NT_WORKSTATION ) strOsName = _T("Windows Server 2008"); else if ( osv.dwMajorVersion == 5 && osv.dwMinorVersion == 2 && GetSystemMetrics(SM_SERVERR2) != 0 ) strOsName = _T("Windows Server 2003 R2"); else if ( osv.dwMajorVersion == 5 && osv.dwMinorVersion == 2 && osv.wSuiteMask == VER_SUITE_WH_SERVER ) strOsName = _T("Windows Home Server"); else if ( osv.dwMajorVersion == 5 && osv.dwMinorVersion == 2 && osv.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) strOsName = _T("Windows XP Professional 64-bit Edition"); else if ( osv.dwMajorVersion == 5 && osv.dwMinorVersion == 2 && GetSystemMetrics(SM_SERVERR2) == 0 ) strOsName = _T("Windows Server 2003"); else if ( osv.dwMajorVersion == 5 && osv.dwMinorVersion == 1 ) strOsName = _T("Windows XP"); else strOsName = boost::str(tformat(_T("UNKNOWN OS %1%.%2%")) % osv.dwMajorVersion % osv.dwMinorVersion ); // TODO: Check for Media Center / Starter / Tablet PC (as per OSVERSIONINFOEX docs) tstring strOsBitness; if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) strOsBitness = _T("64-bit"); else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL ) strOsBitness = _T("32-bit"); else strOsBitness = _T("??-bit"); tstring strOsString = boost::str(tformat(_T("%1% %5% - Build:[%2%], SP:[%3%.%4%]")) % strOsName % osv.dwBuildNumber % osv.wServicePackMajor % osv.wServicePackMinor % strOsBitness.c_str()); TCHAR chBuf[256]; _stprintf_s(chBuf, _countof(chBuf), _T("Running on OS: %s"), strOsString.c_str()); g_tlog.LogMessage(chBuf, TRACELOG_LEVEL_SUCCESS); return true; } // End of CheckOS()