Yokemate of Keyboards
Posts: 2096 from 2003/2/24
From: po-RNO
Quote:NewSense wrote:
Can someone give clear instructions on how to create a new filetype, if this is possible, so I can adapt MorphOS to suit my needs.
Here is how I'd do it:
1) First open the
http://www.iana.org/assignments/media-types/ page (as suggested in the SYS:MorphOS/Ambient/recognition.db file), and look for the wanted media type.
2) We can find wmf there, and it seems to be categorized as image/wmf, let's click the "image/wmf" link in the second column on the page to get more information. We see its full name "Windows Metafile Format", extension .wmf (naturally), and magic numbers (D7 CD C6 9A), which is extremely useful info. Now we know all we need to know and can create a new filetype.
3) Ambient's filetype directory has the same hierarchy with the standard media type categories, so we can place our wmf filetype into the image directory. Let's create a new file there, for example from the shell: Ed SYS:Prefs/Ambient/filetypes/image/wmf
4) Type in the standard headers which all filetypes should contain:
Code:
Then the type line (we got the type in step 2):
Code:
And the name we also got in step 2:
Code:
Name Windows Metafile Format
Then start the match block, which defines how the file is recognized:
Code:
Let's add the pattern hint rule with the extension we know:
Code:
And then the actual matching rule. We got the magic numbers in the step 2 and they indicate the hex numbers found from the beginning of each wmf file. We tell Ambient to look for those numbers to make the recognition. $ tells the searching will be done in hex format.
Code:
Now we can end the match block:
Code:
We also need another End to end the whole filetype definition:
Code:
You can also make the inner blocks intented to make it look cleaner, here's the whole filetype definition:
Code:
AMTD
1
Type image/wmf
Name Windows Metafile Format
Match
PatternHint #?.wmf
Match $D7CDC69A
End
End
5) Save the file and we're done. You can now open the Ambient MIME type settings and add new actions for the new filetype there.
Let's try the same for CGM then. The page in the step 1 tells us that its name is "Computer Graphics Metafile" and it's type is "image/cgm". Unfortunately it doesn't seem to tell more about the recognition, and a quick googling reveals that files may contain the string "BegMF", but not always.
We have to create a rule which will work even if that string isn't found, I think we have to fallback to filename based recognitioning in this case. So, let's create a rule which first tries to match the string (add "s" in front of it to indicate it's a plain text string instead of hex or so) or if it's not found then to filename:
Code:
Match sBegMF
OR
Name #?.cgm
You could also match only to name, but it's more elegant to match the contents when you can.
Full filetype for the cgm would be like this then:
Code:
AMTD
1
Type image/cgm
Name Computer Graphics Metafile
Match
PatternHint #?.cgm
Match sBegMF
OR
Name #?.cgm
End
End