1 |
|
/* |
2 |
|
* extfs_amiga.cpp - MacOS file system for access native file system access, AmigaOS specific stuff |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2000 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
77 |
|
* /path/.finf/file |
78 |
|
* Resource fork: |
79 |
|
* /path/.rsrc/file |
80 |
+ |
* |
81 |
+ |
* The .finf files store a FInfo/DInfo, followed by a FXInfo/DXInfo |
82 |
+ |
* (16+16 bytes) |
83 |
|
*/ |
84 |
|
|
82 |
– |
// Layout of Finder info helper files (all fields big-endian) |
83 |
– |
struct finf_struct { |
84 |
– |
uint32 type; |
85 |
– |
uint32 creator; |
86 |
– |
uint16 flags; |
87 |
– |
uint8 pad0[22]; // total size: 32 bytes to match the size of FInfo+FXInfo |
88 |
– |
}; |
89 |
– |
|
85 |
|
static void make_helper_path(const char *src, char *dest, const char *add, bool only_dir = false) |
86 |
|
{ |
87 |
|
dest[0] = 0; |
105 |
|
{ |
106 |
|
char helper_dir[MAX_PATH_LENGTH]; |
107 |
|
make_helper_path(path, helper_dir, add, true); |
108 |
+ |
if (helper_dir[strlen(helper_dir) - 1] == '/') // Remove trailing "/" |
109 |
+ |
helper_dir[strlen(helper_dir) - 1] = 0; |
110 |
|
return mkdir(helper_dir, 0777); |
111 |
|
} |
112 |
|
|
184 |
|
{".tga", 'TPIC', 'ogle'}, |
185 |
|
{".tif", 'TIFF', 'ogle'}, |
186 |
|
{".tiff", 'TIFF', 'ogle'}, |
187 |
+ |
{".htm", 'TEXT', 'MOSS'}, |
188 |
|
{".html", 'TEXT', 'MOSS'}, |
189 |
|
{".txt", 'TEXT', 'ttxt'}, |
190 |
|
{".rtf", 'TEXT', 'MSWD'}, |
205 |
|
{".mov", 'MooV', 'TVOD'}, |
206 |
|
{".fli", 'FLI ', 'TVOD'}, |
207 |
|
{".avi", 'VfW ', 'TVOD'}, |
208 |
+ |
{".qxd", 'XDOC', 'XPR3'}, |
209 |
+ |
{".hfv", 'DDim', 'ddsk'}, |
210 |
+ |
{".dsk", 'DDim', 'ddsk'}, |
211 |
+ |
{".img", 'rohd', 'ddsk'}, |
212 |
|
{NULL, 0, 0} // End marker |
213 |
|
}; |
214 |
|
|
215 |
< |
void get_finder_type(const char *path, uint32 &type, uint32 &creator) |
215 |
> |
void get_finfo(const char *path, uint32 finfo, uint32 fxinfo) |
216 |
|
{ |
217 |
< |
type = 0; |
218 |
< |
creator = 0; |
217 |
> |
// Set default finder info |
218 |
> |
Mac_memset(finfo, 0, SIZEOF_FInfo); |
219 |
> |
if (fxinfo) |
220 |
> |
Mac_memset(fxinfo, 0, SIZEOF_FXInfo); |
221 |
> |
WriteMacInt16(finfo + fdFlags, DEFAULT_FINDER_FLAGS); |
222 |
> |
WriteMacInt32(finfo + fdLocation, (uint32)-1); |
223 |
|
|
224 |
< |
// Open Finder info file |
224 |
> |
// Read Finder info file |
225 |
|
int fd = open_finf(path, O_RDONLY); |
226 |
|
if (fd >= 0) { |
227 |
< |
|
228 |
< |
// Read file |
229 |
< |
finf_struct finf; |
224 |
< |
if (read(fd, &finf, sizeof(finf_struct)) >= 8) { |
225 |
< |
|
226 |
< |
// Type/creator are in Finder info file, return them |
227 |
< |
type = ntohl(finf.type); |
228 |
< |
creator = ntohl(finf.creator); |
229 |
< |
close(fd); |
230 |
< |
return; |
231 |
< |
} |
227 |
> |
ssize_t actual = read(fd, Mac2HostAddr(finfo), SIZEOF_FInfo); |
228 |
> |
if (fxinfo) |
229 |
> |
actual += read(fd, Mac2HostAddr(fxinfo), SIZEOF_FXInfo); |
230 |
|
close(fd); |
231 |
+ |
if (actual >= SIZEOF_FInfo) |
232 |
+ |
return; |
233 |
|
} |
234 |
|
|
235 |
|
// No Finder info file, translate file name extension to MacOS type/creator |
236 |
< |
int path_len = strlen(path); |
237 |
< |
for (int i=0; e2t_translation[i].ext; i++) { |
238 |
< |
int ext_len = strlen(e2t_translation[i].ext); |
239 |
< |
if (path_len < ext_len) |
240 |
< |
continue; |
241 |
< |
if (!strcmp(path + path_len - ext_len, e2t_translation[i].ext)) { |
242 |
< |
type = e2t_translation[i].type; |
243 |
< |
creator = e2t_translation[i].creator; |
244 |
< |
break; |
236 |
> |
struct stat st; |
237 |
> |
if (stat(path, &st) == 0 && !S_ISDIR(st.st_mode)) { |
238 |
> |
int path_len = strlen(path); |
239 |
> |
for (int i=0; e2t_translation[i].ext; i++) { |
240 |
> |
int ext_len = strlen(e2t_translation[i].ext); |
241 |
> |
if (path_len < ext_len) |
242 |
> |
continue; |
243 |
> |
if (!strcasecmp(path + path_len - ext_len, e2t_translation[i].ext)) { |
244 |
> |
WriteMacInt32(finfo + fdType, e2t_translation[i].type); |
245 |
> |
WriteMacInt32(finfo + fdCreator, e2t_translation[i].creator); |
246 |
> |
break; |
247 |
> |
} |
248 |
|
} |
249 |
|
} |
250 |
|
} |
251 |
|
|
252 |
< |
void set_finder_type(const char *path, uint32 type, uint32 creator) |
250 |
< |
{ |
251 |
< |
// Open Finder info file |
252 |
< |
int fd = open_finf(path, O_RDWR); |
253 |
< |
if (fd < 0) |
254 |
< |
return; |
255 |
< |
|
256 |
< |
// Read file |
257 |
< |
finf_struct finf; |
258 |
< |
finf.flags = DEFAULT_FINDER_FLAGS; |
259 |
< |
memset(&finf, 0, sizeof(finf_struct)); |
260 |
< |
read(fd, &finf, sizeof(finf_struct)); |
261 |
< |
|
262 |
< |
// Set Finder flags |
263 |
< |
finf.type = htonl(type); |
264 |
< |
finf.creator = htonl(creator); |
265 |
< |
|
266 |
< |
// Update file |
267 |
< |
lseek(fd, 0, SEEK_SET); |
268 |
< |
write(fd, &finf, sizeof(finf_struct)); |
269 |
< |
close(fd); |
270 |
< |
} |
271 |
< |
|
272 |
< |
|
273 |
< |
/* |
274 |
< |
* Get/set finder flags for file/dir specified by full path |
275 |
< |
*/ |
276 |
< |
|
277 |
< |
void get_finder_flags(const char *path, uint16 &flags) |
278 |
< |
{ |
279 |
< |
flags = DEFAULT_FINDER_FLAGS; // Default |
280 |
< |
|
281 |
< |
// Open Finder info file |
282 |
< |
int fd = open_finf(path, O_RDONLY); |
283 |
< |
if (fd < 0) |
284 |
< |
return; |
285 |
< |
|
286 |
< |
// Read Finder flags |
287 |
< |
finf_struct finf; |
288 |
< |
if (read(fd, &finf, sizeof(finf_struct)) >= 10) |
289 |
< |
flags = ntohs(finf.flags); |
290 |
< |
|
291 |
< |
// Close file |
292 |
< |
close(fd); |
293 |
< |
} |
294 |
< |
|
295 |
< |
void set_finder_flags(const char *path, uint16 flags) |
252 |
> |
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo) |
253 |
|
{ |
254 |
|
// Open Finder info file |
255 |
|
int fd = open_finf(path, O_RDWR); |
256 |
|
if (fd < 0) |
257 |
|
return; |
258 |
|
|
259 |
< |
// Read file |
260 |
< |
finf_struct finf; |
261 |
< |
memset(&finf, 0, sizeof(finf_struct)); |
262 |
< |
finf.flags = DEFAULT_FINDER_FLAGS; |
306 |
< |
read(fd, &finf, sizeof(finf_struct)); |
307 |
< |
|
308 |
< |
// Set Finder flags |
309 |
< |
finf.flags = htons(flags); |
310 |
< |
|
311 |
< |
// Update file |
312 |
< |
lseek(fd, 0, SEEK_SET); |
313 |
< |
write(fd, &finf, sizeof(finf_struct)); |
259 |
> |
// Write file |
260 |
> |
write(fd, Mac2HostAddr(finfo), SIZEOF_FInfo); |
261 |
> |
if (fxinfo) |
262 |
> |
write(fd, Mac2HostAddr(fxinfo), SIZEOF_FXInfo); |
263 |
|
close(fd); |
264 |
|
} |
265 |
|
|