//------------------------------------------------------------------------ void CLogFile::ChangeLogFile() { setlocale(LC_ALL, "chs"); THREAD_PROTECT; SYSTEMTIME stNow; CriticalSectionProtector m_Protector; GetLocalTime(&stNow); if (stNow.wDay != m_stFileTime.wDay || m_fpLog == NULL) { TCHAR szFile1[256]; TCHAR szFile[1024]; wsprintf(szFile1, L"%04u-%02u-%02u.log", stNow.wYear, stNow.wMonth, stNow.wDay); _wmakepath(szFile, NULL, m_szFile, szFile1, NULL); if (m_fpLog) { fclose(m_fpLog); } m_fpLog = _wfopen(szFile, L"at+,ccs=UTF-8"); if (m_fpLog == nullptr) { ERROR_MSG_LOG_WITH_TIME(L"新日志文件: %s 创建失败.", szFile); } else { INFO_MSG_LOG(L"日志文件更换为: %s .", szFile); } m_stFileTime = stNow; } }
CStdStringW CFilename::MakePath() { CStdStringW res; _wmakepath(res.GetBuffer(MAX_PATH), drive.c_str(), dir.c_str(), fname.c_str(), ext.c_str()); res.ReleaseBuffer(); return res; }
static void test_makepath(void) { WCHAR driveW[MAX_PATH]; WCHAR dirW[MAX_PATH]; WCHAR fileW[MAX_PATH]; WCHAR extW[MAX_PATH]; WCHAR bufferW[MAX_PATH]; char buffer[MAX_PATH]; unsigned int i, n; for (i = 0; i < ARRAY_SIZE(makepath_cases); ++i) { const makepath_case* p = &makepath_cases[i]; memset(buffer, 'X', MAX_PATH); if (p->buffer) strcpy(buffer, p->buffer); /* Ascii */ _makepath(buffer, p->drive == USE_BUFF ? buffer : p->drive, p->dir == USE_BUFF ? buffer : p->dir, p->file == USE_BUFF? buffer : p->file, p->ext == USE_BUFF ? buffer : p->ext); buffer[MAX_PATH - 1] = '\0'; ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i); /* Unicode */ if (p->drive != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->drive, -1, driveW, MAX_PATH); if (p->dir != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->dir, -1, dirW, MAX_PATH); if (p->file != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->file, -1, fileW, MAX_PATH); if (p->ext != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->ext, -1, extW, MAX_PATH); memset(buffer, 0, MAX_PATH); for (n = 0; n < MAX_PATH; ++n) bufferW[n] = 'X'; if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH); _wmakepath(bufferW, p->drive == USE_BUFF ? bufferW : p->drive ? driveW : NULL, p->dir == USE_BUFF ? bufferW : p->dir ? dirW : NULL, p->file == USE_BUFF? bufferW : p->file ? fileW : NULL, p->ext == USE_BUFF ? bufferW : p->ext ? extW : NULL); bufferW[MAX_PATH - 1] = '\0'; WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL); ok(!strcmp(p->expected, buffer), "got '%s' for unicode case %d\n", buffer, i); } }
int __cdecl main(int argc, char **argv) { WCHAR FullPath[128]; WCHAR File[] = {'t','e','s','t','\0'}; WCHAR Ext[] = {'t','x','t','\0'}; char * PrintResult=NULL; /* Used for printing out errors */ char * PrintCorrect=NULL; #if WIN32 WCHAR Drive[] = {'C','\0'}; WCHAR Dir[] = {'\\','t','e','s','t','\0'}; WCHAR PathName[] = {'C',':','\\','t','e','s','t','\\','t','e', 's','t','.','t','x','t','\0'}; #else WCHAR *Drive = NULL; WCHAR Dir[] = {'/','t','e','s','t','\0'}; WCHAR PathName[] = {'/','t','e','s','t','/','t','e','s','t','.','t','x','t','\0'}; #endif /* * Initialize the PAL and return FAIL if this fails */ if (0 != (PAL_Initialize(argc,argv))) { return FAIL; } _wmakepath(FullPath, Drive, Dir, File, Ext); if(wcscmp(FullPath,PathName) != 0) { PrintResult = convertC(FullPath); PrintCorrect = convertC(PathName); Fail("ERROR: The pathname which was created turned out to be %s " "when it was supposed to be %s.\n",PrintResult,PrintCorrect); } PAL_Terminate(); return PASS; }
/* * Gets the pointer to the error file. * * <p>The error file will only be created, if create != 0.</p> * * <p>The error file has the name <executable file name>-error.log and is * created in the same directory as the executable file. If this fails, * the error file is created in the directory designated for temporary files. * </p> * @param create specifies, if the error file should be created (create != 0) * * @return the pointer to the open error file or NULL, if no error file is * open or can be created */ FILE* getErrorFile( int create ) { const wchar_t* MODE = L"w"; const wchar_t* BASEPOSTFIX = L"-error"; const wchar_t* EXTENSION = L".log"; static FILE* ferr = NULL; wchar_t fname[ _MAX_PATH ]; wchar_t drive[ _MAX_DRIVE ]; wchar_t dir[ _MAX_PATH ]; wchar_t base[ _MAX_FNAME ]; wchar_t newbase[ _MAX_FNAME ]; wchar_t ext[ _MAX_EXT ]; if ( ferr == NULL && create ) { /* get the absolute path of the executable file */ if ( GetModuleFileNameW( NULL, fname, MY_SIZE( fname ) ) ) { /* create error file in the directory of the executable file */ _wsplitpath( fname, drive, dir, base, ext ); wcscpy( newbase, base ); wcscat( newbase, BASEPOSTFIX ); _wmakepath( fname, drive, dir, newbase, EXTENSION ); ferr = _wfopen( fname, MODE ); if ( ferr == NULL ) { /* create error file in the temp directory */ GetTempPathW(MY_SIZE( fname ), fname ); wcscat( fname, newbase ); wcscat( fname, EXTENSION ); ferr = _wfopen( fname, MODE ); } } } return ferr; }
/* * Creates the command line for the application process including the absolute * path of the executable. * * <p>The application's executable file name is the name of this executable * prefixed by '_'.</p> * * @param appendix specifies the command line for the application excluding * the executable name * * @return the command line for the application process or NULL, if an error * occurred */ wchar_t* createCommandLine( wchar_t const * appendix ) { const wchar_t* CMDPREFIX = L"_"; const wchar_t* DQUOTE = L"\""; const wchar_t* SPACE = L" "; wchar_t* cmdline = NULL; wchar_t cmdname[ _MAX_PATH ]; wchar_t drive[ _MAX_DRIVE ]; wchar_t dir[ _MAX_PATH ]; wchar_t base[ _MAX_FNAME ]; wchar_t newbase[ _MAX_FNAME ]; wchar_t ext[ _MAX_EXT ]; /* get the absolute path of the executable file */ if ( GetModuleFileNameW( NULL, cmdname, MY_SIZE( cmdname ) ) ) { /* prefix the executable file name by '_' */ _wsplitpath( cmdname, drive, dir, base, ext ); wcscpy( newbase, CMDPREFIX ); wcscat( newbase, base ); _wmakepath( cmdname, drive, dir, newbase, ext ); /* create the command line */ cmdline = (wchar_t*) malloc( (wcslen( DQUOTE ) + wcslen( cmdname ) + wcslen ( DQUOTE ) + wcslen( SPACE ) + wcslen( appendix ) + 1) * sizeof(wchar_t) ); wcscpy( cmdline, DQUOTE ); wcscat( cmdline, cmdname ); wcscat( cmdline, DQUOTE ); wcscat( cmdline, SPACE ); wcscat( cmdline, appendix ); } return cmdline; }
static BOOL CreateMiniDump( EXCEPTION_POINTERS* pExceptionPtrs ) { BOOL bSuccess = FALSE; HANDLE hDumpFile; _wmakepath( g_wszDumpPath, g_wszHercDrive, g_wszHercDir, L"Hercules", L".dmp" ); _tprintf( _T("Creating crash dump \"%ls\"...\n\n"), g_wszDumpPath ); _tprintf( _T("Please wait; this may take a few minutes...\n\n") ); _tprintf( _T("(another message will appear when the dump is complete)\n\n") ); hDumpFile = CreateFileW ( g_wszDumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if ( hDumpFile && INVALID_HANDLE_VALUE != hDumpFile ) { // Create the minidump MINIDUMP_EXCEPTION_INFORMATION mdei; MINIDUMP_USER_STREAM_INFORMATION mdusi; MINIDUMP_CALLBACK_INFORMATION mci; MINIDUMP_TYPE mdt; BuildUserStreams( &mdusi ); mdei.ThreadId = GetCurrentThreadId(); mdei.ExceptionPointers = pExceptionPtrs; mdei.ClientPointers = FALSE; mci.CallbackRoutine = (MINIDUMP_CALLBACK_ROUTINE) MyMiniDumpCallback; mci.CallbackParam = 0; mdt = (MINIDUMP_TYPE) (0 | MiniDumpWithPrivateReadWriteMemory | MiniDumpWithDataSegs | MiniDumpWithHandleData // | MiniDumpWithFullMemoryInfo // | MiniDumpWithThreadInfo | MiniDumpWithUnloadedModules ); bSuccess = g_pfnMiniDumpWriteDumpFunc( GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, mdt, (pExceptionPtrs != 0) ? &mdei : 0, &mdusi, &mci ); CloseHandle( hDumpFile ); if ( bSuccess ) { _tprintf( _T("\nDump \"%ls\" created.\n\n" "Please forward the dump to the Hercules team for analysis.\n\n"), g_wszDumpPath ); } else _tprintf( _T("\nMiniDumpWriteDump failed! Error: %u\n\n"), GetLastError() ); } else { _tprintf( _T("\nCreateFile failed! Error: %u\n\n"), GetLastError() ); } return bSuccess; }
BOOL __stdcall AtlTraceLoadSettingsU(const WCHAR *pszFileName, DWORD_PTR dwProcess /* = 0 */) { WCHAR szFileName[MAX_PATH]; if(!pszFileName) { WCHAR szDrive[_MAX_DRIVE]; WCHAR szDir[_MAX_DIR]; WCHAR szFName[_MAX_FNAME]; WCHAR szExt[_MAX_EXT]; DWORD dwret = ::GetModuleFileNameW(NULL, szFileName, MAX_PATH); if( dwret == 0 || dwret == MAX_PATH ) return FALSE; #if _SECURE_ATL ATL_CRT_ERRORCHECK(_wsplitpath_s(szFileName, szDrive, _countof(szDrive), szDir, _countof(szDir), szFName, _countof(szFName), szExt, _countof(szExt))); ATL_CRT_ERRORCHECK(wcsncpy_s(szExt, _MAX_EXT, TRACE_SETTINGS_EXTW, _countof(TRACE_SETTINGS_EXTW))); ATL_CRT_ERRORCHECK(_wmakepath_s(szFileName, MAX_PATH, szDrive, szDir, szFName, szExt)); #else _wsplitpath(szFileName, szDrive, szDir, szFName, szExt); wcscpy(szExt, L".trc"); _wmakepath(szFileName, szDrive, szDir, szFName, szExt); #endif pszFileName = szFileName; } if(pszFileName) { if(-1 != GetFileAttributesW(pszFileName)) { // file exists WCHAR szSection[MAX_PATH], szKey[MAX_PATH], szValue[MAX_PATH]; WCHAR szName[MAX_PATH]; UINT nModules, nCategories, nStatus, nLevel; UINT nModule; CAtlTraceProcess *pProcess; CAtlTraceModule *pModule; CAtlTraceCategory *pCategory; LPCWSTR pszProcess = L"Process"; WCHAR cEnabled, cFuncAndCategoryNames, cFileNameAndLineInfo; CAtlAllocator *pAllocator = &g_Allocator; if (dwProcess) pAllocator = reinterpret_cast<CAtlAllocator*>(dwProcess); pProcess = pAllocator->GetProcess(); ATLASSERT(pProcess); if(!pProcess) return FALSE; pProcess->m_bLoaded = true; ::GetPrivateProfileStringW(pszProcess, L"Info", L"", szValue, MAX_PATH, pszFileName); szValue[MAX_PATH -1] = 0; #if _SECURE_ATL if(5 != swscanf_s(szValue, L"ModuleCount:%u, Level:%u, Enabled:%c, " L"FuncAndCategoryNames:%c, FileNameAndLineNo:%c", &nModules, &pProcess->m_nLevel, &cEnabled, sizeof(cEnabled), &cFuncAndCategoryNames, sizeof(cFuncAndCategoryNames), &cFileNameAndLineInfo, sizeof(cFileNameAndLineInfo))) #else if(5 != swscanf(szValue, L"ModuleCount:%u, Level:%u, Enabled:%c, " L"FuncAndCategoryNames:%c, FileNameAndLineNo:%c", &nModules, &pProcess->m_nLevel, &cEnabled, &cFuncAndCategoryNames, &cFileNameAndLineInfo)) #endif { return FALSE; } pProcess->m_bEnabled = cEnabled != L'f'; pProcess->m_bFuncAndCategoryNames = cFuncAndCategoryNames != L'f'; pProcess->m_bFileNameAndLineNo = cFileNameAndLineInfo != L'f'; for(UINT i = 0; i < nModules; i++) { if(swprintf(szKey, MAX_PATH, L"Module%d", i+1) < 0) return FALSE; ::GetPrivateProfileStringW(pszProcess, szKey, L"", szSection, MAX_PATH, pszFileName); szSection[MAX_PATH -1] = 0; ::GetPrivateProfileStringW(szSection, L"Name", L"", szName, MAX_PATH, pszFileName); szName[MAX_PATH -1] = 0; if(!pAllocator->FindModule(szName, &nModule)) continue; pModule = pAllocator->GetModule(nModule); ATLASSERT(pModule); if(!pModule) continue; ::GetPrivateProfileStringW(szSection, L"Settings", L"", szValue, MAX_PATH, pszFileName); szValue[MAX_PATH -1] = 0; #if _SECURE_ATL if(3 != swscanf_s(szValue, L"CategoryCount:%u, Level:%u, Status:%u", &nCategories, &nLevel, &nStatus)) #else if(3 != swscanf(szValue, L"CategoryCount:%u, Level:%u, Status:%u", &nCategories, &nLevel, &nStatus)) #endif continue; SetSettings(pModule, nLevel, nStatus); for(UINT j = 0; j < nCategories; j++) { if(swprintf(szKey, MAX_PATH, L"Category%d", j+1) < 0) return FALSE; ::GetPrivateProfileStringW(szSection, szKey, L"", szValue, MAX_PATH, pszFileName); szValue[MAX_PATH -1] = 0; #if _SECURE_ATL if(3 != swscanf_s(szValue, L"Level:%u, Status:%u, Name:%s", &nLevel, &nStatus, szName, _countof(szName))) #else if(3 != swscanf(szValue, L"Level:%u, Status:%u, Name:%s", &nLevel, &nStatus, szName)) #endif continue; UINT iCategory = pModule->m_iFirstCategory; while( iCategory != UINT( -1 ) ) { pCategory = pAllocator->GetCategory(iCategory); if( lstrcmpW(pCategory->Name(), szName) == 0 ) { SetSettings(pCategory, nLevel, nStatus); } iCategory = pCategory->m_iNextCategory; } } } NotifyTool(); } } return TRUE; }
/*--------------------------------------------------------------------------*/ char *getScilabDirectory(BOOL UnixStyle) { char *SciPathName = NULL; wchar_t* wcSciPathName = NULL; wchar_t ScilabModuleName[MAX_PATH + 1]; wchar_t drive[_MAX_DRIVE]; wchar_t dir[_MAX_DIR]; wchar_t fname[_MAX_FNAME]; wchar_t ext[_MAX_EXT]; wchar_t *DirTmp = NULL; if (!GetModuleFileNameW ((HINSTANCE)GetModuleHandleW(L"core"), (wchar_t*) ScilabModuleName, MAX_PATH)) { return NULL; } os_wsplitpath(ScilabModuleName, drive, dir, fname, ext); if (dir[wcslen(dir) - 1] == L'\\') { dir[wcslen(dir) - 1] = L'\0'; } DirTmp = wcsrchr (dir, L'\\'); if (wcslen(dir) - wcslen(DirTmp) > 0) { dir[wcslen(dir) - wcslen(DirTmp)] = L'\0'; } else { return NULL; } wcSciPathName = (wchar_t*)MALLOC((int)( wcslen(drive) + wcslen(dir) + 5) * sizeof(wchar_t)); if (wcSciPathName) { _wmakepath(wcSciPathName, drive, dir, NULL, NULL); if ( UnixStyle ) { int i = 0; for (i = 0; i < (int)wcslen(wcSciPathName); i++) { if (wcSciPathName[i] == L'\\') { wcSciPathName[i] = L'/'; } } } wcSciPathName[wcslen(wcSciPathName) - 1] = '\0'; SciPathName = wide_string_to_UTF8(wcSciPathName); FREE(wcSciPathName); wcSciPathName = NULL; } if (SciPathName) { setSCI(SciPathName); } return SciPathName; }
/**************************** Function Header ******************************** * bGetOEMUIInfo * Retrieves OEM custom UI DLL info. * * RETURNS: * (BOOL) TRUE for success whether this minidriver has a custom * or not. FALSE indicates an error retrieving info about a custom UI * DLL that should be present. * * HISTORY: * *****************************************************************************/ BOOL bGetOEMUIInfo( PRASDDUIINFO pInfo) { RES_ELEM OEMDLLName; BOOL bOK = FALSE; static LPCSTR aAPIs[OEM_IDX_MAX+1] = { OEM_WSTRDEVMODE, OEM_WSTRCOMMONUI, OEM_WSTRDEVQUERYPRINTEX, OEM_WSTRDEVICECAPS, OEM_WSTRUPGRADEPRINTER }; ASSERT(pInfo); TRY /* Bump lock count if it's already loaded. */ if (pInfo->OEMUIInfo.locks) { pInfo->OEMUIInfo.locks++; } /* Check for UI DLL name in gpc resources. */ else if (GetWinRes(&pInfo->WinResData, 1, RC_OEMUIDLL, &OEMDLLName)) { DWORD dwOldErrMode; wchar_t path[_MAX_PATH]; wchar_t drive[_MAX_DRIVE]; wchar_t dir[_MAX_DIR]; HINSTANCE hOEMLib; int i; /* Construct path from data file path. */ _wsplitpath(pInfo->PI.pwstrDataFileName, drive, dir, 0, 0 ); _wmakepath(path, drive, dir, (wchar_t *) OEMDLLName.pvResData, 0 ); /* Load DLL. It stays loaded until a call to vReleaseUIInfo. */ dwOldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS); hOEMLib = LoadLibrary(path); SetErrorMode(dwOldErrMode); if (hOEMLib == NULL) { LEAVE; } /* Get all UI DLL entry points. If any required are missing, abort. */ for (i = 0; i < OEM_IDX_MAX; i++) { pInfo->OEMUIInfo.UIEntryPoints[i] = (OEM_UIENTRYPOINT) GetProcAddress(hOEMLib, aAPIs[i]); } if (pInfo->OEMUIInfo.UIEntryPoints[OEM_IDX_DEVMODE] == 0 || pInfo->OEMUIInfo.UIEntryPoints[OEM_IDX_COMMONUI] == 0) { LEAVE; } pInfo->OEMUIInfo.cbEntryPoints = OEM_IDX_MAX+1; pInfo->OEMUIInfo.hOEMLib = hOEMLib; /* Mark OEM devmode's size as unknown. */ pInfo->OEMUIInfo.dwDevmodeExtra = (DWORD) -1L; /* Allocate custom UI heap. */ if ((pInfo->OEMUIInfo.hCommonUIHeap = HeapCreate(0, OEMUI_INITHEAPSIZE, OEMUI_MAXHEAPSIZE)) == 0) { LEAVE; } /* Done */ pInfo->OEMUIInfo.flags |= OEMUI_HASCUSTOMUI; pInfo->OEMUIInfo.locks++; } bOK = TRUE; ENDTRY FINALLY /* Clean up */ if (!bOK) { vReleaseOEMUIInfo(pInfo); } ENDFINALLY return(bOK); }