win32resourcebundle.cpp

来自「这是VCF框架的代码」· C++ 代码 · 共 809 行 · 第 1/2 页

CPP
809
字号
		VCF_ASSERT( key == L"VS_VERSION_INFO");	BYTE* node = (BYTE*) &versionInfo->szKey[wcslen(versionInfo->szKey)+1];	VS_FIXEDFILEINFO* fixedFileInfo = (VS_FIXEDFILEINFO*) VS_ROUNDPOS(node, versionInfo, 4);	if (versionInfo->wValueLength) {		//showFIXEDFILEINFO(fixedFileInfo);	// Show the 'Value' element	}	std::pair<String,String> entry;		// Iterate over the 'Children' elements of VS_VERSIONINFO (either StringFileInfo or VarFileInfo)	StringFileInfo_W* strFileInfo = (StringFileInfo_W*) VS_ROUNDPOS(((byte*)fixedFileInfo) + versionInfo->wValueLength, fixedFileInfo, 4);	for ( ; ((byte*) strFileInfo) < (((byte*) versionInfo) + versionInfo->wLength); strFileInfo = (StringFileInfo_W*)VS_ROUNDPOS((((byte*) strFileInfo) + strFileInfo->wLength), strFileInfo, 4)) { // StringFileInfo_W / VarFileInfo		if (!wcscmp(strFileInfo->szKey, L"StringFileInfo")) {			// The current child is a StringFileInfo element			VCF_ASSERT(1 == strFileInfo->wType);			VCF_ASSERT(!strFileInfo->wValueLength);			// Iterate through the StringTable elements of StringFileInfo			StringTable_W* strTable = (StringTable_W*) VS_ROUNDPOS(&strFileInfo->szKey[wcslen(strFileInfo->szKey)+1], strFileInfo, 4);			for ( ; ((byte*) strTable) < (((byte*) strFileInfo) + strFileInfo->wLength); strTable = (StringTable_W*)VS_ROUNDPOS((((byte*) strTable) + strTable->wLength), strTable, 4)) {								entry.first = String(L"LangID");				entry.second = strTable->szKey;				map.insert( entry );				VCF_ASSERT(!strTable->wValueLength);				// Iterate through the String elements of StringTable_W				String_W* strElement = (String_W*) VS_ROUNDPOS(&strTable->szKey[wcslen(strTable->szKey)+1], strTable, 4);				for ( ; ((byte*) strElement) < (((byte*) strTable) + strTable->wLength); strElement = (String_W*) VS_ROUNDPOS((((byte*) strElement) + strElement->wLength), strElement, 4)) {					wchar_t* strValue = (wchar_t*) VS_ROUNDPOS(&strElement->szKey[wcslen(strElement->szKey)+1], strElement, 4);					//printf("  %-18S: %.*S\n", strElement->szKey, strElement->wValueLength, strValue); // print <sKey> : <sValue>					entry.first = strElement->szKey;					entry.second.assign( strValue, strElement->wValueLength );					map.insert( entry );				}			}		}		else {			// The current child is a VarFileInfo element			VCF_ASSERT(1 == strFileInfo->wType); // ?? it just seems to be this way...			VarFileInfo_W* varFileInfo = (VarFileInfo_W*) strFileInfo;			VCF_ASSERT(!wcscmp(varFileInfo->szKey, L"VarFileInfo"));			VCF_ASSERT(!varFileInfo->wValueLength);			// Iterate through the Var elements of VarFileInfo (there should be only one, but just in case...)			Var_W* element = (Var_W*) VS_ROUNDPOS(&varFileInfo->szKey[wcslen(varFileInfo->szKey)+1], varFileInfo, 4);			for ( ; ((byte*) element) < (((byte*) varFileInfo) + varFileInfo->wLength); element = (Var_W*)VS_ROUNDPOS((((byte*) element) + element->wLength), element, 4)) {								entry.first = element->szKey;								// Iterate through the array of pairs of 16-bit language ID values that make up the standard 'Translation' VarFileInfo element.				WORD* wordElement = (WORD*) VS_ROUNDPOS(&element->szKey[wcslen(element->szKey)+1], element, 4);				for (WORD* wpos = wordElement ; ((byte*) wpos) < (((byte*) wordElement) + element->wValueLength); wpos+=2) {					entry.second += StringUtils::format( Format(L"%04x%04x ") % (int)*wpos++ % (int)(*(wpos+1)) );				}				map.insert( entry );			}		}	}	delete [] buf;}void getVersionInfoA( VersionMap& map, const String& fileName ){	char fileNameA[MAX_PATH];	int sz = minVal<int>( MAX_PATH,fileName.size() );	fileName.copy( fileNameA,sz );	fileNameA[sz] = 0;	DWORD dummy;	DWORD size = GetFileVersionInfoSizeA( fileNameA, &dummy);	if ( 0 == size ) {		return;	}	unsigned char* buf = new unsigned char[size];	memset(buf, 0, size*sizeof(unsigned char));		if ( !GetFileVersionInfoA(fileNameA, 0, size, buf) ) {		delete [] buf;		return;	}	VS_VERSIONINFO_A* versionInfo = (VS_VERSIONINFO_A*)buf;	String key = versionInfo->szKey;		VCF_ASSERT( key == L"VS_VERSION_INFO");	BYTE* node = (BYTE*) &versionInfo->szKey[strlen(versionInfo->szKey)+1];	VS_FIXEDFILEINFO* fixedFileInfo = (VS_FIXEDFILEINFO*) VS_ROUNDPOS(node, versionInfo, 4);	if (versionInfo->wValueLength) {		//showFIXEDFILEINFO(fixedFileInfo);	// Show the 'Value' element	}	std::pair<String,String> entry;		// Iterate over the 'Children' elements of VS_VERSIONINFO (either StringFileInfo or VarFileInfo)	StringFileInfo_A* strFileInfo = (StringFileInfo_A*) VS_ROUNDPOS(((byte*)fixedFileInfo) + versionInfo->wValueLength, fixedFileInfo, 4);	for ( ; ((byte*) strFileInfo) < (((byte*) versionInfo) + versionInfo->wLength); strFileInfo = (StringFileInfo_A*)VS_ROUNDPOS((((byte*) strFileInfo) + strFileInfo->wLength), strFileInfo, 4)) { // StringFileInfo_A / VarFileInfo		if (!strcmp(strFileInfo->szKey, "StringFileInfo")) {			// The current child is a StringFileInfo element			VCF_ASSERT(1 == strFileInfo->wType);			VCF_ASSERT(!strFileInfo->wValueLength);			// Iterate through the StringTable elements of StringFileInfo			StringTable_A* strTable = (StringTable_A*) VS_ROUNDPOS(&strFileInfo->szKey[strlen(strFileInfo->szKey)+1], strFileInfo, 4);			for ( ; ((byte*) strTable) < (((byte*) strFileInfo) + strFileInfo->wLength); strTable = (StringTable_A*)VS_ROUNDPOS((((byte*) strTable) + strTable->wLength), strTable, 4)) {								entry.first = String(L"LangID");				entry.second = strTable->szKey;				map.insert( entry );				VCF_ASSERT(!strTable->wValueLength);				// Iterate through the String elements of StringTable_W				String_A* strElement = (String_A*) VS_ROUNDPOS(&strTable->szKey[strlen(strTable->szKey)+1], strTable, 4);				for ( ; ((byte*) strElement) < (((byte*) strTable) + strTable->wLength); strElement = (String_A*) VS_ROUNDPOS((((byte*) strElement) + strElement->wLength), strElement, 4)) {					char* strValue = (char*) VS_ROUNDPOS(&strElement->szKey[strlen(strElement->szKey)+1], strElement, 4);										entry.first = strElement->szKey;					entry.second.assign( strValue, strElement->wValueLength );					map.insert( entry );				}			}		}		else {			// The current child is a VarFileInfo element			VCF_ASSERT(1 == strFileInfo->wType); // ?? it just seems to be this way...			VarFileInfo_A* varFileInfo = (VarFileInfo_A*) strFileInfo;			VCF_ASSERT(!strcmp(varFileInfo->szKey, "VarFileInfo"));			VCF_ASSERT(!varFileInfo->wValueLength);			// Iterate through the Var elements of VarFileInfo (there should be only one, but just in case...)			Var_A* element = (Var_A*) VS_ROUNDPOS(&varFileInfo->szKey[strlen(varFileInfo->szKey)+1], varFileInfo, 4);			for ( ; ((byte*) element) < (((byte*) varFileInfo) + varFileInfo->wLength); element = (Var_A*)VS_ROUNDPOS((((byte*) element) + element->wLength), element, 4)) {								entry.first = element->szKey;								// Iterate through the array of pairs of 16-bit language ID values that make up the standard 'Translation' VarFileInfo element.				WORD* wordElement = (WORD*) VS_ROUNDPOS(&element->szKey[strlen(element->szKey)+1], element, 4);				for (WORD* wpos = wordElement ; ((byte*) wpos) < (((byte*) wordElement) + element->wValueLength); wpos+=2) {					entry.second += StringUtils::format( Format(L"%04x%04x ") % (int)*wpos++ % (int)(*(wpos+1)) );				}				map.insert( entry );			}		}	}	delete [] buf;}class FindVersionInfoVal {public:	FindVersionInfoVal( const String& value ): value_(StringUtils::lowerCase( value )){};	bool operator() ( const std::pair<String,String>& x ) const {		String x1 = StringUtils::lowerCase( x.first );		int pos = x1.find( value_ );		return pos != String::npos;	}	String value_;};ProgramInfo* Win32ResourceBundle::getProgramInfoFromFileName( const String& fileName ){	ProgramInfo* result = NULL;	VersionMap map;	if ( System::isUnicodeEnabled() ) {		getVersionInfoW( map, fileName );	}			else {		getVersionInfoA( map, fileName );	}	if ( !map.empty() ) {		String name;		String programFileName;		String author;		String copyright;		String company;		String description;		String programVersion;		String fileVersion;			VersionMap::iterator found =  std::find_if( map.begin(), map.end(), FindVersionInfoVal("Author") );		if ( found != map.end() ) {			author = found->second;		}		found = std::find_if( map.begin(), map.end(), FindVersionInfoVal("ProductName") );		if ( found != map.end() ) {			name = found->second;		}		found = std::find_if( map.begin(), map.end(), FindVersionInfoVal("copyright") );		if ( found != map.end() ) {			copyright = found->second;		}		found = std::find_if( map.begin(), map.end(), FindVersionInfoVal("ProductVersion") );		if ( found != map.end() ) {			fileVersion = found->second;		}		found = std::find_if( map.begin(), map.end(), FindVersionInfoVal("Company") );		if ( found != map.end() ) {			company = found->second;		}		found = std::find_if( map.begin(), map.end(), FindVersionInfoVal("Comments") );		if ( found != map.end() ) {			description = found->second;		}		found = std::find_if( map.begin(), map.end(), FindVersionInfoVal("FileVersion") );		if ( found != map.end() ) {			programVersion = found->second;		}				programFileName = fileName;		result = new ProgramInfo( name, programFileName, author, copyright, company, description, programVersion, fileVersion, "", "" );	}	return result;}ProgramInfo* Win32ResourceBundle::getProgramInfo(){	String fileName;	if ( System::isUnicodeEnabled() ) {		VCF::WideChar tmp[MAX_PATH];				::GetModuleFileNameW( getResourceInstance(), tmp, MAX_PATH );		fileName = tmp;			}			else {		char tmp[MAX_PATH];		::GetModuleFileNameA( getResourceInstance(), tmp, MAX_PATH );		fileName = tmp;			}	return Win32ResourceBundle::getProgramInfoFromFileName(fileName);}/***CVS Log info*$Log$*Revision 1.4  2006/04/07 02:35:36  ddiego*initial checkin of merge from 0.6.9 dev branch.**Revision 1.3.2.5  2006/03/06 15:01:18  kiklop74*fix for borland compiler**Revision 1.3.2.4  2005/12/28 20:43:40  kiklop74*Fixed error - missing strcmp**Revision 1.3.2.3  2005/09/21 02:21:53  ddiego*started to integrate jpeg support directly into graphicskit.**Revision 1.3.2.2  2005/09/19 04:55:56  ddiego*minor updates.**Revision 1.3.2.1  2005/09/07 04:19:55  ddiego*filled in initial code for help support.**Revision 1.3  2005/07/09 23:15:07  ddiego*merging in changes from devmain-0-6-7 branch.**Revision 1.2.2.3  2005/04/13 02:50:45  iamfraggle*Enable Unicode in CodeWarrior**Revision 1.2.2.2  2005/04/09 17:21:35  marcelloptr*bugfix [ 1179853 ] memory fixes around memset. Documentation. DocumentManager::saveAs and DocumentManager::reload**Revision 1.2.2.1  2005/03/15 01:51:52  ddiego*added support for Format class to take the place of the*previously used var arg funtions in string utils and system. Also replaced*existing code in the framework that made use of the old style var arg*functions.**Revision 1.2  2004/12/01 04:31:42  ddiego*merged over devmain-0-6-6 code. Marcello did a kick ass job*of fixing a nasty bug (1074768VCF application slows down modal dialogs.)*that he found. Many, many thanks for this Marcello.**Revision 1.1.2.9  2004/11/21 00:19:11  ddiego*fixed a few more res loading bugs, and added yet another resource example.**Revision 1.1.2.8  2004/11/17 19:02:55  ddiego*fixed compiler error in Win32ResourceBundle::getResource() method.**Revision 1.1.2.7  2004/11/17 04:52:49  ddiego*added some minor fixes to win32 resource loading, and added 2 new examples that demonstrate basic resource loading and basic usage of dialogs.**Revision 1.1.2.6  2004/09/17 11:38:06  ddiego*added program info support in library and process classes.**Revision 1.1.2.5  2004/09/16 03:26:26  ddiego*fixed it so we can now get program information from a resource bundle. This can be embedded in the exe like in windows, or read from an external file a la OS X info.plist xml files.**Revision 1.1.2.4  2004/09/15 21:14:28  ddiego*added support for getting program info from resource bundle.**Revision 1.1.2.3  2004/08/27 03:50:46  ddiego*finished off therest of the resource refactoring code. We*can now load in resoruces either from the burned in data in the .exe*or from resource file following the Apple bundle layout scheme.**Revision 1.1.2.2  2004/08/26 04:29:28  ddiego*added support for getting the resource directory to the System class.**Revision 1.1.2.1  2004/08/21 21:06:53  ddiego*migrated over the Resource code to the FoudationKit.*Added support for a GraphicsResourceBundle that can get images.*Changed the AbstractApplication class to call the System::getResourceBundle.*Updated the various example code accordingly.**Revision 1.2  2004/08/07 02:49:11  ddiego*merged in the devmain-0-6-5 branch to stable**Revision 1.1.2.3  2004/07/09 18:48:05  ddiego*added locale translation support for most classes**Revision 1.1.2.2  2004/04/29 03:43:16  marcelloptr*reformatting of source files: macros and csvlog and copyright sections**Revision 1.1.2.1  2004/04/28 00:28:21  ddiego*migration towards new directory structure**Revision 1.16.8.1  2004/04/21 02:17:26  ddiego*checking in change to FoundationKit, GraphicsKit and Application*Kit to support unicode in Win32**Revision 1.16  2003/05/17 20:37:38  ddiego*this is the checkin for the 0.6.1 release - represents the merge over from*the devmain-0-6-0 branch plus a few minor bug fixes**Revision 1.15.2.1  2003/03/12 03:12:41  ddiego*switched all member variable that used the "m_"<name> prefix to* <name>"_" suffix nameing standard.*Also changed all vcf builder files to accomadate this.*Changes were made to the Stream classes to NOT multiple inheritance and to*be a little more correct. Changes include breaking the FileStream into two*distinct classes, one for input and one for output.**Revision 1.15  2003/02/26 04:30:51  ddiego*merge of code in the devmain-0-5-9 branch into the current tree.*most additions are in the area of the current linux port, but the major*addition to this release is the addition of a Condition class (currently*still under development) and the change over to using the Delegate class*exclusively from the older event handler macros.**Revision 1.14.14.1  2003/01/08 00:19:53  marcelloptr*mispellings and newlines at the end of all source files**Revision 1.14  2002/05/09 03:10:45  ddiego*merged over code from development branch devmain-0-5-1a into the main CVS trunk**Revision 1.13.4.2  2002/04/27 15:52:31  ddiego*Changed a bunch of files include and made it a bit faster and added better include*guards in the common headers**Revision 1.13.4.1  2002/04/08 20:55:30  zzack*changed include style**Revision 1.13  2002/01/24 01:46:49  ddiego*added a cvs "log" comment to the top of all files in vcf/src and vcf/include*to facilitate change tracking**/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?