137 |
|
{NULL, 0, 0, false} // End marker |
138 |
|
}; |
139 |
|
|
140 |
< |
void get_finfo(const char *path, uint32 finfo, uint32 fxinfo) |
140 |
> |
void get_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir) |
141 |
|
{ |
142 |
|
// Set default finder info |
143 |
|
Mac_memset(finfo, 0, SIZEOF_FInfo); |
151 |
|
if (fd < 0) |
152 |
|
return; |
153 |
|
|
154 |
< |
// Read BeOS MIME type |
155 |
< |
char mime[256]; |
156 |
< |
ssize_t actual = fs_read_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, 256); |
157 |
< |
mime[255] = 0; |
154 |
> |
if (!is_dir) { |
155 |
|
|
156 |
< |
if (actual > 0) { |
157 |
< |
|
158 |
< |
// Translate MIME type to MacOS type/creator |
159 |
< |
char mactype[4]; |
160 |
< |
if (sscanf(mime, "application/x-MacOS-%c%c%c%c", mactype, mactype+1, mactype+2, mactype+3) == 4) { |
161 |
< |
|
162 |
< |
// MacOS style type |
163 |
< |
WriteMacInt32(finfo + fdType, mactype); |
164 |
< |
|
165 |
< |
} else { |
166 |
< |
|
167 |
< |
// MIME string, look in table |
168 |
< |
for (int i=0; m2t_translation[i].mime; i++) { |
169 |
< |
if (!strcmp(mime, m2t_translation[i].mime)) { |
170 |
< |
WriteMacInt32(finfo + fdType, m2t_translation[i].type); |
171 |
< |
WriteMacInt32(finfo + fdCreator, m2t_translation[i].creator); |
172 |
< |
break; |
156 |
> |
// Read BeOS MIME type |
157 |
> |
ssize_t actual = fs_read_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, tmp_buf, 256); |
158 |
> |
tmp_buf[255] = 0; |
159 |
> |
|
160 |
> |
if (actual > 0) { |
161 |
> |
|
162 |
> |
// Translate MIME type to MacOS type/creator |
163 |
> |
uint8 mactype[4]; |
164 |
> |
if (sscanf((char *)tmp_buf, "application/x-MacOS-%c%c%c%c", mactype, mactype+1, mactype+2, mactype+3) == 4) { |
165 |
> |
|
166 |
> |
// MacOS style type |
167 |
> |
WriteMacInt32(finfo + fdType, (mactype[0] << 24) | (mactype[1] << 16) | (mactype[2] << 8) | mactype[3]); |
168 |
> |
|
169 |
> |
} else { |
170 |
> |
|
171 |
> |
// MIME string, look in table |
172 |
> |
for (int i=0; m2t_translation[i].mime; i++) { |
173 |
> |
if (!strcmp((char *)tmp_buf, m2t_translation[i].mime)) { |
174 |
> |
WriteMacInt32(finfo + fdType, m2t_translation[i].type); |
175 |
> |
WriteMacInt32(finfo + fdCreator, m2t_translation[i].creator); |
176 |
> |
break; |
177 |
> |
} |
178 |
|
} |
179 |
|
} |
180 |
|
} |
179 |
– |
} |
181 |
|
|
182 |
< |
// Override file type with MACOS:CREATOR attribute |
183 |
< |
if (fs_read_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &mime, 4) == 4) |
184 |
< |
WriteMacInt32(finfo + fdCreator, (mime[0] << 24) | (mime[1] << 16) | (mime[2] << 8) | mime[3]); |
182 |
> |
// Override file type with MACOS:CREATOR attribute |
183 |
> |
if (fs_read_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, tmp_buf, 4) == 4) |
184 |
> |
WriteMacInt32(finfo + fdCreator, (tmp_buf[0] << 24) | (tmp_buf[1] << 16) | (tmp_buf[2] << 8) | tmp_buf[3]); |
185 |
> |
} |
186 |
|
|
187 |
|
// Read MACOS:HFS_FLAGS attribute |
188 |
< |
if (fs_read_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &mime, 2) == 2) |
189 |
< |
WriteMacInt16(finfo + fdFlags, (mime[0] << 8) | mime[1]); |
188 |
> |
if (fs_read_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, tmp_buf, 2) == 2) |
189 |
> |
WriteMacInt16(finfo + fdFlags, (tmp_buf[0] << 8) | tmp_buf[1]); |
190 |
|
|
191 |
|
// Close file |
192 |
|
close(fd); |
193 |
|
} |
194 |
|
|
195 |
< |
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo) |
195 |
> |
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir) |
196 |
|
{ |
195 |
– |
char mime[256]; |
196 |
– |
|
197 |
|
// Open file |
198 |
|
int fd = open(path, O_WRONLY); |
199 |
|
if (fd < 0) |
200 |
|
return; |
201 |
|
|
202 |
< |
// Set BEOS:TYPE attribute |
203 |
< |
uint32 type = ReadMacInt32(finfo + fdType); |
204 |
< |
if (type) { |
205 |
< |
bool written = false; |
206 |
< |
for (int i=0; m2t_translation[i].mime; i++) { |
207 |
< |
if (m2t_translation[i].type == type && m2t_translation[i].reversible) { |
208 |
< |
fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, m2t_translation[i].mime, strlen(m2t_translation[i].mime) + 1); |
209 |
< |
written = true; |
210 |
< |
break; |
202 |
> |
if (!is_dir) { |
203 |
> |
|
204 |
> |
// Set BEOS:TYPE attribute |
205 |
> |
uint32 type = ReadMacInt32(finfo + fdType); |
206 |
> |
if (type) { |
207 |
> |
for (int i=0; m2t_translation[i].mime; i++) { |
208 |
> |
if (m2t_translation[i].type == type && m2t_translation[i].reversible) { |
209 |
> |
fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, m2t_translation[i].mime, strlen(m2t_translation[i].mime) + 1); |
210 |
> |
break; |
211 |
> |
} |
212 |
|
} |
213 |
|
} |
213 |
– |
if (!written) { |
214 |
– |
sprintf(mime, "application/x-MacOS-%c%c%c%c", type >> 24, type >> 16, type >> 8, type); |
215 |
– |
fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime, strlen(mime) + 1); |
216 |
– |
} |
217 |
– |
} |
214 |
|
|
215 |
< |
// Set MACOS:CREATOR attribute |
216 |
< |
uint32 creator = ReadMacInt32(finfo + fdType); |
217 |
< |
if (creator) { |
218 |
< |
mime[0] = creator >> 24; |
219 |
< |
mime[1] = creator >> 16; |
220 |
< |
mime[2] = creator >> 8; |
221 |
< |
mime[3] = creator; |
222 |
< |
fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, &mime, 4); |
215 |
> |
// Set MACOS:CREATOR attribute |
216 |
> |
uint32 creator = ReadMacInt32(finfo + fdCreator); |
217 |
> |
if (creator) { |
218 |
> |
tmp_buf[0] = creator >> 24; |
219 |
> |
tmp_buf[1] = creator >> 16; |
220 |
> |
tmp_buf[2] = creator >> 8; |
221 |
> |
tmp_buf[3] = creator; |
222 |
> |
fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, tmp_buf, 4); |
223 |
> |
} |
224 |
|
} |
225 |
|
|
226 |
|
// Write MACOS:HFS_FLAGS attribute |
227 |
|
uint16 flags = ReadMacInt16(finfo + fdFlags); |
228 |
|
if (flags != DEFAULT_FINDER_FLAGS) { |
229 |
< |
mime[0] = flags >> 8; |
230 |
< |
mime[1] = flags; |
231 |
< |
fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, &mime, 2); |
229 |
> |
tmp_buf[0] = flags >> 8; |
230 |
> |
tmp_buf[1] = flags; |
231 |
> |
fs_write_attr(fd, "MACOS:HFS_FLAGS", B_UINT16_TYPE, 0, tmp_buf, 2); |
232 |
|
} else |
233 |
|
fs_remove_attr(fd, "MACOS:HFS_FLAGS"); |
234 |
|
|