Folder property of File Search Launch Condition: how to specify custom folder under [TARGETDIR]? - wix

I'm trying to set a file search launch condition for my installer. I need it to search for a specified file in a subfolder of my [TARGETDIR] folder.
I tried setting the Folder property to:
[TARGETDIR]/Subfolder
[TARGETDIR]Subfolder
[TARGETDIR]Subfolder/
[TARGETDIR]/Subfolder/
[TARGETDIR]/"Subfolder"
None of the above solutions worked. The file located in subfolder never gets found. It works if I only specify [TARGETDIR] with the Depth property set to 1, but I would rather specify directly the directory to search.
I found a similar question here, but there is no answer.
What is the correct way to set the Folder property to work with a custom folder ?

The difficulty here is that TARGETDIR is not set until later than the search is done, so it has no value yet. Even if if it did have a value, it's what is changed by the browse dialog that can change where the user installs thet app (see the property window of Application Folder in File System on Target Machine).
This means you must use standard folder properties in your search. If you want to search what you think may be where the file is installed, then use:
[ProgramFilesFolder]SomeFolder\SomeOtherFolder
or something similar if your assumed value of TARGETDIR is in Program Files x86.

Related

I want to copy the file in sandbox without NSOpenPanel

I want to copy some files to specified folder by NSOpemPanel.
The source file is reading from XML and show to list in NSTable.
I can copy file by copyItemAtPath.
But now my app will turn to sandbox, then I can’t copy the file by copyItemAtURL.
How do I copy the file in sandbox mode?
I was looked over a lot of post. And I think the Security-scoped Bookmark may be a solution for this.
But I can’t create "Security-scoped Bookmark" from XML inside the path (the path was convert to NSURL ready).
I was setting to sandbox.entitlements but it's not clear this problem.
Is there any way for this?
Develop in macOS10.12 and Xcode8.3.3
Thanks
How do I copy the file in sandbox mode?
It is unclear what your current code is doing, but the rules under the sandbox are simple: To read or write a file located outside of an application's own container (which is hidden away under the Library folder) your application must either:
Use NSOpenPanel to obtain a URL from the user for the file path; or
Use NSOpenPanel to obtain a URL from the user for one of the ancestor folders of the file.
The second option gives access to a whole folder, including any sub-folders; i.e. the whole file/folder subtree rooted in the folder.
As you want to copy "some files" it sounds like asking the user for permission for the folder is appropriate. You can customise the NSOpenPanel to be a "request permission" dialog. If you are requesting a specific folder you can also have the dialog open in it's containing folder and only have the specific folder enabled for selection by the user.
Once you have the URL for the folder from NSOpenPanel you can create a security scoped bookmark for it and save that in your app's preferences or other configuration file (stored within the app's container). Doing this enables your app to regain access to the folder on subsequent executions without asking the user again.
If after investigating this issue and writing some code you hit an issue ask a new question, showing your code, and explaining the problem. Someone will undoubtedly help you with the next step.
HTH

Is there a built in way to hide a file in Wix?

The company I work for has recently taken to generating MSI files with Wix. We're at the tail end of the process, but there's one more thing they need me to do.
We have an XML file with a snapshot of what binaries have gone into the install. However, the customers we deliver to will get somewhat confused about an extra useless file in the install.
Most everything that comes up when I search for 'Wix' and 'hide file' is focused on removing or deleting the files after install. I just need to hide this sucker though.
Is there a way to hide the file through HEAT or something? I can modify the file element in the WXS using XSL or Powershell if need be. Or do I need to resort to a custom action that calls cmd.exe to hide it?
You can try setting the file element's hidden attribute to yes. Taken from here:
Set to yes in order to have the file's hidden attribute set when it is installed on the target machine.

Open a specific file in vb.net

I want my program to open a specific .txt file. The text file will always stay in the same folder within the solution folder. However, the location of the solution folder itself may change if the solution is moved to a different computer, or a different directory on the current computer.
I know how to hardcode the file path append the file name and then open it. But how can I define the file path so that the file can still be opened if the solution moves to a different computer?
If the file is contained within the solution, you can use a virtual path which is then mapped to a physical path using Server.MapPath
The following should work :
Dim filePath As String = Server.MapPath("~/FileName.txt")
Please note that the location of FileName.txt in my example is in the root of the solution and not in any specified folders, ~/ is essentially the root of the current solution.
For more information on the Server.MapPath method and Virtual Paths see below:
Server.MapPath MSDN Documentation
Virtual Path Utility Class
If you are sure that your application (.exe) and (.txt) files are in the same folder, then just use the file name - do not put the path.
IO.File.OpenText("thefile.txt")
Edited:
Mostly "current working directory" is the same directory where the (.exe) file exists. Yes, sometimes, it is not the same directory. Thus, Application.ExecutablePath would be the right solution.
Dim fn As String
fn = Application.ExecutablePath.Remove(Application.ExecutablePath.LastIndexOf("\")+1) & "thefile.txt"
IO.File.OpenText("thefile.txt")
...
If you meant to say your FileName.txt was always present in the same directory as the assembly, you could do something simple like this:
Function GetAssemblyDirectoryPath() As String
Dim fullAssemblyPath As String = System.Reflection.Assembly.GetExecutingAssembly().Location
Return fullAssemblyPath.Substring(0, fullAssemblyPath.LastIndexOf("\"c))
End Function
This just returns the path to the folder where the assembly resides. The "Solution" might not always be present, but the assembly will, so this will work in both cases (if you make sure the file is always copied to the output directory).
If you're asking about a desktop application, application.ExecutablePath will do what you want. It's not really a good idea though, if your application will reside within Program Files - it's best to avoid writing to anywhere within there, and you will have to run as administrator on post-XP OS's .

Copy files from Setup location to installation dir

I am working on my Wix project and have 2 questions:
1) How can I copy file from the same location as my .msi is to the destination folder specified during installation. This file is not part of .msi package but a customized file that needs to be copied after the installer copies the main code files.
2) If this customized file is not available at the location where .msi file is, then I need to show up a OpenFile Dialog so that user can specify the location of this file.
In short, by default the installer should look for the customized file at the same location where the installer is and if the file is not available then show OpenFile Dialog.
Any suggestion or sample code snippet would be very helpful as I am bit new to WIX world.
Thanks for your time.
Ok, first thing you should find out if the file is there. Use DirectorySearch/FileSearch elements for this.
Next, based on the file search result (it will end up in a certain property) schedule and condition a new dialog. You can find how to customize your dialog UI sequence here.
And finally, use CopyFile element to do the copy work.

How do I publish a folder along with my VB.NET program that contains.html?

I have a VB.NET program that I wish to to publish. In the code it references a HTML page that I created. Instead of having the URL hard coded (example: www.test2.com/folder/index.html)
I would like to have it relative to wherever the encoder is installed to (example: /folder/index.html)
How can I do this?
Thanks!
In VB.Net you have either
Dim lPath As String = Application.ExecutablePath
Which gives you the full path and app.name (which you can remove) or
Dim lPath As String = Application.StartupPath
Which gives you the directory the application started up in ..
Not sure I know the answer to the clickonce question, as we use our own deployment method at work but if you :-
Add your file via Project Explorer
Right click on file, select properties and set Build Action to "content"
Go to Project, yourprojectnameProperties, then Publish tab, then
Application Files button
you should see the file listed there then set to Include(auto).
.... or copy and paste them using internet explorer into the project explorer
If the file is referenced within your solution, the publish operation should automatically include the file to be published.
as for reference, if the html is hosted with in same website, then you can use a relative path from the page you are linking to.
You can also reference the file in your code by using Server.MapPath("relativepathtofile") and the relative path to the file you're referencing.