What's that file?

back to section start!
Filetypes are pretty much the source of DOpus' enormous power. Although it can recognise a wide variety of filetypes itself, it's the work you put into this section that will really enable you to reap the benefits of a well-ordered system. In the next section we'll describe a hierarchical filetyping method that should enable DOpus to pick the right filetype action quicker than normal, but for now, let's get to grips with the basics.


What you can do with Filetypes!

Before starting this part of the tutorial I recommend that you read the documentation that comes with Opus5 first. After reading it, you might think: "Wow! Now I know all about filetypes, but how can I start using them?"

The first part is about creating filetypes. As mentioned before it will not explain every step along the way - think of it more like a road map. The tutorial is about the way to go when you have a file and want to create a filetype for it.

The second part describes possible uses of filetypes. Use filetypes to start applications and viewers, use filetypes to add context menus and use filetypes to match directories or devices.

Last but not least there is a bit about the magic of filetypes. If you want to become a wizard when it comes to filetypes this is recommended reading for you.

Creating filetypes

Imagine you have a file on your hard disk and it isn't recognised by Opus. You don't need to become upset with it - there aren't many files that really can't be recognized, they just need a little work.

Let's start with an easy example: You want to recognize AmigaOS preference files. These are normally found in the SYS:Prefs/Presets and ENVARC:Sys directories. Let's have a look at an example.

Open a lister, go to the directory ENVARC:Sys and then read the file screenmode.prefs with SmartRead (the Opus internal text viewer). You should already have this file in that directory. If, somehow, you haven't start the Screenmode preferences program in SYS:Prefs and press Save in the window that pops up.

SmartRead comes up with a window displaying the file as hex dump. If you used the Read command instead, the file will be displayed as text only. In this case switch to hex mode manually via the settings menu of Opus's internal text reader.

Note: you can use the button bank in the file Filetypes-Tutorial that's on the CD to easily access all the stuff described in this tutorial. Just double click on the button bank file, select the file screenmode.prefs and click on the button SmartRead then.


So what do we see here? We see some hexadecimal output and some more or less cryptic characters like FORM and PREF.

Your screenmode.prefs file in hexadecimal.


The more experienced users reading this will know that this file has a special format that is widespread on Amiga systems.

But assume you don't know this already - maybe that is really the case: but what the heck are all those characters about? Why should we have to think about all this ourselves?

Finding a filetype

We don't need to. Let's ask Opus what it thinks about this file! For that purpose we use the Opus command FindFileType. Again we already set up a button for you. Just use the supplied button bank.

For a start, Opus will tell you that the file is an IFF (Interchange File Format) file. Why? Because FindFileType scans the filetypes in DOpus5:Filetypes and DOpus5:Storage/Filetypes and looks for a matching one. On some systems it might not come up with anything. On some it will tell you that it is a Workbench preferences file or maybe even a Workbench Screenmode preferences file depending on what filetypes you have in your filetypes drawers. If you have already installed a proper filetype for a Screenmode prefs file, please ignore it for now. We're going to create our own.

Use the force, Luke - the automatic filetype creator

We still might not have all the information we need. OK, maybe we know now the general type of file, but we'll still have to create the filetype that matches preferences files by hand.

Again this is not the case. When you look into the ENVARC:Sys drawer you see plenty of preferences *.prefs files. So you could use a very advanced and special feature of Opus5 to make our filetype: The automatic filetype creator!

So now we'll ask Opus itself and not it's filetypes about the file! We use the command CreateFileType to do it. Opus' automatic filetype creator scans several files of the same type to see if they share similarities. It'll start to display information as soon as you select the Screenmode preferences file and then press the button Create filetype from our button bank.

Just select a file and the DOpus' filetype creator gets to work.


What do you see? You see that Opus is intelligent because it already detected all necessary information to match the filetype by just looking at this single file. It noticed that it is a IFF file. Thus is set the checkmark before IFF and tells you that this file is of the IFF filetype PREFS.

In some way this is just the information that you saw in the text part of the hex dump of the file. But don't you prefer the way Opus displays this information to you? I know I do.

What other information can you see in the window? You can see the filename doesn't allow matching just yet. You see that the file is from the AmigaOS datatype group syst and the datatype ID iff. Thus the AmigaOS datatypes system itself already recognized it as an IFF file as well. Last but not least you see the first few bytes of the file. Opus uses a intelligent way of displaying them as you can see.

With add you can add another file, but you could have selected more than one file before pressing the Create filetype button anyway. Note that the filename field now changes to #?.prefs as Opus recognized that the .prefs extension is the only part of the filename the two or more files share. Also in the Byte display one byte changed to a ? indicating that it differs and only the other ones are common to both files.

Adding more than one file helps the filetype creator to narrow down the similarities between them.


Try fiddling around with the automatic filetype creator for a while. You will get a hang of it and easily learn how it works. Look at how the fields are changed when you add and delete files from the filetype creator list.

Add a def_????.info icon file from the same drawer as the prefs files and look what happens. You will see the limits of the automatic filetypes detection system: it's really important that you give files of one type to the automatic filetype creator at a time. Otherwise the creator gets confused. If you want to make filetypes for files of several different types you'll have to do them one at a time.

You will see that it isn't that difficult to setup a filetype for these def_????.info files as well when you select some of them and start the automatic filetype creator. Note: Opus isn't a genius. It doesn't recognize def_ as a part of the filename all files of these kind share.

But how do I actually create a filetype right now?

Simply hit the Edit button in the filetype creator window, it's as easy as that! But wait, you are the master of Opus and thus you can tell it what type of information Opus should use for creating the filetype. See the hint box below for further information.

My recommendation for easily creating good filetypes:
  1. Look into DOpus5:Storage/Filetypes for a filetype that matches. If you find one that works well, you don't need to reinvent the wheel and make your own!
  2. Use IFF field for IFF files and use datatype group and datatype ID when you can.
  3. Using the filename or the byte field can easily lead to errors. What if you change the filename of a file? Or you didn't give enough files to the filetype creator to sort out a good byte matching scheme?
  4. Having said that, on some files you might need to use byte matching as well. When using it be sure to throw as many files of this type at the creator as you can find. Normally 10-20 files should be enough.


On IFF files like our Screenmode.prefs file, matching is simple: Let Opus use the IFF field. You don't need anything else. You can use the filename matching as well to speed up filetype matching.

So, for our example, select some preferences files, start the creator, select the name field so that it will be checked too and press edit. You will get two windows. One that contains fields for setting events, icon menu entries and the default icon. The other one contains the actual filetype matching definition. You can reach it manually by clicking on the Edit Class... button.

Editing the filetypes class definition

We concentrate on the window containing the filetype class definition.

Making a filetype


This contains all the commands that are needed to actually match a file of this type.

We selected that Opus should look at the name and the IFF field. This is what Opus made up for us:

Match Name #?.prefs
And
Match FORM PREF

This is already quite good. But with the And operator, both conditions have to be true. Thus this filetype won't match preferences files that have another extension instead of #?.prefs, like #?.pre preset files in SYS:Prefs/Presets. Okay, you can set #?.(pre|prefs) or #?.pre(%|fs) for the Match Name command to also match preset files. But then you may save preset files under a different name anyway and then you're screwed again.

If you replace the And operator with the Or operator you may get better results. Opus first checks for the filename matching #?.prefs or whatever you set Match Name command to. If that works, it won't check the file itself whether it finds a PREF IFF chunk in it. So it doesn't need to open the files and thus is faster on filetype matching.

This only has one drawback: if a file that is not an IFF preferences file, but has the filename extension #?.prefs, it will also be matched. So normally it is safer to skip filename matching at all. Pick whatever suits you.

After fiddling around with the filetype matching commands, you should give the class definition a name such as IFF Preference file, a ID like PREF and a priority like 0. The ID is a unique identifier of this filetype. ARexx scripts may check for such an ID when accessing a file for example. The name you choose will be used as the filename for the filetype in DOpus5:Filetypes when you create a new filetype. If you change the name later the filename of the filetype definition file won't be affected, you will have to rename this file yourself.

Priorities are important. A priority is a number from 127 to -128. Opus will look for the filetypes with the highest priorities first. So the most special filetype definition should have the highest priority. And the most general filetype definition should have the lowest priority. Imagine having a filetype matching all pictures via the AmigaOS datatypes system. Imagine then you have a special filetype for jpeg image files, because you want to set a special jpeg image viewer just for jpeg images. If the jpeg filetype has a lower priority than the general image filetype, the double click action of the general image filetype will be used and you won't get your favourite jpeg image viewer on a double click of a jpeg file. For further information on priorities you may want to have a look at the advanced filetypes tutorial in the Advanced section of this tutorial.

So now we can return to the window containing the events and icon menu settings. Most often you want to set up a function for the double click or the drag and drop action or an icon menu entry. This icon menu is a context menu, that pops up when you click and hold the RMB on a file. Opus will search for all matching filetypes and adds all menu entries defined in them to the context menu in the order of the filetype priorities - highest first. See the Usage chapter for some examples on how to use filetypes. See the Opus documentation for more information about functions. They are set up the same way as buttons or start menu entries.

After this your filetype definition is complete and you can save it. You may find that you can't think of a double click action or something useful at all for the IFF preferences filetype. I think you are right. ;-) So either forget about that filetype, it was only to explain the process of creating a filetype, or add some nice command to its list of matching commands like:

And
Find Chunk SCRM

Now you have a filetype that only matches ScreenMode preferences files. You can find out what string to match for preferences files created by other preferences editors by looking at the preference file itself with SmartRead and when you know which preferences editor created the file you can set up function for the double click action that loads the preferences file into the editor. In this case you may want to start the ScreenMode program. Thus you see although Opus does very much to make your life easy, there are some things left you have to find out on your own! So, SmartRead will be your friend, unless Opus gets even more intelligent.

Now it's getting tricky

So this all now sounds easy to you? Now you know what steps to take to make a filetype definition I think you should do a somewhat harder filetype definition. I'll give you a tough one...

Go into your ARexx script directory, normally REXX:, select some ARexx files and call the filetype creator. And guess what? It fails. It completely fails! It can't detect any similarities between the files even though you made a good selection of similar files. Even the byte matching doesn't work here.

What if the filetype creator can't find a similarity between the files you have selected?


What do you do now? You will have to select Edit and think for yourself how to create a proper definition. I've seen a filetype in my Storage drawer that simply matches for /* - the beginning the comment that is in the first line of an ARexx file - and then checks that the filename doesn't end with *.c or *.h:

Match /*
And
Match Name *.~(c|h)

This is quite intelligent and will work in most cases. But what if you have a file with another name that also contains a /* blah */ comment in the first line? For example MUI2C has *.l files containing such a comment in the first line. These files are matched as ARexx scripts with that filetype class definition.

You may add a check whether the script protection bit is set. But not all ARexx scripts have a correctly set s protection bit.

If you're familiar with ARexx scripts, you'll know it isn't easy to think of something, that almost always occurs in every ARexx script, apart from the starting comment. The only other idea that comes to my mind is to check for the comment, and then check for the text of some common ARexx commands like OPTIONS, PARSE, SAY in the first 1000 or 2000 bytes of the file. You can use the Search Range command for that, such as:

Match /*
And
Search Range 2000 OPTIONS
Or
Search Range 2000 PARSE
...and so on...

You will find an example in the filetypes directory coming with this tutorial.

But we're getting to the limits of the Opus filetypes system: the Search command only does a case sensitive search. So if the author of the ARexx script writes all commands in lower case you will have to add some Search Range commands for lower case ARexx commands. And if he writes Options or oPtions you're completely scuppered.

Maybe this proves again that everything that is developed by humans can be improved even further no matter how long the process of development was. If you want to match ARexx scripts the way I thought of here, you can use the AmigaDOS command Search like this:

SEARCH FROM "(OPTIONS|ADDRESS|SAY|CALL)" PATTERN QUICK

This does it on the ARexx scripts I have in my REXX: directory, but it doesn't check for the comment in the first line so it isn't very safe. So a "SearchPattern" filetype matching command could be a good idea for the next version of Opus...

But even this is not error proof. One can write a text file containing a comment in the first line and then write something about Options.

Another example

OK, I admit matching ARexx scripts is quite tricky. Let's have an easier example. We will try to match PNG images. Go into the Examples/Pictures/PNG coming with this tutorial or go to any other directory containing some PNG images. The pictures coming with this tutorial contain the Opus logo grabbed from the about window saved into different PNG formats with Photogenics2 and ArtEffect. It is always recommended that you use a variety of files with different sources when trying to match a filetype with byte matching. A 24-bit PNG image may differ from a 256 colour PNG image by a few bytes for example.

Just select some PNG images and call CreateFileType - you can use the button on the supplied button bank for that. On a system with a installed AmigaOS PNG datatype you will get something like this:

Name: #?.png
Group: pict
ID: png
Bytes: \137PNG\013\010\026\010\000\000\000\013IHDR (case-insensitive)
or
$89504e47 0d0a1a0a 0000000d 49484452 (case-sensitive)

Making a PNG filetype.


You can use the AmigaOS datatype matching, which should be safe as long as the datatype descriptor in DEVS:Datatypes - which contains the datatype matching information for the datatypes.library - is done correctly which is true for all PNG datatypes I know of.

But let's have a look at the byte matching stuff. Opus has found some bytes that are common the all the files I threw at the filetype creator. This might be enough already. But Opus also matches bytes that are only common to files of the PNG files of today. PNG supports for future extensions. So it can be that PNG files which support newer features might not get picked up by byte matching alone.

You may have noticed that bytes 2-4 contain the word PNG. So it's enough just to check for that word. And it is safer too because it won't fail on future expansions of the PNG file format. You'll notice that it is not always a good idea to blindly trust the Opus filetype creator - especially when it comes to byte matching. It is always better to know the file format to match by hand or to use filetypes that have been predefined by people you know know the file format well.

So you can use the following combinations of matching commands when you don't want to use the AmigaOS datatype system:

  • This example will check for *.png in the filename and only check for the bytes PNG in the file itself if that fails. It gives fast recognition of files named with .png as extension. But if you name an ARexx script with that extension for example it will be matched as PNG image.
    Match Name *.png
    Or
    Match ?PNG
  • This one will check for the filename and the bytes. This is safer because it will fail on PNG images that are not named with *.png as extension.
    Match Name *.png
    And
    Match ?PNG
  • This one will only check for the bytes. In my opinion this is the most accurate method.
    Match ?PNG

So, let me end this chapter now. You may want to try creating some of your own filetypes now. Try to make a GIF filetype or whatever. Learning by doing is a very good method!

Using Filetypes

So you created some filetypes but don't know what to do with them? Oh, come on, there are many uses for them. OK, let me show you the most common uses. I'll differentiate between events, icon menu - the context menu -, and the default icon settings provided in the main filetype editing window:

Events

  • In most cases I guess you want to set a double click function to specify what should happen when you double click a file of that type. Normally you set this to some kind of viewer. For archives of formats other than LhA and LZX you can set it to use the archiver to view the archive contents. When trying to match LhA or LZX archives I strongly recommend that you use the filetypes from the wonderful ArcDir by Edmund Vermeulen and Dave Clarke as a base.
  • In some cases it is good to set a function for the drag and drop operation as well. For archives you can set it to extract the archive contents. So you can extract an archive by simply dragging it to a destination directory. Note: When you do this, you can't simply copy or move the archive file via drag and drop any more. But when you look at the event list in the main filetype editing window, you see that you also can set functions for drag and drop operations that take place while pressing the Alt or the Ctrl key.
  • You may have a use for a User 1 to User 10 command as well. I consider this a relic of older Opus versions - where it didn't support all the other nice stuff - and manage to live without the user commands quite well. Read the Opus documentation if you want to know more about this, or continue down to the end of this chapter.

Icon menu - the context menu

Here you can add some menu entries that will be shown when you press the right mouse button over a file of the given type. There it not much to say about this. Possible uses are:

  • If you have an alternate viewer for that filetype you may add it here. I have done this for MPEG animations. On double click the MPEG viewer "Isis" from the CyberGraphX package will be used, but I often want to use the great "amipeg" viewer as well so I've added it to the context menu.
  • You may want to use AppLauncher or some similar script or program to load the file into the application of your choice. For example, I've added menu entries for Personal Paint, Photogenics2 and ArtEffect to my filetype that matches all images. See the AppLauncher tutorial if you're interested in doing this.

My recommendations for icon menus: Use a menu item without a function called --- name of the filetype --- as the first menu item. Use a menu entry called --- which gives you a separator line at the end of each filetype context menu. This way you know which menu entries are coming from which filetype and the menu entries from each filetype are separated from the ones of the other filetypes. In my opinion this greatly enhances the readability of the context menu!


Default icon

You may want to set a default icon as well. Opus will use it when the file has no icon and it should display all files in icon lister mode. And it will use it when you want to add an icon to a file with the AddIcon command. I use it this way to add icons to files that have to icon or to replace other icons with my favourite NewIcons. See the advanced filetypes tutorial in the next section and look at the All filetype that I provide with it.



The mysterious "User 1" command

One of the things that always puzzled me when I used to use Directory Opus 4 was the User1 command, and my confusion was compounded by the release of DOpus 5 Magellan since there were now ten User commands to play with (if you knew what to do with them!). I never found the explanation for them in the Opus manuals satisfactory since they did explain what these commands were for, but not really how to use them. I needed examples, and I'm going to give you one now so you can figure it out for yourself.

  1. Make a button bank - Start by making a button bank - it doesn't matter what sort, we're only doing this as an example.
  2. Make a button - Call it "user" and give it the command User 1.
  3. What's next? - to be honest that's it. Your button bank will now do almost anything you ask of it. Actually that's not completely true - yet.
  4. Use the Filetypes - That's right. Open up the filetypes editor and pick a filetype. A picture filetype is good for this experiment, so choose Jpeg for example. You will almost certainly have a double click instruction for what happens when you double click on a jpeg file and it will probably be to show the file. Copy that action to the User 1 field.
  5. That's really it now - He's right you know. In the past, if you had a directory full of jpeg and other images and you just wanted to see the jpegs it was hard work going through them all singly, double clicking to see them. If you now select all the jpeg images in said directory and click on your User button in your new button bank, it will show the images one after the other. Not only that, but say you also wanted a button to edit jpegs. Just make the "User 2" function in the filetypes editor for Jpeg images your editing tool for Jpegs and make a new button in your example button bank called User 2 which calls the command User 2. Best of all, if you set up a similar User 1 and a User 2 command for all your filetypes, these two buttons in your new button bank will be able to show or edit all the files you give 'em. Neat, eh?
Funny to think that these two buttons
could be used for viewing and editing
almost all the files on your hard drive.


Pick a chapter:

DOpus PLUS - giving you that bit extra...