56 } |
56 } |
57 |
57 |
58 _dos_setdrive(save, &total); // restore the original drive |
58 _dos_setdrive(save, &total); // restore the original drive |
59 } |
59 } |
60 |
60 |
|
61 bool FiosGetDiskFreeSpace(const char *path, uint32 *tot) |
|
62 { |
|
63 struct diskfree_t free; |
|
64 char drive = path[0] - 'A' + 1; |
|
65 |
|
66 if (tot != NULL && _getdiskfree(drive, &free) == 0) { |
|
67 *tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector; |
|
68 return true; |
|
69 } |
|
70 |
|
71 return false; |
|
72 } |
|
73 |
61 bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) |
74 bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) |
62 { |
75 { |
63 char filename[MAX_PATH]; |
76 char filename[MAX_PATH]; |
64 |
77 |
65 snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name); |
78 snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name); |
66 if (stat(filename, sb) != 0) return false; |
79 if (stat(filename, sb) != 0) return false; |
67 |
80 |
68 return (ent->d_name[0] != '.'); // hidden file |
81 return (ent->d_name[0] != '.'); // hidden file |
69 } |
|
70 |
|
71 // Browse to |
|
72 char *FiosBrowseTo(const FiosItem *item) |
|
73 { |
|
74 char *path = _fios_path; |
|
75 char *s; |
|
76 |
|
77 switch (item->type) { |
|
78 case FIOS_TYPE_DRIVE: |
|
79 sprintf(path, "%c:\\", item->title[0]); |
|
80 break; |
|
81 |
|
82 case FIOS_TYPE_PARENT: |
|
83 s = strrchr(path, '\\'); |
|
84 if (s != path + 2) { |
|
85 s[0] = '\0'; |
|
86 } else { |
|
87 s[1] = '\0'; |
|
88 } |
|
89 break; |
|
90 |
|
91 case FIOS_TYPE_DIR: |
|
92 if (path[3] != '\0') strcat(path, "\\"); |
|
93 strcat(path, item->name); |
|
94 break; |
|
95 |
|
96 case FIOS_TYPE_DIRECT: |
|
97 sprintf(path, "%s\\", item->name); |
|
98 s = strrchr(path, '\\'); |
|
99 if (s[1] == '\0') s[0] = '\0'; // strip trailing slash |
|
100 break; |
|
101 |
|
102 case FIOS_TYPE_FILE: |
|
103 case FIOS_TYPE_OLDFILE: |
|
104 case FIOS_TYPE_SCENARIO: |
|
105 case FIOS_TYPE_OLD_SCENARIO: { |
|
106 static char str_buffr[512]; |
|
107 |
|
108 sprintf(str_buffr, "%s\\%s", path, item->name); |
|
109 return str_buffr; |
|
110 } |
|
111 } |
|
112 |
|
113 return NULL; |
|
114 } |
|
115 |
|
116 /** |
|
117 * Get descriptive texts. Returns the path and free space |
|
118 * left on the device |
|
119 * @param path string describing the path |
|
120 * @param tfs total free space in megabytes, optional (can be NULL) |
|
121 * @return StringID describing the path (free space or failure) |
|
122 */ |
|
123 StringID FiosGetDescText(const char **path, uint32 *tot) |
|
124 { |
|
125 struct diskfree_t free; |
|
126 char drive; |
|
127 |
|
128 *path = _fios_path; |
|
129 drive = *path[0] - 'A' + 1; |
|
130 |
|
131 if (tot != NULL && _getdiskfree(drive, &free) == 0) { |
|
132 *tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector; |
|
133 return STR_4005_BYTES_FREE; |
|
134 } |
|
135 |
|
136 return STR_4006_UNABLE_TO_READ_DRIVE; |
|
137 } |
82 } |
138 |
83 |
139 static void ChangeWorkingDirectory(char *exe) |
84 static void ChangeWorkingDirectory(char *exe) |
140 { |
85 { |
141 char *s = strrchr(exe, '\\'); |
86 char *s = strrchr(exe, '\\'); |