source: dev/trunk/ab5.0/abdev/ab_common/src/ResourceManager/ResourceManager.cpp@ 663

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

i2が0だったときにfree内でアサートが生じてしまう不具合を修正

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