REXX Tips & Tricks, Version 2.80


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Extract the icon from the EAs



A lot of programs save their icon in the Extended Attribute .ICON. You may 
use the following code to extract the icon from the EAs of a program (see 
also Icon resources in default OS/2 DLLs and Get icons from the OS2.INI 
file):   

 
/*                                                                    */
/* Name:     GetIcon.CMD                                              */
/*                                                                    */
/* Function:                                                          */
/*   sample program to get the icons from the OS2.INI file            */
/*                                                                    */
/* Usage:                                                             */
/*   GetIcon fileName                                                 */
/*                                                                    */
/* Where:                                                             */
/*   fileName - name of the file with the .ICON EA                    */
/*                                                                    */
/* Returns:                                                           */
/*   -                                                                */
/*                                                                    */
/* Credits:                                                           */
/*   -                                                                */
/*                                                                    */
/* History:                                                           */
/*   RXT&T v2.00 /bs                                                  */
/*     - initial release                                              */
/*   RXT&T v2.10 /bs                                                  */
/*     - added some error checking code                               */
/*                                                                    */
/* Notes:                                                             */
/*                                                                    */
/*   The .ICO files are created in the current directory.             */
/*                                                                    */
/*   Tested only with WARP.                                           */
/*                                                                    */
/*                                                                    */
/* (c) 1996 Bernd Schemmer, Germany, EMail: 100104.613@compuserve.com */
/*                                                                    */

  parse arg sourceFileName
  sourceFileName = strip( sourceFileName )

                    /* load the necessary REXXUTIL function           */
  call RxFuncAdd "SysGetEA", "REXXUTIL", "SysGetEA"

                    /* check the parameter                            */
  if sourceFileName = "" then
  do
    say "Usage: GetIcon fileName"
    exit 2
  end /* if sourceFileName = "" then */

  iconData = ""

                    /* use ".ICON1" to retrieve the Animation icon of */
                    /* folder                                         */
  if SysGetEA( sourceFileName, ".ICON", "iconData" ) <> 0 | iconData = "" then
  do
    say "Error: Either the file does not exist or the file has no .ICON EA"
    exit 3
  end /* if SysGetEA( ... */

                    /* check the type and format of the EA      v2.10 */
  parse var iconData EAType +2 EALength +2 IconData          /* v2.10 */
  EALength = c2d( translate( "12", EALength, "21" ) )        /* v2.10 */

  if EAType <> "F9FF"x | ,                                   /* v2.10 */
     EALength <> length( iconData ) then                     /* v2.10 */
  do                                                         /* v2.10 */
    say "Error: The .ICON EA is corrupted!"                  /* v2.10 */
    exit 5                                                   /* v2.10 */
  end /* if EAType <> "F9FF"x | ...  */                      /* v2.10 */

                    /* create the name for the target file            */
  i = lastPos( ".", sourceFileName )
  j = lastPos( "\", sourceFileName )

  if i = 0 | ( i < j ) then
    targetFileName = sourceFileName || ".ICO"
  else
    targetFileName = substr( sourceFileName, 1, i ) || "ICO"

  if stream( targetFileName, "c", "QUERY EXISTS" ) <> "" then
  do
    say "Error: The targetfile " || ,
        targetFileName || ,
        " already exist!"
    exit 4
  end /* if stream( ...  */

                    /* create, write and close the ICON file          */
  call stream targetFileName, "c", "OPEN WRITE"
  call CharOut targetFileName, iconData
  call stream targetFileName, "c", "CLOSE"

  say "Iconfile " || targetFileName || " created."
exit 0




Inf-HTML End Run - Successful