ersionInfo(strLine,"FILEVERSION",strVal)) != string::npos) 117 { 118 GetVersion(&ullVer,NULL); 119 strReplace = VerToStrA(ullVer,','); 120 } 121 else if ((pos = ParseVersionInfo(strLine,"PRODUCTVERSION",strVal)) != string::npos) 122 { 123 GetVersion(NULL,&ullVer); 124 strReplace = VerToStrA(ullVer,','); 125 } 126 else if ((pos = ParseBlockInfo(strLine,"VALUE \"CompanyName\"",strVal)) != string::npos) 127 { 128 tstr2astr(m_tstrCompanyName,strReplace); 129 } 130 else if ((pos = ParseBlockInfo(strLine,"VALUE \"FileDescription\"",strVal))!=string::npos) 131 { 132 tstr2astr(m_tstrFileDesc,strReplace); 133 } 134 else if ((pos = ParseBlockInfo(strLine,"VALUE \"FileVersion\"",strVal))!=string::npos) 135 { 136 GetOtherVersion(&ullVer,NULL); 137 strReplace = VerToStrA(ullVer); 138 } 139 else if ((pos = ParseBlockInfo(strLine,"VALUE \"InternalName\"",strVal))!=string::npos) 140 { 141 tstr2astr(m_tstrInternalName,strReplace); 142 } 143 else if ((pos = ParseBlockInfo(strLine,"VALUE \"LegalCopyright\"",strVal))!=string::npos) 144 { 145 tstr2astr(m_tstrCopyright,strReplace); 146 } 147 else if ((pos = ParseBlockInfo(strLine,"VALUE \"OriginalFilename\"",strVal))!=string::npos) 148 { 149 tstr2astr(m_tstrOriginalFileName,strReplace); 150 } 151 else if ((pos = ParseBlockInfo(strLine,"VALUE \"ProductName\"",strVal))!=string::npos) 152 { 153 tstr2astr(m_tstrProductName,strReplace); 154 } 155 else if ((pos = ParseBlockInfo(strLine,"VALUE \"ProductVersion\"",strVal))!=string::npos) 156 { 157 GetOtherVersion(NULL,&ullVer); 158 strReplace = VerToStrA(ullVer); 159 } 160 if (pos != string::npos) 161 { 162 strLine.replace(pos,strVal.length(),strReplace); 163 } 164} 165 166/// 解析文件 167void CRCVersion::ParseRC() 168{ 169 assert(INVALID_HANDLE_VALUE != m_hFile); 170 ParseCharEncode(); 171 ParseContent(); 172} 173 174/// 读头2个字节,获取字符集编码类型 175void CRCVersion::ParseCharEncode() 176{ 177 char buf[2]; DWORD dwReaded; 178 if (ReadFile(m_hFile,buf,sizeof(buf),&dwReaded,0) && sizeof(buf) == dwReaded) 179 { 180 if (buf[0]==(char)0xFF && buf[1]==(char)0xFE) 181 { 182 m_nCharEncodeType = UNICODE_LITTLE; 183 } 184 else if (buf[0]==(char)0xFE && buf[1]==(char)0xFF) 185 { 186 m_nCharEncodeType = UNICODE_BIG; 187 } 188 else 189 { 190 m_nCharEncodeType = ANSI; 191 SetFilePointer(m_hFile,0,NULL,FILE_BEGIN); 192 } 193 } 194 else 195 { 196 m_nCharEncodeType = UNKNOW; 197 } 198} 199 200/**//// 逐次按行读取,解析文件的内容 201void CRCVersion::ParseContent() 202{ 203 for (string strLine;!eof();strLine.clear()) 204 { 205 getline(strLine); 206 ParseLine(strLine); 207 } 208 if (ANSI == m_nCharEncodeType) 209 SetFilePointer(m_hFile,0,NULL,FILE_BEGIN); 210 else 211 SetFilePointer(m_hFile,2,NULL,FILE_BEGIN); 212} 213 214/**//// 解析单行,提取文件版本、产品版本、公司名称、文件描述、文件版本、内部名称、版权信息、源文件名、产品名称 215void CRCVersion::ParseLine(string& strLine) 216{ 217 string strVal; 218 if (ParseVersionInfo(strLine,"FILEVERSION",strVal)!=string::npos) 219 { 2 |