// The callback function BOOL CALLBACK EnumSystemCodePagesProc(LPTSTR cpStr) { //Convert code page string to number UINT cp = _ttoi(cpStr); if (!IsValidCodePage(cp)) return TRUE; //Get Code Page name CPINFOEX info; if (GetCPInfoEx(cp, 0, &info)) { #ifdef _DEBUG BOOLEAN found = FALSE; #endif for (int i = 1;i<CPLENALL;i++) if (CodePageNamesAll[i].CP == cp) { CodePageNamesAll[i].isValid = TRUE; CPLENSUPP++; #ifdef _DEBUG found = TRUE; #endif break; } #ifdef _DEBUG if (!found) { mir_tstrcat(unknownCP, info.CodePageName); mir_tstrcat(unknownCP, _T("\n")); } #endif } return TRUE; }
BOOL AreCpInfoLeads(DWORD nCP, UINT* pnMaxCharSize) { BOOL bLeads = FALSE; static CPINFOEX cpinfo = {}; static BOOL sbLeads = FALSE; if (cpinfo.CodePage != nCP) { if (!GetCPInfoEx(nCP, 0, &cpinfo) || (cpinfo.MaxCharSize <= 1)) { sbLeads = bLeads = FALSE; } else { sbLeads = bLeads = (cpinfo.LeadByte[0] && cpinfo.LeadByte[1]); // At lease one lead-bytes range } } else if (cpinfo.MaxCharSize > 1) { bLeads = sbLeads; } if (pnMaxCharSize) *pnMaxCharSize = cpinfo.MaxCharSize; return bLeads; }
static BOOL CALLBACK enum_cp(wchar_t *cpNum) { const auto cp = static_cast<UINT>(std::wcstoul(cpNum, nullptr, 10)); if (cp == CP_UTF8) return TRUE; // skip standard unicode CPINFOEX cpix; if (!GetCPInfoEx(cp, 0, &cpix)) { CPINFO cpi; if (!GetCPInfo(cp, &cpi)) return TRUE; cpix.MaxCharSize = cpi.MaxCharSize; wcscpy(cpix.CodePageName, cpNum); } if (cpix.MaxCharSize > 0) { string cp_data(cpix.CodePageName); // Windows: "XXXX (Name)", Wine: "Name" const auto OpenBracketPos = cp_data.find(L"("); if (OpenBracketPos != string::npos) { const auto CloseBracketPos = cp_data.rfind(L")"); if (CloseBracketPos != string::npos && CloseBracketPos > OpenBracketPos) { cp_data = cp_data.substr(OpenBracketPos + 1, CloseBracketPos - OpenBracketPos - 1); } } context->insert(cp, cpix.MaxCharSize, cp_data); } return TRUE; }
static BOOL CALLBACK print_cp_info (LPTSTR cp_str) { #ifdef IDNA_DEBUG_ENABLED CPINFOEX cp_info; #endif UINT cp = ATOI (cp_str); if(!IsValidCodePage(cp)) { #ifdef IDNA_DEBUG_ENABLED IDNA_DEBUG ("INVALID CODEPAGE: %u\n", cp); #endif dcassert(0); return (TRUE); } if (cp == cp_requested) cp_found = TRUE; #ifdef IDNA_DEBUG_ENABLED IDNA_DEBUG ("CP: %5u, ", cp); if (GetCPInfoEx(cp, 0, &cp_info)) { IDNA_DEBUG ("name: " STR_FMT "\n", cp_info.CodePageName); } else { IDNA_DEBUG ("name: <unknown>\n"); } #endif return (TRUE); }
DiagnosticsDialog::DiagnosticsDialog( QWidget *parent ) : QDialog( parent ) { setupUi( this ); setAttribute( Qt::WA_DeleteOnClose, true ); QString info; QTextStream s( &info ); s << "<b>" << tr("Locale (time-, number format / codepage):") << "</b> "; QLocale::Language language = QLocale::system().language(); QString locale = (language == QLocale::C ? "English/United States" : QLocale::languageToString( language ) ); CPINFOEX CPInfoEx; if ( GetCPInfoEx( GetConsoleCP(), 0, &CPInfoEx ) != 0 ) locale.append( " / " ).append( CPInfoEx.CodePageName ); s << locale << "<br />"; s << "<b>" << tr("User rights: ") << "</b>" << getUserRights() << "<br />"; QStringList base = Common::packages( QStringList() << "Eesti ID kaardi tarkvara", false ); if ( !base.isEmpty() ) s << "<b>" << tr("Base version:") << "</b> " << base.join( "<br />" ) << "<br />"; s << "<b>" << tr("ID-card utility version:") << "</b> "<< QCoreApplication::applicationVersion() << "<br />"; s << "<b>" << tr("OS:") << "</b> " << Common::applicationOs() << "<br />"; s << "<b>" << tr("CPU:") << "</b> " << getProcessor() << "<br /><br />"; s << "<b>" << tr("Library paths:") << "</b> " << QCoreApplication::libraryPaths().join( ";" ) << "<br />"; s << "<b>" << tr("Libraries") << ":</b><br />"; s << getLibVersion( "digidoc" ) << "<br />"; s << getLibVersion( "digidocpp" ) << "<br />"; s << getLibVersion( "advapi32" ) << "<br />"; s << getLibVersion( "crypt32" ) << "<br />"; s << getLibVersion( "winscard" ) << "<br />"; s << getLibVersion( "esteidcsp|esteidcm" ) << "<br />"; s << getLibVersion( "libeay32" ) << "<br />"; s << getLibVersion( "ssleay32" ) << "<br />"; s << getLibVersion( "opensc-pkcs11" ) << "<br />"; s << "QT (" << qVersion() << ")<br />" << "<br />"; s << "<b>" << tr("Smart Card service status: ") << "</b>" << " " << (isPCSCRunning() ? tr("Running") : tr("Not running")) << "<br /><br />"; s << "<b>" << tr("Card readers") << ":</b><br />" << getReaderInfo() << "<br />"; QStringList browsers = Common::packages( QStringList() << "Mozilla" << "Google Chrome" ); QSettings reg( "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer", QSettings::NativeFormat ); browsers << QString( "Internet Explorer (%1)" ).arg( reg.value( "Version" ).toString() ); s << "<b>" << tr("Browsers:") << "</b><br />" << browsers.join( "<br />" ) << "<br /><br />"; diagnosticsText->setHtml( info ); details = buttonBox->addButton( tr( "More info" ), QDialogButtonBox::HelpRole ); }
static BOOL GetSupportedCP(VOID) { UINT uiCPage, Number; LONG Count; INFCONTEXT infCont; LPCPAGE lpCPage; HANDLE hCPage; CPINFOEX cpInfEx; //TCHAR Section[MAX_PATH]; Count = SetupGetLineCountW(hIntlInf, L"CodePages"); if (Count <= 0) return FALSE; for (Number = 0; Number < (UINT)Count; Number++) { if (SetupGetLineByIndexW(hIntlInf, L"CodePages", Number, &infCont) && SetupGetIntField(&infCont, 0, (PINT)&uiCPage)) { if (!(hCPage = GlobalAlloc(GHND, sizeof(CPAGE)))) return FALSE; lpCPage = GlobalLock(hCPage); lpCPage->CPage = uiCPage; lpCPage->hCPage = hCPage; lpCPage->Status = 0; (lpCPage->Name)[0] = 0; if (GetCPInfoEx(uiCPage, 0, &cpInfEx)) { wcscpy(lpCPage->Name, cpInfEx.CodePageName); } else if (!SetupGetStringFieldW(&infCont, 1, lpCPage->Name, MAX_PATH, NULL)) { GlobalUnlock(hCPage); GlobalFree(hCPage); continue; } lpCPage->NextItem = PCPage; PCPage = lpCPage; } } return TRUE; }
/* * Get ANSI/system codepage. */ static UINT IDNA_GetCodePage (void) { #ifdef IDNA_DEBUG_ENABLED CPINFOEX CPinfo; UINT CP = 0; IDNA_DEBUG ("OEM codepage %u\n", GetOEMCP()); CP = GetACP(); if (GetCPInfoEx(CP, 0, &CPinfo)) { IDNA_DEBUG ("ACP-name " STR_FMT "\n", CPinfo.CodePageName); } return (CP); #else return GetACP(); #endif }
LPCSTR GetCpInfoLeads(DWORD nCP, UINT* pnMaxCharSize) { LPCSTR pszLeads = NULL; static CPINFOEX cpinfo = {}; static char szLeads[256] = {}; if (cpinfo.CodePage != nCP) { if (!GetCPInfoEx(nCP, 0, &cpinfo) || (cpinfo.MaxCharSize <= 1)) { ZeroStruct(szLeads); } else { int c = 0; _ASSERTE(countof(cpinfo.LeadByte)>=10); for (int i = 0; (i < 5) && cpinfo.LeadByte[i*2]; i++) { BYTE c1 = cpinfo.LeadByte[i*2]; BYTE c2 = cpinfo.LeadByte[i*2+1]; for (BYTE j = c1; (j <= c2) && (c < 254); j++, c++) { szLeads[c] = j; } } _ASSERTE(c && c <= 255); szLeads[c] = 0; pszLeads = szLeads; } } else if (cpinfo.MaxCharSize > 1) { pszLeads = szLeads; } if (pnMaxCharSize) *pnMaxCharSize = cpinfo.MaxCharSize; return pszLeads; }
// Получаем информацию о кодовой странице bool GetCodePageInfo(uintptr_t CodePage, CPINFOEX &CodePageInfoEx) { if (!GetCPInfoEx(static_cast<UINT>(CodePage), 0, &CodePageInfoEx)) { // GetCPInfoEx возвращает ошибку для кодовых страниц без имени (например 1125), которые // сами по себе работают. Так что, прежде чем пропускать кодовую страницу из-за ошибки, // пробуем получить для неё информауию через GetCPInfo CPINFO CodePageInfo; if (!GetCPInfo(static_cast<UINT>(CodePage), &CodePageInfo)) return false; CodePageInfoEx.MaxCharSize = CodePageInfo.MaxCharSize; CodePageInfoEx.CodePageName[0] = L'\0'; } // BUBUG: Пока не поддерживаем многобайтовые кодовые страницы if (CodePageInfoEx.MaxCharSize != 1) return (allow_m2 ? (CodePageInfoEx.MaxCharSize == 2) : false); return true; }
void Diagnostics::run() { QString info; QTextStream s( &info ); s << "<b>" << tr("Locale (time-, number format / codepage):") << "</b> "; QLocale::Language language = QLocale::system().language(); QString locale = (language == QLocale::C ? "English/United States" : QLocale::languageToString( language ) ); CPINFOEX CPInfoEx; if( GetCPInfoEx( GetConsoleCP(), 0, &CPInfoEx ) != 0 ) locale.append( " / " ).append( QString( (QChar*)CPInfoEx.CodePageName ) ); s << locale << "<br />"; emit update( info ); info.clear(); s << "<b>" << tr("User rights: ") << "</b>" << getUserRights() << "<br />"; emit update( info ); info.clear(); QStringList base = Common::packages( QStringList() << "Eesti ID-kaardi tarkvara" << "Estonian ID-card software", false ); if( !base.isEmpty() ) s << "<b>" << tr("Base version:") << "</b> " << base.join( "<br />" ) << "<br />"; s << "<b>" << tr("Application version:") << "</b> "<< QCoreApplication::applicationVersion() #ifdef INTERNATIONAL << " INTERNATIONAL" #endif << "<br />"; emit update( info ); info.clear(); s << "<b>" << tr("OS:") << "</b> " << Common::applicationOs() << "<br />"; SYSTEM_INFO sysinfo; GetSystemInfo( &sysinfo ); s << "<b>" << tr("CPU:") << "</b> " << QString::number( sysinfo.dwProcessorType ) << "<br /><br />"; emit update( info ); info.clear(); s << "<b>" << "URLs:" << "</b>"; const QHash<QString,QString> urls = qApp->urls(); for(auto i = urls.constBegin(); i != urls.constEnd(); ++i) s << "<br />" << i.key() << ": " << i.value(); s << "<br /><br />"; s << "<b>" << tr("Arguments:") << "</b> " << qApp->arguments().join(" ") << "<br />"; s << "<b>" << tr("Library paths:") << "</b> " << QCoreApplication::libraryPaths().join( ";" ) << "<br />"; s << "<b>" << tr("Libraries") << ":</b><br />" << "QT (" << qVersion() << ")<br />"; Q_FOREACH( const QString &lib, QStringList() << "digidoc" << "digidocpp" << "qdigidocclient.exe" << "qesteidutil.exe" << "id-updater.exe" << "esteidcsp" << "esteidcm" << "opensc-pkcs11" << "esteid-pkcs11" << "EsteidShellExtension" << "esteid-plugin-ie" << "npesteid-firefox-plugin" << "chrome-token-signing.exe" << "zlib1" << "libeay32" << "ssleay32" << "xerces-c_3_1" << "xsec_1_7" << "libxml2" << "advapi32" << "crypt32" << "winscard" ) { DWORD infoHandle = 0; LONG sz = GetFileVersionInfoSize( LPCWSTR(lib.utf16()), &infoHandle ); if( !sz ) continue; QByteArray data( sz * 2, 0 ); if( !GetFileVersionInfoW( LPCWSTR(lib.utf16()), 0, sz, data.data() ) ) continue; VS_FIXEDFILEINFO *info = 0; UINT len = 0; if( !VerQueryValueW( data.constData(), L"\\", (LPVOID*)&info, &len ) ) continue; s << QString( "%1 (%2.%3.%4.%5)" ).arg( lib ) .arg( HIWORD(info->dwFileVersionMS) ) .arg( LOWORD(info->dwFileVersionMS) ) .arg( HIWORD(info->dwFileVersionLS) ) .arg( LOWORD(info->dwFileVersionLS) ) << "<br />"; } s << "<br />"; emit update( info ); info.clear(); enum { Running, Stopped, NotFound } atrfiltr = NotFound, certprop = NotFound; if( SC_HANDLE h = OpenSCManager( 0, 0, SC_MANAGER_CONNECT ) ) { if( SC_HANDLE s = OpenService( h, L"atrfiltr", SERVICE_QUERY_STATUS ) ) { SERVICE_STATUS status; QueryServiceStatus( s, &status ); atrfiltr = (status.dwCurrentState == SERVICE_RUNNING) ? Running : Stopped; CloseServiceHandle( s ); } if( SC_HANDLE s = OpenService( h, L"CertPropSvc", SERVICE_QUERY_STATUS )) { SERVICE_STATUS status; QueryServiceStatus( s, &status ); certprop = (status.dwCurrentState == SERVICE_RUNNING) ? Running : Stopped; CloseServiceHandle( s ); } CloseServiceHandle( h ); } s << "<br /><b>" << tr("ATRfiltr service status: ") << "</b>" << " "; switch( atrfiltr ) { case NotFound: s << tr("Not found"); break; case Stopped: s << tr("Not running"); break; case Running: s << tr("Running"); break; } s << "<br /><b>" << tr("Certificate Propagation service status: ") << "</b>" << " "; switch( certprop ) { case NotFound: s << tr("Not found"); break; case Stopped: s << tr("Not running"); break; case Running: s << tr("Running"); break; } s << "<br />"; getReaderInfo( s ); emit update( info ); info.clear(); QStringList browsers = Common::packages( QStringList() << "Firefox" << "Google Chrome" ); QSettings reg( "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer", QSettings::NativeFormat ); browsers << QString( "Internet Explorer (%1)" ).arg( reg.value("svcVersion", reg.value( "Version" ) ).toString() ); s << "<br /><br /><b>" << tr("Browsers:") << "</b><br />" << browsers.join( "<br />" ) << "<br /><br />"; emit update( info ); info.clear(); }
char* iupdrvLocaleInfo(void) { CPINFOEX info; GetCPInfoEx(CP_ACP, 0, &info); return iupStrGetMemoryCopy(info.CodePageName); }
char* iupdrvGetGlobal(const char* name) { if (iupStrEqual(name, "VIRTUALSCREEN")) { int x = GetSystemMetrics(SM_XVIRTUALSCREEN); int y = GetSystemMetrics(SM_YVIRTUALSCREEN); int w = GetSystemMetrics(SM_CXVIRTUALSCREEN); int h = GetSystemMetrics(SM_CYVIRTUALSCREEN); return iupStrReturnStrf("%d %d %d %d", x, y, w, h); } if (iupStrEqual(name, "MONITORSINFO")) { int i; int monitors_count = GetSystemMetrics(SM_CMONITORS); RECT* monitors_rect = malloc(monitors_count*sizeof(RECT)); char* str = iupStrGetMemory(monitors_count*50); char* pstr = str; win_monitor_index = 0; EnumDisplayMonitors(NULL, NULL, winGlobalMonitorInfoEnum, (LPARAM)monitors_rect); for (i=0; i < monitors_count; i++) pstr += sprintf(pstr, "%d %d %d %d\n", (int)monitors_rect[i].left, (int)monitors_rect[i].top, (int)(monitors_rect[i].right-monitors_rect[i].left), (int)(monitors_rect[i].bottom-monitors_rect[i].top)); free(monitors_rect); return str; } if (iupStrEqual(name, "TRUECOLORCANVAS")) { return iupStrReturnBoolean(iupdrvGetScreenDepth() > 8); } if (iupStrEqual(name, "UTF8MODE")) { return iupStrReturnBoolean(iupwinStrGetUTF8Mode()); } if (iupStrEqual(name, "UTF8MODE_FILE")) { return iupStrReturnBoolean(iupwinStrGetUTF8ModeFile()); } if (iupStrEqual(name, "DLL_HINSTANCE")) { return (char*)iupwin_dll_hinstance; } if (iupStrEqual(name, "COMCTL32VER6")) { return iupStrReturnBoolean(iupwin_comctl32ver6); } if (iupStrEqual(name, "SYSTEMCODEPAGE")) { CPINFOEX info; GetCPInfoEx(CP_ACP, 0, &info); return iupStrReturnInt(info.CodePage); } if (iupStrEqual(name, "LASTERROR")) { DWORD error = GetLastError(); if (error) { LPTSTR lpMsgBuf = NULL; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM| FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, (LPTSTR)&lpMsgBuf, /* weird but that's correct */ 0, NULL); if (lpMsgBuf) { char* str = iupStrReturnStr(iupwinStrFromSystem(lpMsgBuf)); LocalFree(lpMsgBuf); return str; } else return "Unknown Error"; } } if (iupStrEqual(name, "DWM_COMPOSITION")) { typedef HRESULT(STDAPICALLTYPE *PtrDwmIsCompositionEnabled)(BOOL*); static PtrDwmIsCompositionEnabled dwmIsCompositionEnabled = NULL; if (dwmIsCompositionEnabled == NULL) { HMODULE dwmLibrary = LoadLibrary(TEXT("dwmapi.dll")); if (dwmLibrary) dwmIsCompositionEnabled = (PtrDwmIsCompositionEnabled)GetProcAddress(dwmLibrary, "DwmIsCompositionEnabled"); } if (dwmIsCompositionEnabled != NULL) { /* windows vista or higher (has aero): see if disabled */ BOOL enabled; dwmIsCompositionEnabled(&enabled); return iupStrReturnBoolean(enabled); } else return NULL; } return NULL; }
int main(int argc, char **argv) { DWORD cp; CPINFOEX info; struct cp *cur; int rnd = 0; /*if (argc < 2) { printf("Usage: cpinfoex cp_id\n"); return 0; } cp = atoi(argv[1]);*/ #if 0 /* Ref: http://www.iana.org/assignments/character-sets/character-sets.xhtml https://msdn.microsoft.com/en-us/goglobal/bb964653 http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/ */ #endif /* struct php_win32_cp { DWORD id; DWORD to_w_fl; DWORD from_w_fl; DWORD char_size; char *name; char *enc; char *desc; }; */ /*printf("struct php_win32_cp {\n\tDWORD id;\n\tDWORD to_w_fl;\n\tDWORD from_w_fl;\n\tDWORD char_size;\n\tchar *name;\n\tchar *enc;\n\tchar *desc;\n};\n\n"); */ printf("/* Autogenerated file. Update cp_enc_map_gen.c and regen like \n" " cp_enc_map_gen.exe > cp_enc_map.c \n*/\n\n"); printf("static const struct php_win32_cp php_win32_cp_map[] = {"); cur = &cp_map[0]; #ifdef ORDER_IT while (rnd <= 2 && ++rnd && (cur = &cp_map[0])) #endif while (cur->desc != NULL) { if (!IsValidCodePage(cur->id)) { #ifdef ORDER_IT if (2 == rnd) #endif printf("\t/* %u is invalid */\n", cur->id); //printf("#if 0\n\t{ %u, 0, \"%s\", \"%s\" },\n#endif\n", cur->id, cur->name, cur->desc); } else if (GetCPInfoEx(cur->id, 0, &info)) { DWORD to_w_fl = 0, from_w_fl = 0; if (65001U == cur->id || 54936U == cur->id) { from_w_fl = WC_ERR_INVALID_CHARS; to_w_fl = MB_ERR_INVALID_CHARS; } //printf("\t{ %u, %u, \"%s\", \"%s\" },\n", cur->id, info.MaxCharSize, cur->name, cur->desc); if (!cur->enc[0]) { #ifdef ORDER_IT if (2 == rnd) #endif //printf("\t/* { %u, %u, \"%s\", NULL, \"%s\" }, */\n", info.CodePage, info.MaxCharSize, cur->name, info.CodePageName); printf("\t{ %u, %u, %u, %u, \"%s\", NULL, \"%s\" },\n", info.CodePage, to_w_fl, from_w_fl, info.MaxCharSize, cur->name, info.CodePageName); } else { #ifdef ORDER_IT if (1 == rnd) #endif printf("\t{ %u, %u, %u, %u, \"%s\", \"%s\", \"%s\" },\n", info.CodePage, to_w_fl, from_w_fl, info.MaxCharSize, cur->name, cur->enc, info.CodePageName); } } cur++; } printf("};\n\n"); return 0; }