I'm making a setup script in Inno and I was wondering, how can I get non "hardcoded" path. Here is example:
Thanks in advance!
SOLUTION:
You can get .iss folder by using predefined variable
SourcePath
Usage would be like: {#SourcePath}\???\bin\x86\Release\???.exe
Thanks all who contributed!
The reference about the source directory says (emphasized by me):
By default, the Setup Compiler expects to find files referenced in the script's [Files] section Source parameters, and files referenced
in the [Setup] section, under the same directory the script file is
located if they do not contain fully qualified pathnames. To specify
a different source directory, create a SourceDir directive in the
script's [Setup] section.
This includes also option to specify relative path to the files. So let's assume that you have the following file structure and you didn't specify a different path in the SourceDir directive:
C:\Deploy\Script.iss
C:\Deploy\MyProg.exe
C:\Deploy\SubFolder\MyOtherProg.exe
C:\Folder\SomeFile.txt
Now if you'd like to include the MyProg.exe into the setup compiled from the Script.iss script, you could specify just the file name without the path, since the MyProg.exe file is stored in the same folder as the script, so you could write just:
[Files]
Source: "MyProg.exe"; DestDir: "{app}"
And you can use a relative path to the MyOtherProg.exe which is stored in the subfolder of the folder where the Script.iss script is stored this way:
[Files]
Source: "SubFolder\MyOtherProg.exe"; DestDir: "{app}"
As well as you can use a relative path to include the SomeFile.txt stored in a subfolder of the parent folder where the script is stored:
[Files]
Source: "..\Folder\SomeFile.txt"; DestDir: "{app}"
More about relative path conventions you can read in this chapter.
Like OP has said in his own question,
You can get .iss folder by using predefined variable
SourcePath
Usage would be like: {#SourcePath}\???\bin\x86\Release\???.exe
Related
I need to include StyleUtils.inc and StyleAPI.inc in my source file, but I don't want to copy the files to my project folder, or reference the files directly, as the contents and location could change on newer versions of Delphi, although I can see the files under C:\Program Files (x86)\Embarcadero\Studio\22.0\source\vcl.
The BDS environment variable points to C:\Program Files (x86)\Embarcadero\Studio\22.0, so I was wanting to include the files as below, but I have tried escaping with $(), ${}, %%, but the variable is not being referenced.
{$I $(BDS)\Source\Vcl\StyleUtils.inc}
No, you cannot use environment variables in {$I} directive. What you need to do instead is use a relative path in the directive, and then specify the root folder in the project's Search path configuration, per the documentation:
https://docwiki.embarcadero.com/RADStudio/en/Include_file_(Delphi)
If the filename does not specify a directory path, then, in addition to searching for the file in the same directory as the current module, Delphi searches in the directories specified in the Search path input box on the Delphi Compiler page of the Project > Options dialog box (or in the directories specified in a -I option on the command line compiler).
How do you specify a directory - the following only work if I put my helloworld.proto in a folder named protos
protoc --dart_out=. -Iprotos helloworld.proto
protos: warning: directory does not exist.
helloworld.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
You should not need to include -I in this case because helloworld.proto is in the current working directory.
-I (proto path) is used by protoc to reference directories that aren't in the current working directory. If you were to use ${PWD}/helloworld.proto for example, I think you'd need need to -I=${PWD}. Even though ${PWD} is equivalent to the current working directory, protoc sees a proto with a directory prefix and expects it to be added to the proto path.
Customarily, you'd need to add a proto path when you have protobuf imports that aren't local. Then, you add -I= and list the directories where these imports may be found.
I am trying to write a Inno Setup script to install files from a CD drive to a predefined system C drive folder. Naturally, the CD/DVD ROM may have a different path ID on different systems. How do I code this variable path for the Source Files?
Assuming your installer is located along with the files you are going to install, you can use the {src} constant to refer to installer's folder along with the external flag:
[Files]
Source: "{src}\file.dat"; DestDir: "..."; Flags: external
If your installer is located elsewhere, there's no generic solution. Note that there may be even more CD/DVD drives on the computer.
You would have to programmatically enumerate all drives, testing for their type (CD/DVD) and presence of certain files for example.
I have a project with the following dir tree structure:
CMakeLists.txt
\src
test.cpp
\include
test.h
\resources
various resource files
test.cpp contains the correct path (relative to the root) in order to point to the resources in the resources dir.
When running CMake with an out-of-source building in the build directory, the \build directory is created as subdir of the root, but now the resources pointed by previously correct paths hard-coded in test.cpp cannot be accessed anymore, because the working dir is not the root.
How can I manage resources with CMake and out-of-source building??
It's up to you as program author to make sense of relative paths. With a relative path, you must always be clear about what it's relative to. "Source file directory" is a terrible reference point, since it doesn't exist at runtime.
Is a path relative to the current (= working) directory? Then that's beyond CMake's control and you must launch your program correctly. For tests purposes, you can set test property WORKING_DIRECTORY.
Is a path relative to the executable location? If so, you can either position the executable through its RNTIME_OUTPUT_DIRECTORY property, and/or copy the resources to the proper place using file(COPY) or configure_file(COPYONLY).
I am trying to figure out how to use relative paths for Powershell scripts. I have dot sourced with absolute paths, but the scripts that I am writing may end up in a different base directory so I need to make sure the path is relative so it can be picked up. How can I do that?
So far I have tried:
. .\scripts\variables.ps1
That always throws this exception:
The term '.\scripts\variables.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program...
That lets me know it can't find my script? So, what am I doing wrong?
You can use : . $PSScriptRoot\scripts\variables.ps1
Here $PSScriptRoot is the path of directory of the running script.
This is not what the OP asked for but may be useful for others who are searching:
If you need to traverse up, you can use . $PSScriptRoot\..\scripts\variables.ps1
This works for structures such as:
root
scripts/shared directory
directory your script is executing in
If you know that your script directory structure is going to remain the same, you could use $PWD; eg:
. "$PWD\scripts\variables.ps1"
The above assumes that your script (the calling script) is in the same directory that contains the scripts directory.
Also, the assumption made here is that you're checking out/downloading all your scripts in the same structure, but as you put it, they may end up being in a different base directory.