src/fileio.cpp
branchNewGRF_ports
changeset 6871 5a9dc001e1ad
parent 6870 ca3fd1fbe311
child 6872 1c4a4a609f85
equal deleted inserted replaced
6870:ca3fd1fbe311 6871:5a9dc001e1ad
    22 /*************************************************/
    22 /*************************************************/
    23 /* FILE IO ROUTINES ******************************/
    23 /* FILE IO ROUTINES ******************************/
    24 /*************************************************/
    24 /*************************************************/
    25 
    25 
    26 #define FIO_BUFFER_SIZE 512
    26 #define FIO_BUFFER_SIZE 512
    27 #define MAX_HANDLES 64
       
    28 
    27 
    29 struct Fio {
    28 struct Fio {
    30 	byte *buffer, *buffer_end;          ///< position pointer in local buffer and last valid byte of buffer
    29 	byte *buffer, *buffer_end;             ///< position pointer in local buffer and last valid byte of buffer
    31 	uint32 pos;                         ///< current (system) position in file
    30 	uint32 pos;                            ///< current (system) position in file
    32 	FILE *cur_fh;                       ///< current file handle
    31 	FILE *cur_fh;                          ///< current file handle
    33 	const char *filename;               ///< current filename
    32 	const char *filename;                  ///< current filename
    34 	FILE *handles[MAX_HANDLES];         ///< array of file handles we can have open
    33 	FILE *handles[MAX_FILE_SLOTS];         ///< array of file handles we can have open
    35 	byte buffer_start[FIO_BUFFER_SIZE]; ///< local buffer when read from file
    34 	byte buffer_start[FIO_BUFFER_SIZE];    ///< local buffer when read from file
    36 	const char *filenames[MAX_HANDLES]; ///< array of filenames we (should) have open
    35 	const char *filenames[MAX_FILE_SLOTS]; ///< array of filenames we (should) have open
    37 #if defined(LIMITED_FDS)
    36 #if defined(LIMITED_FDS)
    38 	uint open_handles;                  ///< current amount of open handles
    37 	uint open_handles;                     ///< current amount of open handles
    39 	uint usage_count[MAX_HANDLES];      ///< count how many times this file has been opened
    38 	uint usage_count[MAX_FILE_SLOTS];      ///< count how many times this file has been opened
    40 #endif /* LIMITED_FDS */
    39 #endif /* LIMITED_FDS */
    41 };
    40 };
    42 
    41 
    43 static Fio _fio;
    42 static Fio _fio;
    44 
    43 
   362 {
   361 {
   363 #if defined(WIN32) || defined(WINCE)
   362 #if defined(WIN32) || defined(WINCE)
   364 	CreateDirectory(OTTD2FS(name), NULL);
   363 	CreateDirectory(OTTD2FS(name), NULL);
   365 #elif defined(OS2) && !defined(__INNOTEK_LIBC__)
   364 #elif defined(OS2) && !defined(__INNOTEK_LIBC__)
   366 	mkdir(OTTD2FS(name));
   365 	mkdir(OTTD2FS(name));
       
   366 #elif defined(__MORPHOS__) || defined(__AMIGAOS__)
       
   367 	char buf[MAX_PATH];
       
   368 	ttd_strlcpy(buf, name, MAX_PATH);
       
   369 
       
   370 	size_t len = strlen(name) - 1;
       
   371 	if (buf[len] == '/') {
       
   372 		buf[len] = '\0'; // Kill pathsep, so mkdir() will not fail
       
   373 	}
       
   374 
       
   375 	mkdir(OTTD2FS(buf), 0755);
   367 #else
   376 #else
   368 	mkdir(OTTD2FS(name), 0755);
   377 	mkdir(OTTD2FS(name), 0755);
   369 #endif
   378 #endif
   370 }
   379 }
   371 
   380 
   507 
   516 
   508 		DEBUG(misc, 6, "Found file in tar: %s (%d bytes, %d offset)", name, skip, pos);
   517 		DEBUG(misc, 6, "Found file in tar: %s (%d bytes, %d offset)", name, skip, pos);
   509 		if (_tar_filelist.insert(TarFileList::value_type(name, entry)).second) num++;
   518 		if (_tar_filelist.insert(TarFileList::value_type(name, entry)).second) num++;
   510 
   519 
   511 		/* Skip to the next block.. */
   520 		/* Skip to the next block.. */
   512 		skip = ALIGN(skip, 512);
   521 		skip = Align(skip, 512);
   513 		fseek(f, skip, SEEK_CUR);
   522 		fseek(f, skip, SEEK_CUR);
   514 		pos += skip;
   523 		pos += skip;
   515 	}
   524 	}
   516 
   525 
   517 	DEBUG(misc, 1, "Found tar '%s' with %d new files", filename, num);
   526 	DEBUG(misc, 1, "Found tar '%s' with %d new files", filename, num);
   719 
   728 
   720 	char *save_dir     = str_fmt("%s%s", _personal_dir, FioGetSubdirectory(SAVE_DIR));
   729 	char *save_dir     = str_fmt("%s%s", _personal_dir, FioGetSubdirectory(SAVE_DIR));
   721 	char *autosave_dir = str_fmt("%s%s", _personal_dir, FioGetSubdirectory(AUTOSAVE_DIR));
   730 	char *autosave_dir = str_fmt("%s%s", _personal_dir, FioGetSubdirectory(AUTOSAVE_DIR));
   722 
   731 
   723 	/* Make the necessary folders */
   732 	/* Make the necessary folders */
       
   733 #if !defined(__MORPHOS__) && !defined(__AMIGA__) && defined(WITH_PERSONAL_DIR)
   724 	FioCreateDirectory(_personal_dir);
   734 	FioCreateDirectory(_personal_dir);
       
   735 #endif
       
   736 
   725 	FioCreateDirectory(save_dir);
   737 	FioCreateDirectory(save_dir);
   726 	FioCreateDirectory(autosave_dir);
   738 	FioCreateDirectory(autosave_dir);
   727 
   739 
   728 	free(save_dir);
   740 	free(save_dir);
   729 	free(autosave_dir);
   741 	free(autosave_dir);