diff options
author | Darkvater <darkvater@openttd.org> | 2006-08-05 00:53:09 +0000 |
---|---|---|
committer | Darkvater <darkvater@openttd.org> | 2006-08-05 00:53:09 +0000 |
commit | 198f6caf20bf425bd1d3c8b91291f58213f6b60b (patch) | |
tree | 060490cbd9c8e7eb1a0f6a326ba4b273c535f7d7 /os2.c | |
parent | 525a0ad4c033b378511a3bfc8da79b67a94c2497 (diff) | |
download | openttd-198f6caf20bf425bd1d3c8b91291f58213f6b60b.tar.xz |
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Diffstat (limited to 'os2.c')
-rw-r--r-- | os2.c | 79 |
1 files changed, 12 insertions, 67 deletions
@@ -58,82 +58,27 @@ void FiosGetDrives(void) _dos_setdrive(save, &total); // restore the original drive } -bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) +bool FiosGetDiskFreeSpace(const char *path, uint32 *tot) { - char filename[MAX_PATH]; - - snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name); - if (stat(filename, sb) != 0) return false; - - return (ent->d_name[0] != '.'); // hidden file -} - -// Browse to -char *FiosBrowseTo(const FiosItem *item) -{ - char *path = _fios_path; - char *s; + struct diskfree_t free; + char drive = path[0] - 'A' + 1; - switch (item->type) { - case FIOS_TYPE_DRIVE: - sprintf(path, "%c:\\", item->title[0]); - break; - - case FIOS_TYPE_PARENT: - s = strrchr(path, '\\'); - if (s != path + 2) { - s[0] = '\0'; - } else { - s[1] = '\0'; - } - break; - - case FIOS_TYPE_DIR: - if (path[3] != '\0') strcat(path, "\\"); - strcat(path, item->name); - break; - - case FIOS_TYPE_DIRECT: - sprintf(path, "%s\\", item->name); - s = strrchr(path, '\\'); - if (s[1] == '\0') s[0] = '\0'; // strip trailing slash - break; - - case FIOS_TYPE_FILE: - case FIOS_TYPE_OLDFILE: - case FIOS_TYPE_SCENARIO: - case FIOS_TYPE_OLD_SCENARIO: { - static char str_buffr[512]; - - sprintf(str_buffr, "%s\\%s", path, item->name); - return str_buffr; - } + if (tot != NULL && _getdiskfree(drive, &free) == 0) { + *tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector; + return true; } - return NULL; + return false; } -/** - * Get descriptive texts. Returns the path and free space - * left on the device - * @param path string describing the path - * @param tfs total free space in megabytes, optional (can be NULL) - * @return StringID describing the path (free space or failure) - */ -StringID FiosGetDescText(const char **path, uint32 *tot) +bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) { - struct diskfree_t free; - char drive; - - *path = _fios_path; - drive = *path[0] - 'A' + 1; + char filename[MAX_PATH]; - if (tot != NULL && _getdiskfree(drive, &free) == 0) { - *tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector; - return STR_4005_BYTES_FREE; - } + snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name); + if (stat(filename, sb) != 0) return false; - return STR_4006_UNABLE_TO_READ_DRIVE; + return (ent->d_name[0] != '.'); // hidden file } static void ChangeWorkingDirectory(char *exe) |