home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Installers / Smaller Installer 1.1 / Hook Proc Examples / DemoHook / DemoHook.c next >
Encoding:
C/C++ Source or Header  |  1993-07-03  |  7.5 KB  |  233 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.     Smaller Installer © 1993 Bill Goodman, All Rights Reserved
  3. *******************************************************************************
  4.  
  5. Demonstration Hook Example
  6.  
  7. This is an example of an installer hook procedure. It displays an alert each
  8. time the hook procedure is called.
  9.  
  10. To use this hook procedure, you must compile this code and create a code
  11. resource with type 'SICR' and an ID of 500.  This resource should be
  12. non-preloaded, nonpurgeable, unlocked, unprotected and non-sysheap.  Copy this
  13. resource and the ALRT/DITL resources from the "DemoHook.Misc.rsrc" file to your
  14. installer's resource file.
  15.  
  16. ******************************************************************************/
  17.  
  18. #include <SetUpA4.h>
  19. #include "SIHookProc.h"
  20.  
  21.  
  22. /******************************************************************************
  23.     Module Internal Function Prototypes
  24. ******************************************************************************/
  25. void SetTargetVolFunction(void);
  26. void BeginInstallFunction(void);
  27. void EndInstallFunction(void);
  28. void BuildGroupString(unsigned char *groupPStr);
  29.  
  30.  
  31. /******************************************************************************
  32.     Constant Declarations
  33. ******************************************************************************/
  34. /* Alert Definitions */
  35. #define setTgtAlrt            500    /* Resource ID of SetTargetVol alert */
  36. #define beginAlrt                501    /* Resource ID of BeginInstall alert */
  37. #define cancel_beginAlrt    2        /* Item number of CANCEL button */
  38. #define endAlrt                502    /* Resource ID of EndInstall alert */
  39. #define cancel_endAlrt        2        /* Item number of CANCEL button */
  40.  
  41.  
  42. /******************************************************************************
  43.     Module Variables Declarations
  44. ******************************************************************************/
  45. SIHookParmBlk *parms;                    /* Global pointer to parameter block */
  46. unsigned char emptyPStr[] = "\p";    /* Empty Pascal string */
  47.  
  48.  
  49. /*****************************************************************************/
  50. pascal void main(
  51.         SIHookParmBlk *parmBlk    /* Pointer to parameter block */
  52.         )
  53. /******************************************************************************
  54.     This is the main entry point for the installer hook procedure.
  55. ******************************************************************************/
  56. {
  57. RememberA0();    /* This is necessary to access any global variables */
  58. SetUpA4();
  59. parms = parmBlk;
  60.  
  61. switch (parms->function)
  62.     {
  63.     case siHookSetTargetVol:
  64.         SetTargetVolFunction();
  65.         break;
  66.  
  67.     case siHookBeginInstall:
  68.         BeginInstallFunction();
  69.         break;
  70.  
  71.     case siHookEndInstall:
  72.         EndInstallFunction();
  73.         break;
  74.     }
  75. RestoreA4();
  76. }
  77.  
  78.  
  79. /*****************************************************************************/
  80. void SetTargetVolFunction(void)
  81. /******************************************************************************
  82.     Input parameters:
  83.         "targetVRefNum" - Volume reference number of target volume
  84.         "groupAPFlags", "groupQUSel", "groupVZSel" - Groups currently selected
  85.                                                                     for installation
  86.     Returns:
  87.         "groupAPFlags", "groupQUSel", "groupVZSel" - New installation groups
  88.  
  89.     This function is called at startup and whenever the target volume is
  90.     changed.
  91. ******************************************************************************/
  92. {
  93. HParamBlockRec pb;
  94. Str255 volumePStr;
  95. Str255 selectedGroupsPStr;
  96. OSErr error;
  97.  
  98. BuildGroupString(selectedGroupsPStr);
  99.  
  100. /* Get volume name */
  101. pb.volumeParam.ioVRefNum = parms->targetVRefNum;
  102. pb.volumeParam.ioNamePtr = volumePStr;
  103. pb.volumeParam.ioVolIndex = 0;
  104. error = PBHGetVInfoSync(&pb);
  105. if (error == noErr)
  106.     {    /* Display the target volume name and the selected groups in an alert */
  107.     ParamText(volumePStr, selectedGroupsPStr, emptyPStr, emptyPStr);
  108.     NoteAlert(setTgtAlrt, NULL);
  109.     }
  110. }
  111.  
  112.  
  113. /*****************************************************************************/
  114. void BeginInstallFunction(void)
  115. /******************************************************************************
  116.     Input parameters:
  117.         "targetVRefNum" - Volume reference number of target volume
  118.         "groupAPFlags", "groupQUSel", "groupVZSel" - Groups currently selected
  119.                                                                     for installation
  120.     Returns:
  121.         "result" - Hook result code
  122.  
  123.     This function is called when the install button is clicked to begin
  124.     installing files.
  125. ******************************************************************************/
  126. {
  127. HParamBlockRec pb;
  128. Str255 volumePStr;
  129. Str255 selectedGroupsPStr;
  130. OSErr error;
  131.  
  132. BuildGroupString(selectedGroupsPStr);
  133.  
  134. /* Get volume name */
  135. pb.volumeParam.ioVRefNum = parms->targetVRefNum;
  136. pb.volumeParam.ioNamePtr = volumePStr;
  137. pb.volumeParam.ioVolIndex = 0;
  138. error = PBHGetVInfoSync(&pb);
  139. if (error != noErr)
  140.     goto Error;
  141.  
  142. /* Display the target volume name and the selected groups in an alert */
  143. ParamText(volumePStr, selectedGroupsPStr, emptyPStr, emptyPStr);
  144. if (NoteAlert(beginAlrt, NULL) == cancel_beginAlrt)
  145.     goto Error;    /* Return error to indicate user cancelled operation */
  146.  
  147. return;    /* Note that it is not necessary to set the result if no error */
  148.  
  149. /* Error occurred or user cancelled operation */
  150. Error:
  151. parms->result = siHookAbort;
  152. }
  153.  
  154.  
  155. /*****************************************************************************/
  156. void EndInstallFunction(void)
  157. /******************************************************************************
  158.     Input parameters:
  159.         "targetVRefNum" - Volume reference number of target volume
  160.         "groupAPFlags", "groupQUSel", "groupVZSel" - Groups currently selected
  161.                                                                     for installation
  162.         "completionSts" - Indicates any errors which occurred during installation
  163.     Returns:
  164.         "result" - Hook result code
  165.  
  166.     This function is called at the end of the installation process.
  167. ******************************************************************************/
  168. {
  169. HParamBlockRec pb;
  170. Str255 volumePStr;
  171. Str255 selectedGroupsPStr;
  172. StringPtr statusPtr;
  173. OSErr error;
  174.  
  175. if (parms->completionSts == siHookComplete)
  176.     statusPtr = "\pInstallation complete. All files installed.";
  177. else if (parms->completionSts == siHookFileSkipped)
  178.     statusPtr = "\pInstallation complete. Some files were skipped.";
  179. else
  180.     statusPtr = "\pInstallation was aborted.";
  181.  
  182. BuildGroupString(selectedGroupsPStr);
  183.  
  184. /* Get volume name */
  185. pb.volumeParam.ioVRefNum = parms->targetVRefNum;
  186. pb.volumeParam.ioNamePtr = volumePStr;
  187. pb.volumeParam.ioVolIndex = 0;
  188. error = PBHGetVInfoSync(&pb);
  189. if (error != noErr)
  190.     goto Error;
  191.  
  192. /* Display the target volume name, the selected groups and the completion */
  193. /* status in an alert */
  194. ParamText(volumePStr, selectedGroupsPStr, statusPtr, emptyPStr);
  195. if (NoteAlert(endAlrt, NULL) == cancel_endAlrt)
  196.     goto Error;    /* Return error to indicate user cancelled operation */
  197.  
  198. return;    /* Note that it is not necessary to set the result if no error */
  199.  
  200. /* Error occurred or user cancelled operation */
  201. Error:
  202. parms->result = siHookAbort;
  203. }
  204.  
  205.  
  206. /*****************************************************************************/
  207. void BuildGroupString(
  208.         unsigned char *groupPStr    /* Returned group string */
  209.         )
  210. /******************************************************************************
  211.     Build a list of selected groups and return in the specified string.
  212. ******************************************************************************/
  213. {
  214. short index;
  215. short count;
  216.  
  217. index = 1;
  218. for (count = 0; count < 16; count++)
  219.     {
  220.     if (parms->groupAPFlags & (0x0001 << count))
  221.         {    /* Group is selected - add to list */
  222.         groupPStr[index++] = 'A' + count;
  223.         groupPStr[index++] = ',';
  224.         groupPStr[index++] = ' ';
  225.         }
  226.     }
  227. groupPStr[index++] = 'Q' + parms->groupQUSel;
  228. groupPStr[index++] = ',';
  229. groupPStr[index++] = ' ';
  230. groupPStr[index] = 'V' + parms->groupVZSel;
  231. groupPStr[0] = index;
  232. }
  233.