Humble Framework for SkyOS


Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

HResMgr Class Reference
[System]

#include <HResMgr.h>

Inheritance diagram for HResMgr:

HZipFile HFile HObjNoCopy HObj

Detailed Description

One of the utopian goals of every software developer is the ability to cleanly install—and uninstall—any software package with a minimum of effort. Because of this, packages which spray files and configuration settings all over the file system can quickly become persona non grata, because trying to find and remove them can be frustrating. Ever tried to completely remove Microsoft Office™ from a Windows™ system? To avoid this kind of nest- fouling, the goal of the Humble Framework is to have every application consist of only three files: the executable (.app), a resource file (.pkg) and a settings file (.ini); strictly speaking, the settings file is optional because the Framework will automatically generate it the first time the application is run.

Any files that the application requires can be stored inside the resource file, from where they will be automatically extracted when needed. Future versions of the HResMgr class will be able to 'clean up' resources, or ultimately eliminate the reliance on external files.

So why use a package (.pkg) file? First of all, because it's easy: it's just a .zip archive with a different extension, which means there are numerous tools available to create and manage the resource file during development. Secondly, the zip library is portable, fast, stable, and readily available. Thirdly, the .zip file format already has all kinds of developer goodness inside, including industry-standard compression, hierarchical file names, and the ability to add comments to files contained inside the archive.

From within any application built with the Humble Framework, using resources can be as simple as a couple of lines of code:

    if (theApp.ExtractResource("Splash.jpg") != NO_ERROR)
        { 
        // handle a 'resource not found' error
        } 

This code snippet first goes out to the resource directory (currently the same directory as the resource file) and checks to see if the file has already been extracted; if so, no further work is necessary, and a success result is returned. If the file doesn't exist yet, the resource file managed by the HResMgr class—and originally opened in the HApp::Init() method—is searched for a file with the name Splash.jpg, which if found, is decompressed and written out to the resource directory. This example uses a JPEG image, but an application resource can be anything: a text file, a binary data file, even an application or another resource file! Since the .zip archive doesn't place many restrictions on what kinds of files can be stored within an archive, the HResMgr class is subsequently equally versatile.

Definition at line 72 of file HResMgr.h.

Public Member Functions

ErrCode Extract (StringPtr pstrSrc, StringPtr pstrDst=NULL)
 Extracts a resource file.
ErrCode Open (HFilename &fsFile)
 Opens a resource file.


Member Function Documentation

ErrCode HResMgr::Extract StringPtr  pstrSrc,
StringPtr  pstrDst = NULL
[virtual]
 

This method looks for a given source file in the .zip archive and reads in the file's contents, inflating it if needed. The resulting data is then written out to a file. Although hierarchical filename can be used, the caller is responsible for ensuring that any or all subdirectories exist.

Returns:
NO_ERROR on success, error code otherwise
Parameters:
pstrSrc File name inside .zip archive
pstrDst [optional] File name to copy to

Reimplemented from HZipFile.

Definition at line 105 of file HResMgr.h.

ErrCode HResMgr::Open HFilename fsFile  ) 
 

Returns:
NO_ERROR on success, error code otherwise
Parameters:
fsFile Fully-qualified filespec to resource file

Definition at line 116 of file HResMgr.h.


The documentation for this class was generated from the following file:
 

2006.01.09-16:37