Debugging non working Pascal Check condition (DirExists) in Inno Setup - installation

I trying to compile a little setup program for future users, I have understood how change some stuff.
But now I would like to create a shortcut ONLY if the directory exist. I tried to do something like that but nothing happened ... :
[Icons]
; Start menu icon
Name: "{group}\Myprogram"; Filename: "{app}\Myprogram.exe"
; Desktop icon
Name: "{userdesktop}\Myprogram.exe"; Filename: "{app}\Myprogram.exe"; \
Check: DirExists(ExpandConstant('C:\[path]\test'))

Your code is ok. It should do what you want. To help with the debugging, implement a user function that logs the test like:
[Icons]
Name: "{userdesktop}\P680.exe"; Filename: "{app}\P680.exe"; \
Check: DirExistsLogged('C:\Users\administrator\Documents\Test')
[Code]
function DirExistsLogged(Path: string): Boolean;
begin
Result := DirExists(Path);
Log(Format('DirExists [%s] => %d', [Path, Result]));
end;
Log example, when the folder exists:
2019-12-31 15:04:59.565 DirExists [C:\Users\administrator\Documents\Test] => 1
2019-12-31 15:04:59.565 -- Icon entry --
2019-12-31 15:04:59.565 Dest filename: C:\Users\martin\Desktop\My Program.exe.lnk
2019-12-31 15:04:59.566 Creating the icon.
2019-12-31 15:04:59.583 Successfully created the icon.
2019-12-31 15:04:59.594 Saving uninstall information.
Log example, when the folder does not exist:
2019-12-31 15:06:23.960 DirExists [C:\Users\administrator\Documents\Test] => 0
2019-12-31 15:06:23.960 Saving uninstall information.

Related

Chef notification within each method

I have a recipe that iterates a hash containing SQL scripts in an each method and -- in case the script changed from the previous run -- the cookbook_file resource notifies the execute resource to run.
The issue is that it seems it always runs the execute using the last element of the hash.
Following the attributes file
default['sql_scripts_dir'] = 'C:\\DBScripts'
default['script_runner']['scripts'] = [
{ 'name' => 'test', 'hostname' => 'local' },
{ 'name' => 'test2', 'hostname' => 'local' },
{ 'name' => 'test3', 'hostname' => 'local' },
{ 'name' => 'test4', 'hostname' => 'local' },
]
And the recipe
directory node['sql_scripts_dir'] do
recursive true
end
node['script_runner']['scripts'].each do |script|
cookbook_file "#{node['sql_scripts_dir']}\\#{script['name']}.sql" do
source "#{script['name']}.sql"
action :create
notifies :run, 'execute[Create_scripts]', :immediately
end
execute 'Create_scripts' do
command "sqlcmd -S \"#{script['hostname']}\" -i \"#{node['sql_scripts_dir']}\\#{script['name']}.sql\""
action :nothing
end
end
And it produces the following output:
Recipe: test_runner::default
* directory[C:\DBScripts] action create
- create new directory C:\DBScripts
* cookbook_file[C:\DBScripts\test.sql] action create
- create new file C:\DBScripts\test.sql
- update content in file C:\DBScripts\test.sql from none to 8c40f1
--- C:\DBScripts\test.sql 2020-07-30 17:30:30.959220400 +0000
+++ C:\DBScripts/chef-test20200730-1500-11bz3an.sql 2020-07-30 17:30:30.959220400 +0000
## -1 +1,2 ##
+select ##version
* execute[Create_scripts] action run
================================================================================
Error executing action `run` on resource 'execute[Create_scripts]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of sqlcmd -S "local" -i "C:\DBScripts\test4.sql" ----
STDOUT:
STDERR: Sqlcmd: 'C:\DBScripts\test4.sql': Invalid filename.
---- End output of sqlcmd -S "local" -i "C:\DBScripts\test4.sql" ----
Ran sqlcmd -S "local" -i "C:\DBScripts\test4.sql" returned 1
The expected behavior is that the recipe runs sequentially the 4 scripts in the example instead of running just the last one. What am I missing for getting it done?
You are creating 4 nearly identical resources all named execute[Create_scripts] and when the notification fires from the first cookbook_file resource being updated it finds the last one of them to be notified and runs against test4 (no matter which cookbook_file resource updates).
The fix is to use string interpolation to change the name of the execute resources to be unique and to notify based on that unique name:
directory node['sql_scripts_dir'] do
recursive true
end
node['script_runner']['scripts'].each do |script|
cookbook_file "#{node['sql_scripts_dir']}\\#{script['name']}.sql" do
source "#{script['name']}.sql"
action :create
notifies :run, "execute[create #{script['name']} scripts]", :immediately
end
execute "create #{script['name']} scripts" do
command "sqlcmd -S \"#{script['hostname']}\" -i \"#{node['sql_scripts_dir']}\\#{script['name']}.sql\""
action :nothing
end
end
Note that this is a manifestation of the same issues behind the old CHEF-3694 warning message where what would happen is that all the four execute resources would be merged into one resource via "resource cloning" with the properties of the subsequent resource being "last-writer-wins".
In Chef 13 this was changed to remove resource cloning and the warning, and in most circumstances having two resources named the same thing in the resource collection is totally harmless -- until you try to notify one of those resources. The resource notification system should really warn in this situation rather than silently picking the last resource that matches (but between notifications, subscribes, lazy resolution and now unified_mode that code is very complicated and you only want it to be firing under exactly the right conditions).

Move a file from one server to another server via plsql or shell

I have a server with details :
server ip: 192.168.141.96 : 21 credentials: user: tss password: T#l30P#ss path: /home/ttt/
This is the server where a file is getting generated. I want to move this file to another server with credentials
Host: sftp://sftpabc.learn.com
User name: abc
Password: jQrE7wvg
Port: 22
import dir: upload/source
I am trying to use the following plsql script for this :
DECLARE
l_conn UTL_TCP.connection;
begin
l_conn := ftp.login('192.168.141.96', '21', 'tss', 'T#l30P#ss');
ftp.ascii(p_conn => l_conn);
FTP.GET(P_CONN => L_CONN,
P_FROM_FILE => 'filename_test.csv',
p_to_dir => 'DIR_INBOUND',
p_to_file => 'test_get.txt');
ftp.logout(l_conn);
END;
But this is not executing and no file is getting transgerred. Is there a shell script/plsql script for this ?
What do you mean by 'is not executing'. What is the error? A quick search shows that you may be using this site as reference for your code. If that is the case, did you make sure to compile the ftp.pks and ftp.pkb in your database?

Lazarus - loading picture form file

I have an issue with loading a picture from z file. The picture has a .png extension.
Can anyone explain me why it doesn't work anymore ?
if (FileExists('file.png')) then
Image1.Picture.LoadFromFile('file.png');
Errors:
Project project1 raised exception class 'PNGImageException' with message: This is not PNG-data
Project project1 raised exception class 'FPImageException' with message: Wrong image format
At the first create your image component:
MyPicture := TImage.Create(FormCanvas);
MyPicture.Name := 'picture';
MyPicture.Parent := FormCanvas;
V1 - use direct path
Edit_pic_path.Text := 'C:\Images\';
Prop_Picture_Name.Text := 'image.png';
try
if (FileExists(Edit_pic_path.Text + Prop_Picture_Name.Text)) then
begin
MyPicture.Picture.LoadFromFile(Edit_pic_path.Text + Prop_Picture_Name.Text);
end;
finally
end;
V2 - image must be in project folder
...
MyPicture.Picture.LoadFromFile(Prop_Picture_Name.Text);
...

How to Translate texts contained in MsgBox in Inno Setup?

I have got a [code] section contained within my inno setup script which displays some information for the user during install. I would like to be able to translate these in the same language the user selected during install. They texts are currently in English and for example want to translate it in Russian, etc. I know I have to do something in the Language.isl file. Below is a example of such text.
if MsgBox('Previous program found. It is recommendeded to uninstall it and install a fresh program. Please note that your data will not be deleted during the uninstallation. Do you want to continue?', mbConfirmation, MB_YESNO) = IDYES then
begin etc
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"
[CustomMessages]
CustomMessage=Undefined //just in case (should be equal to English)
english.CustomMessage=English Selected
german.CustomMessage=German Selected
polish.CustomMessage=Polish Selected
[Code]
function InitializeSetup: Boolean;
begin
Result := True;
MsgBox(ExpandConstant('{cm:CustomMessage}'), mbInformation, MB_OK);
end;

How to let user to browse to a file to be copied with Inno Setup

I need user to browse to a file, select it, and then have this file copied from selected source to app folder.
Following this post
How to show/use the user selected app path {app} in InputDirPage in Inno Setup?
and Inno Setup documentation, i came to this piece of code:
[Files]
Source: {code:GetDBPath}; DestDir: "{app}"; Flags: confirmoverwrite uninsneveruninstall;
[Code]
var
SelectDBPage: TInputDirWizardPage;
DBPath: String;
procedure InitializeWizard;
begin
SelectDBPage := CreateInputDirPage(wpSelectDir, 'Select file', 'Select file', 'Select file', False, '');
SelectDBPage.Add('');
SelectDBPage.Values[0] := ExpandConstant('{src}\DB.FDB');
DBPath := SelectDBPage.Values[0];
end;
function GetDBPath():String;
begin
Result := DBPath;
end;
My problem is to retrieve file path. At instruction 'Source: {code:GetDBPath}' i get an 'Unknown filename prefix {code:' error.
How can I refer to the selected file path in [File] section?
Thank you
You need to add the external flag to the [Files] entry. This means the source will be evaluated at run time and CAN include {code:...} constants.
You're also not getting the correct value in your GetDBPath() function. You're returning the value of DBPath that isn't updated after creating the page, instead of getting the latest value form the SelectDBPage.Values[0].

Resources