1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | using namespace ActiveBasic::Common;
|
---|
4 |
|
---|
5 |
|
---|
6 | void ResourceManager::Clear()
|
---|
7 | {
|
---|
8 | this->cursorResources.clear();
|
---|
9 | this->bitmapResources.clear();
|
---|
10 | this->iconResources.clear();
|
---|
11 | this->manifestFilePath.clear();
|
---|
12 | }
|
---|
13 |
|
---|
14 | bool ResourceManager::Load( const std::string &resourceFilePath )
|
---|
15 | {
|
---|
16 | // まずはクリアする
|
---|
17 | this->Clear();
|
---|
18 |
|
---|
19 |
|
---|
20 | int i2,i3;
|
---|
21 | char temp2[MAX_PATH];
|
---|
22 | HANDLE hFile;
|
---|
23 |
|
---|
24 | hFile=CreateFile(resourceFilePath.c_str(),GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
|
---|
25 | if(hFile==INVALID_HANDLE_VALUE)
|
---|
26 | {
|
---|
27 | return false;
|
---|
28 | }
|
---|
29 | i2=GetFileSize(hFile,NULL);
|
---|
30 | extern HANDLE hHeap;
|
---|
31 | char *_buf = (char *)malloc(i2+i2);
|
---|
32 | ReadFile(hFile,_buf,i2,(DWORD *)&i3,NULL);
|
---|
33 | CloseHandle(hFile);
|
---|
34 | _buf[i3]=0;
|
---|
35 | std::string buffer = _buf;
|
---|
36 | free(_buf);
|
---|
37 |
|
---|
38 | // 改行コードのCRLFをLFに変換
|
---|
39 | Jenga::Common::StringReplace( buffer, "\r\n", "\n" );
|
---|
40 |
|
---|
41 | std::string baseDir = Jenga::Common::Path::ExtractDirPath( resourceFilePath );
|
---|
42 |
|
---|
43 | i2=0;
|
---|
44 | while(1){
|
---|
45 | //ID
|
---|
46 | while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
|
---|
47 |
|
---|
48 | std::string _idname = Jenga::Common::EasyToken::GetIdentifierToken( buffer, i2 );
|
---|
49 |
|
---|
50 | if( _idname.size() == 0 )
|
---|
51 | {
|
---|
52 | break;
|
---|
53 | }
|
---|
54 |
|
---|
55 | //Type
|
---|
56 | while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
|
---|
57 | char temporary[MAX_PATH];
|
---|
58 | lstrcpy( temporary, Jenga::Common::EasyToken::GetIdentifierToken( buffer, i2 ).c_str() );
|
---|
59 |
|
---|
60 | //FileName
|
---|
61 | while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
|
---|
62 | if(buffer[i2]!='\"'){
|
---|
63 | //エラー
|
---|
64 | return false;
|
---|
65 | }
|
---|
66 | for(i2++,i3=0;;i2++,i3++){
|
---|
67 | if(buffer[i2]=='\"'){
|
---|
68 | temp2[i3]=0;
|
---|
69 | break;
|
---|
70 | }
|
---|
71 | temp2[i3]=buffer[i2];
|
---|
72 | }
|
---|
73 | lstrcpy( temp2, Jenga::Common::Directory( baseDir ).GetFullPath( temp2 ).c_str() );
|
---|
74 |
|
---|
75 | ResourceItem item;
|
---|
76 | item.idName = _idname;
|
---|
77 | item.filepath = temp2;
|
---|
78 |
|
---|
79 | if(lstrcmpi(temporary,"CURSOR")==0)
|
---|
80 | {
|
---|
81 | this->cursorResources.push_back( item );
|
---|
82 | }
|
---|
83 | else if(lstrcmpi(temporary,"BITMAP")==0)
|
---|
84 | {
|
---|
85 | this->bitmapResources.push_back( item );
|
---|
86 | }
|
---|
87 | else if(lstrcmpi(temporary,"ICON")==0)
|
---|
88 | {
|
---|
89 | this->iconResources.push_back( item );
|
---|
90 | }
|
---|
91 | else if(lstrcmpi(temporary,"RT_MANIFEST")==0)
|
---|
92 | {
|
---|
93 | if( !this->manifestFilePath.empty() )
|
---|
94 | {
|
---|
95 | // 埋め込みマニフェストが2つ以上指定された
|
---|
96 | return false;
|
---|
97 | }
|
---|
98 |
|
---|
99 | this->manifestFilePath = temp2;
|
---|
100 | }
|
---|
101 | else
|
---|
102 | {
|
---|
103 | return false;
|
---|
104 | }
|
---|
105 |
|
---|
106 | i2++;
|
---|
107 | while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
|
---|
108 | if(buffer[i2]=='\0') break;
|
---|
109 | else if(buffer[i2]!='\n')
|
---|
110 | {
|
---|
111 | return false;
|
---|
112 | }
|
---|
113 | i2++;
|
---|
114 | }
|
---|
115 |
|
---|
116 | return true;
|
---|
117 | }
|
---|
118 |
|
---|
119 | bool ResourceManager::HasManifest() const
|
---|
120 | {
|
---|
121 | return !this->manifestFilePath.empty();
|
---|
122 | }
|
---|