libusbk-sys 0.2.0

Rust Windows library for accessing USB devices via libusbK
Documentation
; @K_LIBUSBK_NAME@ (KMDF) USB Library - installer/upgrader script
; 
; Copyright (c) 2012 Travis Lee Robinson <libusbdotnet@gmail.com>
; All rights reserved.
; 
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; 
;     * Redistributions of source code must retain the above copyright
;       notice, this list of conditions and the following disclaimer.
; 	  
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
; IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TRAVIS LEE ROBINSON 
; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
; THE POSSIBILITY OF SUCH DAMAGE. 
; 

[Setup]
AppName				= @K_USBK_NAME@ Development Kit
AppVerName			= @K_USBK_NAME@ Development Kit v@TARGET_VERSION@
AppId				= @K_LIBUSBK_NAME@-dev-kit
AppPublisher		= Travis Lee Robinson 
AppPublisherURL		= http://libusb-win32.sourceforge.net
AppVersion			= @TARGET_VERSION@
VersionInfoVersion	= @TARGET_VERSION@
DefaultDirName		= {sd}\@K_LIBUSBK_NAME@-dev-kit
DefaultGroupName	= @K_USBK_NAME@ Development Kit
Compression			= lzma/ultra64
SolidCompression	= yes
OutputDir			= @G_PACKAGE_ABS_DIR@
OutputBaseFilename	= @K_LIBUSBK_SETUP_NAME@
PrivilegesRequired	= admin
WizardSmallImageFile = @K_LIBUSBK_NAME@.bmp
AllowNoIcons		= yes
InfoBeforeFile		= .\output\ChangeLog.txt

; requires Win2k, or higher (x86 or amd64 only)
MinVersion						= 0, 5.0.2195 
ArchitecturesAllowed			= x86 x64
ArchitecturesInstallIn64BitMode	= x64

[Code]
function IsX64: Boolean;
begin
  Result := Is64BitInstallMode and (ProcessorArchitecture = paX64);
end;

function IsI64: Boolean;
begin
  Result := Is64BitInstallMode and (ProcessorArchitecture = paIA64);
end;

function IsX86: Boolean;
begin
  Result := not IsX64 and not IsI64;
end;

function Is64: Boolean;
begin
  Result := IsX64 or IsI64;
end;

function IntToBoolStr(val: Longint) : string;
begin
  if val <> 0 then
    Result := 'True';
  if val=0 then
    Result := 'False';
end;

procedure CheckInstallerResults();
var
  infDir : String;
  resultsIni : String;
  infIndex : Longint;
  Installer_Cancelled: Longint;
  Installer_Prepared: Longint;
  Installer_Installed: Longint;
begin
  resultsIni := ExpandConstant('{tmp}')+'\results.ini';
  Log('Results INI='+resultsIni);
  
  if IniKeyExists('InfWizard','Cancelled',resultsIni) then begin
    Installer_Cancelled :=  GetIniInt('InfWizard','Cancelled',0,0,0,resultsIni);
    Installer_Prepared :=  GetIniInt('InfWizard','Prepared',0,0,0,resultsIni);
    Installer_Installed :=  GetIniInt('InfWizard','Installed',0,0,0,resultsIni);
    
    Log('Installer_Cancelled = '+IntToStr(Installer_Cancelled));
    Log('Installer_Prepared  = '+IntToStr(Installer_Prepared));
    Log('Installer_Installed = '+IntToStr(Installer_Installed));
    
    infIndex := -1;
    repeat

      infIndex := infIndex+1;
      if not IniKeyExists('InfWizard','infDir'+IntToStr(infIndex),resultsIni) then break;

      infDir := GetIniString('InfWizard','InfDir'+IntToStr(infIndex),'',resultsIni);
      Log('InfDir'+IntToStr(infIndex)+' = '+infDir);
      
      if FileExists(infDir+'\installer_x86.exe') then
        DeleteFile(infDir+'\installer_x86.exe');
	    
      if FileExists(infDir+'\installer_x64.exe') then
	     DeleteFile(infDir+'\installer_x64.exe');

    until False;
  end;
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Result := false;
  if PageID=wpFinished then
    Result := IsTaskSelected('installer') and not IsComponentSelected('programIcons');
end;

[Components]
Name: "devpackage"; Description: "@K_USBK_NAME@ Development Kit"; Types: full custom; Flags: exclusive;
Name: "devpackage\examples"; Description: "@K_USBK_NAME@ Example Source Code"; Types: full custom;
Name: "devpackage\chmhelp"; Description: "@K_USBK_NAME@ Documentation (.chm)"; Types: full custom;

[Tasks]
Name: installer; Description: "Create and install a libusb-win32 device driver a package."; Flags: unchecked;
Name: upgrader;  Description: "Upgrade libusb-win32 components"; Flags: unchecked;
Name: upgrader\sys;  Description: "Driver (@K_LIBUSBK_NAME@.sys)";
Name: upgrader\libusb0sys;  Description: "Driver (@K_LIBUSB0_NAME@.sys)";
;Name: upgrader\dll;  Description: "User libraries (@K_LIBUSBK_NAME@, @K_LIBUSB10_NAME@, @K_LIBUSB0_NAME@)";
Name: upgrader\dll;  Description: "User libraries (@K_LIBUSBK_NAME@, @K_LIBUSB0_NAME@)";
Name: filter; Description: "Install a @K_LIBUSB0_NAME@ device filter. (advanced users)"; Flags: unchecked;

[Icons]
; these icons are only used in debug builds
Name: "{group}\Example Source Code"; Filename: {app}\examples; Flags: foldershortcut; Components: devpackage\examples; 
Name: "{group}\@K_USBK_NAME@ License"; Filename: {app}\license\AUTHORS-@K_LIBUSBK_NAME@.txt; Flags: createonlyiffileexists; Components: devpackage; 
Name: "{group}\@K_USBK_NAME@ Documentation"; Filename: {app}\@K_LIBUSBK_NAME@-help.chm; Flags: createonlyiffileexists; Components: devpackage\chmhelp;
Name: "{group}\libusb-win32 Filter Wizard"; Filename: {app}\install-filter-win.exe; Flags: createonlyiffileexists;  Components: devpackage;
Name: "{group}\Driver Install Creator Wizard"; Filename: {app}\@K_LIBUSBK_NAME@-inf-wizard.exe; Flags: createonlyiffileexists;  Components: devpackage;
Name: "{group}\Uninstall @K_USBK_NAME@ Development Kit"; Filename: "{uninstallexe}"

[Files]
; ============================================================================
; ** @K_LIBUSBK_NAME@ x86 (Windows 2000/XP and greater)
Source: "@K_PKG_BIN@\sys\x86\@K_LIBUSBK_NAME@.sys"; DestDir: {sys}\drivers; Flags: uninsneveruninstall replacesameversion restartreplace promptifolder; Check: IsX86; Tasks: upgrader\sys;
Source: "@K_LIBUSB0_REDIST_DIR@\bin\x86\@K_LIBUSB0_NAME@.sys"; DestDir: {sys}\drivers; Flags: uninsneveruninstall replacesameversion restartreplace promptifolder; Check: IsX86; Tasks: upgrader\libusb0sys;

; 32 bit program support
Source: "@K_PKG_BIN@\dll\x86\@K_LIBUSBK_NAME@.dll"; DestDir: {sys}; Flags: replacesameversion restartreplace promptifolder; Check: IsX86; Tasks: upgrader\dll;
Source: "@K_PKG_BIN@\dll\x86\@K_LIBUSB0_NAME@.dll"; DestDir: {sys}; Flags: replacesameversion restartreplace promptifolder; Check: IsX86; Tasks: upgrader\dll;
;Source: "@K_PKG_BIN@\dll\x86\@K_LIBUSB10_NAME@.dll"; DestDir: {sys}; Flags: replacesameversion restartreplace promptifolder; Check: IsX86; Tasks: upgrader\dll;

; ============================================================================
; ** @K_LIBUSBK_NAME@ AMD 64bit
Source: "@K_PKG_BIN@\sys\amd64\@K_LIBUSBK_NAME@.sys"; DestDir: {sys}\drivers; Flags: uninsneveruninstall replacesameversion restartreplace promptifolder; Check: IsX64; Tasks: upgrader\sys;
Source: "@K_LIBUSB0_REDIST_DIR@\bin\amd64\@K_LIBUSB0_NAME@.sys"; DestDir: {sys}\drivers; Flags: uninsneveruninstall replacesameversion restartreplace promptifolder; Check: IsX64; Tasks: upgrader\libusb0sys;

; 32 bit program support
Source: "@K_PKG_BIN@\dll\x86\@K_LIBUSBK_NAME@.dll"; DestDir: {syswow64}; Flags: replacesameversion restartreplace promptifolder; Check: IsX64; Tasks: upgrader\dll;
Source: "@K_PKG_BIN@\dll\x86\@K_LIBUSB0_NAME@.dll"; DestDir: {syswow64}; Flags: replacesameversion restartreplace promptifolder; Check: IsX64; Tasks: upgrader\dll;
;Source: "@K_PKG_BIN@\dll\x86\@K_LIBUSB10_NAME@.dll"; DestDir: {syswow64}; Flags: replacesameversion restartreplace promptifolder; Check: IsX64; Tasks: upgrader\dll;

; 64bit bit program support
Source: "@K_PKG_BIN@\dll\amd64\@K_LIBUSBK_NAME@.dll"; DestDir: {sys}; Flags: replacesameversion restartreplace promptifolder; Check: IsX64; Tasks: upgrader\dll;
Source: "@K_PKG_BIN@\dll\amd64\@K_LIBUSB0_NAME@.dll"; DestDir: {sys}; Flags: replacesameversion restartreplace promptifolder; Check: IsX64; Tasks: upgrader\dll;
;Source: "@K_PKG_BIN@\dll\amd64\@K_LIBUSB10_NAME@.dll"; DestDir: {sys}; Flags: replacesameversion restartreplace promptifolder; Check: IsX64; Tasks: upgrader\dll;

; ============================================================================
; ** @K_LIBUSBK_NAME@/@K_LIBUSB0_NAME@ inf-wizard
Source: "@K_PKG@\@K_LIBUSBK_NAME@-inf-wizard.exe"; DestDir: {app}; Components: devpackage; Flags: replacesameversion restartreplace;

; ============================================================================
; ** @K_LIBUSB0_NAME@ filter installer
Source: "@K_LIBUSB0_REDIST_DIR@\bin\x86\install-filter-win.exe"; DestDir: {app}; Check: IsX86; Components: devpackage;
Source: "@K_LIBUSB0_REDIST_DIR@\bin\amd64\install-filter-win.exe"; DestDir: {app}; Check: IsX64; Components: devpackage;

; ============================================================================
; ** documentation and examples
Source: "@K_PKG@\@K_LIBUSBK_NAME@-help.chm"; DestDir: {app}; Components: devpackage\chmhelp;
Source: "@K_PKG@\includes\*"; DestDir: {app}\includes; Components: devpackage\examples;
Source: "@K_PKG@\examples\*"; Flags: recursesubdirs; DestDir: {app}\examples; Components: devpackage\examples;
Source: "@K_PKG@\bindings\*"; Flags: recursesubdirs; DestDir: {app}\bindings; Components: devpackage\examples;
Source: "@K_PKG_BIN@\dll\@K_LIBUSBK_NAME@*";  Flags: recursesubdirs; DestDir: {app}\bin\dll; Components: devpackage\examples;
Source: "@K_PKG_BIN@\lib\@K_LIBUSBK_NAME@*";  Flags: recursesubdirs; DestDir: {app}\bin\lib; Components: devpackage\examples;
Source: "@K_PKG@\license\*"; Flags: recursesubdirs; DestDir: {app}\license;

; ============================================================================
; ** test applications
Source: "@K_PKG@\bin\exe\x86\kList.exe"; DestDir: {app}; Components: devpackage;
Source: "@K_PKG@\bin\exe\x86\kBench.exe"; DestDir: {app}; Components: devpackage;

[Run]
Filename: "{app}\@K_LIBUSBK_NAME@-inf-wizard.exe"; Parameters: "--no-welcome"; Description: "@K_LIBUSBK_NAME@ Driver Installer"; Flags: hidewizard runascurrentuser; Tasks: installer; AfterInstall: CheckInstallerResults;
Filename: "{app}\install-filter-win.exe"; Description: "@K_LIBUSB0_NAME@ Filter Installer"; Flags: hidewizard runascurrentuser; Tasks: filter;