17 #pragma comment(lib,"version.lib")
48 CFileVersion(
void) : m_pFileInfo(NULL), m_pLangCodePage(NULL), m_langCodePageSize(0)
59 return m_pFileInfo != NULL;
69 bool Open(LPCTSTR lpszFile = NULL, HINSTANCE hInst = NULL)
72 if ( lpszFile != NULL )
78 ::GetModuleFileName(hInst, strFile.
GetBuffer(MAX_PATH), MAX_PATH);
82 DWORD size = ::GetFileVersionInfoSize(strFile.
GetBuffer(), &dummy);
86 ZeroMemory(m_workMem, size);
87 if ( ::GetFileVersionInfo(strFile.
GetBuffer(), 0, size, m_workMem) )
90 if ( ::VerQueryValue(m_workMem, _T(
"\\"),
reinterpret_cast<LPVOID*
>(&m_pFileInfo), &uLen) )
92 if ( m_pFileInfo->dwSignature == VS_FFI_SIGNATURE )
94 if ( ::VerQueryValue(m_workMem,
95 _T(
"\\VarFileInfo\\Translation"),
96 reinterpret_cast<LPVOID*
>(&m_pLangCodePage),
97 &m_langCodePageSize) )
99 m_langCodePageSize /=
sizeof(DWORD);
101 m_fileName = strFile;
119 m_pLangCodePage = NULL;
120 m_langCodePageSize = 0;
164 CStr Get(LPCTSTR lpszType, WORD wLanguage = 0)
const
166 LPVOID P = m_GetTextPtr(lpszType, wLanguage);
169 if ( HasUnicodeType() )
171 return CStr(
reinterpret_cast<LPCWSTR
>(P));
175 return CStr(
reinterpret_cast<LPCSTR
>(P));
191 ,
Get(_T(
"FileDescription"))
208 Get(_T(
"LegalCopyright"), wLanguage),
209 Get(_T(
"CompanyName"), wLanguage));
220 return m_GetVersionText(_T(
"FileVersion"), wLanguage);
231 return m_GetVersionText(_T(
"ProductVersion"), wLanguage);
243 DWORD f = m_pFileInfo->dwFileFlags & m_pFileInfo->dwFileFlagsMask;
244 return (f & VS_FF_SPECIALBUILD) != 0;
258 DWORD f = m_pFileInfo->dwFileFlags & m_pFileInfo->dwFileFlagsMask;
259 return (f & VS_FF_PRIVATEBUILD) != 0;
276 INT_PTR
Modify(LPCTSTR lpszType, LPCTSTR lpszValue, WORD wLanguage = 0)
281 LPVOID P = m_GetTextPtr(lpszType, wLanguage);
284 if ( HasUnicodeType() )
286 LPWSTR lpsz =
reinterpret_cast<LPWSTR
>(P);
293 LPSTR lpsz =
reinterpret_cast<LPSTR
>(P);
319 s.
Format(_T(
"%d,%d,%d,%d"), v1, v2, v3, v4);
320 m_pFileInfo->dwFileVersionMS = MAKELONG(v2, v1);
321 m_pFileInfo->dwFileVersionLS = MAKELONG(v4, v3);
322 return Modify(_T(
"FileVersion"), s, wLanguage);
343 s.
Format(_T(
"%d,%d,%d,%d"), v1, v2, v3, v4);
344 m_pFileInfo->dwProductVersionMS = MAKELONG(v2, v1);
345 m_pFileInfo->dwProductVersionLS = MAKELONG(v4, v3);
346 return Modify(_T(
"ProductVersion"), s, wLanguage);
361 HANDLE h = ::BeginUpdateResource(m_fileName, FALSE);
364 bool r = !! ::UpdateResource(h,
365 RT_VERSION, MAKEINTRESOURCE(VS_VERSION_INFO), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
367 r &= !! ::EndUpdateResource(h, FALSE);
386 if ( (flag & VS_FF_SPECIALBUILD) != 0 )
389 _str +=
Get(_T(
"SpecialBuild"), wLanguage);
391 if ( (flag & VS_FF_PRIVATEBUILD) != 0 )
394 _str +=
Get(_T(
"PrivateBuild"), wLanguage);
396 if ( (flag & VS_FF_PRERELEASE) != 0 )
398 _str += _T(
" [PreRelease版]");
400 if ( (flag & VS_FF_DEBUG) != 0 )
402 _str += _T(
" ≪Debug版≫");
408 struct TLangAndCodePage
415 TLangAndCodePage* m_pLangCodePage;
416 UINT m_langCodePageSize;
419 LPVOID m_GetTextPtr(LPCTSTR lpszType, WORD wLanguage = 0)
const
424 for ( UINT i = 0; i < m_langCodePageSize; i++ )
426 if ( wLanguage == 0 || m_pLangCodePage[i].wLanguage == wLanguage )
430 _T(
"\\StringFileInfo\\%04x%04x\\%s"),
431 m_pLangCodePage[i].wLanguage,
432 m_pLangCodePage[i].wCodePage,
436 if ( HasUnicodeType() )
440 if ( ::VerQueryValueW(m_workMem,
442 reinterpret_cast<LPVOID*
>(&P),
453 if ( ::VerQueryValueA(m_workMem,
455 reinterpret_cast<LPVOID*
>(&P),
473 bool HasUnicodeType(
void)
const
476 if ( m_pFileInfo != NULL )
478 switch ( m_pFileInfo->dwFileOS )
480 case VOS_DOS_WINDOWS16:
492 CStr m_GetVersionText(LPCTSTR lpszVer, WORD wLanguage = 0)
const
497 s =
Get(lpszVer, wLanguage);
498 DWORD f = m_pFileInfo->dwFileFlags & m_pFileInfo->dwFileFlagsMask;
bool Open(LPCTSTR lpszFile=NULL, HINSTANCE hInst=NULL)
[設定] オープン
CStr GetCopyrightText(WORD wLanguage=0) const
[取得] 著作権文字列取得.
CStr GetAboutText(LPCTSTR lpszVerText, WORD wLanguage=0) const
[取得] About画面用文字列取得.
INT_PTR Modify(LPCTSTR lpszType, LPCTSTR lpszValue, WORD wLanguage=0)
[変更] 情報変更.
CFileVersion(void)
コンストラクタ
CStr Get(LPCTSTR lpszType, WORD wLanguage=0) const
[取得] 情報取得(文字列)
bool IsValid(void) const
[確認] 有効か
bool WritePush(void)
[設定] 書き込み.
INT_PTR ModifyProductVersion(WORD v1, WORD v2, WORD v3, WORD v4, WORD wLanguage=0)
[変更] プロダクトバージョン変更.
void Close(void)
[設定] クローズ
CStr GetFileVersionText(WORD wLanguage=0) const
[取得] ファイルバージョン文字列取得.
bool IsSpecialBuild(void) const
[取得] スペシャルビルドチェック.
VS_FIXEDFILEINFO * GetFileInfo(void)
[取得] 情報取得.
virtual void OnGetVerisonText(CStr &_str, DWORD flag, WORD wLanguage) const
[通知] GetVersionText コール通知.
INT_PTR ModifyFileVersion(WORD v1, WORD v2, WORD v3, WORD v4, WORD wLanguage=0)
[変更] ファイルバージョン変更.
const VS_FIXEDFILEINFO * GetFileInfo(void) const
[取得] 情報取得
bool IsPrivateBuild(void) const
[取得] プライベートビルドチェック.
CStr GetProductVersionText(WORD wLanguage=0) const
[取得] プロダクトバージョン文字列取得.
CStrT Left(size_t iSize) const
[作成] 範囲取得.
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
static CStrT Fmt(const TCHAR *lpszFormat,...)
[作成] 書式付き文字列作成
void Format(const TYP *lpszFormat,...)
[代入] 書式付き文字列代入.
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
size_t GetSize(void) const
[取得] サイズ取得
void Resize(size_t l)
[設定] サイズ再設定
const TYP * Ref(void) const
[取得] ポインタ取得
size_t GetLen(LPCSTR lpsz)
[計算] 文字列長計算(ASCII/SJIS用)
DWORD ToDword(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
TNB::CStrT< TCHAR > CStr
文字列クラス
void Copy(LPSTR _dst, LPCSTR src)
[複製] 文字列コピー(ASCII/SJIS用)