Difference between revisions of "Creating Ambient Filetypes"

From MorphOS Library

(Created page with "== About == == Examples == === Creating a Filetype for WMF files === #Open the [http://www.iana.org/assignments/media-types/ http://www.iana.org/assignments/media-types/] p...")
 
 
Line 1: Line 1:
 
== About ==
 
== About ==
 +
This tutorial is '''only''' for creating new filetypes when Ambient doesn't recognize certain files '''at all'''. This isn't for situations when nothing happens if you double click a known file.
  
 +
If you can see the correct type for a file in its context menu when right clicking on it or when looking the ''Filetype'' column on an Ambient window, or you can find the correct type from the Mime page in the Ambient settings, this tutorial isn't for you. You're probably looking how to configure different kinds of actions for files then, and there are couple of examples for that available [http://library.morph.zone/Getting_Started#Setting_MPlayer_as_the_Default_Player_on_Ambient here] and [http://library.morph.zone/Getting_Started#Setting_Jukebox_as_the_Default_Player_for_MP3_Files here].
 +
 +
Ambient should recognize most of the files you come across in normal use, and it would be enough just to configure actions in the Ambient Mime settings. But if you find a file which isn't recognized by Ambient, here's what you should do:
 +
#'''Check, and double check''', that you can't find the corresponding filetype in the '''SYS:MorphOS/Ambient/recognition.db''' file!
 +
#'''Read the instructions''' about creating new filetypes from the '''SYS:MorphOS/Ambient/recognition.db''' file!
  
  
Line 36: Line 42:
 
Let's try the same for the '''CGM''' filetype then. The [http://www.iana.org/assignments/media-types/ page] in the step 1 tells us that its name is '''Computer Graphics Metafile''' and its 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.
 
Let's try the same for the '''CGM''' filetype then. The [http://www.iana.org/assignments/media-types/ page] in the step 1 tells us that its name is '''Computer Graphics Metafile''' and its 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, and the only reasonable way seems to be to check the filename in this case. So, let's create a rule which first tries to look if the known string is found inside a file (add ''s'' in front of the string to indicate it's a plain text string instead of hex or something else) or if it's not found, make the recognition by the extension:
+
We have to create a rule which will work even if that string isn't found, and the only reasonable way seems to be to check the filename in this case. So, let's create a rule which tries to look if the known string is found inside a file (add ''s'' in front of the string to indicate it's a plain text string instead of hex or something else) or by making the recognition by the extension:
 
  <nowiki>Match sBegMF
 
  <nowiki>Match sBegMF
 
OR
 
OR
Line 54: Line 60:
 
End
 
End
 
End</nowiki>
 
End</nowiki>
 +
 +
Save it as a '''SYS:Prefs/Ambient/filetypes/image/cgm''' file.

Latest revision as of 15:39, 8 March 2017

About

This tutorial is only for creating new filetypes when Ambient doesn't recognize certain files at all. This isn't for situations when nothing happens if you double click a known file.

If you can see the correct type for a file in its context menu when right clicking on it or when looking the Filetype column on an Ambient window, or you can find the correct type from the Mime page in the Ambient settings, this tutorial isn't for you. You're probably looking how to configure different kinds of actions for files then, and there are couple of examples for that available here and here.

Ambient should recognize most of the files you come across in normal use, and it would be enough just to configure actions in the Ambient Mime settings. But if you find a file which isn't recognized by Ambient, here's what you should do:

  1. Check, and double check, that you can't find the corresponding filetype in the SYS:MorphOS/Ambient/recognition.db file!
  2. Read the instructions about creating new filetypes from the SYS:MorphOS/Ambient/recognition.db file!


Examples

Creating a Filetype for WMF files

  1. 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'll see its full name is Windows Metafile Format, its extension is .wmf (naturally), and magic numbers are D7 CD C6 9A, which is extremely useful information. Now we know all we need to know to 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 following lines with the text editor.
    1. The standard headers which all filetypes should contain:
      AMTD
      1
    2. Then a line containing the type, which we got in the step 2:
      Type image/wmf
    3. And the name we also got in the step 2:
      Name Windows Metafile Format
    4. Then start the match block, which defines how the file is recognized:
      Match
    5. Let's add a pattern hint rule with the extension we know:
      PatternHint #?.wmf
    6. And then an actual matching rule. We got the magic numbers in the step 2 and they indicate 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 the hex format.
      Match $D7CDC69A
    7. Now we can end the match block:
      End
    8. We also need another End to end the whole filetype definition:
      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.


Note: the inner block can be made indented to make it look cleaner, here's the whole filetype definition:

AMTD
1
Type image/wmf
Name Windows Metafile Format
Match
	PatternHint #?.wmf
	Match $D7CDC69A
	End
End


Creating a Filetype for CGM files

Let's try the same for the CGM filetype then. The page in the step 1 tells us that its name is Computer Graphics Metafile and its 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, and the only reasonable way seems to be to check the filename in this case. So, let's create a rule which tries to look if the known string is found inside a file (add s in front of the string to indicate it's a plain text string instead of hex or something else) or by making the recognition by the extension:

Match sBegMF
OR
Name #?.cgm

You could also make matching only by the extension, but it's more elegant to match the contents when you can.

The full filetype for the cgm files would be like this then:

AMTD
1
Type image/cgm
Name Computer Graphics Metafile
Match
	PatternHint #?.cgm
	Match sBegMF
	OR
	Name #?.cgm
	End
End

Save it as a SYS:Prefs/Ambient/filetypes/image/cgm file.