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

Last change on this file since 622 was 622, checked in by dai_9181, 16 years ago

ResourceManagerクラスを追加。既存のリソース管理モジュールの置き換えを行った。

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