B4J Question [SOLVED]Inno Setup Problem

Zvi

Member
Licensed User
Hi, I'm using Inno Setup Compiler 6.2.2 with B4J Build Standalone Package and I'm going crazy trying to figure out the following:
My program includes a number of screens whose layouts are set up in Designer but whose elements are repositioned programmatically.
After I run the Build Standalone Package option I get a Build folder as shown in Files_1.jpg (attached) and a Temp folder containing an InstallerScript.iss file.

When I run the exe file in the Build folder the program runs normally (see screenshots Exe screenshot_1 & Exe screenshot_2).

But when I use the exe file made with the installer I get what's shown in After install_1 & After install_2.

The install parameters are shown in Installer1 and Installer2 (attached pictures).

I've tried using Sleep(0) in the program to allow more time for the processor but still get the same result... the exe in the Build folder works perfectly but the exe installed with Inno does not.

Can someone please give me a clue what I'm doing wrong before I go completely crazy :) ?

Any help will be much appreciated.
 

Attachments

  • Exe screenshot_1.jpg
    Exe screenshot_1.jpg
    164.4 KB · Views: 171
  • Exe screenshot_2.jpg
    Exe screenshot_2.jpg
    129.2 KB · Views: 188
  • Files_1.jpg
    Files_1.jpg
    83.3 KB · Views: 173
  • Files_2.jpg
    Files_2.jpg
    95.9 KB · Views: 176
  • Installer1.jpg
    Installer1.jpg
    180.3 KB · Views: 170
  • Installer2.jpg
    Installer2.jpg
    161.4 KB · Views: 173
  • After install_1.jpg
    After install_1.jpg
    73.1 KB · Views: 162
  • After install_2.jpg
    After install_2.jpg
    125.2 KB · Views: 179

Chris2

Active Member
Licensed User
Longtime User
What does the folder that you are installing into look like after you run the installer?
It should look the same as what you see in Files_1.jpg with the addition of a couple of uninstall files.

Which exe are you running after the install?
The second layout looks OK- AfterInstall_2.jpg, is that correct?

It might help if you can reproduce the problem in a small project (just loading your first layout perhaps) and upload it and the installer script file.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
I think.... that the script... you must have it like this:
B4X:
[Files]
Source: "c:\your_build_folder\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "c:\your_build_folder\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
 
Upvote 0

Zvi

Member
Licensed User
Thank you both, Chris2 and Magma.

Magma, changing the Inno Setup script the way you suggested didn't solve the problem.

Chris2, I compared the folders and files in the B4J project with the ones in the installed folder and they were exactly the same.

My breakthrough came when I compared the debug printouts from the B4J project with that of the installed program (shown attached).

There is a data file that is produced by the app that is causing the problem.

If I prevent this data file from being produced by the program then the exe made by the install works exactly like the exe in the project folder (shown attached).

Of course this is far from perfect. I need the data file for the program to work properly. Now I have to figure out how to produce/store the data file without it impacting the installed program.
 

Attachments

  • Debug_b4j.jpg
    Debug_b4j.jpg
    87 KB · Views: 144
  • Debug_install.jpg
    Debug_install.jpg
    255.7 KB · Views: 152
  • No data file.jpg
    No data file.jpg
    86 KB · Views: 147
Upvote 0

Magma

Expert
Licensed User
Longtime User
...Another thing you must have in your mind...

* When we are using Program Files... our app must run with Admin Priveleges to have the "right/permission" to write into this folder ! <-- "Access Denied"
* The best way is to make your not using DirApp but DirData... which is the folder under users\yourusername\appdata\roaming\yourappname... that no need any special permission
 
Upvote 0

Zvi

Member
Licensed User
Thanks Magma.

I think the problem is in this line of code:
Data file excerpt:
Sub getFile
    Dim UserDir As String = GetSystemProperty("user.dir", "")
    If File.Exists(UserDir,"NmicroCore") = True Then
 
Upvote 0

Zvi

Member
Licensed User
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
B4X:
Dim UserDir As String = File.DirData("Checkers")
'OR'
Private xui as XUI
xui.SetDataFolder("Checkers")
Dim UserDir As String = xui.DefaultFolder

If File.Exists(UserDir,"NmicroCore") = True Then...
 
Upvote 0

Zvi

Member
Licensed User
Hi Chris2, I tried both your options.
No success.
On the install debug I saw that the installed program was looking for the data file in the Bin folder although in the B4J project folder it saves the file in the Objects folder.
So I copied the data file from the Object folder into the installed program's Bin folder.
Still didn't work.
The permissions in the project folder allowed write, but in the copied file the write permission was cancelled.
So I changed the copied data file write permission to allow.
Still didn't work.
As a last resort I tried running the installed program as administrator... Worked perfectly!
So now my problem is how to get my program to setup the data file with write permission.
How to define a write-allowed directory?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Hi Chris2, I tried both your options.
No success.
On the install debug I saw that the installed program was looking for the data file in the Bin folder although in the B4J project folder it saves the file in the Objects folder.
So I copied the data file from the Object folder into the installed program's Bin folder.
Still didn't work.
The permissions in the project folder allowed write, but in the copied file the write permission was cancelled.
So I changed the copied data file write permission to allow.
Still didn't work.
As a last resort I tried running the installed program as administrator... Worked perfectly!
So now my problem is how to get my program to setup the data file with write permission.
How to define a write-allowed directory?
hey... you are saying you ve tried... but... the file must created into File.DirData("Checkers") & "\" & yourfilename...and not in program files\yourapp\bin and and generally in program files !!

In case you need it only at the bin and in program files (that always need admin permissions) go at 2nd way !

1st way (i think the right way)
----
B4X:
Dim UserDir As String = File.DirData("Checkers")
*usually dirdata no \users\yourusername\appdata\roaming\appname no need any special-admin permissions...


This a right start... to have access without admin permissions... but may be you will need admin permissions (as i said) in case your system has some user different configuration (who knows?)

----
2nd way
in case you need Admin Rights...
you can do it with Inno Script...

B4X:
[Icons]
Name: "{userdesktop}\YourAppname"; Filename: "{app}\youexefile.exe"; \
  AfterInstall: SetElevationBit('{userdesktop}\yourappname.lnk')


[Code]

procedure SetElevationBit(Filename: string);
var
  Buffer: string;
  Stream: TStream;
begin
  Filename := ExpandConstant(Filename);
  Log('Setting elevation bit for ' + Filename);

  Stream := TFileStream.Create(FileName, fmOpenReadWrite);
  try
    Stream.Seek(21, soFromBeginning);
    SetLength(Buffer, 1);
    Stream.ReadBuffer(Buffer, 1);
    Buffer[1] := Chr(Ord(Buffer[1]) or $20);
    Stream.Seek(-1, soFromCurrent);
    Stream.WriteBuffer(Buffer, 1);
  finally
    Stream.Free;
  end;
end;

[Registry]
Root: "HKLM"; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"; \
    ValueType: String; ValueName: "{app}\yourexefile.exe"; ValueData: "RUNASADMIN"; \
    Flags: uninsdeletekeyifempty uninsdeletevalue; MinVersion: 0,6.1

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: runascurrentuser nowait postinstall skipifsilent;
 
Last edited:
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
On the install debug I saw that the installed program was looking for the data file in the Bin folder although in the B4J project folder it saves the file in the Objects folder.
The ...\Bin\ folder is File.DirApp I think.
Your code must write the file to File.DirData("Checkers") and read it from there.
Can you post all the code that writes & reads the file so we can help check it?

I'd suggest adding to it:
B4X:
Log(File.DirData("Checkers"))
So you can see the full path

Or. as @Magma said, install it with Admin rights. But depending on whether the app is just for you or a wider realease, you may run into trouble down the road with that.
 
Upvote 0

Zvi

Member
Licensed User
Brilliant!

Thanks so much, both Chris2 and Magma.

I used
B4X:
Dim UserDir As String = File.DirData("Checkers")

for both read and write (obviously :) )

B4X:
File.Writemap(UserDir, "NmicroCore", Main.checkers)

Works perfectly. Saves the data file in AppData\Roaming (see attachment).
 

Attachments

  • Screenshot - 31_05_2023 , 13_11_59.jpg
    Screenshot - 31_05_2023 , 13_11_59.jpg
    80.2 KB · Views: 133
Upvote 0
Top