/****************************** Module Header ******************************\ * Module Name: femgrate.c * * Copyright (c) 1985 - 1999, Microsoft Corporation * * FEMGRATE, main functions * \***************************************************************************/ #include "femgrate.h" #include FUNC_DIR FuncDir[FUNC_NumofFunctions] = { {'l',FUNC_PatchInLogon}, {'s',FUNC_PatchInSetup}, {'u',FUNC_PatchFEUIFont}, {'p',FUNC_PatchPreload}, {'t',FUNC_PatchTest}, {'c',FUNC_PatchCHSAnsiEMB} }; HINSTANCE ghInst=NULL; // // Function Declaration // // // Max size of a value's data // // // Max number of Functions NO_FUNCTION - 1 // UINT GetFunctions( int *pCmdList, int nNum) { int i,j; int nMaxNum; int nCommands; if ((__argc <=1) || nNum < 2) return 0; // // reserved one cell for terminiator // nMaxNum = (__argc-1 > nNum-1) ? nNum-1 : __argc-1; for (nCommands = 0,i=1; i <= nMaxNum; i++) { if (__argv[i][0] != '-') { continue; } for (j=0; j (KL_NAMELENGTH) * sizeof(TCHAR))) { // // wrong data, ignore it // continue; } if (bFoundDefaultLocale) { continue; } // if (_tcsncmp(szDefaultLocaleID,szLayoutID,KL_NAMELENGTH-1)==0) { if (_tcsncmp(L"123",L"123",KL_NAMELENGTH-1)==0) { bFoundDefaultLocale = TRUE; continue; } if (_tcsncmp(szLayoutID,TEXT("00000409"),KL_NAMELENGTH-1)==0) { nFound0409 = i; } } } if (bReplaceDefaultLCID) { if (!bFoundDefaultLocale) { if (nFound0409 != -1 ) { wsprintf(szPreloadID,TEXT("%d"),nFound0409); lResult = RegSetValueEx(hkLayoutPreload, szPreloadID, 0, REG_SZ, (LPBYTE) szDefaultLocaleID, sizeof(TCHAR) * KL_NAMELENGTH); if (lResult != ERROR_SUCCESS) { DebugMsg((DM_VERBOSE,TEXT("IMECONV: Failed to set %s = %s \n"),szPreloadID,szLayoutID)); } } } } RegCloseKey (hkLayoutPreload); if (i > 999) return FALSE; else return TRUE; } const TCHAR g_szCaptionFont[] = TEXT("CaptionFont"); const TCHAR g_szSmCaptionFont[] = TEXT("SmCaptionFont"); const TCHAR g_szMenuFont[] = TEXT("MenuFont"); const TCHAR g_szStatusFont[] = TEXT("StatusFont"); const TCHAR g_szMessageFont[] = TEXT("MessageFont"); const TCHAR g_szIconFont[] = TEXT("IconFont"); const LPCTSTR g_rgpszFontMetrics[] = { g_szCaptionFont, g_szSmCaptionFont, g_szMenuFont, g_szStatusFont, g_szMessageFont, g_szIconFont}; BOOL FixIncorrectCharSet(LOGFONT *plf) { struct NameCharSet { char szFaceName[LF_FACESIZE*2]; BYTE bCharSet; } Pairs[] = { {"\x74\xad\xbc\xb9\x00\x00",0x81}, {"\xb0\x65\x30\x7d\x0e\x66\xd4\x9a\x00\x00",0x88}, {"\x8b\x5b\x53\x4f\x00\x00",0x86} }; int i; for (i=0; ilfFaceName,(LPTSTR)(Pairs[i].szFaceName)) == 0) { if (plf->lfCharSet != Pairs[i].bCharSet) { plf->lfCharSet = Pairs[i].bCharSet; DebugMsg((DM_VERBOSE,TEXT("FixIncorrectCharSet, we found and we fixed. [%X]\n"),Pairs[i].bCharSet)); return TRUE; } } } DebugMsg((DM_VERBOSE,TEXT("FixIncorrectCharSet, Input %s, %d, no fix needed !\n"),plf->lfFaceName,plf->lfCharSet)); return TRUE; } BOOL FixMSPGothic(LOGFONT *plf) { int i; char szMSPGothic[LF_FACESIZE*2] = "\x2D\xFF\x33\xFF\x20\x00\x30\xFF\xB4\x30\xB7\x30\xC3\x30\xAF\x30\x00\x00"; DebugMsg((DM_VERBOSE,TEXT("FixMSPGothic, [%s] == [%s] ?\n"),plf->lfFaceName,szMSPGothic)); if (lstrcmp(plf->lfFaceName,(LPTSTR)szMSPGothic) == 0) { lstrcpy(plf->lfFaceName,TEXT("MS UI Gothic")); DebugMsg((DM_VERBOSE,TEXT("FixMSPGothic, we found and we fixed. [%s]\n"),plf->lfFaceName)); return TRUE; } return TRUE; } BOOL UpdateUIFont( BOOL bJapan, HKEY hkeyMetrics, LPCTSTR pszValueName, LOGFONT *plf ) { DWORD dwResult = ERROR_SUCCESS; LOGFONT lfCopy; BOOL bOkToUpdate = FALSE; DebugMsg((DM_VERBOSE,TEXT("UpdateUIFont, Starting ...\n"))); // // First see if this face name should be updated. // if (bJapan) { bOkToUpdate = FixMSPGothic(plf); } else { bOkToUpdate = FixIncorrectCharSet(plf); } if (bOkToUpdate) { // // Yep. Update the face name string in the logfont. // Also make sure that the point size is 8 or greater // if we're updating the icon font. // DebugMsg((DM_VERBOSE,TEXT("UpdateUIFont, update %s 's charset %X\n"), plf->lfFaceName, plf->lfCharSet)); dwResult = RegSetValueEx(hkeyMetrics, pszValueName, 0, REG_BINARY, (const LPBYTE)plf, sizeof(*plf)); if (ERROR_SUCCESS != dwResult) { DebugMsg((DM_VERBOSE,TEXT("Error %d setting NC font data for \"%s\"\n"), dwResult, pszValueName)); return FALSE; } } return TRUE; } void FixCurrentSchemeName(HINF hInf) { HKEY hkeyAppearance; TCHAR szCurrentSchemeName[MAX_PATH]; DWORD cbValue; DWORD dwType; INFCONTEXT InfContext; UINT LineCount,LineNo; LPCTSTR szSectionName = TEXT("CurrentScheme"); LPCTSTR pszStandard; LPCTSTR pszClassic; DWORD dwResult = ERROR_SUCCESS; if(hInf == INVALID_HANDLE_VALUE) { DebugMsg((DM_VERBOSE,TEXT("[FixCurrentSchemeName] Open femgrate.inf failed !\n"))); goto Exit1; } LineCount = (UINT)SetupGetLineCount(hInf,szSectionName); if((LONG)LineCount <= 0) { DebugMsg((DM_VERBOSE,TEXT("[FixCurrentSchemeName] line count == 0 !\n"))); goto Exit1; } dwResult = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance"), 0, KEY_ALL_ACCESS, &hkeyAppearance); if (ERROR_SUCCESS != dwResult ) { DebugMsg((DM_VERBOSE,TEXT("[FixCurrentSchemeName] Key Control Panel\\Appearance doesn't exist\r\n"))); goto Exit1; } cbValue = sizeof(szCurrentSchemeName); dwResult = RegQueryValueEx(hkeyAppearance, TEXT("Current"), NULL, &dwType, (LPBYTE)szCurrentSchemeName, &cbValue); if (ERROR_SUCCESS != dwResult) { DebugMsg((DM_VERBOSE,TEXT("[FixCurrentSchemeName] No Current value, not an error !\r\n"))); goto Exit2; } for(LineNo=0; LineNo