News Archive

Date

Modify Path

Introduction

Modify Path is a fairly simple Windows script that allows users to easily modify the system path by adding a new or removing an existing directory.  It was written to facilitate installation of Inno Setup packages that require path changes.  As such, it is likely to be more useful for developers and administrators than end-users.

Note:  I've rewritten Modify Path in native Inno Setup Pascal script.  Since this was my primary use for Modify Path, I'll likely only update the Pascal script going forward.  However, feel free to e-mail me if you have a need for an updated AutoIt script as well.  I'll be happy to assist if I'm able.

Modify Path was originally written in the powerful, open source AutoIt scripting language.

Return to top

Download  Current Version: 1.3.1, Released: 10/14/2007

ModPath Inno Setup Source (4.95 KB) - This is the Inno Setup Pascal script source

ModPath AutoIt Binary (119 KB) - This is the compiled AutoIt ModPath executable

ModPath AutoIt Source (3.16 KB) - The AutoIt source code for ModPath

ChangeLog - ModPath development details

Return to top

Installation and Usage (Inno Setup)

To use ModPath in your Inno Setup package, follow these steps:

  1. Copy modpath.iss to the same directory as your setup script
  2. Add this statement to your [Setup] section
    • ChangesEnvironment=yes
  3. Add this statement to your [Tasks] section;  You can change the Description or Flags, but the Name must be modifypath
    • Name: modifypath; Description: Add application directory to your system path; Flags: unchecked
  4. Add the following to the end of your [Code] section;  setArrayLength must specify the total number of dirs to be added;  Dir[0] contains first directory, Dir[1] contains second (optional), etc.
    • function ModPathDir(): TArrayOfString;
      var
          Dir: TArrayOfString;
      begin
          setArrayLength(Dir, 1)
          Dir[0] := ExpandConstant('{app}');
          Result := Dir;
      end;
      #include "modpath.iss"

Once the above statements have been included and compiled into your package, the system path will be automatically updated with the main application directory upon installation and uninstallation if the modifypath task is enabled.

Return to top

Installation and Usage (AutoIt)

ModPath has no installation process, per say.  If you want to use the AutoIt script on your system, simply download it to any folder in your default system path.  C:\WINNT\ or C:\WINDOWS\ (whichever is appropriate) is usually a good choice.

Usage of the program should be very straightforward.  The syntax for ModPath is modpath.exe {/add | /del} <path>.  This states that modpath.exe should be called, told whether to add a new directory to or remove an existing directory from the current path, then given the location of the new directory.  Be sure to enclose the location in quotes if it contains a space.

For example, the following command will add the "New Application" directory to the system path:
modpath.exe /add "C:\Program Files\New Application"

Conversely, the next command will remove the same directory if it already exists in the path:
modpath.exe /del "C:\Program Files\New Application"

Return to top

Technical Details

Note: The following description was written for the AutoIt version of ModPath, but it also applies to the Inno Setup version.

ModPath will add or remove the specified directory to the path under both Windows 9x and NT (in the context, NT refers to any NT-based version of Windows, including 2000 and XP).  However, removal support is somewhat limited under Windows 9x.  ModPath can be used to remove any directory currently in the system path from Windows NT, but it can only remove directories that it had previously added itself from Windows 9x.  This is because Windows 9x provides multiple methods of setting the path, which makes it difficult to account for every possibility.

Under Windows NT, the system path is stored as a semi-colon delimited list in the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\[Path].  When run, ModPath tokenizes this path into an array, and loops through each entry.  If adding a directory and it already exists, it simply exists; otherwise, it appends it to the end of the current path.  If removing a directory, it deletes any existing matching entries.  It then writes the new key back to the registy.  The updated path will take effect immediately in all newly-spawned shells.

Under Windows 9x, ModPath uses C:\autoexec.bat to store the path.  If adding a directory, it searches through autoexec.bat to first check if it already exists.  If adding a directory and already exists, it simply; exists; otherwise, it adds a new line appending the directory to the existing path.  If removing a directory, it deletes any previously added lines to autoexec.bat that match the specified directory.

Path changes take effect immediately under Windows NT, but require a reboot under Windows 9x.  A workaround for Windows 9x is to use the winset.exe utility (found on any Windows 98 CD-ROM).  This utility can be used to set the path for all future processes, though it doesn't modify the currently running explorer.exe, nor does it permanently set the path.  It makes a good compliment to ModPath when used during an installation.

Return to top

Inno Setup CLI Help

Introduction

Inno Setup CLI Help is a set of functions that can be included in any Inno Setup installer to display command line usage information to the user.  This help info can be displayed by passing /?, /h, or /help to the installer.  If one of these arguments is passed, the installer display the help usage information, then exit.

This help information, for the most part, is a copy of the "Setup Command Line Parameters" of the Inno Setup help file.  The reason I want to include this information in the installer itself is to make it as easy as possible for end-users to access it.  Otherwise, it's difficult to track down this information, especially if the user does not even know that the installer uses Inno Setup.

In addition to the Inno Setup help text, this help information can also contains a list of all components, tasks, and custom parameters used by the given installer.  Again, the purpose here is to educate the user and make it as easy as possible for him to automate and/or customize installation to suit his needs.

Inno Setup CLI Help was inspired by, and uses code from, the Windows GIMP installer by Jernej Simoncic.

Return to top

Screenshots

CLI Help example
CLI Help example
Click to Enlarge

Download  Current Version: 1.3, Released: 08/08/2007

Inno Setup CLI Help Source (16.91 KB) - This is the Inno Setup Pascal script source

ChangeLog - Inno Setup CLI Help development details

Return to top

Installation and Usage

To use Inno Setup CLI Help, download the source .iss script above and follow these directions:

  1. Copy clihelp.iss to the same directory as your setup script
  2. Add the following to the end of your [Code] section
    Constants should be set according to the instructions below
    • const
         ComponentList = '';
         TaskList = '';
         ParameterList = '';
      #include "clihelp.iss"

The ComponentList, TaskList, and ParameterList constants must follow a specific naming convention:
Name1 - Description1 | Name2 - Description2

Use a hyphen (-) to separate the name from the description, and use a pipe (|) to delineate between each item. For example:

ComponentList = '';
TaskList = 'associate - Enable context menu integration | modifypath - Add application to your system path | desktopicon - Create a desktop icon';
ParameterList = '/NOHISTORY - Disables history functionality.';

This states that there are no components available for this app, three tasks are available (associate, modifypath, and desktopicon), and it supports a custom /NOHISTORY parameter.

Note:  The three constants must always be defined.  If your program does not use any components, tasks, or custom parameters, simply define the constant(s) as an empty string.  For example, if your program has no components, the ComponentList should be set to the following:

ComponentList = '';

Once the above statements have been included and compiled into your package, the help information window will automatically displayed anytime /?, /h, or /help is passed to your installer.

Return to top

Get Album Art

Introduction

Get Album Art is CLI (comment line interface) PHP script designed to locate and download the CD cover art for any given album.  Currently it will search buy.com, walmart.com, and amazon.com (in that order) and download the first image it finds matching the appropriate criteria (title match, image dimensions, etc.).  In the event that it finds multiple matches on a single site, it will download all appropriate images and the user can manually choose which one to keep.  Get Album Art can also optionally create a freedesktop.org directory icon, which can be read by compatible file managers to display the album cover instead of a generic folder icon when viewing that album directory (ImageMagick is required for this option).

Get Album Art is written in PHP 4.  It was originally written for Linux, but should be easily portable to any other platform that supports PHP.

Return to top

Download  Current Version: 1.0

getalbumart.php tarball (3.33 KB) - This is a compressed version of the Get Album Art PHP script.

ChangeLog - Get Album Art development details

Return to top

Installation

Installation of Get Album Art is simple:

  1. Download the tarball
  2. Extract the script from the tarball: tar zxf getalbumart.tgz
  3. Copy to a directory in your $PATH (eg, /usr/local/bin/)
  4. Ensure that getalbumart.php has the execute bit set (eg, chmod a+x /usr/local/bin/getalbumart.php)

To complete installation, please open up getalbumart.php in any text editor and verify that the programs defined in the "Setup environment" section are installed, and modify the path to each as appropriate.

Return to top

Usage

Execute getalbumart.php -h to display the Get Album Art help information.  This will describe the syntax for running the program and list all available options.

To download an album cover, the album title and artist's name must be specified.  This can either be done by specifying both on the command line with the -l and -r parameters, or by passing -c to let Get Album Art determine it automatically from the directory names.  In order for the -c parameter to work, the album must be stored in this directory structure:
/path/to/music/Artist Name/Album Name/

If you do not follow this naming convention, you must specify the -l and -r parameters.  Additionally, the -n and -p parameters can be used to specify how and where the images are saved, and -d will instruct Get Album Art to create a freedesktop.org directory icon.

Return to top

Technical Details

When getalbumart.php is executed, it begins by verifying that all arguments are correctly passed, and verifies that ImageMagick is available if -d is specified.  It then checks to see if an image already exists for this album; if found, Get Album Art will not download a new image.

If no existing image is found, Get Album Art builds the search strings for buy.com, walmart.com, and amazon.com, then search each store in order.  If the search only returns a single result, the cover image for that album will be downloaded and verified.  If multiple results are returned, Get Album Art determines the album cover URL for each result and downloads all available covers for verification.  Image verification ensures that any downloaded image meets minimum dimension requirements (to ensure we get a good quality image rather than a thumbnail) and, in the case of multiple matches, that only unique images are saved.

Any images that meet the requirements are named appropriately and saved; all remaining images are deleted.  If at least one image is saved, Get Album Art will create the freedesktop.org directory icon (if specified), then exit.  If no images are found at the given store, Get Album Art begins processing the next store, and repeats the process.

Return to top

ExtractMHT

Introduction

ExtractMHT is a fairly simple program that can be used to extract individual files out of MHTML files.  MHTML groups multiple individual files into a single .mht file.  This is most often used to save a web page to a single file for offline viewing, and is supported by Opera, Internet Explorer, and various other Microsoft applications.  While MHTML files can be convenient, there are rather supported outside of Windows, and even when using Windows one may be more interested in a single component of the MHTML file rather than the entire archive.  ExtractMHT solves this problem by allowing users to extract all components out of an MHTML file and save them as individual files.

ExtractMHT began as a request to add support for MHTML files to Universal Extractor.  I had planned on simply incorporating an existing program into Universal Extractor to handle MHTML support, but I was unable to find any freely redistributable programs for Windows that was capable of doing this.  I was about to give up on adding support, but after doing a bit more research into the actual structure of MHTML files I realized that it would be possible to write an extractor myself.  Thus, ExtractMHT was born.

ExtractMHT has since been incorporated into Universal Extractor, but it is available here as well as a standalone binary.  You can use it if you need to extract the contents of an MHTML file, but don't want or need to install Universal Extractor to do the job.

ExtractMHT, like most of my Windows programs, is written in AutoIt, a free and powerful open source scripting language.

Return to top

Screenshots

ExtractMHT Application
ExtractMHT file/destination GUI

Download  Current Version: 1.0, Released: 09/10/2006

ExtractMHT Binary Archive (281.96 KB) - This archive contains the ExtractMHT executable, as well as all source code.

ChangeLog - ExtractMHT development details

Return to top

Installation and Usage

ExtractMHT does not include an installer.  To use, simply download the archive, extract the files to your computer, and double-click on ExtractMHT.exe to launch the ExtractMHT GUI.  Enter (or use the file browser to select) the file you wish to extract and the destination directory, then click OK.

ExtractMHT also supports command line usage.  Please run ExtractMHT.exe /help to view usage instructions.

Return to top

Technical Details

When a file is passed to ExtractMHT, it begins by checking the file to ensure it's a valid MHTML file.  ExtractMHT then begins processing each of the parts contained in the file.  Each part will be written to an individual file in the specified output directory.

ExtractMHT will attempt to use the original filenames as described in the MHTML file, but it will ensure that each file is given a unique filename to prevent any files from being overwritten.  It may also be impossible in some circumstances to determine the original filename.  In this event, the file will be named "unknown".

Return to top

Known Limitations

ExtractMHT does not perform any analysis or rewriting of URLs to make links point to the extracted files rather than the original file.  Eg, if the Microsoft home page is saved as an MHT file and then extracted, the resulting index.html will still reference images on html://www.microsoft.com/... rather than the local copies.

I currently do not plan on implementing this capability, as the primary purpose of ExtractMHT is to simply extract the nested files from MHTML files.

Return to top

Credits

ExtractMHT would not exist without the following contributions from the Free Software community:

  • AutoIt (Jonathan Bennett, Open Source) - General-purpose Windows scripting language; used to write ExtractMHT
  • Crystal SVG (Everaldo Coelho, Free) - Collection of extremely high-quality icons for Linux/KDE; used as the source graphics for the ExtractMHT icon
  • GIMP (Spencer Kimball and Peter Mattis, Open Source) - The GNU Image Manipulation Program; used to create the icons used by ExtractMHT

Additionally, ExtractMHT uses the following code to perform Base64 decoding: http://www.autoitscript.com/forum/index.php?showtopic=21399&view=findpost&p=148460

Return to top

Convert to FLAC

Introduction

FLAC is a free, open source lossless compression audio codec.  The Convert to FLAC script, converts audio files compressed with alternative lossless codecs (Monkey's Audio, Shorten, etc.) to the FLAC format.  FLAC is my preferred audio format for archiving music, so I wanted an easy way to convert other formats to FLAC.  In addition to simply transcoding the file to the FLAC format, Convert to FLAC also preserves any existing tags from the original file.

Convert to FLAC is a BASH shell script, and was originally written for use under Linux.  It should, however, run under any OS that supports BASH.

Convert to FLAC currently supports the following input formats:

Return to top

Download  Current Version: 1.1, Released: 02/18/2007

convtoflac.sh (5.9 KB) - The Convert to FLAC BASH shell script

ChangeLog - Convert to FLAC development details

Return to top

Installation

Installation of Convert to FLAC is simple:

  1. Download the BASH script
  2. Copy to a directory in your $PATH (eg, /usr/local/bin/)
  3. Ensure that the script has the execute bit set (eg, chmod a+x /usr/local/bin/convtoflac.sh)
  4. Verify that required binaries are available for the format you want to encode (see supported formats list above)

To complete installation, please open up convtoflac.sh in any text editor and verify that the programs defined in the "Setup environment" section are installed, and modify the path to each as appropriate.

Return to top

Usage

Execute convtoflac.sh -h to display the convtoflac help information.  This will describe the syntax for running the program and list all available options.

When run on a supported audio file, convtoflac.sh will automatically determine the input filetype and transcode it to a FLAC file

Tip:  Convert to FLAC can only operate on a single audio file at a time.  However, if you need to process multiple files at once (such as an entire album), so you can so with a little shell magic:
for i in *.ape; do convtoflac.sh "$i"; done

This example converts APE files, but the same can be done for any supported filetype by changing the extension in the above command.

Return to top

Technical Details

convtoflac begins execution by verifying that all arguments have been passed correctly.  It the determines the input filetype by checking the extension (case-insensitive match).  Using the file command to more accurately identify the input file is not possible because it does not recognize every supported filetype.  Support files are then verified based on the input file format; eg., if you are missing wvunpack but are trying to convert an APE file, then you will not get an error about wvunpack.

convtoflac transcodes the file by piping the decompression output directly to the flac command to make the process as quick as possible.  flac will apply maximum compression to the file, and the resulting output file will have the same name as the original file, but with the .flac extension.

If the input file format includes tags, convtoflac will then attempt to apply the tags to the new FLAC file.  It does this by first outputting the tags from the original file to a temp file, converting the tags to the VORBISCOMMENT format if necessary (the tag format used by FLAC), then applying them to the new file using metaflac.

Depending on which options were passed, convtoflac may either delete or prompt you to delete the input file at this point.  If you passed the -d option, it will attempt to verify that transcoding was successful before deleting the file.  If not, convtoflac simply exists with an error message.

Return to top