Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
In need of a Pascal script for an installer Posted by MrRadicalEd on 12 Feb 2005 at 2:28 PM
This message was edited by MrRadicalEd at 2005-2-12 14:32:55

I'm currently writing an installer script with Inno Setup that can use Pascal scripts for more functionality, but isn't required to actually make a decent installer. Anyway I had run in to a problem that requires a Pascal script, and while I am highly interested in learning Pascal I am actually focused on getting this installer completed to get this side project out the door.

In my installer script file I have a line like this:
Source: C:\MFCMproject\Game Directories\counter-strike\cstrike\MFCM\mfcm.cfg; DestDir: {reg:HKCU\SOFTWARE\Valve\Steam,ModInstallPath}\counter-strike\cstrike\MFCM

The source file's destination directory is read from an existing registry entry. The problem is that the path read from the registry key is too long and an extra directory needs to be removed at the end.

the entry ModInstallPath is "c:\program files\valve\steam\steamapps\email@address.net\half-life"

and needs to look like:
"c:\program files\valve\steam\steamapps\email@address.net"

The way Pascal code is inserted in to the installer script is by placing Open Bracket"["Code"]"Close Bracket in the script and using the constant {code:...} where you need to use the function

so instead of {reg:HKxx...} it would be {code:function...} The function being the script needed.

Help with this matter would be very greatly appreciated and would installer help would be included in the credits
Report
Re: In need of a Pascal script for an installer Posted by zibadian on 13 Feb 2005 at 12:13 AM
: This message was edited by MrRadicalEd at 2005-2-12 14:32:55

: I'm currently writing an installer script with Inno Setup that can use Pascal scripts for more functionality, but isn't required to actually make a decent installer. Anyway I had run in to a problem that requires a Pascal script, and while I am highly interested in learning Pascal I am actually focused on getting this installer completed to get this side project out the door.
:
: In my installer script file I have a line like this:
: Source: C:\MFCMproject\Game Directories\counter-strike\cstrike\MFCM\mfcm.cfg; DestDir: {reg:HKCU\SOFTWARE\Valve\Steam,ModInstallPath}\counter-strike\cstrike\MFCM
:
: The source file's destination directory is read from an existing registry entry. The problem is that the path read from the registry key is too long and an extra directory needs to be removed at the end.
:
: the entry ModInstallPath is "c:\program files\valve\steam\steamapps\email@address.net\half-life"
:
: and needs to look like:
: "c:\program files\valve\steam\steamapps\email@address.net"
:
: The way Pascal code is inserted in to the installer script is by placing Open Bracket"["Code"]"Close Bracket in the script and using the constant {code:...} where you need to use the function
:
: so instead of {reg:HKxx...} it would be {code:function...} The function being the script needed.
:
: Help with this matter would be very greatly appreciated and would installer help would be included in the credits
:
Here is a code to remove the last subdirectory. It is based on Turbo Pascal and might not work in the Installer Pascal:
  if SubDir[Length(SubDir)] = '\' then 
    Delete(SubDir, Length(SubDir), 1); { Remove trailing backslash, if any }
  while SubDir[Length(SubDir)] <> '\' do
    Delete(SubDir, Length(SubDir), 1); { Remove all until the next backslash }
  Delete(SubDir, Length(SubDir), 1); { Remove the backslash }

The parts between the {} are comments to indicate what that statement does.
Report
Re: In need of a Pascal script for an installer Posted by MrRadicalEd on 13 Feb 2005 at 8:21 AM
Thanks for the reply, but when I compiled it I got an error:
"Unknown identifier SubDir"

This is an example script from an example file:

var
MyProgChecked: Boolean;
MyProgCheckResult: Boolean;
FinishedInstall: Boolean;

function InitializeSetup(): Boolean;
begin
Result := MsgBox('InitializeSetup:' #13#13 'Setup is initializing. Do you really want to start setup?', mbConfirmation, MB_YESNO) = idYes;
if Result = False then
MsgBox('InitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
end;

procedure DeinitializeSetup();
var
FileName: String;
ResultCode: Integer;
begin
if FinishedInstall then begin
if MsgBox('DeinitializeSetup:' #13#13 'The
 scripting demo has finished. Do you want to uninstall My Program now?', mbConfirmation, MB_YESNO) = idYes then begin
      FileName := ExpandConstant('{uninstallexe}');
      if not Exec(FileName, '', '', SW_SHOWNORMAL, ewNoWait, ResultCode) then
        MsgBox('DeinitializeSetup:' #13#13 'Execution of ''' + FileName + ''' failed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
    end else
      MsgBox('DeinitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
    FinishedInstall := True;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ResultCode: Integer;
begin
  case CurPageID of
    wpSelectDir:
      MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardDirValue + '''.', mbInformation, MB_OK);
    wpSelectProgramGroup:
      MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardGroupValue + '''.', mbInformation, MB_OK);
    wpReady:
      begin
        if MsgBox('NextButtonClick:' #13#13 'Using the script, files can now be extracted before the installation starts. For example we could extract ''MyProg.exe'' now and run it.' #13#13 'Do you want to do this?', mbConfirmation, MB_YESNO) = idYes then begin
          ExtractTemporaryFile('myprog.exe');
          if not Exec(ExpandConstant('{tmp}\myprog.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
            MsgBox('NextButtonClick:' #13#13 'The file could not be executed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
        end;
        BringToFrontAndRestore();
        MsgBox('NextButtonClick:' #13#13 'The normal installation will now start.', mbInformation, MB_OK);
      end;
  end;

  Result := True;
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  { Skip wpInfoBefore page; show all others }
  case PageID of
    wpInfoBefore:
      Result := True;
  else
    Result := False;
  end;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  case CurPageID of
    wpWelcome:
      MsgBox('CurPageChanged:' #13#13 'Welcome to the 
 scripting demo. This demo will show you some possibilities of the scripting support.' #13#13 'The scripting engine used is RemObjects Pascal Script by Carlo Kok. See http://www.remobjects.com/?ps for more information.', mbInformation, MB_OK);
    wpFinished:
      MsgBox('CurPageChanged:' #13#13 'Welcome to final page of this demo. Click Finish to exit.', mbInformation, MB_OK);
  end;
end;

function MyProgCheck(): Boolean;
begin
  if not MyProgChecked then begin
    MyProgCheckResult := MsgBox('MyProg:' #13#13 'Do you want to install MyProg.exe and MyProg.hlp to ' + ExtractFilePath(CurrentFileName) + '?', mbConfirmation, MB_YESNO) = idYes;
    MyProgChecked := True;
  end;
  Result := MyProgCheckResult;
end;

procedure BeforeMyProgInstall(S: String);
begin
  MsgBox('BeforeMyProgInstall:' #13#13 'Setup is now going to install ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;

procedure AfterMyProgInstall(S: String);
begin
  MsgBox('AfterMyProgInstall:' #13#13 'Setup just installed ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;

function MyConst(Param: String): String;
begin
  Result := ExpandConstant('{pf}');
end;
Report
Re: In need of a Pascal script for an installer Posted by MrRadicalEd on 13 Feb 2005 at 8:23 AM
Thanks for the reply, but when I compiled it I got an error:
"Unknown identifier SubDir"

This is an example script from an example file:
var
  MyProgChecked: Boolean;
  MyProgCheckResult: Boolean;
  FinishedInstall: Boolean;

function InitializeSetup(): Boolean;
begin
  Result := MsgBox('InitializeSetup:' #13#13 'Setup is initializing. Do you really want to start setup?', mbConfirmation, MB_YESNO) = idYes;
  if Result = False then
    MsgBox('InitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
end;

procedure DeinitializeSetup();
var
  FileName: String;
  ResultCode: Integer;
begin
  if FinishedInstall then begin
    if MsgBox('DeinitializeSetup:' #13#13 'The 
 scripting demo has finished. Do you want to uninstall My Program now?', mbConfirmation, MB_YESNO) = idYes then begin
      FileName := ExpandConstant('{uninstallexe}');
      if not Exec(FileName, '', '', SW_SHOWNORMAL, ewNoWait, ResultCode) then
        MsgBox('DeinitializeSetup:' #13#13 'Execution of ''' + FileName + ''' failed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
    end else
      MsgBox('DeinitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
    FinishedInstall := True;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ResultCode: Integer;
begin
  case CurPageID of
    wpSelectDir:
      MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardDirValue + '''.', mbInformation, MB_OK);
    wpSelectProgramGroup:
      MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardGroupValue + '''.', mbInformation, MB_OK);
    wpReady:
      begin
        if MsgBox('NextButtonClick:' #13#13 'Using the script, files can now be extracted before the installation starts. For example we could extract ''MyProg.exe'' now and run it.' #13#13 'Do you want to do this?', mbConfirmation, MB_YESNO) = idYes then begin
          ExtractTemporaryFile('myprog.exe');
          if not Exec(ExpandConstant('{tmp}\myprog.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
            MsgBox('NextButtonClick:' #13#13 'The file could not be executed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
        end;
        BringToFrontAndRestore();
        MsgBox('NextButtonClick:' #13#13 'The normal installation will now start.', mbInformation, MB_OK);
      end;
  end;

  Result := True;
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  { Skip wpInfoBefore page; show all others }
  case PageID of
    wpInfoBefore:
      Result := True;
  else
    Result := False;
  end;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  case CurPageID of
    wpWelcome:
      MsgBox('CurPageChanged:' #13#13 'Welcome to the 
 scripting demo. This demo will show you some possibilities of the scripting support.' #13#13 'The scripting engine used is RemObjects Pascal Script by Carlo Kok. See http://www.remobjects.com/?ps for more information.', mbInformation, MB_OK);
    wpFinished:
      MsgBox('CurPageChanged:' #13#13 'Welcome to final page of this demo. Click Finish to exit.', mbInformation, MB_OK);
  end;
end;

function MyProgCheck(): Boolean;
begin
  if not MyProgChecked then begin
    MyProgCheckResult := MsgBox('MyProg:' #13#13 'Do you want to install MyProg.exe and MyProg.hlp to ' + ExtractFilePath(CurrentFileName) + '?', mbConfirmation, MB_YESNO) = idYes;
    MyProgChecked := True;
  end;
  Result := MyProgCheckResult;
end;

procedure BeforeMyProgInstall(S: String);
begin
  MsgBox('BeforeMyProgInstall:' #13#13 'Setup is now going to install ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;

procedure AfterMyProgInstall(S: String);
begin
  MsgBox('AfterMyProgInstall:' #13#13 'Setup just installed ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;

function MyConst(Param: String): String;
begin
  Result := ExpandConstant('{pf}');
end;
Report
Re: In need of a Pascal script for an installer Posted by zibadian on 13 Feb 2005 at 8:26 AM
: Thanks for the reply, but when I compiled it I got an error:
: "Unknown identifier SubDir"
:
: This is an example script from an example file:
:
: var
:   MyProgChecked: Boolean;
:   MyProgCheckResult: Boolean;
:   FinishedInstall: Boolean;
: 
: function InitializeSetup(): Boolean;
: begin
:   Result := MsgBox('InitializeSetup:' #13#13 'Setup is initializing. Do you really want to start setup?', mbConfirmation, MB_YESNO) = idYes;
:   if Result = False then
:     MsgBox('InitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
: end;
: 
: procedure DeinitializeSetup();
: var
:   FileName: String;
:   ResultCode: Integer;
: begin
:   if FinishedInstall then begin
:     if MsgBox('DeinitializeSetup:' #13#13 'The 
 scripting demo has finished. Do you want to uninstall My Program now?', mbConfirmation, MB_YESNO) = idYes then begin
:       FileName := ExpandConstant('{uninstallexe}');
:       if not Exec(FileName, '', '', SW_SHOWNORMAL, ewNoWait, ResultCode) then
:         MsgBox('DeinitializeSetup:' #13#13 'Execution of ''' + FileName + ''' failed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
:     end else
:       MsgBox('DeinitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
:   end;
: end;
: 
: procedure CurStepChanged(CurStep: TSetupStep);
: begin
:   if CurStep = ssPostInstall then
:     FinishedInstall := True;
: end;
: 
: function NextButtonClick(CurPageID: Integer): Boolean;
: var
:   ResultCode: Integer;
: begin
:   case CurPageID of
:     wpSelectDir:
:       MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardDirValue + '''.', mbInformation, MB_OK);
:     wpSelectProgramGroup:
:       MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardGroupValue + '''.', mbInformation, MB_OK);
:     wpReady:
:       begin
:         if MsgBox('NextButtonClick:' #13#13 'Using the script, files can now be extracted before the installation starts. For example we could extract ''MyProg.exe'' now and run it.' #13#13 'Do you want to do this?', mbConfirmation, MB_YESNO) = idYes then begin
:           ExtractTemporaryFile('myprog.exe');
:           if not Exec(ExpandConstant('{tmp}\myprog.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
:             MsgBox('NextButtonClick:' #13#13 'The file could not be executed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
:         end;
:         BringToFrontAndRestore();
:         MsgBox('NextButtonClick:' #13#13 'The normal installation will now start.', mbInformation, MB_OK);
:       end;
:   end;
: 
:   Result := True;
: end;
: 
: function ShouldSkipPage(PageID: Integer): Boolean;
: begin
:   { Skip wpInfoBefore page; show all others }
:   case PageID of
:     wpInfoBefore:
:       Result := True;
:   else
:     Result := False;
:   end;
: end;
: 
: procedure CurPageChanged(CurPageID: Integer);
: begin
:   case CurPageID of
:     wpWelcome:
:       MsgBox('CurPageChanged:' #13#13 'Welcome to the 
 scripting demo. This demo will show you some possibilities of the scripting support.' #13#13 'The scripting engine used is RemObjects Pascal Script by Carlo Kok. See http://www.remobjects.com/?ps for more information.', mbInformation, MB_OK);
:     wpFinished:
:       MsgBox('CurPageChanged:' #13#13 'Welcome to final page of this demo. Click Finish to exit.', mbInformation, MB_OK);
:   end;
: end;
: 
: function MyProgCheck(): Boolean;
: begin
:   if not MyProgChecked then begin
:     MyProgCheckResult := MsgBox('MyProg:' #13#13 'Do you want to install MyProg.exe and MyProg.hlp to ' + ExtractFilePath(CurrentFileName) + '?', mbConfirmation, MB_YESNO) = idYes;
:     MyProgChecked := True;
:   end;
:   Result := MyProgCheckResult;
: end;
: 
: procedure BeforeMyProgInstall(S: String);
: begin
:   MsgBox('BeforeMyProgInstall:' #13#13 'Setup is now going to install ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
: end;
: 
: procedure AfterMyProgInstall(S: String);
: begin
:   MsgBox('AfterMyProgInstall:' #13#13 'Setup just installed ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
: end;
: 
: function MyConst(Param: String): String;
: begin
:   Result := ExpandConstant('{pf}');
: end;
: 
: SubDir is a string variable holding the name of the subdirectory.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.