source: dev/branches/egtra/ab5.0/abdev/ab_common/src/ResourceManager/ResourceManager.cpp

Last change on this file was 809, checked in by イグトランス (egtra), 14 years ago

実行時で落っこちるところ(2ヶ所)を修正

File size: 2.6 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,FILE_SHARE_READ,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 if (buffer.empty())
43 {
44 return false;
45 }
46
47 i2=0;
48 while(1){
49 //ID
50 while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
51
52 std::string _idname = Jenga::Common::EasyToken::GetIdentifierToken( buffer, i2 );
53
54 if( _idname.size() == 0 )
55 {
56 break;
57 }
58
59 //Type
60 while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
61 char temporary[MAX_PATH];
62 lstrcpy( temporary, Jenga::Common::EasyToken::GetIdentifierToken( buffer, i2 ).c_str() );
63
64 //FileName
65 while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
66 if(buffer[i2]!='\"'){
67 //エラー
68 return false;
69 }
70 for(i2++,i3=0;;i2++,i3++){
71 if(buffer[i2]=='\"'){
72 temp2[i3]=0;
73 break;
74 }
75 temp2[i3]=buffer[i2];
76 }
77 lstrcpy( temp2, Jenga::Common::Directory( baseDir ).GetFullPath( temp2 ).c_str() );
78
79 ResourceItem item;
80 item.idName = _idname;
81 item.filepath = temp2;
82
83 if(lstrcmpi(temporary,"CURSOR")==0)
84 {
85 this->cursorResources.push_back( item );
86 }
87 else if(lstrcmpi(temporary,"BITMAP")==0)
88 {
89 this->bitmapResources.push_back( item );
90 }
91 else if(lstrcmpi(temporary,"ICON")==0)
92 {
93 this->iconResources.push_back( item );
94 }
95 else if(lstrcmpi(temporary,"RT_MANIFEST")==0)
96 {
97 if( !this->manifestFilePath.empty() )
98 {
99 // 埋め込みマニフェストが2つ以上指定された
100 return false;
101 }
102
103 this->manifestFilePath = temp2;
104 }
105 else
106 {
107 return false;
108 }
109
110 i2++;
111 while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
112 if(buffer[i2]=='\0') break;
113 else if(buffer[i2]!='\n')
114 {
115 return false;
116 }
117 i2++;
118 }
119
120 return true;
121}
122
123bool ResourceManager::HasManifest() const
124{
125 return !this->manifestFilePath.empty();
126}
Note: See TracBrowser for help on using the repository browser.