Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill-Stewart committed Jun 10, 2021
1 parent 981d29d commit a7cc2fe
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 281 deletions.
60 changes: 27 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ https://github.com/Bill-Stewart/UninsIS/releases/

Inno Setup is a powerful, freely available tool for building installers for the Windows OS platform.

The Inno Setup philosophy for upgrading software is, put simply, install the new version "on top" of the old version. Files will be upgraded automatically according to version numbering rules (where selected/applicable), etc. However, there are some limitations:
The Inno Setup philosophy for upgrading or downgrading software is, put simply, install the new version "on top" of the old version. Files will be overwritten or retained according to version numbering rules (where selected/applicable), etc. However, there are some limitations:

* If a new version of an application makes obsolete any files installed by a previous version, the obsolete files remain on the target system after upgrading. This can be mitigated in simple use cases by using Inno Setup's `[InstallDelete]` section or custom code, but this has the potential to be awkward, unwieldy, and error-prone for larger setup projects.

* The above problem can also apply to registry entries: Suppose an older version of an application stores configuration data using the Windows registry but a newer version uses text-based configuration files. Without custom code, the obsolete registry entries remain on the target system after an upgrade.

* Downgrading an application is only possible by uninstalling a newer version and then installing an older version.
* Unless file versioning is handled carefully, downgrading can result in a corrupted application due to mismatched file versions.

Depending on your needs, it may be preferable to uninstall an existing installed version first. UninsIS.dll provides the following capabilities:

Expand Down Expand Up @@ -70,40 +70,34 @@ For example, you can use the UninsIS.dll functions to automatically uninstall an
```
// Wrapper for UninsIS.dll IsISPackageInstalled() function
// Returns true if package is detected as installed, or false otherwise
function IsISPackageInstalled(): boolean;
begin
result := DLLIsISPackageInstalled(
'Your_Appid_Here', // AppId
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode()) // IsAdminInstallMode
) = 1;
end;
function IsISPackageInstalled(): Boolean;
begin
result := DLLIsISPackageInstalled('Your_Appid_Here', // AppId
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode())) = 1; // IsAdminInstallMode
end;
// Wrapper for UninsIS.dll CompareISPackageVersion() function
// Returns:
// < 0 if version we are installing is < installed version
// 0 if version we are installing is = installed version
// > 0 if version we are installing is > installed version
function CompareISPackageVersion(): longint;
begin
result := DLLCompareISPackageVersion(
'Your_AppId_Here', // AppId
'Your_AppVersion_Here', // InstallingVersion
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode()) // IsAdminInstallMode
);
end;
function CompareISPackageVersion(): LongInt;
begin
result := DLLCompareISPackageVersion('Your_AppId_Here', // AppId
'Your_AppVersion_Here', // InstallingVersion
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode())); // IsAdminInstallMode
end;
// Wrapper for UninsIS.dll UninstallISPackage() function
// Returns 0 for success, non-zero for failure
function UninstallISPackage(): DWORD;
begin
result := DLLUninstallISPackage(
'Your_AppId_Here', // AppId
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode()) // IsAdminInstallMode
);
end;
begin
result := DLLUninstallISPackage('Your_AppId_Here', // AppId
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode())); // IsAdminInstallMode
end;
```
In the above code, replace:
Expand All @@ -116,12 +110,12 @@ For example, you can use the UninsIS.dll functions to automatically uninstall an
4. In the `[Code]` section after the wrapper functions, add or update the `PrepareToInstall()` event function to use the wrapper functions:
```
function PrepareToInstall(var NeedsRestart: boolean): string;
begin
function PrepareToInstall(var NeedsRestart: Boolean): string;
begin
result := '';
if IsISPackageInstalled() and (CompareISPackageVersion() <> 0) then
UninstallISPackage();
end;
end;
```
Change the comparison with the `CompareISPackageVersion()` function to suit your needs:
Expand Down Expand Up @@ -175,7 +169,7 @@ DWORD IsISPackageInstalled(
Pascal:
```
function IsISPackageInstalled(AppId: pwidechar;
function IsISPackageInstalled(AppId: PWideChar;
Is64BitInstallMode, IsAdminInstallMode: DWORD): DWORD;
```
Expand Down Expand Up @@ -240,8 +234,8 @@ DWORD CompareISPackageVersion(
Pascal:
```
function CompareISPackageVersion(AppId, InstallingVersion: pwidechar;
Is64BitInstallMode, IsAdminInstallMode: DWORD): longint;
function CompareISPackageVersion(AppId, InstallingVersion: PWideChar;
Is64BitInstallMode, IsAdminInstallMode: DWORD): LongInt;
```
### Parameters
Expand Down Expand Up @@ -305,7 +299,7 @@ DWORD UninstallISPackage(
Pascal:
```
function UninstallISPackage(AppId: pwidechar;
function UninstallISPackage(AppId: PWideChar;
Is64BitInstallMode, IsAdminInstallMode: DWORD): DWORD;
```
Expand Down
61 changes: 27 additions & 34 deletions UninsIS.iss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#endif

#define AppGUID "{9F49B8E7-BAB8-40DB-A106-316CCCCE0823}"
#define AppVersion "1.0.0.0"
#define AppVersion "1.0.1.0"

[Setup]
AppId={{#AppGUID}
Expand All @@ -47,75 +47,68 @@ Source: "README.md"; DestDir: "{app}"
[Code]
// Import IsISPackageInstalled() function from UninsIS.dll at setup time
function DLLIsISPackageInstalled(AppId: string;
Is64BitInstallMode, IsAdminInstallMode: DWORD): DWORD;
function DLLIsISPackageInstalled(AppId: string; Is64BitInstallMode,
IsAdminInstallMode: DWORD): DWORD;
external 'IsISPackageInstalled@files:UninsIS.dll stdcall setuponly';
// Import CompareISPackageVersion() function from UninsIS.dll at setup time
function DLLCompareISPackageVersion(AppId, InstallingVersion: string;
Is64BitInstallMode, IsAdminInstallMode: DWORD): longint;
Is64BitInstallMode, IsAdminInstallMode: DWORD): LongInt;
external 'CompareISPackageVersion@files:UninsIS.dll stdcall setuponly';
// Import UninstallISPackage() function from UninsIS.dll at setup time
function DLLUninstallISPackage(AppId: string;
Is64BitInstallMode, IsAdminInstallMode: DWORD): DWORD;
function DLLUninstallISPackage(AppId: string; Is64BitInstallMode,
IsAdminInstallMode: DWORD): DWORD;
external 'UninstallISPackage@files:UninsIS.dll stdcall setuponly';
// Wrapper for UninsIS.dll IsISPackageInstalled() function
// Returns true if package is detected as installed, or false otherwise
function IsISPackageInstalled(): boolean;
begin
result := DLLIsISPackageInstalled(
'{#AppGUID}', // AppId
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode()) // IsAdminInstallMode
) = 1;
function IsISPackageInstalled(): Boolean;
begin
result := DLLIsISPackageInstalled('{#AppGUID}', // AppId
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode())) = 1; // IsAdminInstallMode
if result then
Log('UninsIS.dll - Package detected as installed')
else
Log('UninsIS.dll - Package not detected as installed');
end;
end;
// Wrapper for UninsIS.dll CompareISPackageVersion() function
// Returns:
// < 0 if version we are installing is < installed version
// 0 if version we are installing is = installed version
// > 0 if version we are installing is > installed version
function CompareISPackageVersion(): longint;
begin
result := DLLCompareISPackageVersion(
'{#AppGUID}', // AppId
'{#AppVersion}', // InstallingVersion
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode()) // IsAdminInstallMode
);
function CompareISPackageVersion(): LongInt;
begin
result := DLLCompareISPackageVersion('{#AppGUID}', // AppId
'{#AppVersion}', // InstallingVersion
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode())); // IsAdminInstallMode
if result < 0 then
Log('UninsIS.dll - This version {#AppVersion} older than installed version')
else if result = 0 then
Log('UninsIS.dll - This version {#AppVersion} same as installed version')
else
Log('UninsIS.dll - This version {#AppVersion} newer than installed version');
end;
end;
// Wrapper for UninsIS.dll UninstallISPackage() function
// Returns 0 for success, non-zero for failure
function UninstallISPackage(): DWORD;
begin
result := DLLUninstallISPackage(
'{#AppGUID}', // AppId
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode()) // IsAdminInstallMode
);
begin
result := DLLUninstallISPackage('{#AppGUID}', // AppId
DWORD(Is64BitInstallMode()), // Is64BitInstallMode
DWORD(IsAdminInstallMode())); // IsAdminInstallMode
if result = 0 then
Log('UninsIS.dll - Installed package uninstall completed successfully')
else
Log('UninsIS.dll - installed package uninstall did not complete successfully');
end;
end;
function PrepareToInstall(var NeedsRestart: boolean): string;
begin
function PrepareToInstall(var NeedsRestart: Boolean): string;
begin
result := '';
// If package installed, uninstall it automatically if the version we are
// installing does not match the installed version; If you want to
Expand All @@ -124,4 +117,4 @@ function PrepareToInstall(var NeedsRestart: boolean): string;
// ...when upgrading: change <> to >
if IsISPackageInstalled() and (CompareISPackageVersion() <> 0) then
UninstallISPackage();
end;
end;
22 changes: 11 additions & 11 deletions UninsIS.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@
{$H+}
{$R *.res}

library
UninsIS;
library UninsIS;

uses
wsISPackage;

function IsISPackageInstalled(AppId: pwidechar; Is64BitInstallMode, IsAdminInstallMode: DWORD): DWORD; stdcall;
begin
function IsISPackageInstalled(AppId: PWideChar; Is64BitInstallMode, IsAdminInstallMode: DWORD): DWORD; stdcall;
begin
InnoSetupPackage.Init(AppId, Is64BitInstallMode <> 0, IsAdminInstallMode <> 0);
result := InnoSetupPackage.IsInstalled();
end;
end;

function CompareISPackageVersion(AppId, InstallingVersion: pwidechar; Is64BitInstallMode, IsAdminInstallMode: DWORD): longint; stdcall;
begin
function CompareISPackageVersion(AppId, InstallingVersion: PWideChar; Is64BitInstallMode, IsAdminInstallMode: DWORD): LongInt;
stdcall;
begin
InnoSetupPackage.Init(AppId, Is64BitInstallMode <> 0, IsAdminInstallMode <> 0);
result := InnoSetupPackage.CompareVersion(InstallingVersion);
end;
end;

function UninstallISPackage(AppId: pwidechar; Is64BitInstallMode, IsAdminInstallMode: DWORD): DWORD; stdcall;
begin
function UninstallISPackage(AppId: PWideChar; Is64BitInstallMode, IsAdminInstallMode: DWORD): DWORD; stdcall;
begin
InnoSetupPackage.Init(AppId, Is64BitInstallMode <> 0, IsAdminInstallMode <> 0);
result := InnoSetupPackage.Uninstall();
end;
end;

exports
IsISPackageInstalled,
Expand Down
8 changes: 4 additions & 4 deletions UninsIS.rc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEVERSION 1,0,1,0
PRODUCTVERSION 1,0,1,0
FILEOS 0x4
FILETYPE 1
{
Expand All @@ -10,12 +10,12 @@ FILETYPE 1
{
VALUE "CompanyName", ""
VALUE "FileDescription", "UninsIS.dll"
VALUE "FileVersion", "1.0.0.0"
VALUE "FileVersion", "1.0.1.0"
VALUE "InternalName", "UninsIS.dll"
VALUE "LegalCopyright", "Copyright 2021 by Bill Stewart (bstewart at iname.com)"
VALUE "OriginalFilename", "UninsIS.dll"
VALUE "ProductName", ""
VALUE "ProductVersion", "1.0.0.0"
VALUE "ProductVersion", "1.0.1.0"
}
}

Expand Down
10 changes: 10 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# UninsIS.dll Version History

## 1.0.1 (10 Jun 2021)

* Update code formatting.

* String-read from registry updated to avoid potential (but very low probability) buffer overflow error.

* Compile using FPC 3.2.2.

* Minor tweaks.

## 1.0.0 (19 Mar 2021)

* Initial version.
Loading

0 comments on commit a7cc2fe

Please sign in to comment.