Inno Setup StringChangeEx Failure - inno-setup

I'm using an Inno Setup script to install my 32- and 64-bit DLLs in a 64-bit install. I can get the 64-bit path from a registry setting, but the 32-bit path is missing does not exist. However, I know that the path's 'tail' is constant, just the head needs to be modified. Ie,
64-bit (from registry) = c:\Program Files\My Application\Bin
32-bit (derived) = c:\Program Files (x86)\My Application\Bin
So what I do is swap out the 64-bit program file path with the 32-bit one. I do this easily with StringChangeEx:
RegQueryStringValue(HKLM, 'SOFTWARE\My Application', 'RootDir', sPath)
if IsWin64() then
StringChangeEx(sPath, ExpandConstant('{pf}'), ExpandConstant('{pf32}'), False);
sPath is returned with my 32-bit path. This works great on most systems, but it seems that sometimes StringChangeEx does not swap out 'C:\Program Files' for 'C:\Program Files (x86)'. I have verified (using MsgBox's) that the {pf} and {pf32} constants are what I think they are. Casing is the same and there are no leading/trailing spaces. It just seems that on some systems, the function doesn't work.
I'm using the latest version of InnoSetup (10/2010). The web site doesn't mention any problems with this function. Has anyone else seen this and/or have any ideas on what it could be?

I threw together this little script and using 5.4.0 (10/2010 release), it worked:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{AE1A6BBB-7582-43AA-85F5-C7F984D1A68B}
AppName=My Program
AppVersion=1.5
;AppVerName=My Program 1.5
AppPublisher=My Company, Inc.
AppPublisherURL=http://www.example.com/
AppSupportURL=http://www.example.com/
AppUpdatesURL=http://www.example.com/
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
[Code]
function InitializeSetup(): Boolean;
var
sPath : string;
begin
sPath := ExpandConstant('{pf}') + '\mypath';
if IsWin64() then
StringChangeEx(sPath, ExpandConstant('{pf}'), ExpandConstant('{pf32}'), False);
MsgBox(sPath, mbInformation, MB_OK);
result := true;
end;
Does my script work or fail for you?
Is sPath correct before your call to StringChangeEx?
I would suggest the /LOG option but code isn't logged automatically. You would need to add Log(const S: String) calls.

Turns out that the registry entry sometimes had a lower-case drive letter. I changed the code to:
RegQueryStringValue(HKLM, 'SOFTWARE\My Application', 'RootDir', sPath)
sPath := Lowercase(sPath);
if IsWin64() then
StringChangeEx(sPath, Lowercase(ExpandConstant('{pf}')), Lowercase(ExpandConstant('{pf32}')), False)
I had assumed the registry entry was not the problem, but not quite so.

Related

Inno Setup Check if file exist in selected destination location

I have created files for a program I want to make as an update.
I would like it, before the installation, to check whether the program is also in the standard directory, and if not the one itself the right directory can choose where the program is.
I have tried this:
[Files]
Source: "C:\Data"; DestDir: "{app}"; Flags: ignoreversion
[Code]
function NextButtonClick(PageId: Integer): Boolean;
begin
Result := True;
if (PageId = wpSelectDir) and not FileExists(ExpandConstant('C:\Program\Test\Test.exe')) then begin
MsgBox('YourApp does not seem to be installed in that folder. Please select the correct folder.', mbError, MB_OK);
Result := False;
exit;
end;
end;
But during the installation it does not check it.
Whether the program is available or not, it installs it anyway.
I hope someone can help me.
You have to use the {app} constant in the test to check the selected folder:
FileExists(ExpandConstant('{app}\Test.exe'))

Inno Setup will not create folder under C:\Users\Public - will instead do C:\Users\Public\Public Documents

I am using Inno Setup to build my installer and I have the C:\Users\Public folder hardcoded in my [Files] section to place some files (Inno Setup does not have a constant for this folder)
My goal is to have the install create a C:\Users\Public\MyApp folder with some files in it. However when I run the install, it is creating the folder here:
C:\Users\Public\Public Documents\MyApp
Is this a permissions issue where the installer doesn't have access to create a folder directly under C:\Users\Public?
[Files]
Source: "MyApp\db.mdf"; DestDir: "{drive:{src}}\Users\Public\MyApp"; Flags: ignoreversion;
I cannot reproduce your problem. For me your code works. I've tested it on Windows Vista, 7 and 10. It always installs to C:\Users\Public\MyApp.
Though I do not understand the {drive:{src}}. How does the drive of the Users folder relate to the drive of the installer? You should use the {sd} constant:
[Files]
Source: "MyApp\db.mdf"; DestDir: "{sd}\Users\Public\MyApp"; Flags: ignoreversion
But anyway, to resolve the path to the C:\Users\Public, you can use the PUBLIC environment variable:
[Files]
Source: "MyApp\db.mdf"; DestDir: "{%PUBLIC}\MyApp"; Flags: ignoreversion
It works since Windows Vista.
Alternatively, you can use SHGetKnownFolderPath with FOLDERID_Public. For an example code, see Constant for AppData\LocalLow?
If you need to support even Windows XP, where there is no C:\Users\Public folder or PUBLIC variable, you have to find out, what path your need to use there instead (probably C:\Documents and Settings\All Users), and implement a fallback using a scripted constant:
[Files]
Source: "MyProg.exe"; DestDir: "{code:GetPublicPath}\MyApp"; Flags: ignoreversion
[Code]
function GetPublicPath(Param: string): string;
begin
Result := GetEnv('PUBLIC');
if Result <> '' then
begin
Log(Format('PUBLIC is "%s"', [Result]));
end
else
begin
Result := GetEnv('ALLUSERSPROFILE');
Log(Format('PUBLIC is not set, ALLUSERSPROFILE is "%s"', [Result]));
end;
end;
And for others, it's worth noting that your need for resolve C:\Users\Public is very specific, related to this question: C++ app MDB in ProgramData copies to user's AppData folder when I dont want it to.
One usually does not want the C:\Users\Public, but C:\Users\Public\Documents (= {commondocs}) or C:\ProgramData aka C:\Users\All Users (= {commonappdata}).

$(build_executable) producing shared object

I'm trying to create an native executable for android and it keeps crashing. testing the file with readelf and objdump revivals that the file is considered to be an shared object file.
I'm using the r8e and compiling with ndk-build
test.c:
int main(){
return 0;
}
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC FILES := test.c
LOCAL_MODULE := test
include(BUILD_EXECUTABLE)
--
Setting the app_platform to android-9 results in the creation of an executable file ( and no crashes).
Have you tried specifying arguments int args and char *argv[] for your main() method? Also, where are you trying to run it?
I confirm this bug... I had a project that compiled perfectly with ndk-r8, but when I switched to ndk-8e my executable did not build properly anymore.
I reported it here: https://code.google.com/p/android/issues/detail?id=55769
Here is the answer I got from google:
This is normal.
By default, when targetting API level 17 or higher, "Position Independent Executables" (a.k.a. PIE) are generated by the BUILD_EXECUTABLE rule.
These are executable binaries, but they are only supported on Android 4.1 or higher. See [1] for more details.
If you really don't want these (e.g. because you want your program to run on previous releases of the platform), you have two choices:
Target a lower API level.
Use 'APP_PIE := false' in your Application.mk

How to get path to the current InnoSetup script file?

How to get path, where the InnoSetup script file you are currently compiling is located ?
To get script source path, use the preprocessor's predefined variable SourcePath. That variable you can expand in your script as an ordinary define. In case, the script was not yet been saved, it returns path to My Documents directory. Here's just a useless example to test:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
procedure InitializeWizard;
begin
MsgBox(ExpandConstant('{#SourcePath}'), mbInformation, MB_OK);
end;
Don't forget that you have to compile the script (CTRL + F9) not only run (F9) to invoke preprocessor to rebuild the script.

jre 1.6 check and progress bar in inno

I want to check whether hre 1.6 or higher is installed or not. If installed I want to progress my application. If not installed , I want to install jre-6u17-windows-i586-s.exe after successfully installing jre , my control not returns to inno again. Please send a inno script for that.
best regards
SOumen
For the [FILES] section:
[Files]
Source: "jre-6u17-windows-i586-s.exe"; DestDir: "{app}\JRE 1.6"; Flags: onlyifdoesntexist
For the [CODE] section:
[Code]
Function JREInstallPrompt:Boolean;
begin
if ((msgBox ('Do you want to install JRE 1.6?',mbinformation,mb_YesNo)=idYes)) then
begin
msgBox ('JRE 1.6 will being installing now. Please do not restart the machine or log off until it is complete!',mbinformation,mb_OK);
Result:=True;
end
else Result:=False;
end;
Function JREVerifyInstall:Boolean;
begin
if ((RegValueExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\JavaSoft','InstallerVersion')) or (JREInstallPrompt=False)) then //Exists or do not install
Result:=False
else Result:=True;
end;
And for the RUN section:
[Run]
;SQL Server Express 2005 Installer
Filename: "{app}\JRE 1.6\jre-6u17-windows-i586-s.exe"; WorkingDir: {app}\JRE 1.6; StatusMsg: Installing Java Runtime Environment... Please Wait...;Check:JREVerifyInstall
Hopefully that will get you pointed in the right direction.

Resources