Raz-Soft » Blog Archive » How To: make IssProc language aware (Pascal scripting)
Decorative purposes plugin: Snow effect (wp-flake) »
« Hard Disk Thermometer (HyperIM plugin)

How To: make IssProc language aware (Pascal scripting)

 This is a small article describing how to enable IssProc to be multi-language aware by expanding and using the {language} constant with InnoSetup Pascal scripting.
 Before we start you should know that some pascal scripting knowledge is required to fully understand and modify (if required) the iss script snippet (see below links if you're new with Inno).

Intro

  The power of Inno Setup (the best free installer for Windows programs) lies in the integrated Pascal scripting engine giving the setup developers control over all the setup actions. Because you can use Pascal code in your setup script you will not be limited to the setup build-in actions, you can take control over the entirely setup and write your own code. If you're not to familiar with Pascal scripting you can build your own extensions (dll - Dynamic-link library ) and use them when/if needed, hence you'll have no limits.

IssProc and multilingual installations

  In version 1.0.1, of IssProc extension, support for multi-language has been added. This enables setup authors to display the File-In-Use Window with text informations in any language or even the one selected by user at startup, if the setup was build with multi-language support. To make that work all you need to do is expand the {language} constant and use it with IssFindModule function from IssProc extension. That's easy, right? Oh, yeah I almost forgot, you will need to add your language translation in the IssProcLanguage.ini file and add this file to the setup. Adding an extra language to IssProcLanguage.ini file it's easy: just copy & paste the english section (english section for install it's named [en] and for uninstall it's [enu] ), translate them in your language and rename the sections according to your language name (first two characters of the language name, or any other name as long as you pass that section name on IssFindModule language parameter ). For example if you need french translation you should have one section called [fr], used on install with info texts in french, and one called [fru], used on unistall.

Let's code

  • Part 1: The standard iss script sections, app info, files, icons, languages etc.
  • INNO:
    1. ; Script generated by the Inno Setup Script Wizard.
    2. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
    3.  
    4. [Setup]
    5. AppName=My Program
    6. AppVerName=My Program 1.5
    7. AppPublisher=My Company, Inc.
    8. AppPublisherURL=http://www.example.com/
    9. AppSupportURL=http://www.example.com/
    10. AppUpdatesURL=http://www.example.com/
    11. DefaultDirName={pf}\My Program
    12. DefaultGroupName=My Program
    13. OutputBaseFilename=setup
    14. Compression=lzma
    15. SolidCompression=yes
    16.  
    17. [Languages]
    18. Name: english; MessagesFile: compiler:Default.isl
    19. Name: basque; MessagesFile: compiler:Languages\Basque.isl
    20. Name: brazilianportuguese; MessagesFile: compiler:Languages\BrazilianPortuguese.isl
    21. Name: catalan; MessagesFile: compiler:Languages\Catalan.isl
    22. Name: czech; MessagesFile: compiler:Languages\Czech.isl
    23. Name: danish; MessagesFile: compiler:Languages\Danish.isl
    24. Name: dutch; MessagesFile: compiler:Languages\Dutch.isl
    25. Name: finnish; MessagesFile: compiler:Languages\Finnish.isl
    26. Name: french; MessagesFile: compiler:Languages\French.isl
    27. Name: german; MessagesFile: compiler:Languages\German.isl
    28. Name: hebrew; MessagesFile: compiler:Languages\Hebrew.isl
    29. Name: hungarian; MessagesFile: compiler:Languages\Hungarian.isl
    30. Name: italian; MessagesFile: compiler:Languages\Italian.isl
    31. Name: norwegian; MessagesFile: compiler:Languages\Norwegian.isl
    32. Name: polish; MessagesFile: compiler:Languages\Polish.isl
    33. Name: portuguese; MessagesFile: compiler:Languages\Portuguese.isl
    34. Name: russian; MessagesFile: compiler:Languages\Russian.isl
    35. Name: slovak; MessagesFile: compiler:Languages\Slovak.isl
    36. Name: slovenian; MessagesFile: compiler:Languages\Slovenian.isl
    37. Name: spanish; MessagesFile: compiler:Languages\Spanish.isl
    38.  
    39. [Tasks]
    40. Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: unchecked
    41.  
    42. [Files]
    43. Source: C:\Program Files\Inno Setup 5\Examples\MyProg.exe; DestDir: {app}; Flags: ignoreversion
    44. ; NOTE: Do not use "Flags: ignoreversion" on any shared system files
    45. ;------ add Files In Use Extension
    46. Source: IssProc.dll; DestDir: {tmp}; Flags: dontcopy
    47. ;------ add Files In Use Extension extra language file (you don t need to add this file if you are using english only)
    48. Source: IssProcLanguage.ini; DestDir: {tmp}; Flags: dontcopy
    49. ;------ Copy IssProc.dll in your app folder if you want to use it on unistall
    50. Source: IssProc.dll; DestDir: {app}
    51. Source: IssProcLanguage.ini; DestDir: {app}
    52. ;------
    53.  
    54. [Icons]
    55. Name: {group}\My Program; Filename: {app}\MyProg.exe
    56. Name: {commondesktop}\My Program; Filename: {app}\MyProg.exe; Tasks: desktopicon
    57.  
    58. [Run]
    59. Filename: {app}\MyProg.exe; Description: {cm:LaunchProgram,My Program}; Flags: nowait postinstall skipifsilent

  • Part 2: The Code section (Inno Pascal scripting)
  • PASCAL:
    1. [Code]
    2. // IssFindModule called on install
    3. function IssFindModule(hWnd: Integer; Modulename: PChar; Language: PChar; Silent: Boolean; CanIgnore: Boolean ): Integer;
    4. external 'IssFindModule@files:IssProc.dll stdcall setuponly';
    5. // IssFindModule called on uninstall
    6. function IssFindModuleU(hWnd: Integer; Modulename: PChar; Language: PChar; Silent: Boolean; CanIgnore: Boolean ): Integer;
    7. external 'IssFindModule@{app}\IssProc.dll stdcall uninstallonly';
    8. //********************************************************************************************************************************************
    9. // IssFindModule function returns: 0 if no module found; 1 if cancel pressed; 2 if ignore pressed; -1 if an error occured
    10. //
    11. //  hWnd        = main wizard window handle.
    12. //
    13. //  Modulename  = module name(s) to check. You can use a full path to a DLL/EXE/OCX or wildcard file name/path. Separate multiple modules with semicolon.
    14. //         Example1 : Modulename='*mymodule.dll';    -  will search in any path for mymodule.dll
    15. //         Example2 : Modulename=ExpandConstant('{app}\mymodule.dll');   -  will search for mymodule.dll only in {app} folder (the application directory)
    16. //         Example3 : Modulename=ExpandConstant('{app}\mymodule.dll;*myApp.exe');   - just like Example2 + search for myApp.exe regardless of his path.
    17. //
    18. //  Language    = files in use language dialog. Set this value to empty '' and default english will be used
    19. //        ( see and include IssProcLanguage.ini if you need custom text or other language)
    20. //
    21. //  Silent    = silent mode : set this var to true if you don't want to display the files in use dialog.
    22. //        When Silent is true IssFindModule will return 1 if it founds the Modulename or 0 if nothing found
    23. //
    24. //  CanIgnore   = set this var to false to Disable the Ignore button forcing the user to close those applications before continuing
    25. //        set this var to true to Enable the Ignore button allowing the user to continue without closing those applications
    26. //******************************************************************************************************************************************
    27. function NextButtonClick(CurPage: Integer): Boolean;
    28. var
    29.   hWnd: Integer;
    30.   sModuleName: String;
    31.   sCurLanguage: String;
    32.   nCode: Integer{IssFindModule returns: 0 if no module found; 1 if cancel pressed; 2 if ignore pressed; -1 if an error occured }
    33. begin
    34.   Result := true;
    35.  if CurPage = wpReady then
    36.    begin
    37.       Result := false;
    38.       sCurLanguage:=Copy(ExpandConstant('{language}'),0,2){ extract first 2 characters from current setup language name }
    39.       ExtractTemporaryFile('IssProcLanguage.ini');           { extract extra language file - you don't need to add this line if you are using english only }
    40.       hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));      { get main wizard handle }
    41.       sModuleName :=ExpandConstant('*ker*');                   { searched modules. Tip: separate multiple modules with semicolon Ex: '*mymodule.dll;*mymodule2.dll;*mymodule3.dll'}
    42.       nCode:=IssFindModule(hWnd,sModuleName,sCurLanguage,false,true);            { search for module and display files-in-use window if found  }
    43.      if nCode=1 then  begin    { cancel pressed or files-in-use window closed }
    44.           PostMessage (WizardForm.Handle, $0010, 0, 0);   { quit setup, $0010=WM_CLOSE }
    45.      end else if (nCode=0) or (nCode=2) then begin        { no module found or ignored pressed}
    46.           Result := true;                              { continue setup  }
    47.      end;
    48.   end;
    49. end;
    50.  
    51.  
    52. function InitializeUninstall(): Boolean;
    53. var
    54.   sModuleName: String;
    55.   sCurLanguage: String;
    56.   nCode: Integer{IssFindModule returns: 0 if no module found; 1 if cancel pressed; 2 if ignore pressed; -1 if an error occured }
    57. begin
    58.     Result := false;
    59.      sCurLanguage:=Copy(ExpandConstant('{language}'),0,2)+'u';   { extract first 2 characters from current setup language name and add 'u' for uninstall}
    60.    sModuleName := ExpandConstant('*ker*;');                    { searched module. Tip: separate multiple modules with semicolon Ex: '*mymodule.dll;*mymodule2.dll;*myapp.exe'}
    61.      nCode:=IssFindModuleU(0,sModuleName,sCurLanguage,false,false);     { search for module and display files-in-use window if found  }
    62.      if (nCode=0) or (nCode=2) then begin                            { no module found or ignored pressed}
    63.           Result := true;                                                 { continue setup  }
    64.      end;
    65.     // Unload the extension, otherwise it will not be deleted by the uninstaller
    66.     UnloadDLL(ExpandConstant('{app}\IssProc.dll'));
    67. end;

Final words

  The only code changes are made before using the IssFindModule function (on Part 2 line 38,for install and on line 59, for uninstall). We just extract the first characters from the expanded constant {language}, which contains the selected user language name, and use it with IssFindModule function in order to use/load the right language section from IssProcLanguage.ini file, easy right?

Resources

related things:

Author: Raz | On November 27th, 2007 | Others, Bookmarks, [ En ], Inno Setup | 2 Comments

Q: So what can I do next?
A: You can Buy me a Beer or Coffee. You can say Hi! or peek on the related stuff. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

    2 Responses to “How To: make IssProc language aware (Pascal scripting)”

  1. Unknown Says:

    what a nice way to teach... really liked it..


  2. Raz ROMANIA Says:

    I'm glad you like it.
    Thanks for your feedback.


Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> and all YM emotions