00001
00002
00003
00004 #include <string.h>
00005
00006 #include <ALL.H>
00007 #include <OSYS.H>
00008 #include <ORESX.H>
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00042
00043 long dataSize;
00044
00045 if( init_flag )
00046 deinit();
00047
00048
00049
00050 file_open( resName );
00051
00052
00053
00054 read_all = readAll;
00055 use_common_buf = useCommonBuf;
00056 data_buf = NULL;
00057 data_buf_size = 0;
00058
00059 rec_count = file_get_short();
00060 cur_rec_no = -1;
00061
00062 user_data_buf = NULL;
00063 user_data_buf_size = 0;
00064 user_start_read_pos = 0;
00065
00066
00067
00068 index_buf = (ResIndex*) mem_add( (rec_count+1) * sizeof(ResIndex) );
00069
00070
00071
00072 file_read( index_buf, sizeof(ResIndex) * (rec_count+1) );
00073
00074
00075
00076 if( read_all ) {
00077 dataSize = index_buf[rec_count].pointer - index_buf[0].pointer;
00078
00079 data_buf = mem_add( dataSize );
00080
00081 file_read( data_buf, dataSize );
00082 file_close();
00083 }
00084 else {
00085 if( use_common_buf )
00086 data_buf = sys.common_data_buf;
00087 }
00088
00089 init_flag = 1;
00090 }
00091
00092
00093
00094
00096
00097 if( init_flag ) {
00098 if( index_buf ) {
00099 mem_del(index_buf);
00100 index_buf = NULL;
00101 }
00102
00103 if( data_buf && data_buf != sys.common_data_buf ) {
00104 mem_del(data_buf);
00105 data_buf = NULL;
00106 }
00107
00108 if( !read_all )
00109 file_close();
00110
00111 init_flag=0;
00112 }
00113 }
00114
00115
00116
00117
00131
00132 err_when( !init_flag || !dataName );
00133
00134 int indexId = get_index(dataName);
00135
00136 if( !indexId )
00137 return 0;
00138
00139
00140
00141 set_user_buf(userBuf, userBufSize, userStartReadPos);
00142
00143 int rc = get_data(indexId)!=NULL;
00144
00145 reset_user_buf();
00146
00147 return rc;
00148 }
00149
00150
00151
00152
00166
00167 err_when( !init_flag || !dataName );
00168
00169 int indexId = get_index(dataName);
00170
00171 if( indexId )
00172 return get_data(indexId);
00173 else
00174 return NULL;
00175 }
00176
00177
00178
00179
00189
00190 err_when( !init_flag || !dataName );
00191
00192 int i;
00193
00194 for( i=0 ; i<rec_count ; i++ ) {
00195 if( strcmp( index_buf[i].name, dataName ) == 0 )
00196 return i+1;
00197 }
00198
00199 return 0;
00200 }
00201
00202
00203
00204
00215
00216 err_when( !init_flag );
00217
00218 unsigned dataSize;
00219
00220 err_when( indexId < 1 || indexId > rec_count );
00221
00222 indexId--;
00223
00224
00225
00226 if( read_all )
00227 return data_buf + index_buf[indexId].pointer - index_buf[0].pointer;
00228
00229
00230
00231 if( indexId == cur_rec_no && !use_common_buf )
00232 return data_buf;
00233
00234 dataSize = index_buf[indexId+1].pointer - index_buf[indexId].pointer;
00235
00236 file_seek( index_buf[indexId].pointer );
00237
00238
00239
00240 if( user_data_buf ) {
00241 if( user_start_read_pos > 0 ) {
00242 file_seek(user_start_read_pos,FILE_CURRENT);
00243 dataSize -= user_start_read_pos;
00244 }
00245
00246 if( dataSize > user_data_buf_size )
00247 return NULL;
00248
00249 file_read( user_data_buf, dataSize );
00250
00251 return user_data_buf;
00252 }
00253 else {
00254 err_when( use_common_buf && dataSize > COMMON_DATA_BUF_SIZE );
00255
00256 if( !use_common_buf && data_buf_size < dataSize )
00257 data_buf = mem_resize( data_buf, dataSize );
00258
00259 data_buf_size = dataSize;
00260
00261 file_read( data_buf, dataSize );
00262
00263 return data_buf;
00264 }
00265 }
00266
00267
00268
00269
00282
00283 err_when( !init_flag || !dataName || read_all);
00284
00285 int i;
00286
00287
00288
00289 for( i=0 ; i<rec_count ; i++ ) {
00290 if( strcmp( index_buf[i].name, dataName ) == 0 ) {
00291 file_seek( index_buf[i].pointer );
00292
00293 dataSize = index_buf[i+1].pointer - index_buf[i].pointer;
00294
00295 return this;
00296 }
00297 }
00298
00299 return NULL;
00300 }
00301
00302
00303
00304
00317
00318 err_when( !init_flag || !bitmapId || read_all );
00319
00320
00321
00322 file_seek( index_buf[bitmapId-1].pointer );
00323
00324 dataSize = index_buf[bitmapId].pointer - index_buf[bitmapId-1].pointer;
00325
00326 return this;
00327 }
00328
00329
00330
00331
00341
00342 user_data_buf = userDataBuf;
00343 user_data_buf_size = bufSize;
00344 user_start_read_pos = userStartReadPos;
00345 }
00346
00347
00348
00349
00353
00354 user_data_buf = NULL;
00355 user_data_buf_size = 0;
00356 }
00357
00358
00359
00360
00361 char *ResourceIdx::data_name(int i) {
00362 if( i < 1 || i > rec_count)
00363 return NULL;
00364
00365 return( index_buf[i-1].name );
00366 }
00367
00368