source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/RSrcSection.cpp@ 797

Last change on this file since 797 was 769, checked in by イグトランス (egtra), 16 years ago

読み取りのみのファイル操作の場合、CreateFileでFILE_SHARE_READ指定を追加。コンパイラを同時起動しても正常動作させるための修正。

File size: 28.4 KB
RevLine 
[206]1#include "stdafx.h"
2
[4]3#include "../BasicCompiler_Common/common.h"
4
5#ifndef RT_MANIFEST
6#define RT_MANIFEST MAKEINTRESOURCE(24)
7#endif
8
9//リソースアドレススケジュール
10DWORD *lpdwRSrcAddrSchedule;
11int RSrcAddrScheduleNum;
12
13void AddRSrcAddrSchedule(DWORD pos){
14 extern HANDLE hHeap;
15
16 //グローバル変数アドレススケジュールに追加する
17 lpdwRSrcAddrSchedule=(DWORD *)HeapReAlloc(hHeap,0,lpdwRSrcAddrSchedule,(RSrcAddrScheduleNum+1)*sizeof(DWORD));
18 lpdwRSrcAddrSchedule[RSrcAddrScheduleNum]=pos;
19 RSrcAddrScheduleNum++;
20}
21
22char *PermutationString(char *buffer,char *lpszSearch,char *lpszRewrite){
23 //バッファ長
24 int length;
25 length=lstrlen(buffer);
26
27 //サーチ文字列の長さ
28 int search_length;
29 search_length=lstrlen(lpszSearch);
30
31 //置換文字列の長さ
32 int write_length;
33 write_length=lstrlen(lpszRewrite);
34
35 //置換時オフセット
36 int offset;
37 offset=lstrlen(lpszRewrite)-search_length;
38
39 int i;
40 for(i=0;i<length-search_length;i++){
41 if(memcmp(buffer+i,lpszSearch,search_length)==0){
42 if(offset>0){
43 length+=offset;
44 buffer=(char *)HeapReAlloc(hHeap,0,buffer,length+1);
45 }
46
47 SlideString(buffer+i+search_length,offset);
48 memcpy(buffer+i,lpszRewrite,write_length);
49 i+=write_length-1;
50 }
51 }
52
53 return buffer;
54}
55
56char *GetRSrcSectionBuffer(int *pLen){
57 extern HANDLE hHeap;
58 char *buffer,*temporary;
59 int i2,i3,i4,i5,i6,i7,sw,BufSize,TypeNum,NextBase;
60 HANDLE hFile;
61
62 //カーソルリソース
63 int CursorNum;
64 CURSORDIR *pCursorDir;
65 CURSORDIRENTRY *pCursorDirEntry;
66 CURSORDIRENTRY_RES CursorDirEntry_Res;
67 CursorNum=0;
68
69 //アイコンリソース
70 int IconNum;
71 ICONDIR *pIconDir;
72 ICONDIRENTRY *pIconDirEntry;
73 ICONDIRENTRY_RES IconDirEntry_Res;
74 IconNum=0;
75
76 BufSize=8192*2;
77 buffer=(char *)HeapAlloc(hHeap,0,BufSize);
78 i2=0;
79 NextBase=0;
80
81 //リソースアドレススケジュール
82 lpdwRSrcAddrSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
83 RSrcAddrScheduleNum=0;
84
85 *pLen=0;
86
[622]87 if( compiler.resourceManager.cursorResources.empty()
88 && compiler.resourceManager.bitmapResources.empty()
89 && compiler.resourceManager.iconResources.empty()
90 && compiler.resourceManager.manifestFilePath.empty() )
91 {
92 return buffer;
93 }
[4]94
95 sw=0;
96
97 //カーソルの枚数を計算(CursorNumに格納)
[750]98 foreach( const ActiveBasic::Common::ResourceItem &resourceItem, compiler.resourceManager.cursorResources )
[624]99 {
[769]100 hFile=CreateFile(resourceItem.filepath.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
[4]101 if(hFile==INVALID_HANDLE_VALUE){
[624]102 compiler.errorMessenger.Output(23,resourceItem.filepath.c_str(),-1);
[4]103 sw=1;
104 continue;
105 }
106 i4=GetFileSize(hFile,NULL);
107 temporary=(char *)HeapAlloc(hHeap,0,i4);
108 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
109 CloseHandle(hFile);
110
111 pCursorDir=(CURSORDIR *)temporary;
112 CursorNum+=pCursorDir->idCount;
113
114 HeapDefaultFree(temporary);
115 }
116
117 //ビットマップのファイルの有無を確認
[750]118 foreach( const ActiveBasic::Common::ResourceItem &resourceItem, compiler.resourceManager.bitmapResources )
[624]119 {
[769]120 hFile=CreateFile(resourceItem.filepath.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
[4]121 if(hFile==INVALID_HANDLE_VALUE){
[624]122 compiler.errorMessenger.Output(23,resourceItem.filepath.c_str(),-1);
[4]123 sw=1;
124 continue;
125 }
126 CloseHandle(hFile);
127 }
128
129 //アイコンの枚数を計算(IconNumに格納)
[750]130 foreach( const ActiveBasic::Common::ResourceItem &resourceItem, compiler.resourceManager.iconResources )
[624]131 {
[769]132 hFile=CreateFile(resourceItem.filepath.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
[4]133 if(hFile==INVALID_HANDLE_VALUE){
[624]134 compiler.errorMessenger.Output(23,resourceItem.filepath.c_str(),-1);
[4]135 sw=1;
136 continue;
137 }
138 i4=GetFileSize(hFile,NULL);
139 temporary=(char *)HeapAlloc(hHeap,0,i4);
140 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
141 CloseHandle(hFile);
142
143 pIconDir=(ICONDIR *)temporary;
144 IconNum+=pIconDir->idCount;
145
146 HeapDefaultFree(temporary);
147 }
148
149 //ファイルの読み込みに失敗した場合
150 if(sw) return buffer;
151
152
153 /////////////////////////
154 // ディレクトリ エントリ
155 /////////////////////////
156 TypeNum=0;
[622]157 if( !compiler.resourceManager.cursorResources.empty() ) TypeNum+=2;
158 if( !compiler.resourceManager.bitmapResources.empty() ) TypeNum++;
159 if( !compiler.resourceManager.iconResources.empty() ) TypeNum+=2;
160 if( !compiler.resourceManager.manifestFilePath.empty() ) TypeNum++;
[4]161
162 NextBase=sizeof(IMAGE_RESOURCE_DIRECTORY)+
163 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*TypeNum;
164
165 //1階層
166 IMAGE_RESOURCE_DIRECTORY ImgResDir;
167 ImgResDir.Characteristics=0;
168 ImgResDir.TimeDateStamp=0;
169 ImgResDir.MajorVersion=0;
170 ImgResDir.MinorVersion=0;
171 ImgResDir.NumberOfNamedEntries=0;
172 ImgResDir.NumberOfIdEntries=TypeNum;
173 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
174 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
175
176 i6=0;
177 IMAGE_RESOURCE_DIRECTORY_ENTRY ImgDirEntry;
178 if(CursorNum){
179 //RT_CURSOR
180 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_CURSOR;
181 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
182 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
183 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
184
185 //2階層のサイズ
186 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
187 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*CursorNum;
188 }
[622]189 if( !compiler.resourceManager.bitmapResources.empty() ){
[4]190 //RT_BITMAP
191 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_BITMAP;
192 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
193 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
194 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
195
196 //2階層のサイズ
197 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
[622]198 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY) * compiler.resourceManager.bitmapResources.size();
[4]199 }
200 if(IconNum){
201 //RT_ICON
202 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_ICON;
203 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
204 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
205 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
206
207 //2階層のサイズ
208 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
209 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*IconNum;
210 }
[622]211 if( !compiler.resourceManager.cursorResources.empty() )
212 {
[4]213 //RT_GROUP_CURSOR
214 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_GROUP_CURSOR;
215 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
216 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
217 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
218
219 //2階層のサイズ
220 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
221 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*CursorNum;
222 }
[622]223 if( !compiler.resourceManager.iconResources.empty() )
224 {
[4]225 //RT_GROUP_ICON
226 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_GROUP_ICON;
227 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
228 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
229 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
230
231 //2階層のサイズ
232 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
[622]233 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY) * compiler.resourceManager.iconResources.size();
[4]234 }
[622]235 if( !compiler.resourceManager.manifestFilePath.empty() )
236 {
[4]237 //RT_MANIFEST
238 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_MANIFEST;
239 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
240 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
241 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
242
243 //2階層のサイズ
244 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
[622]245 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY) * 1/*XPManiResourceNum*/ ;
[4]246 }
247
248 NextBase+=i6;
249
250 //2階層
251 i6=0;
252 i7=0;
253 if(CursorNum){
254 //RT_CURSOR
255 ImgResDir.Characteristics=0;
256 ImgResDir.TimeDateStamp=0;
257 ImgResDir.MajorVersion=0;
258 ImgResDir.MinorVersion=0;
259 ImgResDir.NumberOfNamedEntries=0;
260 ImgResDir.NumberOfIdEntries=CursorNum;
261 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
262 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
263
264 for(i3=0;i3<CursorNum;i3++,i7++){
265 ImgDirEntry.Name=i7+1;
266 ImgDirEntry.OffsetToData=(NextBase+i6+
267 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
268 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
269 |0x80000000;
270 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
271 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
272 }
273
274 //3階層のサイズ
275 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
276 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*CursorNum;
277 }
[622]278 if( !compiler.resourceManager.bitmapResources.empty() ){
[4]279 //RT_BITMAP
280 ImgResDir.Characteristics=0;
281 ImgResDir.TimeDateStamp=0;
282 ImgResDir.MajorVersion=0;
283 ImgResDir.MinorVersion=0;
284 ImgResDir.NumberOfNamedEntries=0;
[622]285 ImgResDir.NumberOfIdEntries = compiler.resourceManager.bitmapResources.size();
[4]286 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
287 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
288
[624]289 for(i3=0;i3<static_cast<int>(compiler.resourceManager.bitmapResources.size());i3++)
[622]290 {
[624]291 ImgDirEntry.Name = static_cast<DWORD>(compiler.GetObjectModule().meta.GetGlobalConsts().GetWholeData(
[622]292 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol(
293 compiler.resourceManager.bitmapResources[i3].idName
294 )
[624]295 ));
[4]296 ImgDirEntry.OffsetToData=(NextBase+i6+
297 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
298 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
299 |0x80000000;
300 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
301 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
302 }
303
304 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
[622]305 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)) * compiler.resourceManager.bitmapResources.size();
[4]306 }
307 if(IconNum){
308 //RT_ICON
309 ImgResDir.Characteristics=0;
310 ImgResDir.TimeDateStamp=0;
311 ImgResDir.MajorVersion=0;
312 ImgResDir.MinorVersion=0;
313 ImgResDir.NumberOfNamedEntries=0;
314 ImgResDir.NumberOfIdEntries=IconNum;
315 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
316 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
317
318 for(i3=0;i3<IconNum;i3++,i7++){
319 ImgDirEntry.Name=i7+1;
320 ImgDirEntry.OffsetToData=(NextBase+i6+
321 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
322 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
323 |0x80000000;
324 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
325 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
326 }
327
328 //3階層のサイズ
329 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
330 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*IconNum;
331 }
[622]332 if( !compiler.resourceManager.cursorResources.empty() )
333 {
[4]334 //RT_GROUP_CURSOR
335 ImgResDir.Characteristics=0;
336 ImgResDir.TimeDateStamp=0;
337 ImgResDir.MajorVersion=0;
338 ImgResDir.MinorVersion=0;
339 ImgResDir.NumberOfNamedEntries=0;
[622]340 ImgResDir.NumberOfIdEntries = compiler.resourceManager.cursorResources.size();
[4]341 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
342 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
343
[624]344 for(i3=0;i3<static_cast<int>(compiler.resourceManager.cursorResources.size());i3++){
345 ImgDirEntry.Name = static_cast<DWORD>(compiler.GetObjectModule().meta.GetGlobalConsts().GetWholeData(
[622]346 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol(
347 compiler.resourceManager.cursorResources[i3].idName
348 )
[624]349 ));
[4]350 ImgDirEntry.OffsetToData=(NextBase+i6+
351 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
352 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
353 |0x80000000;
354 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
355 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
356 }
357
358 //3階層のサイズ
359 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
[622]360 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)) * compiler.resourceManager.cursorResources.size();
[4]361 }
[622]362 if( !compiler.resourceManager.iconResources.empty() )
363 {
[4]364 //RT_GROUP_ICON
365 ImgResDir.Characteristics=0;
366 ImgResDir.TimeDateStamp=0;
367 ImgResDir.MajorVersion=0;
368 ImgResDir.MinorVersion=0;
369 ImgResDir.NumberOfNamedEntries=0;
[622]370 ImgResDir.NumberOfIdEntries = compiler.resourceManager.iconResources.size();
[4]371 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
372 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
373
[624]374 for(i3=0;i3<static_cast<int>(compiler.resourceManager.iconResources.size());i3++){
375 ImgDirEntry.Name = static_cast<DWORD>(compiler.GetObjectModule().meta.GetGlobalConsts().GetWholeData(
[622]376 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol(
377 compiler.resourceManager.iconResources[i3].idName
378 )
[624]379 ));
[4]380 ImgDirEntry.OffsetToData=(NextBase+i6+
381 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
382 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
383 |0x80000000;
384 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
385 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
386 }
387
388 //3階層のサイズ
389 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
[622]390 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)) * compiler.resourceManager.iconResources.size();
[4]391 }
[622]392 if( !compiler.resourceManager.manifestFilePath.empty() )
393 {
[4]394 //RT_MANIFEST
395 ImgResDir.Characteristics=0;
396 ImgResDir.TimeDateStamp=0;
397 ImgResDir.MajorVersion=0;
398 ImgResDir.MinorVersion=0;
399 ImgResDir.NumberOfNamedEntries=0;
[622]400 ImgResDir.NumberOfIdEntries = 1 /*XPManiResourceNum*/ ;
[4]401 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
402 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
403
[622]404 i3 = 0;
405 {
[4]406 ImgDirEntry.Name=i3+1;
407 ImgDirEntry.OffsetToData=(NextBase+i6+
408 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
409 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
410 |0x80000000;
411 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
412 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
413 }
414
415 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
[622]416 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)) * 1 /*XPManiResourceNum*/ ;
[4]417 }
418
419
420 NextBase+=i6;
421
422 while(i2+8192>BufSize){
423 BufSize+=8192;
424 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
425 }
426
427 //3階層
428 i6=0;
429 if(CursorNum){
430 //RT_CURSOR
431 for(i3=0;i3<CursorNum;i3++){
432 ImgResDir.Characteristics=0;
433 ImgResDir.TimeDateStamp=0;
434 ImgResDir.MajorVersion=0;
435 ImgResDir.MinorVersion=0;
436 ImgResDir.NumberOfNamedEntries=0;
437 ImgResDir.NumberOfIdEntries=1;
438 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
439 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
440
441 ImgDirEntry.Name=0x411;
442 ImgDirEntry.OffsetToData=NextBase+i6+
443 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
444 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
445 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
446 }
447
448 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY)*CursorNum;
449 }
[622]450 if( !compiler.resourceManager.bitmapResources.empty() ){
[4]451 //RT_BITMAP
[624]452 for(i3=0;i3<static_cast<int>(compiler.resourceManager.bitmapResources.size());i3++){
[4]453 ImgResDir.Characteristics=0;
454 ImgResDir.TimeDateStamp=0;
455 ImgResDir.MajorVersion=0;
456 ImgResDir.MinorVersion=0;
457 ImgResDir.NumberOfNamedEntries=0;
458 ImgResDir.NumberOfIdEntries=1;
459 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
460 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
461
462 ImgDirEntry.Name=0x411;
463 ImgDirEntry.OffsetToData=NextBase+i6+
464 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
465 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
466 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
467 }
468
[622]469 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY) * compiler.resourceManager.bitmapResources.size();
[4]470 }
471 if(IconNum){
472 //RT_ICON
473 for(i3=0;i3<IconNum;i3++){
474 ImgResDir.Characteristics=0;
475 ImgResDir.TimeDateStamp=0;
476 ImgResDir.MajorVersion=0;
477 ImgResDir.MinorVersion=0;
478 ImgResDir.NumberOfNamedEntries=0;
479 ImgResDir.NumberOfIdEntries=1;
480 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
481 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
482
483 ImgDirEntry.Name=0x411;
484 ImgDirEntry.OffsetToData=NextBase+i6+
485 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
486 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
487 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
488 }
489
490 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY)*IconNum;
491 }
[622]492 if( !compiler.resourceManager.cursorResources.empty() )
493 {
[4]494 //RT_GROUP_CURSOR
[624]495 for(i3=0;i3<static_cast<int>(compiler.resourceManager.cursorResources.size());i3++){
[4]496 ImgResDir.Characteristics=0;
497 ImgResDir.TimeDateStamp=0;
498 ImgResDir.MajorVersion=0;
499 ImgResDir.MinorVersion=0;
500 ImgResDir.NumberOfNamedEntries=0;
501 ImgResDir.NumberOfIdEntries=1;
502 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
503 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
504
505 ImgDirEntry.Name=0x411;
506 ImgDirEntry.OffsetToData=NextBase+i6+
507 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
508 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
509 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
510 }
511
[622]512 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY) * compiler.resourceManager.cursorResources.size();
[4]513 }
[622]514 if( !compiler.resourceManager.iconResources.empty() )
515 {
[4]516 //RT_GROUP_ICON
[624]517 for(i3=0;i3<static_cast<int>(compiler.resourceManager.iconResources.size());i3++){
[4]518 ImgResDir.Characteristics=0;
519 ImgResDir.TimeDateStamp=0;
520 ImgResDir.MajorVersion=0;
521 ImgResDir.MinorVersion=0;
522 ImgResDir.NumberOfNamedEntries=0;
523 ImgResDir.NumberOfIdEntries=1;
524 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
525 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
526
527 ImgDirEntry.Name=0x411;
528 ImgDirEntry.OffsetToData=NextBase+i6+
529 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
530 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
531 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
532 }
533
[622]534 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY)*compiler.resourceManager.iconResources.size();
[4]535 }
[622]536 if( !compiler.resourceManager.manifestFilePath.empty() ){
[4]537 //RT_MANIFEST
[622]538 i3 = 0;
539 {
[4]540 ImgResDir.Characteristics=0;
541 ImgResDir.TimeDateStamp=0;
542 ImgResDir.MajorVersion=0;
543 ImgResDir.MinorVersion=0;
544 ImgResDir.NumberOfNamedEntries=0;
545 ImgResDir.NumberOfIdEntries=1;
546 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
547 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
548
549 ImgDirEntry.Name=0x411;
550 ImgDirEntry.OffsetToData=NextBase+i6+
551 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
552 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
553 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
554 }
555
[622]556 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY) * 1 /*XPManiResourceNum*/ ;
[4]557 }
558
559 NextBase+=i6;
560
561 while(i2+8192>BufSize){
562 BufSize+=8192;
563 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
564 }
565
566
567
568 ////////////////////////////////////////
569 // データ エントリ
570 ////////////////////////////////////////
571
572 DWORD dwDataEntrySchedule[100];
573 int DataEntryScheduleNum;
574 int CursorEntryBase;
575 int CursorGroupEntryBase;
576 int BitmapEntryBase;
577 int IconEntryBase;
578 int IconGroupEntryBase;
579
580 DataEntryScheduleNum=0;
581
582 //空のデータエントリ領域を作成
583
584 //RT_CURSOR
585 CursorEntryBase=DataEntryScheduleNum;
586 for(i3=0;i3<CursorNum;i3++){
587 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
588 DataEntryScheduleNum++;
589 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
590 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
591 }
592
593 //RT_BITMAP
594 BitmapEntryBase=DataEntryScheduleNum;
[624]595 for(i3=0;i3<static_cast<int>(compiler.resourceManager.bitmapResources.size());i3++){
[4]596 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
597 DataEntryScheduleNum++;
598 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
599 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
600 }
601
602 //RT_ICON
603 IconEntryBase=DataEntryScheduleNum;
604 for(i3=0;i3<IconNum;i3++){
605 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
606 DataEntryScheduleNum++;
607 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
608 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
609 }
610
611 //RT_GROUP_CURSOR
612 CursorGroupEntryBase=DataEntryScheduleNum;
[624]613 for(i3=0;i3<static_cast<int>(compiler.resourceManager.cursorResources.size());i3++){
[4]614 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
615 DataEntryScheduleNum++;
616 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
617 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
618 }
619
620 //RT_GROUP_ICON
621 IconGroupEntryBase=DataEntryScheduleNum;
[624]622 for(i3=0;i3<static_cast<int>(compiler.resourceManager.iconResources.size());i3++){
[4]623 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
624 DataEntryScheduleNum++;
625 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
626 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
627 }
628
629 //RT_MANIFEST
630 int XPManiEntryBase;
631 XPManiEntryBase=DataEntryScheduleNum;
[622]632 i3 = 0;
633 {
[4]634 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
635 DataEntryScheduleNum++;
636 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
637 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
638 }
639
640 i4=i2%8;
641 if(i4){
642 memset(buffer+i2,0,8-i4);
643 i2+=8-i4;
644 }
645
646 while(i2+8192>BufSize){
647 BufSize+=8192;
648 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
649 }
650
651
652 ///////////////////////////////////////
653 // バイナリ データ
654 // ※データエントリの内容も変更する
655 ///////////////////////////////////////
656
657 IMAGE_RESOURCE_DATA_ENTRY *pImgDataEntry;
658
659 i7=0;
660
661 //カーソルリソース
[624]662 for(i3=0,i6=0;i3<static_cast<int>(compiler.resourceManager.cursorResources.size());i3++){
[769]663 hFile=CreateFile(compiler.resourceManager.cursorResources[i3].filepath.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
[4]664 if(hFile==INVALID_HANDLE_VALUE){
[622]665 compiler.errorMessenger.Output(23,compiler.resourceManager.cursorResources[i3].filepath.c_str(),-1);
[4]666 return buffer;
667 }
668 i4=GetFileSize(hFile,NULL);
669 temporary=(char *)HeapAlloc(hHeap,0,i4);
670 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
671 CloseHandle(hFile);
672
673 pCursorDir=(CURSORDIR *)temporary;
674
675 for(i5=0;i5<pCursorDir->idCount;i5++,i6++){
676 pCursorDirEntry=(CURSORDIRENTRY *)(temporary+sizeof(CURSORDIR)+sizeof(CURSORDIRENTRY)*i5);
677
678 //データエントリ
679 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[CursorEntryBase+i6]);
680 pImgDataEntry->OffsetToData=i2;
681 pImgDataEntry->Size=pCursorDirEntry->dwBytesInRes+sizeof(WORD)*2;
682 AddRSrcAddrSchedule(dwDataEntrySchedule[CursorEntryBase+i6]);
683
684 //RT_CURSOR バイナリ データ
685 *(WORD *)(buffer+i2)=0x001F;
686 i2+=sizeof(WORD);
687 *(WORD *)(buffer+i2)=0x001F;
688 i2+=sizeof(WORD);
689 memcpy(buffer+i2,temporary+pCursorDirEntry->dwImageOffset,pCursorDirEntry->dwBytesInRes);
690 i2+=pCursorDirEntry->dwBytesInRes;
691
692 i4=i2%8;
693 if(i4){
694 memset(buffer+i2,0,8-i4);
695 i2+=8-i4;
696 }
697
698 while(i2+8192>BufSize){
699 BufSize+=8192;
700 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
701 }
702 }
703
704 //データエントリ
705 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[CursorGroupEntryBase+i3]);
706 pImgDataEntry->OffsetToData=i2;
707 pImgDataEntry->Size=sizeof(CURSORDIR)+0xE*pCursorDir->idCount;
708 AddRSrcAddrSchedule(dwDataEntrySchedule[CursorGroupEntryBase+i3]);
709
710 //RT_GROUP_CURSORヘッダデータ(CURSORDIR)
711 memcpy(buffer+i2,temporary,sizeof(CURSORDIR));
712 i2+=sizeof(CURSORDIR);
713
714 for(i5=0;i5<pCursorDir->idCount;i5++,i7++){
715 pCursorDirEntry=(CURSORDIRENTRY *)(temporary+sizeof(CURSORDIR)+sizeof(CURSORDIRENTRY)*i5);
716 CursorDirEntry_Res.wWidth=pCursorDirEntry->bWidth;
717 CursorDirEntry_Res.wHeight=CursorDirEntry_Res.wWidth*2;
718 CursorDirEntry_Res.wXHotspot=pCursorDirEntry->wXHotspot;
719 CursorDirEntry_Res.wYHotspot=pCursorDirEntry->wYHotspot;
720 CursorDirEntry_Res.dwBytesInRes=pCursorDirEntry->dwBytesInRes+sizeof(WORD)*2;
721 CursorDirEntry_Res.wCursorNum=i7+1;
722
723 //RT_GROUP_CURSORヘッダデータ(CURSORDIRENTRY_RES)
724 memcpy(buffer+i2,&CursorDirEntry_Res,0xE);
725 i2+=0xE;
726
727 while(i2+8192>BufSize){
728 BufSize+=8192;
729 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
730 }
731 }
732 i4=i2%8;
733 if(i4){
734 memset(buffer+i2,0,8-i4);
735 i2+=8-i4;
736 }
737
738 HeapDefaultFree(temporary);
739 }
740
741 //ビットマップリソース
[624]742 for(i3=0;i3<static_cast<int>(compiler.resourceManager.bitmapResources.size());i3++){
[769]743 hFile=CreateFile(compiler.resourceManager.bitmapResources[i3].filepath.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
[4]744 if(hFile==INVALID_HANDLE_VALUE){
[622]745 compiler.errorMessenger.Output(23,compiler.resourceManager.bitmapResources[i3].filepath.c_str(),-1);
[4]746 return buffer;
747 }
748 i4=GetFileSize(hFile,NULL);
749 temporary=(char *)HeapAlloc(hHeap,0,i4);
750 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
751 CloseHandle(hFile);
752
753 BufSize+=i4;
754 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
755
756 //データエントリ
757 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[BitmapEntryBase+i3]);
758 pImgDataEntry->OffsetToData=i2;
759 pImgDataEntry->Size=i4-sizeof(BITMAPFILEHEADER);
760 AddRSrcAddrSchedule(dwDataEntrySchedule[BitmapEntryBase+i3]);
761
762 //RT_BITMAP バイナリ データ
763 memcpy(buffer+i2,temporary+sizeof(BITMAPFILEHEADER),i4-sizeof(BITMAPFILEHEADER));
764 i2+=i4-sizeof(BITMAPFILEHEADER);
765
766 HeapDefaultFree(temporary);
767 }
768
769 //アイコンリソース
[624]770 for(i3=0,i6=0;i3<static_cast<int>(compiler.resourceManager.iconResources.size());i3++){
[769]771 hFile=CreateFile(compiler.resourceManager.iconResources[i3].filepath.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
[4]772 if(hFile==INVALID_HANDLE_VALUE){
[622]773 compiler.errorMessenger.Output(23,compiler.resourceManager.iconResources[i3].filepath.c_str(),-1);
[4]774 return buffer;
775 }
776 i4=GetFileSize(hFile,NULL);
777 temporary=(char *)HeapAlloc(hHeap,0,i4);
778 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
779 CloseHandle(hFile);
780
781 pIconDir=(ICONDIR *)temporary;
782
783 for(i5=0;i5<pIconDir->idCount;i5++,i6++){
784 pIconDirEntry=(ICONDIRENTRY *)(temporary+sizeof(ICONDIR)+sizeof(ICONDIRENTRY)*i5);
785
786 //データエントリ
787 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[IconEntryBase+i6]);
788 pImgDataEntry->OffsetToData=i2;
789 pImgDataEntry->Size=pIconDirEntry->dwBytesInRes;
790 AddRSrcAddrSchedule(dwDataEntrySchedule[IconEntryBase+i6]);
791
792 //RT_ICON バイナリ データ
793 memcpy(buffer+i2,temporary+pIconDirEntry->dwImageOffset,pIconDirEntry->dwBytesInRes);
794 i2+=pIconDirEntry->dwBytesInRes;
795
796 i4=i2%8;
797 if(i4){
798 memset(buffer+i2,0,8-i4);
799 i2+=8-i4;
800 }
801
802 while(i2+8192>BufSize){
803 BufSize+=8192;
804 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
805 }
806 }
807
808 //データエントリ
809 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[IconGroupEntryBase+i3]);
810 pImgDataEntry->OffsetToData=i2;
811 pImgDataEntry->Size=sizeof(ICONDIR)+0xE*pIconDir->idCount;
812 AddRSrcAddrSchedule(dwDataEntrySchedule[IconGroupEntryBase+i3]);
813
814 //RT_GROUP_ICONヘッダデータ(ICONDIR)
815 memcpy(buffer+i2,temporary,sizeof(ICONDIR));
816 i2+=sizeof(ICONDIR);
817
818 for(i5=0;i5<pIconDir->idCount;i5++,i7++){
819 pIconDirEntry=(ICONDIRENTRY *)(temporary+sizeof(ICONDIR)+sizeof(ICONDIRENTRY)*i5);
820 IconDirEntry_Res.bWidth=pIconDirEntry->bWidth;
821 IconDirEntry_Res.bHeight=pIconDirEntry->bHeight;
822 IconDirEntry_Res.bColorCount=pIconDirEntry->bColorCount;
823 IconDirEntry_Res.bReserved=0;
824 IconDirEntry_Res.wPlanes=1;
825 if(pIconDirEntry->bColorCount==16)
826 IconDirEntry_Res.wBitCount=4;
827 else if(pIconDirEntry->bColorCount==0)
828 IconDirEntry_Res.wBitCount=8;
829 IconDirEntry_Res.dwBytesInRes=pIconDirEntry->dwBytesInRes;
830 IconDirEntry_Res.wIconNum=i7+1;
831
832 //RT_GROUP_ICONヘッダデータ(ICONDIRENTRY_RES)
833 memcpy(buffer+i2,&IconDirEntry_Res,0xE);
834 i2+=0xE;
835
836 while(i2+8192>BufSize){
837 BufSize+=8192;
838 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
839 }
840 }
841 i4=i2%8;
842 if(i4){
843 memset(buffer+i2,0,8-i4);
844 i2+=8-i4;
845 }
846
847 HeapDefaultFree(temporary);
848 }
849
850 //XPManifestリソース
[622]851 i3 = 0;
852 if( !compiler.resourceManager.manifestFilePath.empty() )
853 {
[769]854 hFile=CreateFile(compiler.resourceManager.manifestFilePath.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
[4]855 if(hFile==INVALID_HANDLE_VALUE){
[622]856 compiler.errorMessenger.Output(59,compiler.resourceManager.manifestFilePath.c_str(),-1);
[4]857 return buffer;
858 }
859 i4=GetFileSize(hFile,NULL);
860 temporary=(char *)HeapAlloc(hHeap,0,i4+1);
861 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
862 temporary[i4]=0;
863 CloseHandle(hFile);
864
865 //プラットフォームをセット
866#ifdef _AMD64_
867 temporary=PermutationString(temporary,"#PLATFORM#","amd64");
868#else
869 temporary=PermutationString(temporary,"#PLATFORM#","x86");
870#endif
871
872 //アプリケーション名をセット
873 char szAppliName[MAX_PATH];
[622]874 char temp2[MAX_PATH];
[467]875 _splitpath( program.GetOutputFilePath().c_str(),NULL,NULL,szAppliName,temp2);
[4]876 lstrcat(szAppliName,temp2);
877 temporary=PermutationString(temporary,"#APPLI_FILE_NAME#",szAppliName);
878
879 i4=lstrlen(temporary)+1;
880
881 BufSize+=i4;
882 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
883
884 //データエントリ
885 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[XPManiEntryBase+i3]);
886 pImgDataEntry->OffsetToData=i2;
887 pImgDataEntry->Size=i4-1; //※NULL文字はサイズに含めない
888 AddRSrcAddrSchedule(dwDataEntrySchedule[XPManiEntryBase+i3]);
889
890 //XMLデータ
891 memcpy(buffer+i2,temporary,i4);
892 i2+=i4;
893
894 HeapDefaultFree(temporary);
895 }
896
897 *pLen=i2;
898
899 return buffer;
900}
Note: See TracBrowser for help on using the repository browser.