MSVS Installer Projects: How to reference file in source? - c++

I have a Windows service application written in C++ that I would like users to install as a .msi file, so I am using MSVS Installer Projects 2022. The service requires a read from a file config.cfg to setup some parameters on each start. My current implementation installs to wherever a user specifies, but C:\Program Files\<Install Dir> is the default directory. In my source code I hardcoded that directory to get to the configuration file, i.e. C:\Program Files\<Install Dir>\config.cfg which is obviously not very portable, but it has allowed me to do some testing.
I would love to link the file relatively to the executable, but Windows Service applications set the working directory to System32, so doing something like loadFile("config.cfg") would expand to loadFile("C:\Windows\System32\config.cfg"). Installer Projects does allow me to drop the config file there or any sub-folder, but this seems unideal. What is a good way of going about referencing the configuration file in source? Some things to consider:
%appdata% of the installer and %appdata% of the service are completely different.
Installer allows for setting registry values, but setting a string PATH directing to the installation folder does not seem possible.
My application is hosting a server using a class that requires the config file.
Any help is appreciated.

Related

Including external folder in UWP visual studio project

I have a UWP project in Visual Studio (2015, c++) and I want to include an external folder tree of assets (e.g. images) so that when I run it in the emulator those files are available (similarly, when I build a final package I want the files with the package). The files aren't fixed (i.e. I may add/remove files at a later time)
In a regular desktop application I would simply use a post-build step and do an xcopy on the folder into the target directory. This, however, does not work for the UWP build. When I run in the emulator nothing is there (or even in the target directory).
Is there some way to add a build step to copy files (retaining directory structure) or even better a way to add an external folder reference to the project?
I know I am not the only one that does this. Most results in searches are irrelevant, others aren't dynamic, or rely on the files to be within the project's directory tree.
Use AppxPackagePayload element in your .vcxproj file:
<AppxPackagePayload Include="PathToYourImage.jpg">
<TargetPath>SubfolderInPackage\FileName.jpg</TargetPath>
</AppxPackagePayload>
Unfortunately, you'll need to reference every file your want to copy separately. I don't know if there is a way to do it for a directory.
I have a UWP project in Visual Studio (2015, c++) and I want to include an external folder tree of assets (e.g. images) so that when I run it in the emulator those files are available (similarly, when I build a final package I want the files with the package). The files aren't fixed (i.e. I may add/remove files at a later time)
From your description, I think you want to mount an external folder for your uwp app. However, not all path can be accessed directly under current file access rules.
Access to other locations is available only through a broker process. This broker process runs with the user’s full privileges, and it can use these privileges on the app’s behalf for locations the app has requested via capabilities, locations requested by the user via file pickers, etc. The StorageItem encapsulates this brokerage procedure so the app doesn’t need to deal with it directly.
As Rob said that you can access to other locations with the user’s full privileges. For more you could refer to File access permissions official documentation.

how to make stand-alone setup file of a mfc project including all data files

I have a project in VC++ MFC and works fine with the .mdb files. But just copying the project's .exe file on other system does not let the project work as it searches for the same path as mentioned in the code for the .mdb files and fails to find one. Also, apart from .mdb files, theres a need for certain .ocx files and io library suite to be registered in the system prior to the project's execution. How to overcome this problem?
You need to wrap up all the files into a package also known as installer. One of the most popular (and free) at the moment is Inno Setup. This will produce a single exe file that you will be deploying to users / other machines. You need to make sure that you include all the needed files, libraries etc in your setup.

How to open existing C++ project with Eclipse?

I have two projects in C++ that I need to run and build both in Windows and Linux.
We are using Microsoft TFS for source control.
For windows we are using Visual Studio.
For Linux we are using Eclipse. (I don't have much experience with Eclipse)
I had managed to configure and build properly the projects in both platforms.
I checked in TFS the .cproject and .project from eclipse, so I can use it in another computer.
Now I am trying to get the projects in another Linux computer and I don't know how to do it.
I tried following this instructions, but I don't have my source code zipped.
Other places like here suggest creating a new project.
Isn't there a way to open an existing project in Eclipse similar to Visual Studio?
Do I have to create a new project? If so, how can I keep the configurations I did to be able to build the project so other developer can use them?
File > Import... > General > Existing projects into workspace
Don't select an archive file. Set the root directory to where your .project and .cproject files are located. Your project should show up in the list. Make sure you don't forget to check the checkbox in front of your project.
Committing eclipse project files to a version control system is perfectly fine as long as you don't use absolute paths in your project settings. Use environment variables to specify paths which differ between developer machines.

Project files in KDevelop

I am trying to use KDevelop to write a cmake based simple application. KDevelop created two myProject.kdev4 project files: one in the project folder and one in .kdev4 hidden subfolder. Both are non-empty. Which ones should I check in? How can I make kdevelop use just one project file (and preferably not use hidden folders)?
The .kdev4 file is used for kdevelop specific information (It mainly only tells KDevelop to use the CMake project manager). The folder includes user specific configuration (If you are familiar with Visual Studio, it is like the .user files).
Usually only the CMakeLists.txt files are needed as they should have all the relevant generic data. You can throw in the .kdev4 file so that you don't need to 'import' the project through the CMakeLists.txt on another machine. But the .kdev4 folder should stay in your local machine, as you don't want to mix user's configurations.

More with eclipse cdt

What is done when we import an existing project(maybe a visual studio project)?
Which files are used for configuration?
Try this one, you may get some information.
Migrate Visual Studio C and C++ projects to Eclipse CDT
Eclipse manages files completely differently than Visual Studio, files are managed by Eclipse and placed into the project workspace. Adding existing files has the aggravating effect of copying the files from their location into the workspace. There are workarounds for this (adding a link to existing file, makefile-only projects) but the default is to copy files around.
This is great if your project is managed by Eclipse alone, not great if you want a VS project AND an Eclipse project for the same codebase.
I'm don't think you can import a VS project into Eclipse CDT, at least not the way you're thinking.
The files used for configuration are stored in (path to workspace)/.metadata, there are a LOT of files that change constantly and can contain absolute paths. Caveat emptor.
There is no explicit wizard for importing visual studio project files. What you import is a directory tree full of source code files. Basic information about this is worked out and stored in a file called .project, which contains the settings from Project/properties.
If, when you create or import the project, 'use default location' is specified, the tree is copied into a workspace directory. If not, it is left where it is.
If the project type is 'makefile project', the only real assumption is that there is some external command to be run to build the software. Project properties/C++ build can be used to specify this command - by default, it is 'make'.
DevStudio can export a makefile for one of it's projects - from the Project menu, select 'Export Makefile'. Or you can just write one by hand, or use some other build tool such as ant.
If all else fails, set the build command to 'cat' (e.g. from cygwin) and the build argument to the name of a file that contains the output log from however the software was built.
Eclipse itself has two kinds of projects - those with makefiles, and those that it manages itself.
Makefile projects have a separate make file that you generally write on your own.
Eclipse managed projects have a .project file that is used by the IDE to create make files on the fly, when you build your project.
Are you asking specifically for visual studio projects, or is that just an example?