📄 stafutil.cpp
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2001 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/#include "STAF.h"#include "STAFString.h"#include "STAFUtil.h"#include "STAFUtilWin32.h"#include "STAFMutexSem.h"#include "STAFTrace.h"#include <time.h>char *STAFUtilGetCurrentProcessCodePage(char *codepage){ if (codepage != 0) sprintf(codepage, "%s%d", "IBM-", GetOEMCP()); return codepage;}unsigned int STAFUtilWin32GetWinType(){ static STAFMutexSem helperSem; static bool haveChecked = false; static unsigned int type; if (!haveChecked) { STAFMutexSemLock lock(helperSem); if (!haveChecked) { OSVERSIONINFO osVersionInfo = { sizeof(OSVERSIONINFO), 0 }; if (!GetVersionEx(&osVersionInfo)) { STAFTrace::trace( kSTAFTraceError, "GetVersionEx() failed in STAFUtilWin32GetWinType()"); type = 0; } else if (osVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { if (osVersionInfo.dwMinorVersion == 0) type = kSTAFWin95; else if (osVersionInfo.dwMinorVersion == 10) type = kSTAFWin98; else if (osVersionInfo.dwMinorVersion == 90) type = kSTAFWinMe; else type = kSTAFWin9XUnknown; } else if (osVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) { if (osVersionInfo.dwMajorVersion == 4) type = kSTAFWinNT; else if ((osVersionInfo.dwMajorVersion == 5) && (osVersionInfo.dwMinorVersion == 0)) type = kSTAFWin2K; else if ((osVersionInfo.dwMajorVersion == 5) && (osVersionInfo.dwMinorVersion == 1)) type = kSTAFWinXP; else if ((osVersionInfo.dwMajorVersion == 5) && (osVersionInfo.dwMinorVersion == 2)) type = kSTAFWin2K3; else if ((osVersionInfo.dwMajorVersion == 6) && (osVersionInfo.dwMinorVersion == 0)) type = kSTAFWinVista; else type = kSTAFWinNTUnknown; } else { type = kSTAFWin32Unknown; } haveChecked = true; } } return type;}unsigned int STAFUtilGetConfigInfo(STAFConfigInfo *configInfo, STAFString_t *errorBuffer, unsigned int *osRC){ static STAFMutexSem helperSem; static bool haveChecked = false; static unsigned long physicalMemory = 0; static STAFString bootDrive; static STAFString exePath; static STAFString osMajorVersion; static STAFString osMinorVersion; static STAFString osRevision; static STAFString osName; static STAFString crlfString; static STAFString fileSeparator; static STAFString pathSeparator; static STAFString commandSeparator; if (!haveChecked) { STAFMutexSemLock lock(helperSem); if (!haveChecked) { // Get total physical memory MEMORYSTATUS memoryStatus = { sizeof(MEMORYSTATUS), 0 }; GlobalMemoryStatus(&memoryStatus); physicalMemory = memoryStatus.dwTotalPhys; // Get boot drive char systemPathBuffer[MAX_PATH]; if (GetSystemDirectory(systemPathBuffer, MAX_PATH) == 0) { if (errorBuffer) *errorBuffer = STAFString( "GetSystemDirectory()").adoptImpl(); if (osRC) *osRC = static_cast<unsigned int>(GetLastError()); return kSTAFBaseOSError; } bootDrive = STAFString(systemPathBuffer).subString(0, 2); // Get STAFRoot char buffer[256] = { 0 }; char *filePart = 0; if (SearchPath(0, "STAFPROC.EXE", 0, sizeof(buffer), buffer, &filePart) == 0) { if (errorBuffer) *errorBuffer = STAFString("SearchPath()").adoptImpl(); if (osRC) *osRC = static_cast<unsigned int>(GetLastError()); return kSTAFBaseOSError; } exePath = STAFString(buffer).subWord(0); exePath = exePath.subString(0, exePath.findLastOf(kUTF8_BSLASH)); exePath = exePath.subString(0, exePath.findLastOf(kUTF8_BSLASH)); // Get OS Name, Major and Minor Version, and Revision OSVERSIONINFO osVersionInfo = { sizeof(OSVERSIONINFO), 0 }; if (GetVersionEx(&osVersionInfo) != TRUE) { if (errorBuffer) *errorBuffer = STAFString("GetVersionEx()").adoptImpl(); if (osRC) *osRC = 1; return kSTAFBaseOSError; } osMajorVersion = STAFString(osVersionInfo.dwMajorVersion); osMinorVersion = STAFString(osVersionInfo.dwMinorVersion); osRevision = STAFString(osVersionInfo.dwBuildNumber & 0x0000FFFF); switch (STAFUtilWin32GetWinType()) { case kSTAFWin95: osName = "Win95"; break; case kSTAFWin98: osName = "Win98"; break; case kSTAFWinMe: osName = "WinMe"; break; case kSTAFWin9XUnknown: osName = "Unknown Win9X"; break; case kSTAFWinNT: osName = "WinNT"; break; case kSTAFWin2K: osName = "Win2000"; break; case kSTAFWinXP: osName = "WinXP"; break; case kSTAFWin2K3: osName = "Win2003"; break; case kSTAFWinVista: osName = "WinVista"; break; case kSTAFWinNTUnknown: osName = "Unknown WinNT"; break; case kSTAFWin32Unknown: osName = "Unknown Win32"; break; } crlfString = STAFString(kUTF8_CR) + STAFString(kUTF8_LF); fileSeparator = STAFString(kUTF8_BSLASH); pathSeparator = STAFString(kUTF8_SCOLON); commandSeparator = STAFString(kUTF8_AMP); haveChecked = true; } } configInfo->physicalMemory = physicalMemory; configInfo->lineSeparator = crlfString.getImpl(); configInfo->fileSeparator = fileSeparator.getImpl(); configInfo->pathSeparator = pathSeparator.getImpl(); configInfo->commandSeparator = commandSeparator.getImpl(); configInfo->osName = osName.getImpl(); configInfo->osMajorVersion = osMajorVersion.getImpl(); configInfo->osMinorVersion = osMinorVersion.getImpl(); configInfo->osRevision = osRevision.getImpl(); configInfo->exePath = exePath.getImpl(); configInfo->bootDrive = bootDrive.getImpl(); configInfo->defaultProcessStopMethod = kSTAFProcessStopWithSigKill; configInfo->envVarCaseSensitive = 0; // Case insensitive return 0;}void *STAFUtilGetSystemMemory(unsigned long size, unsigned int *osRC){ void *theMem = GlobalAlloc(GMEM_FIXED, size); if ((theMem == 0) && osRC) *osRC = 0; return theMem;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -