Wnd_file.cpp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //*****************************************************************************
  19. // C O N F I D E N T I A L -- W E S T W O O D S T U D I O S
  20. //*****************************************************************************
  21. //
  22. // Project name: Blade Runner CD-ROM Windows 95
  23. //
  24. // File name: WND_FILE.CPP
  25. //
  26. // Functions: WND_FILE.H
  27. //
  28. // Compatibility: Microsoft Visual C++ 4.0
  29. // Borland C++ 5.0
  30. // Watcom C++ 10.6
  31. //
  32. // Start Date: See comments in version control log
  33. // Last Update: See comments in version control log
  34. //
  35. // Programmer(s): Michael Legg
  36. // Mike Grayford
  37. //
  38. //*****************************************************************************
  39. //-----------------------------------------------------------------------------
  40. // include files...
  41. //-----------------------------------------------------------------------------
  42. #include "windows.h"
  43. #include <stdio.h>
  44. #include <sys/stat.h>
  45. #include "wnd_file.h"
  46. #include "winfix.h"
  47. //#include "autorun.h"
  48. //-----------------------------------------------------------------------------
  49. // private defines...
  50. //-----------------------------------------------------------------------------
  51. #define DEBUG_FILE "DebugAutorun.txt"
  52. // TC? This is non-Westwood Library 32-bit file access!
  53. #define MAX_FILES_OPEN_AT_A_TIME 25 // includes .MIX files
  54. //-----------------------------------------------------------------------------
  55. // private data...
  56. //-----------------------------------------------------------------------------
  57. char HD_Path [ MAX_PATH ] = { '\0' };
  58. char CD_Path [ MAX_PATH ] = { '\0' };
  59. char DebugFile [ MAX_PATH ] = { '\0' };
  60. // HANDLE Windows_File_Handles[ MAX_FILES_OPEN_AT_A_TIME ];
  61. // #if( SUPPORT_STREAMS )
  62. // FILE *Windows_File_Streams[ MAX_FILES_OPEN_AT_A_TIME ];
  63. // #endif
  64. //-----------------------------------------------------------------------------
  65. // non-class private functions in this module...
  66. //-----------------------------------------------------------------------------
  67. // int Get_Internal_File_Handle( void );
  68. // #if( SUPPORT_STREAMS )
  69. // FILE *Get_Internal_File_Stream( void );
  70. // #endif
  71. //-----------------------------------------------------------------------------
  72. // public file class functions...
  73. //-----------------------------------------------------------------------------
  74. #if(0)
  75. #ifndef _DEBUG
  76. void __cdecl Msg( int, char *, char *, ... ) { }; // line, file, fmt
  77. void Delete_Msg_File ( void ) { };
  78. #endif
  79. #endif
  80. #ifdef _DEBUG
  81. /****************************************************************************
  82. * MSG -- Write Message to Debug file with line and filename. *
  83. * *
  84. * INPUT: int line -- line where message originated. *
  85. * char *filename -- file where message originated. *
  86. * char *fmt -- variable argument list. *
  87. * *
  88. * OUTPUT: none. *
  89. * *
  90. * WARNINGS: none. *
  91. * *
  92. * HISTORY: *
  93. * 08/19/1998 MML : Created. *
  94. *==========================================================================*/
  95. void __cdecl Msg( int line, char *filename, char *fmt, ... )
  96. {
  97. char szBuffer1[ MAX_PATH * 3 ];
  98. char szBuffer2[ MAX_PATH * 2 ];
  99. char szFile[ MAX_PATH ];
  100. va_list va;
  101. DWORD nBytes;
  102. StandardFileClass file;
  103. //----------------------------------------------------------------------
  104. // Variable Arguments
  105. //----------------------------------------------------------------------
  106. va_start( va, fmt );
  107. if ( DebugFile[0] == '\0' ) {
  108. return;
  109. }
  110. if ( filename[0] == '\0' ) {
  111. return;
  112. }
  113. //----------------------------------------------------------------------
  114. // Make filename.
  115. //----------------------------------------------------------------------
  116. char *temp = strrchr( filename, '\\' );
  117. if ( temp != NULL || temp[0] != '\0' ) {
  118. temp++;
  119. strcpy( szFile, temp );
  120. }
  121. //----------------------------------------------------------------------
  122. // format message with header
  123. //----------------------------------------------------------------------
  124. memset( szBuffer1, '\0', MAX_PATH * 3 );
  125. memset( szBuffer2, '\0', MAX_PATH * 2 );
  126. wvsprintf( szBuffer2, fmt, va );
  127. wsprintf( szBuffer1, "%4d %14s %s\n", line, szFile, szBuffer2 );
  128. //----------------------------------------------------------------------
  129. // Open debug file and write to it.
  130. //----------------------------------------------------------------------
  131. file.Open( DebugFile, MODE_WRITE_APPEND );
  132. if ( file.Query_Open( )) {
  133. int length = strlen( szBuffer1 );
  134. nBytes = file.Write( szBuffer1, length );
  135. if ( nBytes != strlen( szBuffer1 )) {
  136. }
  137. file.Close();
  138. }
  139. //----------------------------------------------------------------------
  140. // To the debugger unless we need to be quiet
  141. //----------------------------------------------------------------------
  142. OutputDebugString( szBuffer1 );
  143. } /* Msg */
  144. /****************************************************************************
  145. * MSG -- Write Message to Debug file with line and filename. *
  146. * *
  147. * INPUT: int line -- line where message originated. *
  148. * wchar_t *filename -- file where message originated. *
  149. * wchar_t *fmt -- variable argument list. *
  150. * *
  151. * OUTPUT: none. *
  152. * *
  153. * WARNINGS: none. *
  154. * *
  155. * HISTORY: *
  156. * 08/19/1998 MML : Created. *
  157. *==========================================================================*/
  158. void __cdecl Msg( int line, char *filename, wchar_t *fmt, UINT codepage, ... )
  159. {
  160. wchar_t szBuffer1[ MAX_PATH * 3 ];
  161. wchar_t szBuffer2[ MAX_PATH * 3 ];
  162. char szBuffer3[ MAX_PATH * 3 ];
  163. wchar_t szFile[ MAX_PATH ];
  164. wchar_t szArgs[ MAX_PATH ];
  165. va_list va;
  166. int length;
  167. DWORD nBytes;
  168. StandardFileClass file;
  169. //----------------------------------------------------------------------
  170. // Variable Arguments
  171. //----------------------------------------------------------------------
  172. // va_start( va, fmt );
  173. va_start( va, codepage );
  174. memset( szArgs, '\0', MAX_PATH );
  175. memset( szFile, '\0', MAX_PATH );
  176. memset( szBuffer1, '\0', MAX_PATH * 3 );
  177. memset( szBuffer2, '\0', MAX_PATH * 2 );
  178. if ( DebugFile == NULL ) {
  179. return;
  180. }
  181. if ( filename == NULL ) {
  182. return;
  183. }
  184. //----------------------------------------------------------------------
  185. // Make filename.
  186. //----------------------------------------------------------------------
  187. char *temp = strrchr( filename, '\\' );
  188. if ( temp != NULL || temp[0] != '\0' ) {
  189. temp++;
  190. length = strlen( temp );
  191. mbstowcs( szFile, temp, length );
  192. }
  193. //----------------------------------------------------------------------
  194. // format message with header
  195. //----------------------------------------------------------------------
  196. vswprintf( szBuffer2, fmt, va );
  197. swprintf( szBuffer1, L"%4d %14s %s\n", line, szFile, szBuffer2 );
  198. //----------------------------------------------------------------------
  199. // Open debug file and write to it.
  200. //----------------------------------------------------------------------
  201. file.Open( DebugFile, MODE_WRITE_APPEND );
  202. if ( file.Query_Open( )) {
  203. //---------------------------------------------------------------------
  204. // Identifier Meaning
  205. // 932 Japan
  206. // 949 Korean
  207. // 950 Chinese (Taiwan; Hong Kong SAR, PRC)
  208. // 1252 Windows 3.1 Latin 1 (US, Western Europe)
  209. //---------------------------------------------------------------------
  210. WideCharToMultiByte( codepage, 0, szBuffer1, -1, szBuffer3, MAX_PATH*3, NULL, NULL );
  211. length = strlen( szBuffer3 );
  212. nBytes = file.Write( szBuffer3, length );
  213. if ( nBytes != strlen( szBuffer3 )) {
  214. }
  215. file.Close();
  216. }
  217. //----------------------------------------------------------------------
  218. // To the debugger unless we need to be quiet
  219. //----------------------------------------------------------------------
  220. OutputDebugString( szBuffer3 );
  221. } /* Msg */
  222. /***************************************************************************
  223. * DELETE_MSG_FILE -- Delete the Debug file. *
  224. * *
  225. * INPUT: none. *
  226. * *
  227. * OUTPUT: none. *
  228. * *
  229. * WARNINGS: none. *
  230. * *
  231. * HISTORY: *
  232. * 08/19/1998 MML : Created. *
  233. *=========================================================================*/
  234. //----------------------------------------------------------------------
  235. // Delete_Msg_File
  236. //----------------------------------------------------------------------
  237. void Delete_Msg_File ( void )
  238. {
  239. DWORD nBytes;
  240. char buff [ 300 ];
  241. char date [ 50 ];
  242. char time [ 30 ];
  243. StandardFileClass file;
  244. //----------------------------------------------------------------------
  245. // Make path to debug file.
  246. //----------------------------------------------------------------------
  247. // strcat( strcpy( DebugFile, ".\\" ), DEBUG_FILE );
  248. GetWindowsDirectory( DebugFile, MAX_PATH );
  249. if ( DebugFile[ strlen( DebugFile )-1 ] != '\\' ) {
  250. strcat( DebugFile, "\\" );
  251. }
  252. strcat( DebugFile, DEBUG_FILE );
  253. //--------------------------------------------------------------------------
  254. // Delete previous file.
  255. //--------------------------------------------------------------------------
  256. DeleteFile( DebugFile );
  257. //--------------------------------------------------------------------------
  258. // Create/Open new file.
  259. //--------------------------------------------------------------------------
  260. file.Open( DebugFile, MODE_WRITE_TRUNCATE );
  261. if ( file.Query_Open( )) {
  262. wsprintf( buff, "===========================================================\r\n" );
  263. nBytes = file.Write( buff, strlen( buff ));
  264. GetDateFormat( LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, date, 50 );
  265. // GetTimeFormat( LOCALE_USER_DEFAULT, TIME_NOSECONDS, NULL, NULL, time, 30 );
  266. GetTimeFormat( LOCALE_USER_DEFAULT, NULL, NULL, "hh':'mm':'ss tt", time, 30 );
  267. wsprintf( buff, "SETUP: File: %s Date: %s Time: %s.\r\n", DebugFile, date, time );
  268. nBytes = file.Write( buff, strlen( buff ));
  269. wsprintf( buff, "===========================================================\r\n\r\n" );
  270. nBytes = file.Write( buff, strlen( buff ));
  271. file.Close();
  272. }
  273. }
  274. #endif
  275. //------------------------------------------------------------------------------
  276. // StandardFileClass::StandardFileClass
  277. //------------------------------------------------------------------------------
  278. StandardFileClass::StandardFileClass( void )
  279. {
  280. //
  281. // reset all internal data
  282. //
  283. Reset();
  284. }
  285. //------------------------------------------------------------------------------
  286. // StandardFileClass::~StandardFileClass
  287. //------------------------------------------------------------------------------
  288. StandardFileClass::~StandardFileClass( void )
  289. {
  290. //
  291. // make sure this file got shut down before we destruct
  292. //
  293. #if( SUPPORT_HANDLES )
  294. ASSERT( File_Handle == INVALID_FILE_HANDLE );
  295. #endif
  296. #if( SUPPORT_STREAMS )
  297. ASSERT( File_Stream_Ptr == NULL );
  298. #endif
  299. ASSERT( Currently_Open == FALSE );
  300. //
  301. // reset all internal data
  302. //
  303. Reset();
  304. }
  305. //------------------------------------------------------------------------------
  306. // bool StandardFileClass::Open
  307. //------------------------------------------------------------------------------
  308. bool StandardFileClass::Open( const char *no_path_file_name, int open_mode )
  309. {
  310. int test;
  311. char *attributes;
  312. char pathed_file_name[ MAX_PATH_SIZE ];
  313. //
  314. // debug checks...
  315. //
  316. ASSERT( no_path_file_name != NULL );
  317. ASSERT( Currently_Open == FALSE );
  318. ASSERT( strlen( no_path_file_name ) < MAX_PATH );
  319. ASSERT( open_mode == MODE_READ_ONLY ||
  320. open_mode == MODE_WRITE_ONLY ||
  321. open_mode == MODE_READ_AND_WRITE ||
  322. open_mode == MODE_WRITE_TRUNCATE ||
  323. open_mode == MODE_WRITE_APPEND );
  324. //
  325. // open the file
  326. //
  327. #if( SUPPORT_HANDLES )
  328. ASSERT( File_Handle == INVALID_FILE_HANDLE );
  329. //
  330. // try HD open
  331. //
  332. strcpy( pathed_file_name, HD_Path );
  333. strcat( pathed_file_name, no_path_file_name );
  334. File_Handle = Open_File( pathed_file_name, open_mode );
  335. //
  336. // if not success with HD open, try CD
  337. //
  338. if ( File_Handle == INVALID_FILE_HANDLE ) {
  339. //
  340. // try CD open
  341. //
  342. strcpy( pathed_file_name, CD_Path );
  343. strcat( pathed_file_name, no_path_file_name );
  344. File_Handle = Open_File( pathed_file_name, open_mode );
  345. }
  346. //
  347. // not successful HD or CD open?
  348. //
  349. if ( File_Handle == INVALID_FILE_HANDLE ) {
  350. ASSERT( FALSE );
  351. return( FALSE );
  352. }
  353. #endif
  354. #if( SUPPORT_STREAMS )
  355. ASSERT( File_Stream_Ptr == NULL );
  356. //
  357. // "r" - open existing file for reading.
  358. // "w" - create new file, or truncate existing one, for output.
  359. // "a" - create new file, or append to if existing, for output.
  360. // "r+" - open existing file for read and write, starting at beginning of file. File must exist.
  361. // "w+" - create new file, or truncate if existing, for read and write.
  362. // "a+" - create new file, or append to existing, for read and write.
  363. //
  364. // add "b" to any string for binary instead of text
  365. //
  366. if ( open_mode == MODE_READ_ONLY ) {
  367. //
  368. // open existing file for input (binary)
  369. //
  370. attributes = "rb";
  371. }
  372. else if ( open_mode == MODE_WRITE_ONLY || open_mode == MODE_WRITE_TRUNCATE ) {
  373. //
  374. // create new or open/truncate existing file for output (binary)
  375. //
  376. attributes = "wb";
  377. }
  378. else if ( open_mode == MODE_READ_AND_WRITE ) {
  379. //
  380. // open existing for for read and write, starting at beginning of file
  381. //
  382. attributes = "r+b";
  383. }
  384. else if ( open_mode == MODE_WRITE_UPDATE ) {
  385. //
  386. // Create a new file for update (reading and writing). If a file by
  387. // that name already exists, it will be overwritten.
  388. //
  389. attributes = "w+b";
  390. }
  391. else if ( open_mode == MODE_WRITE_APPEND ) {
  392. //
  393. // append to existing file for output (binary)
  394. //
  395. attributes = "a";
  396. }
  397. else {
  398. ASSERT( FALSE );
  399. }
  400. //
  401. // try HD open
  402. //
  403. strcpy( pathed_file_name, HD_Path );
  404. strcat( pathed_file_name, no_path_file_name );
  405. File_Stream_Ptr = fopen( pathed_file_name, attributes );
  406. //
  407. // if not success with HD open, try CD
  408. //
  409. if ( File_Stream_Ptr == NULL ) {
  410. //
  411. // try CD open
  412. //
  413. strcpy( pathed_file_name, CD_Path );
  414. strcat( pathed_file_name, no_path_file_name );
  415. File_Stream_Ptr = fopen( pathed_file_name, attributes );
  416. }
  417. //
  418. // not successful?
  419. //
  420. if ( File_Stream_Ptr == NULL ) {
  421. return( FALSE );
  422. }
  423. //
  424. // get file stats
  425. //
  426. test = stat( pathed_file_name, &File_Statistics );
  427. ASSERT( test == 0 );
  428. #endif
  429. //
  430. // successful, set name and open status
  431. //
  432. strncpy( File_Name, pathed_file_name, MAX_PATH_SIZE-1 );
  433. Currently_Open = TRUE;
  434. //
  435. // success!
  436. //
  437. return( TRUE );
  438. }
  439. //------------------------------------------------------------------------------
  440. // bool StandardFileClass::Close
  441. //------------------------------------------------------------------------------
  442. bool StandardFileClass::Close( void )
  443. {
  444. int status;
  445. #if( SUPPORT_HANDLES )
  446. bool success;
  447. #endif
  448. //
  449. // debug checks...
  450. //
  451. ASSERT( Currently_Open == TRUE );
  452. #if( SUPPORT_HANDLES )
  453. ASSERT( File_Handle > INVALID_FILE_HANDLE );
  454. //
  455. // error?
  456. //
  457. if ( File_Handle == INVALID_FILE_HANDLE || Currently_Open == FALSE ) {
  458. //
  459. // no success
  460. //
  461. ASSERT( FALSE );
  462. return( FALSE );
  463. }
  464. //
  465. // close file
  466. //
  467. // status = Close_File( File_Handle );
  468. success = Close_File( File_Handle );
  469. ASSERT( success == TRUE );
  470. //
  471. // reset file data
  472. //
  473. File_Handle = INVALID_FILE_HANDLE;
  474. Currently_Open = FALSE;
  475. //
  476. // error on close?
  477. //
  478. // if ( status == INVALID_FILE_HANDLE ) {
  479. // return( FALSE );
  480. // }
  481. return( success );
  482. #endif
  483. #if( SUPPORT_STREAMS )
  484. ASSERT( File_Stream_Ptr != NULL );
  485. //
  486. // error?
  487. //
  488. if ( File_Stream_Ptr == NULL || Currently_Open == FALSE ) {
  489. //
  490. // no success
  491. //
  492. ASSERT( FALSE );
  493. return( FALSE );
  494. }
  495. //
  496. // close file
  497. //
  498. status = fclose( File_Stream_Ptr );
  499. ASSERT( status == 0 );
  500. //
  501. // reset file data
  502. //
  503. File_Stream_Ptr = NULL;
  504. Currently_Open = FALSE;
  505. //
  506. // error on close?
  507. //
  508. if ( status != 0 ) {
  509. return( FALSE );
  510. }
  511. #endif
  512. //
  513. // success!
  514. //
  515. return( TRUE );
  516. }
  517. //------------------------------------------------------------------------------
  518. // int StandardFileClass::Read
  519. //------------------------------------------------------------------------------
  520. int StandardFileClass::Read( void *buffer, unsigned long int bytes_to_read )
  521. {
  522. int bytes_read;
  523. int items_read;
  524. //
  525. // debug checks ( Fails if condition is FALSE ).
  526. //
  527. ASSERT( buffer != NULL );
  528. ASSERT( bytes_to_read > 0 );
  529. ASSERT( Currently_Open == TRUE );
  530. #if( SUPPORT_HANDLES )
  531. ASSERT( File_Handle != INVALID_FILE_HANDLE );
  532. //
  533. // error?
  534. //
  535. if ( File_Handle == INVALID_FILE_HANDLE || Currently_Open == FALSE ) {
  536. //
  537. // nothing read
  538. //
  539. return( 0 );
  540. }
  541. //
  542. // read in the bytes
  543. //
  544. bytes_read = Read_File( File_Handle, buffer, bytes_to_read );
  545. #endif
  546. #if( SUPPORT_STREAMS )
  547. ASSERT( File_Stream_Ptr != NULL );
  548. //
  549. // error?
  550. //
  551. if ( File_Stream_Ptr == NULL || Currently_Open == FALSE ) {
  552. //
  553. // nothing read
  554. //
  555. return( 0 );
  556. }
  557. //
  558. // read in the bytes
  559. //
  560. items_read = fread( buffer, bytes_to_read, 1, File_Stream_Ptr );
  561. // Msg( __LINE__, __FILE__, "Read --- bytes_to_read = %d, items_read = %d.", bytes_to_read, items_read );
  562. //
  563. // &&& we should leave this enabled!
  564. //
  565. // The TRR system causes an error when we load strings into RAM
  566. // IF the strings are kept on disk, then no error occurs!
  567. //
  568. ASSERT( items_read == 1 );
  569. bytes_read = items_read * bytes_to_read;
  570. #endif
  571. //
  572. // return how many bytes we read
  573. //
  574. return( bytes_read );
  575. }
  576. //------------------------------------------------------------------------------
  577. // int StandardFileClass::Write
  578. //------------------------------------------------------------------------------
  579. int StandardFileClass::Write( void *buffer, unsigned long int bytes_to_write )
  580. {
  581. int items_written;
  582. int bytes_written;
  583. //
  584. // debug checks
  585. //
  586. ASSERT( buffer != NULL );
  587. ASSERT( bytes_to_write > 0 );
  588. ASSERT( Currently_Open == TRUE );
  589. if ( buffer == NULL ) {
  590. return( 0 );
  591. }
  592. if ( bytes_to_write < 1 ) {
  593. return( 0 );
  594. }
  595. #if( SUPPORT_HANDLES )
  596. ASSERT( File_Handle != INVALID_FILE_HANDLE );
  597. //
  598. // error?
  599. //
  600. if ( File_Handle == INVALID_FILE_HANDLE || Currently_Open == FALSE ) {
  601. //
  602. // nothing written
  603. //
  604. return( 0 );
  605. }
  606. //
  607. // write out the bytes
  608. //
  609. bytes_written = Write_File( File_Handle, buffer, bytes_to_write );
  610. ASSERT( bytes_written == bytes_to_write );
  611. #endif
  612. #if( SUPPORT_STREAMS )
  613. ASSERT( File_Stream_Ptr != NULL );
  614. //
  615. // error?
  616. //
  617. if ( File_Stream_Ptr == NULL || Currently_Open == FALSE ) {
  618. //
  619. // nothing written
  620. //
  621. return( 0 );
  622. }
  623. //
  624. // write out the bytes
  625. //
  626. items_written = fwrite( buffer, bytes_to_write, 1, File_Stream_Ptr );
  627. ASSERT( items_written == 1 );
  628. bytes_written = items_written * bytes_to_write;
  629. #endif
  630. //
  631. // return how many bytes we wrote
  632. //
  633. return( bytes_written );
  634. }
  635. //------------------------------------------------------------------------------
  636. // bool StandardFileClass::Seek
  637. //------------------------------------------------------------------------------
  638. bool StandardFileClass::Seek( int distance, int seek_file_position )
  639. {
  640. //
  641. // debug checks...
  642. //
  643. ASSERT( Currently_Open == TRUE );
  644. ASSERT( seek_file_position == SEEK_SET ||
  645. seek_file_position == SEEK_CUR ||
  646. seek_file_position == SEEK_END );
  647. #if( SUPPORT_HANDLES )
  648. bool success;
  649. ASSERT( File_Handle != INVALID_FILE_HANDLE );
  650. //
  651. // error?
  652. //
  653. if ( File_Handle == INVALID_FILE_HANDLE || Currently_Open == FALSE ) {
  654. //
  655. // error
  656. //
  657. return( FALSE );
  658. }
  659. //
  660. // do the seek!
  661. //
  662. success = Seek_File( File_Handle, distance, seek_file_position );
  663. ASSERT( success == TRUE );
  664. return( success );
  665. #endif
  666. #if( SUPPORT_STREAMS )
  667. ASSERT( File_Stream_Ptr != NULL );
  668. //
  669. // error?
  670. //
  671. if ( File_Stream_Ptr == NULL || Currently_Open == FALSE ) {
  672. //
  673. // error
  674. //
  675. return( FALSE );
  676. }
  677. //
  678. // do the seek!
  679. //
  680. int result = fseek( File_Stream_Ptr, distance, seek_file_position );
  681. ASSERT( result == 0 );
  682. if ( ! result ) {
  683. return( TRUE );
  684. }
  685. return( FALSE );
  686. #endif
  687. }
  688. //------------------------------------------------------------------------------
  689. // int StandardFileClass::Tell
  690. //------------------------------------------------------------------------------
  691. //
  692. // return file position
  693. //
  694. int StandardFileClass::Tell( void )
  695. {
  696. int file_pos;
  697. //
  698. // debug checks...
  699. //
  700. ASSERT( Currently_Open == TRUE );
  701. #if( SUPPORT_HANDLES )
  702. ASSERT( File_Handle != INVALID_FILE_HANDLE );
  703. //
  704. // error?
  705. //
  706. if ( File_Handle == INVALID_FILE_HANDLE || Currently_Open == FALSE ) {
  707. //
  708. // error
  709. //
  710. return( -1 );
  711. }
  712. //
  713. // do the tell
  714. //
  715. file_pos = Tell_File( File_Handle );
  716. ASSERT( file_pos != -1 );
  717. return( file_pos );
  718. #endif
  719. #if( SUPPORT_STREAMS )
  720. ASSERT( File_Stream_Ptr != NULL );
  721. //
  722. // error?
  723. //
  724. if ( File_Stream_Ptr == NULL || Currently_Open == FALSE ) {
  725. //
  726. // error
  727. //
  728. return( -1 );
  729. }
  730. //
  731. // do the tell!
  732. //
  733. file_pos = ftell( File_Stream_Ptr );
  734. ASSERT( file_pos != -1 );
  735. return( file_pos );
  736. #endif
  737. }
  738. //------------------------------------------------------------------------------
  739. // int StandardFileClass::Query_Size
  740. //------------------------------------------------------------------------------
  741. int StandardFileClass::Query_Size( void )
  742. {
  743. int size;
  744. //
  745. // debug checks...
  746. //
  747. ASSERT( Currently_Open == TRUE );
  748. #if( SUPPORT_HANDLES )
  749. ASSERT( File_Handle != INVALID_FILE_HANDLE );
  750. //
  751. // error?
  752. //
  753. if ( File_Handle == INVALID_FILE_HANDLE || Currently_Open == FALSE ) {
  754. //
  755. // error
  756. //
  757. return( -1 );
  758. }
  759. size = File_Size( File_Handle );
  760. ASSERT( size > -1 );
  761. #endif
  762. #if( SUPPORT_STREAMS )
  763. ASSERT( File_Stream_Ptr != NULL );
  764. //
  765. // error?
  766. //
  767. if ( File_Stream_Ptr == NULL || Currently_Open == FALSE ) {
  768. //
  769. // error
  770. //
  771. return( -1 );
  772. }
  773. size = File_Statistics.st_size;
  774. ASSERT( size > -1 );
  775. #endif
  776. return( size );
  777. }
  778. //------------------------------------------------------------------------------
  779. // int StandardFileClass::Query_Size
  780. //------------------------------------------------------------------------------
  781. bool StandardFileClass::Query_Open( void )
  782. {
  783. return( Currently_Open );
  784. }
  785. //------------------------------------------------------------------------------
  786. // char *StandardFileClass::Query_Name_String
  787. //------------------------------------------------------------------------------
  788. char *StandardFileClass::Query_Name_String( void )
  789. {
  790. return( File_Name );
  791. }
  792. #if( SUPPORT_STREAMS )
  793. //------------------------------------------------------------------------------
  794. // FILE *StandardFileClass::Query_File_Stream_Pointer
  795. //------------------------------------------------------------------------------
  796. FILE *StandardFileClass::Query_File_Stream_Pointer( void )
  797. {
  798. return( File_Stream_Ptr );
  799. }
  800. #endif
  801. //------------------------------------------------------------------------------
  802. // private file class functions...
  803. //------------------------------------------------------------------------------
  804. //------------------------------------------------------------------------------
  805. // void StandardFileClass::Reset
  806. //------------------------------------------------------------------------------
  807. void StandardFileClass::Reset( void )
  808. {
  809. //
  810. // reset all internal data
  811. //
  812. #if( SUPPORT_HANDLES )
  813. File_Handle = INVALID_FILE_HANDLE;
  814. #endif
  815. #if( SUPPORT_STREAMS )
  816. File_Stream_Ptr = NULL;
  817. #endif
  818. Currently_Open = FALSE;
  819. File_Name[ 0 ] = '\0';
  820. }
  821. int StandardFileClass::End_Of_File ( void )
  822. {
  823. #if( SUPPORT_HANDLES )
  824. return( TRUE );
  825. #endif
  826. #if( SUPPORT_STREAMS )
  827. ASSERT( File_Stream_Ptr != NULL );
  828. if ( File_Stream_Ptr == NULL || Currently_Open == FALSE ) {
  829. return( -1 );
  830. }
  831. return( feof( File_Stream_Ptr ));
  832. #endif
  833. }
  834. int StandardFileClass::Flush ( void )
  835. {
  836. #if( SUPPORT_STREAMS )
  837. ASSERT( File_Stream_Ptr != NULL );
  838. if ( File_Stream_Ptr == NULL || Currently_Open == FALSE ) {
  839. return( -1 );
  840. }
  841. return( fflush( File_Stream_Ptr ));
  842. #endif
  843. }
  844. //------------------------------------------------------------------------------
  845. // non-class public functions from wnd_file.h
  846. //------------------------------------------------------------------------------
  847. #if( SUPPORT_HANDLES )
  848. //------------------------------------------------------------------------------
  849. // int Open_File
  850. //------------------------------------------------------------------------------
  851. // &&& - if enabled, must handle read and write combined
  852. HANDLE Open_File( char const *file_name, int mode )
  853. {
  854. HANDLE windows_file_handle;
  855. DWORD access;
  856. DWORD creation;
  857. DWORD share;
  858. // int fh;
  859. //
  860. // debug checks...
  861. //
  862. ASSERT( file_name != NULL );
  863. // ASSERT( mode == READ || mode == WRITE );
  864. ASSERT( mode == MODE_READ_ONLY ||
  865. mode == MODE_WRITE_ONLY ||
  866. mode == MODE_READ_AND_WRITE );
  867. //
  868. // get an available file handle
  869. //
  870. // fh = Get_Internal_File_Handle();
  871. // ASSERT( fh > INVALID_FILE_HANDLE );
  872. // if ( fh == INVALID_FILE_HANDLE ) {
  873. // return( INVALID_FILE_HANDLE );
  874. // }
  875. //
  876. // set the attributes based on read or write for the open
  877. //
  878. // if ( mode == READ ) {
  879. if ( mode == MODE_READ_ONLY ) {
  880. access = GENERIC_READ;
  881. share = FILE_SHARE_READ;
  882. creation = OPEN_EXISTING;
  883. }
  884. // else if ( mode == WRITE ) {
  885. else if ( mode == MODE_WRITE_ONLY ) {
  886. access = GENERIC_WRITE;
  887. share = 0;
  888. creation = CREATE_ALWAYS;
  889. }
  890. else if ( mode == MODE_READ_AND_WRITE ) {
  891. //
  892. // &&& are these correct?
  893. //
  894. access = GENERIC_READ | GENERIC_WRITE;
  895. share = FILE_SHARE_READ | FILE_SHARE_WRITE;
  896. creation = OPEN_EXISTING;
  897. }
  898. else {
  899. //
  900. // error;
  901. //
  902. ASSERT( FALSE );
  903. }
  904. //
  905. // 32-bit open file
  906. //
  907. windows_file_handle = CreateFile( file_name,
  908. access,
  909. share,
  910. NULL,
  911. creation,
  912. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
  913. NULL );
  914. //
  915. // error?
  916. //
  917. // we don't want to assert because we may be looking for a file
  918. // to just see if it is there...
  919. //
  920. // ASSERT( windows_file_handle != INVALID_HANDLE_VALUE );
  921. //
  922. // error!
  923. //
  924. if ( windows_file_handle == INVALID_HANDLE_VALUE ) {
  925. // #if( _DEBUG )
  926. // Debug_Printf( "%s: Create file error is %d\r\n", file_name, GetLastError());
  927. // #endif
  928. return( INVALID_FILE_HANDLE );
  929. }
  930. //
  931. // store the windows handle
  932. //
  933. // Windows_File_Handles[ fh ] = windows_file_handle;
  934. //
  935. // return our internal file handle
  936. //
  937. // return( fh );
  938. //
  939. // &&& this should be HANDLE, not int
  940. //
  941. // return( windows_file_handle );
  942. return( windows_file_handle );
  943. }
  944. //------------------------------------------------------------------------------
  945. // int Close_File
  946. //------------------------------------------------------------------------------
  947. bool Close_File( HANDLE handle )
  948. {
  949. bool success;
  950. //
  951. // debug checks...
  952. //
  953. // ASSERT( handle > INVALID_FILE_HANDLE );
  954. // ASSERT( Windows_File_Handles[ handle ] != NULL );
  955. ASSERT( handle != INVALID_FILE_HANDLE );
  956. //
  957. // close the file
  958. //
  959. // success = CloseHandle( Windows_File_Handles[ handle ] );
  960. //
  961. // &&& - this should be an actual HANDLE
  962. //
  963. success = CloseHandle( (HANDLE) handle );
  964. ASSERT( success == TRUE );
  965. // Debug_Printf( "File %d closed.\r\n", handle );
  966. //
  967. // free the entry
  968. //
  969. // Windows_File_Handles[ handle ] = NULL;
  970. //
  971. // return success or not
  972. //
  973. // if ( success == TRUE ) {
  974. // //
  975. // // return the invalid handle that closed
  976. // //
  977. // return( handle );
  978. // }
  979. // //
  980. // // error
  981. // //
  982. // return( INVALID_FILE_HANDLE );
  983. return( success );
  984. }
  985. //------------------------------------------------------------------------------
  986. // int Read_File
  987. //------------------------------------------------------------------------------
  988. int Read_File( HANDLE handle, void *buffer, unsigned long int bytes_to_read )
  989. {
  990. bool success;
  991. DWORD bytes_actually_read;
  992. //
  993. // debug checks...
  994. //
  995. ASSERT( handle > INVALID_FILE_HANDLE );
  996. ASSERT( buffer != NULL );
  997. // ASSERT( bytes_to_read > 0 );
  998. // ASSERT( Windows_File_Handles[ handle ] != NULL );
  999. // Debug_Printf( "Reading file %d\r\n", handle );
  1000. // success = ReadFile( Windows_File_Handles[ handle ],
  1001. // (void *) buffer,
  1002. // (DWORD) bytes_to_read,
  1003. // (DWORD *) &bytes_actually_read,
  1004. // NULL );
  1005. //
  1006. // &&& use real HANDLE
  1007. //
  1008. success = ReadFile( (HANDLE) handle,
  1009. (void *) buffer,
  1010. (DWORD) bytes_to_read,
  1011. (DWORD *) &bytes_actually_read,
  1012. NULL );
  1013. ASSERT( success == TRUE );
  1014. if ( success == FALSE ) {
  1015. //
  1016. // no bytes read
  1017. //
  1018. return( 0 );
  1019. }
  1020. return( bytes_actually_read );
  1021. }
  1022. //------------------------------------------------------------------------------
  1023. // int Write_File
  1024. //------------------------------------------------------------------------------
  1025. int Write_File( HANDLE handle, void const *buffer, unsigned long int bytes_to_write )
  1026. {
  1027. bool success;
  1028. DWORD bytes_actually_written;
  1029. //
  1030. // debug checks...
  1031. //
  1032. ASSERT( handle != INVALID_FILE_HANDLE );
  1033. ASSERT( buffer != NULL );
  1034. // ASSERT( bytes_to_write > 0 );
  1035. // ASSERT( Windows_File_Handles[ handle ] != NULL );
  1036. // Debug_Printf( "Writing file %d\r\n", handle );
  1037. // success = WriteFile( Windows_File_Handles[ handle ],
  1038. // buffer,
  1039. // (DWORD) bytes_to_write,
  1040. // (DWORD *) &bytes_actually_written,
  1041. // NULL );
  1042. //
  1043. // &&& make this a real handle
  1044. //
  1045. success = WriteFile( (HANDLE) handle,
  1046. buffer,
  1047. (DWORD) bytes_to_write,
  1048. (DWORD *) &bytes_actually_written,
  1049. NULL );
  1050. ASSERT( success == TRUE );
  1051. ASSERT( bytes_actually_written == bytes_to_write );
  1052. if ( success == FALSE ) {
  1053. //
  1054. // no bytes written
  1055. //
  1056. return( 0 );
  1057. }
  1058. return( bytes_actually_written );
  1059. }
  1060. //------------------------------------------------------------------------------
  1061. // bool Seek_File
  1062. //------------------------------------------------------------------------------
  1063. bool Seek_File( HANDLE handle, int distance, int seek_file_location )
  1064. {
  1065. DWORD success;
  1066. int move_method;
  1067. //
  1068. // debug checks...
  1069. //
  1070. ASSERT( handle != INVALID_FILE_HANDLE );
  1071. // ASSERT( distance >= 0 );
  1072. ASSERT( seek_file_location == SEEK_SET ||
  1073. seek_file_location == SEEK_CUR ||
  1074. seek_file_location == SEEK_END );
  1075. // ASSERT( Windows_File_Handles[ handle ] != NULL );
  1076. //
  1077. // set the seek movement method
  1078. //
  1079. if ( seek_file_location == SEEK_SET ) {
  1080. move_method = FILE_BEGIN;
  1081. }
  1082. else if ( seek_file_location == SEEK_CUR ) {
  1083. move_method = FILE_CURRENT;
  1084. }
  1085. else if ( seek_file_location == SEEK_END ) {
  1086. move_method = FILE_END;
  1087. }
  1088. // success = SetFilePointer( Windows_File_Handles[ handle ],
  1089. // distance,
  1090. // NULL,
  1091. // move_method );
  1092. //
  1093. // make this a real handle
  1094. //
  1095. success = SetFilePointer( (HANDLE) handle,
  1096. distance,
  1097. NULL,
  1098. move_method );
  1099. if ( success == 0xFFFFFFFF ) {
  1100. return( FALSE );
  1101. }
  1102. return( TRUE );
  1103. }
  1104. //------------------------------------------------------------------------------
  1105. // int Tell_File
  1106. //------------------------------------------------------------------------------
  1107. int Tell_File( HANDLE handle )
  1108. {
  1109. int move_method;
  1110. int pos;
  1111. //
  1112. // debug checks...
  1113. //
  1114. ASSERT( handle != INVALID_FILE_HANDLE );
  1115. // ASSERT( Windows_File_Handles[ handle ] != NULL );
  1116. //
  1117. // set the seek movement method
  1118. //
  1119. move_method = FILE_CURRENT;
  1120. //
  1121. // move nowhere
  1122. //
  1123. pos = SetFilePointer( handle,
  1124. 0, // distance to move
  1125. NULL,
  1126. move_method );
  1127. if ( pos == 0xFFFFFFFF ) {
  1128. return( -1 );
  1129. }
  1130. return( pos );
  1131. }
  1132. //------------------------------------------------------------------------------
  1133. // int File_Size
  1134. //------------------------------------------------------------------------------
  1135. int File_Size( HANDLE handle )
  1136. {
  1137. DWORD file_size;
  1138. //
  1139. // debug checks...
  1140. //
  1141. ASSERT( handle != INVALID_FILE_HANDLE );
  1142. // ASSERT( Windows_File_Handles[ handle ] != NULL );
  1143. file_size = GetFileSize( handle, NULL );
  1144. ASSERT( file_size != 0xFFFFFFFF );
  1145. //
  1146. // error!
  1147. //
  1148. if ( file_size == 0xFFFFFFFF ) {
  1149. return( -1 );
  1150. }
  1151. //
  1152. // return size
  1153. //
  1154. return( (int) file_size );
  1155. }
  1156. //------------------------------------------------------------------------------
  1157. // bool Full_Path_File_Exists
  1158. //------------------------------------------------------------------------------
  1159. bool Full_Path_File_Exists( char const *file_name )
  1160. {
  1161. HANDLE fh;
  1162. //
  1163. // debug checks...
  1164. //
  1165. ASSERT( file_name != NULL );
  1166. //
  1167. // if we can open the file for read, it exists...
  1168. //
  1169. fh = Open_File( file_name, MODE_READ_ONLY );
  1170. //
  1171. // don't assert, because the we might be checking for a file
  1172. // that actually does not exist!
  1173. //
  1174. // ASSERT( fh > INVALID_FILE_HANDLE );
  1175. //
  1176. // close the file and return success if opened
  1177. //
  1178. if ( fh != INVALID_FILE_HANDLE ) {
  1179. Close_File( fh );
  1180. return( TRUE );
  1181. }
  1182. //
  1183. // no success if file was not opened
  1184. //
  1185. return( FALSE );
  1186. }
  1187. //------------------------------------------------------------------------------
  1188. // bool HD_File_Exists
  1189. //------------------------------------------------------------------------------
  1190. bool HD_File_Exists( char const *file_name )
  1191. {
  1192. HANDLE fh;
  1193. char full_path[ MAX_PATH_SIZE ];
  1194. //
  1195. // debug checks...
  1196. //
  1197. ASSERT( file_name != NULL );
  1198. strcpy( full_path, HD_Path );
  1199. strcat( full_path, file_name );
  1200. //
  1201. // if we can open the file for read, it exists...
  1202. //
  1203. fh = Open_File( full_path, MODE_READ_ONLY );
  1204. //
  1205. // don't assert, because the we might be checking for a file
  1206. // that actually does not exist!
  1207. //
  1208. //
  1209. // close the file and return success if opened
  1210. //
  1211. if ( fh != INVALID_FILE_HANDLE ) {
  1212. Close_File( fh );
  1213. return( TRUE );
  1214. }
  1215. //
  1216. // no success if file was not opened
  1217. //
  1218. return( FALSE );
  1219. }
  1220. //------------------------------------------------------------------------------
  1221. // bool CD_File_Exists
  1222. //------------------------------------------------------------------------------
  1223. bool CD_File_Exists( char const *file_name )
  1224. {
  1225. HANDLE fh;
  1226. char full_path[ MAX_PATH_SIZE ];
  1227. //
  1228. // debug checks...
  1229. //
  1230. ASSERT( file_name != NULL );
  1231. strcpy( full_path, CD_Path );
  1232. strcat( full_path, file_name );
  1233. //
  1234. // if we can open the file for read, it exists...
  1235. //
  1236. fh = Open_File( full_path, MODE_READ_ONLY );
  1237. //
  1238. // don't assert, because the we might be checking for a file
  1239. // that actually does not exist!
  1240. //
  1241. //
  1242. // close the file and return success if opened
  1243. //
  1244. if ( fh != INVALID_FILE_HANDLE ) {
  1245. Close_File( fh );
  1246. return( TRUE );
  1247. }
  1248. //
  1249. // no success if file was not opened
  1250. //
  1251. return( FALSE );
  1252. }
  1253. #if( 0 )
  1254. //------------------------------------------------------------------------------
  1255. // bool Find_File
  1256. //------------------------------------------------------------------------------
  1257. bool Find_File( char const *file_name )
  1258. {
  1259. return( File_Exists( file_name ) );
  1260. }
  1261. #endif
  1262. #if( 0 )
  1263. //------------------------------------------------------------------------------
  1264. // int Get_Internal_File_Handle
  1265. //------------------------------------------------------------------------------
  1266. //
  1267. // private...
  1268. //
  1269. int Get_Internal_File_Handle( void )
  1270. {
  1271. static bool _initialized = FALSE;
  1272. int i;
  1273. //
  1274. // initialize file handle table once!
  1275. //
  1276. if ( ! _initialized ) {
  1277. for ( i = 0; i < MAX_FILES_OPEN_AT_A_TIME; i ++ ) {
  1278. Windows_File_Handles[ i ] = NULL;
  1279. }
  1280. _initialized = TRUE;
  1281. }
  1282. //
  1283. // look for free slot
  1284. //
  1285. for ( i = 0; i < MAX_FILES_OPEN_AT_A_TIME; i ++ ) {
  1286. if ( Windows_File_Handles[ i ] == NULL ) {
  1287. return( i );
  1288. }
  1289. }
  1290. //
  1291. // no free slot found
  1292. //
  1293. ASSERT( FALSE );
  1294. return( INVALID_FILE_HANDLE );
  1295. }
  1296. #endif
  1297. #endif // SUPPORT_HANDLES
  1298. #if( SUPPORT_STREAMS )
  1299. //------------------------------------------------------------------------------
  1300. // bool Full_Path_File_Exists
  1301. //------------------------------------------------------------------------------
  1302. bool Full_Path_File_Exists( char const *file_name )
  1303. {
  1304. FILE *file_stream_ptr;
  1305. file_stream_ptr = fopen( file_name, "rb" );
  1306. if ( file_stream_ptr != NULL ) {
  1307. fclose( file_stream_ptr );
  1308. return( TRUE );
  1309. }
  1310. return( FALSE );
  1311. }
  1312. //------------------------------------------------------------------------------
  1313. // bool HD_File_Exists
  1314. //------------------------------------------------------------------------------
  1315. bool HD_File_Exists( char const *file_name )
  1316. {
  1317. FILE *file_stream_ptr;
  1318. char full_path[ MAX_PATH_SIZE ];
  1319. //
  1320. // debug checks...
  1321. //
  1322. ASSERT( file_name != NULL );
  1323. strcpy( full_path, HD_Path );
  1324. strcat( full_path, file_name );
  1325. file_stream_ptr = fopen( full_path, "rb" );
  1326. if ( file_stream_ptr != NULL ) {
  1327. fclose( file_stream_ptr );
  1328. return( TRUE );
  1329. }
  1330. return( FALSE );
  1331. }
  1332. //------------------------------------------------------------------------------
  1333. // bool CD_File_Exists
  1334. //------------------------------------------------------------------------------
  1335. bool CD_File_Exists( char const *file_name )
  1336. {
  1337. FILE *file_stream_ptr;
  1338. char full_path[ MAX_PATH_SIZE ];
  1339. //
  1340. // debug checks...
  1341. //
  1342. ASSERT( file_name != NULL );
  1343. strcpy( full_path, CD_Path );
  1344. strcat( full_path, file_name );
  1345. file_stream_ptr = fopen( full_path, "rb" );
  1346. if ( file_stream_ptr != NULL ) {
  1347. fclose( file_stream_ptr );
  1348. return( TRUE );
  1349. }
  1350. return( FALSE );
  1351. }
  1352. #if( 0 )
  1353. //------------------------------------------------------------------------------
  1354. // bool Find_File
  1355. //------------------------------------------------------------------------------
  1356. bool Find_File( char const *file_name )
  1357. {
  1358. return( File_Exists( file_name ) );
  1359. }
  1360. #endif
  1361. #endif // SUPPORT_STREAMS