|
C++ Plugin Source Codefor Directory OpusReal-world example source-code to help programmers write Opus plugins. Directory Opus is a file manager for Windows. Read my guide, Getting to know Directory Opus, for an introduction. |
The complete C++ source code to many of my Directory Opus plugins is available here to help other people write their own Directory Opus plugins.
(Delphi developers: The RVF File Viewer plugin by Sergey Tkachenko is written in Delphi and comes with source code which you should find very useful.)
To understand the Directory Opus plugin API for Viewer and VFS (virtual file-system) plugins you should download the Opus Plugins SDK from GPSoftware's downloads page. This includes several manuals and some additional example source code.
If you wish to discuss Opus plugin development, or ask for help, your best bet is the Developers Forum at the Opus Resource Centre.
Unless otherwise stated, all of the plugins below are written in C++ using only the Win32 API (and the C RunTime, STL, etc.). In particular, MFC is not used.
The source code comes packaged in Visual Studio projects/solutions but should be fairly easy to convert to other build environments, if required.
The source code here is not always kept up-to-date with the actual plugin releases. It's here to serve as an example, not to invite development forks or custom versions of the plugins. Please don't fork the code or put out your own releases of the plugins. If you want something changed or added then please contact me first. Of course, I am happy to accept code patches for things which make sense but do get in touch before you start work in case your change conflicts with something else that I'm working on.
Eventually all of the plugins will be part of a single Visual Studio solution. At the moment two of the plugins are still in standalone solutions as the plan is to completely re-write those plugins.
| Plugin | Source | Unicode | x64 | USB |
|---|---|---|---|---|
| GIFAnim | PNOpusPlugins_2008-05-14.zip (PGP sig) | Yes | Yes | Yes |
| NFO | Yes | Yes | Yes | |
| TextThumb | Yes | Yes | Yes | |
| JP2Raw | dopus8_jp2raw_1100_source.zip (PGP sig) | No | No | No |
| Ogg | dopus8_ogg_1006_source.zip (PGP sig) | No | No | No |
(For information from a user perspective, see the main page for the plugin.)
The Animated GIF plugin source demonstrates the following:
- Viewer & Thumbnails plugin.
- Creates its own window. (The second, more powerful and more complex method described in the Plugin SDK. See the NFO plugin for a more simple example, though.)
- Emulates the internal viewer code:
- Zooming.
- Tiling.
- Rotation (right-angles only).
- Croping.
- Printing.
- Set Desktop background.
- Clipboard support.
- F1 info box (alpha blended).
- Transparency.
- Image borders.
- Automatic background colour choice.
- Mouse button configuration.
- Context-sensitive mouse pointers (loaded via Plugin API).
- Exact copy of the way Opus scrolls images when dragging with the mouse or scrollbars, for consistency.
- Alpha blended selection rectangle.
- Full-screen support (including allowing the menu/toolbar to appear).
- Animation.
- Thumbnail alpha channel.
- Streams (i.e. works with files within archives).
- Configuration dialog (with layout code which adjusts to the system font & localised string lengths).
- Adds items to the viewer menus.
- Custom toolbar (i.e. in addition to the viewer's standard toolbar).
- Recognises files by inspecting their contents.
- XML config files (using the more simple of the two config methods provided by the Plugin SDK).
- USB-Mode.
- Unicode.
- x64.
(For information from a user perspective, see the main page for the plugin.)
The TGA, JPEG 2000, PNM, Rasterfile and Raw Digital Camera plugin source demonstrates the following:
- Viewer & Thumbnails plugin.
- Decodes bitmaps and passes them back to the internal Opus viewer. (The first, less powerful and more simple method described in the Plugin SDK.)
- Handles multiple image formats in a single plugin. (I no longer think this is a good idea, though. Sharing code is okay but I think it should look like there is one plugin per format unless the formats are closely related. You could have one big DLL that does all the work and some little proxy DLLs which make it appear to be several plugins, for example. Makes it easier to replace individual plugins without replacing the entire thing, and easier for the user to configure things.)
- Alpha channel support for (for the TGA type, at least).
- Streams (i.e. works with files within archives).
- Configuration dialog.
- Registry-based config. (NOT recommended as it means the plugin cannot be used with USB-mode.)
- Does not support USB mode, Unicode or x64.
I plan to completely re-write this plugin and replace it with several smaller plugins. A new JPEG2000 plugin has already been written, based on a different library. The Raw digital camera support will be changed to call a pre-made dcraw.exe instead of building the DCRaw code into the plugin as it has proven far too time consuming to convert the DCRaw code to thread-safe C++ every time it is updated. TGA alpha support will be rolled into the old sample TGA plugin which comes with the plugin SDK. PNM and RAS would be easy enough to re-write by hand (I don't want to be tied to CXImage anymore due to x64/Unicode issues and there not being much point in using it just for RAS/PNM). I may just abandon RAS/PNM as they don't seem to be used much and were only supported because DCRaw used to require them.
You will need CxImage to compile the JP2Raw plugin. CxImage itself comes with the other required libraries. Below is the CxImage configuration used to built the DLL. Also note that CxImage and all child projects must be changed to statically link to the Multithreaded C-Runtime.
// CxImage supported features #define CXIMAGE_SUPPORT_ALPHA 1 #define CXIMAGE_SUPPORT_SELECTION 0 #define CXIMAGE_SUPPORT_TRANSFORMATION 0 #define CXIMAGE_SUPPORT_DSP 0 #define CXIMAGE_SUPPORT_LAYERS 0 #define CXIMAGE_SUPPORT_INTERPOLATION 0 #define CXIMAGE_SUPPORT_DECODE 1 #define CXIMAGE_SUPPORT_ENCODE 0 #define CXIMAGE_SUPPORT_WINDOWS 1 #define CXIMAGE_SUPPORT_WINCE 0 // CxImage supported formats #define CXIMAGE_SUPPORT_BMP 0 #define CXIMAGE_SUPPORT_GIF 0 #define CXIMAGE_SUPPORT_JPG 1 #define CXIMAGE_SUPPORT_PNG 0 #define CXIMAGE_SUPPORT_MNG 0 #define CXIMAGE_SUPPORT_ICO 0 #define CXIMAGE_SUPPORT_TIF 0 #define CXIMAGE_SUPPORT_TGA 1 #define CXIMAGE_SUPPORT_PCX 0 #define CXIMAGE_SUPPORT_WBMP 0 #define CXIMAGE_SUPPORT_WMF 0 #define CXIMAGE_SUPPORT_J2K 0 #define CXIMAGE_SUPPORT_JBG 0 #define CXIMAGE_SUPPORT_JP2 1 #define CXIMAGE_SUPPORT_JPC 1 #define CXIMAGE_SUPPORT_PGX 1 #define CXIMAGE_SUPPORT_PNM 1 #define CXIMAGE_SUPPORT_RAS 1
(For information from a user perspective, see the main page for the plugin.)
The NFO plugin source demonstrates the following:
- Viewer-only plugin. (No thumbnails.)
- Creates its own window. (The second, more powerful and more complex method described in the Plugin SDK.)
- Streams (i.e. works with files within archives).
- Recognises files by extension only.
- USB mode. (Trivial in this case as the NFO plugin has no configuration data and just has to say "Yes, I support USB mode.")
- Unicode.
- x64.
The NFO plugin's custom viewer window is based on a subcalssed edit control. The source to the NFO plugin could be a good starting point for a text-editor plugin, or if you want to see how custow-window plugins work in general. The GIFANim plugin also creates its own window but I would advise looking at the less complex NFO plugin first and only refering to the GIFAnim plugin if you want to know how to do some the more advanced things.
(For information from a user perspective, see the main page for the plugin.)
The Ogg Vorbis & FLAC plugin source demonstrates the following:
- File information plugin. (Only returns information about file metadata. No viewer. No thumbnails.)
- Streams (i.e. works with files within archives).
- Does not support USB mode, Unicode or x64.
I plan to re-write this plugin, either using a music tag library or by writing my own tag decoder. At the moment the plugin is linked against the entire Ogg/Vorbis/FLAC libs which is a waste since none of the decoding/encoding code is used and the tag-decoding code should be tiny. A re-written version may also be extended to support APEv2 and iTunes tags as well as embedded cover art (for thumbnails).
(For information from a user perspective, see the main page for the plugin.)
The Text-File Thumbnails plugin source demonstrates the following:
- Thumbnail-only plugin (no viewer).
- Thumbnail alpha channels.
- Tells Opus not to cache & scale its thumbnails so that they are regenerated when the thumbnail size changes (so the text is readable).
- Maintains a process-wide cache of background images to speed up thumbnail generation. This cache has a "housekeeper" thread that frees data after it has not been used for a few seconds. The cache is created in the DVP_Init call and destroyed in the DVP_Uninit call. Critical Sections provide thread-safety.
- Streams (i.e. works with files within archives).
- Configuration dialog (with layout code which adjusts to the system font & localised string lengths).
- Recognises files by inspecting their contents.
- XML configuration file (using the more complex, more powerful config API in the Plugin SDK).
- USB mode.
- Unicode.
- x64.
