78 |
|
* /path/.finf/file |
79 |
|
* Resource fork: |
80 |
|
* /path/.rsrc/file |
81 |
+ |
* |
82 |
+ |
* The .finf files store a FInfo/DInfo, followed by a FXInfo/DXInfo |
83 |
+ |
* (16+16 bytes) |
84 |
|
*/ |
85 |
|
|
83 |
– |
// Layout of Finder info helper files (all fields big-endian) |
84 |
– |
struct finf_struct { |
85 |
– |
uint32 type; |
86 |
– |
uint32 creator; |
87 |
– |
uint16 flags; |
88 |
– |
uint8 pad0[22]; // total size: 32 bytes to match the size of FInfo+FXInfo |
89 |
– |
}; |
90 |
– |
|
86 |
|
static void make_helper_path(const char *src, char *dest, const char *add, bool only_dir = false) |
87 |
|
{ |
88 |
|
dest[0] = 0; |
110 |
|
{ |
111 |
|
char helper_dir[MAX_PATH_LENGTH]; |
112 |
|
make_helper_path(path, helper_dir, add, true); |
113 |
+ |
if (helper_dir[strlen(helper_dir) - 1] == '/') // Remove trailing "/" |
114 |
+ |
helper_dir[strlen(helper_dir) - 1] = 0; |
115 |
|
return mkdir(helper_dir, 0777); |
116 |
|
} |
117 |
|
|
148 |
|
|
149 |
|
|
150 |
|
/* |
151 |
< |
* Get/set finder type/creator for file specified by full path |
151 |
> |
* Get/set finder info for file/directory specified by full path |
152 |
|
*/ |
153 |
|
|
154 |
|
struct ext2type { |
189 |
|
{".tga", 'TPIC', 'ogle'}, |
190 |
|
{".tif", 'TIFF', 'ogle'}, |
191 |
|
{".tiff", 'TIFF', 'ogle'}, |
192 |
+ |
{".htm", 'TEXT', 'MOSS'}, |
193 |
|
{".html", 'TEXT', 'MOSS'}, |
194 |
|
{".txt", 'TEXT', 'ttxt'}, |
195 |
|
{".rtf", 'TEXT', 'MSWD'}, |
210 |
|
{".mov", 'MooV', 'TVOD'}, |
211 |
|
{".fli", 'FLI ', 'TVOD'}, |
212 |
|
{".avi", 'VfW ', 'TVOD'}, |
213 |
+ |
{".qxd", 'XDOC', 'XPR3'}, |
214 |
+ |
{".hfv", 'DDim', 'ddsk'}, |
215 |
+ |
{".dsk", 'DDim', 'ddsk'}, |
216 |
+ |
{".img", 'rohd', 'ddsk'}, |
217 |
|
{NULL, 0, 0} // End marker |
218 |
|
}; |
219 |
|
|
220 |
< |
void get_finder_type(const char *path, uint32 &type, uint32 &creator) |
220 |
> |
void get_finfo(const char *path, uint32 finfo, uint32 fxinfo) |
221 |
|
{ |
222 |
< |
type = 0; |
223 |
< |
creator = 0; |
222 |
> |
// Set default finder info |
223 |
> |
Mac_memset(finfo, 0, SIZEOF_FInfo); |
224 |
> |
if (fxinfo) |
225 |
> |
Mac_memset(fxinfo, 0, SIZEOF_FXInfo); |
226 |
> |
WriteMacInt16(finfo + fdFlags, DEFAULT_FINDER_FLAGS); |
227 |
> |
WriteMacInt32(finfo + fdLocation, (uint32)-1); |
228 |
|
|
229 |
< |
// Open Finder info file |
229 |
> |
// Read Finder info file |
230 |
|
int fd = open_finf(path, O_RDONLY); |
231 |
|
if (fd >= 0) { |
232 |
< |
|
233 |
< |
// Read file |
234 |
< |
finf_struct finf; |
229 |
< |
if (read(fd, &finf, sizeof(finf_struct)) >= 8) { |
230 |
< |
|
231 |
< |
// Type/creator are in Finder info file, return them |
232 |
< |
type = ntohl(finf.type); |
233 |
< |
creator = ntohl(finf.creator); |
234 |
< |
close(fd); |
235 |
< |
return; |
236 |
< |
} |
232 |
> |
ssize_t actual = read(fd, Mac2HostAddr(finfo), SIZEOF_FInfo); |
233 |
> |
if (fxinfo) |
234 |
> |
actual += read(fd, Mac2HostAddr(fxinfo), SIZEOF_FXInfo); |
235 |
|
close(fd); |
236 |
+ |
if (actual >= SIZEOF_FInfo) |
237 |
+ |
return; |
238 |
|
} |
239 |
|
|
240 |
|
// No Finder info file, translate file name extension to MacOS type/creator |
241 |
< |
int path_len = strlen(path); |
242 |
< |
for (int i=0; e2t_translation[i].ext; i++) { |
243 |
< |
int ext_len = strlen(e2t_translation[i].ext); |
244 |
< |
if (path_len < ext_len) |
245 |
< |
continue; |
246 |
< |
if (!strcmp(path + path_len - ext_len, e2t_translation[i].ext)) { |
247 |
< |
type = e2t_translation[i].type; |
248 |
< |
creator = e2t_translation[i].creator; |
249 |
< |
break; |
241 |
> |
struct stat st; |
242 |
> |
if (stat(path, &st) == 0 && !S_ISDIR(st.st_mode)) { |
243 |
> |
int path_len = strlen(path); |
244 |
> |
for (int i=0; e2t_translation[i].ext; i++) { |
245 |
> |
int ext_len = strlen(e2t_translation[i].ext); |
246 |
> |
if (path_len < ext_len) |
247 |
> |
continue; |
248 |
> |
if (!strcmp(path + path_len - ext_len, e2t_translation[i].ext)) { |
249 |
> |
WriteMacInt32(finfo + fdType, e2t_translation[i].type); |
250 |
> |
WriteMacInt32(finfo + fdCreator, e2t_translation[i].creator); |
251 |
> |
break; |
252 |
> |
} |
253 |
|
} |
254 |
|
} |
255 |
|
} |
256 |
|
|
257 |
< |
void set_finder_type(const char *path, uint32 type, uint32 creator) |
255 |
< |
{ |
256 |
< |
// Open Finder info file |
257 |
< |
int fd = open_finf(path, O_RDWR); |
258 |
< |
if (fd < 0) |
259 |
< |
return; |
260 |
< |
|
261 |
< |
// Read file |
262 |
< |
finf_struct finf; |
263 |
< |
finf.flags = DEFAULT_FINDER_FLAGS; |
264 |
< |
memset(&finf, 0, sizeof(finf_struct)); |
265 |
< |
read(fd, &finf, sizeof(finf_struct)); |
266 |
< |
|
267 |
< |
// Set Finder flags |
268 |
< |
finf.type = htonl(type); |
269 |
< |
finf.creator = htonl(creator); |
270 |
< |
|
271 |
< |
// Update file |
272 |
< |
lseek(fd, 0, SEEK_SET); |
273 |
< |
write(fd, &finf, sizeof(finf_struct)); |
274 |
< |
close(fd); |
275 |
< |
} |
276 |
< |
|
277 |
< |
|
278 |
< |
/* |
279 |
< |
* Get/set finder flags for file/dir specified by full path |
280 |
< |
*/ |
281 |
< |
|
282 |
< |
void get_finder_flags(const char *path, uint16 &flags) |
283 |
< |
{ |
284 |
< |
flags = DEFAULT_FINDER_FLAGS; // Default |
285 |
< |
|
286 |
< |
// Open Finder info file |
287 |
< |
int fd = open_finf(path, O_RDONLY); |
288 |
< |
if (fd < 0) |
289 |
< |
return; |
290 |
< |
|
291 |
< |
// Read Finder flags |
292 |
< |
finf_struct finf; |
293 |
< |
if (read(fd, &finf, sizeof(finf_struct)) >= 10) |
294 |
< |
flags = ntohs(finf.flags); |
295 |
< |
|
296 |
< |
// Close file |
297 |
< |
close(fd); |
298 |
< |
} |
299 |
< |
|
300 |
< |
void set_finder_flags(const char *path, uint16 flags) |
257 |
> |
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo) |
258 |
|
{ |
259 |
|
// Open Finder info file |
260 |
|
int fd = open_finf(path, O_RDWR); |
261 |
|
if (fd < 0) |
262 |
|
return; |
263 |
|
|
264 |
< |
// Read file |
265 |
< |
finf_struct finf; |
266 |
< |
memset(&finf, 0, sizeof(finf_struct)); |
267 |
< |
finf.flags = DEFAULT_FINDER_FLAGS; |
311 |
< |
read(fd, &finf, sizeof(finf_struct)); |
312 |
< |
|
313 |
< |
// Set Finder flags |
314 |
< |
finf.flags = htons(flags); |
315 |
< |
|
316 |
< |
// Update file |
317 |
< |
lseek(fd, 0, SEEK_SET); |
318 |
< |
write(fd, &finf, sizeof(finf_struct)); |
264 |
> |
// Write file |
265 |
> |
write(fd, Mac2HostAddr(finfo), SIZEOF_FInfo); |
266 |
> |
if (fxinfo) |
267 |
> |
write(fd, Mac2HostAddr(fxinfo), SIZEOF_FXInfo); |
268 |
|
close(fd); |
269 |
|
} |
270 |
|
|