Currently I am messing around with a Click-Once WPF application. That application is some third-party application that was not developed by me. I also do not have access to its sources.
It is run on a Windows server periodically and automatically (using a self made launcher written in standard C++) by executing the corresponding *.appref-ms link that was placed in the start menu path on installation of the application. This works fine.
Due to periodically arising problems with that application my launcher needs to wipe all configuration files before starting it so I get a well defined run at all times. Those files are placed in one of the application's folders. That config path for its settings reads like this (I found it by searching the AppData tree manually):
C:\Users\<UserName>\AppData\Local\Apps\2.0\Data\WM4WPKCW.P5Z\67QVXD6C.0NT\<app>_f6187a2321850a68_0003.0004_1a67f9f1633c43fc\Data\AppFiles\
Please note that this config path is pretty different from the application path (which uses differently named folders):
C:\Users\<User>\AppData\Local\Apps\2.0\5HN2CKMO.MPL\YOL20MYR.O8L\<app>_f6187a2321850a68_0003.0004_f6ab8c93b3a43b7c\
Since this config path changes on each update of the Click-Once application I need to find it by code (preferably C++) automatically. Unfortunately I could not figure out a way to do this.
How can I make my launcher find the config path of the Click-Once application based on its *.appref-ms file?
From Raghavendra Prabhu’s blog entry “Client Settings FAQ”:
” If you want to get to the path programmatically, you can do it using the Configuration Management API (you need to add a reference to System.Configuration.dll). For example, here is how you can get the local user.config file path:
Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
Console.WriteLine("Local user config path: {0}", config.FilePath);
The code is C# (evidently), but shouldn't be that hard to translate to C++/CLI.
Raghavendra Prabhu further writes:
” If you need to store the settings in a different location for some reason, the recommended way is to write your own SettingsProvider. This is fairly simple to implement and you can find samples in the .NET 2.0 SDK that show how to do this. Keep in mind however that you may run into the same isolation issues mentioned above .
Disclaimer: I have not tested any of this.
Related
I am currently working on a C++ gui application. The application uses the Python/C API to call some python scripts. The scripts are located in the solution directory, and I call them by simply providing the path. This is currently working fine while debugging the application or even running the generated .exe file, but I am wondering how this could work if I want to release and distribute the application onto a different computer for someone to use. How can these scripts be deployed with the application?
I also have a .ttf font file with the same situation. How can this resource file be deployed with the application?
In other words, I want to deploy/release a C++ application with the scripts and resource files.
FYI: the C++ application is a Visual Studio project.
Thanks for the help in advance, and let me know if any more information is needed!
Update:
I just wanted to clear up the way my project is working currently:
PyObject* pArgs = PyTuple_New(5); // I setup the arguments the python function needs
PyImport_ImportModule("requests"); // imports...
// make python call
PyObject* pResult = PyObject_CallObject(pFunc, pArgs);
So this is (for the most part) how I call the scripts with the C++ source code. The scripts are located in a folder that is located in the solution directory.
I hope this explains my problem a little better.
Update:
Just another little update... Using some answers to other similar questions got me to the following point:
I need to obtain a python library, compile and link it with my C++ application, and then bundle the dependencies with the application (How to distribute C++ application which calls Python?)
So I guess my question is now shifting to how I would be able to get this done. What are the specific steps to do this? I also got a link (https://docs.python.org/3.5/using/windows.html#embedded-distribution) to an embedded distribution of a python environment (maybe this should somehow be used?). Also, I am able to statically link python into the application. I just don't know how to bundle and deploy the scripts I created and use in the application.
PyImport_ImportModule("requests")
The parameter is "requests".
Put the py file aside exe file when distributing.
So, you need to make sure that the C++ application can still access the python libraries when its released and those libraries/dependencies arent necessarily available on other systems.
You'll need to, like another commenter suggested, use one of the importing modules utilities, like PyImport_ImportModule("library name").
You can see these utilities here: https://docs.python.org/3/c-api/import.html
You'll also need to either
Put the libraries that you want with the exe (in the same directory) or
put them in the system environment path ( which is probably less straightforward).
Hope that helps and that I understood you're question correctly.
I am using QSettings in my Qt application to store prefences and all was fine until I start to run it on Linux mint 19. Default location for settings file is application folder, but now it is creating in users home folder.
QDir::currentPath() returns home folder, if I am running application by double click, and correct executable location if I am running it from terminal. I have never seen this before. Maybe somebody knows how to fix it and run application by double click from it's own folder.
Don't depend on current working directory (returned by QDir::currentPath()), because that can be basically anything. Looks like your desktop environment's file manager sets current directory to home folder when you run software by double clicking, and this is generally sensible, because that is usually what user would want, when opening files from the app etc.
If I read correctly what you want, that is path to application folder to store settings in, you need QCoreApplication::applicationDirPath(). But note that doing this will force you to install the application to user home folder (because you can't write to system folders like /user/local/bin, and you shouldn't change this by changing permissions, either).
Based on comments, it seems QCoreApplication::applicationDirPath() gives wrong directory, but QCoreApplication::applicationFilePath() gives correct path. If that is really the case, then take the file path, and remove the executable file from it. However, looking at the Qt source, this shouldn't be possible because applicationDirPath() already does just that...
I recommend you instead use QSettings as documented in its basic usage.
I have an application which is installed and run as a Windows service. In a given time, I need to locate the current application path (that is, the installation path) where other, needed files are located.
Unfortunately I'm being unable to find this directory using the traditional methods (QCoreApplication::applicationDirPath(), dir.absolutePath(), QDir::currentPath()). Every time this functions are called, they either return blank or the system32 folder.
I tried to improvise using QStandardPaths::findExecutable, but it didn't solve my problems. My last resort for now is creating a script that creates an entry in the registry telling the service where to look for, but since the installation is supposed to be just an "extract from compressed file", I'd like to avoid this option.
So which other method Qt makes available to make this specific circunstancial task?
I'm deploying an iphone application through QtCreator. I'd like to create a simple file using standard C++ libraries. I try to do this in the sandbox Documents folder.
I compiled boost, so I use this library to check if the sandbox Document folder exists.
My application starts in /private/var/mobile/Containers/Bundle/Application/<UUID>/<application name>.app. Then, I simply try to access /private/var/mobile/Containers/Bundle/Application/<UUID>/<application name>.app/../Documents folder (using boost::filesystem::is_directorty), as it does not exist, I try to create it (using boost::filesystem::create_directories), but it fails (boost raises an exception).
Am I doing it wrong? Am I not in the right PATH? Or do I have to set any special permission to my app in order to be able to do this (as for Android, I add to list EXTERNAL_STORAGE in my application manifest).
My path for documents was wrong. Could find the good one using Qt API:
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
This returns:
/var/mobile/Containers/Data/Application/<another UUID>/Documents
(different than what I was trying to access in /private/var/mobile/Containers/Bundle/Application)
I have developed an application that I plan to deploy on Windows, Mac, and Linux. The program requires access to some files (scripts and the like) at run-time.
The installation process should install the files to a location that my application can later determine without user-intervention (or perhaps just a prompt allowing the user to change the location, if desired).
What is the best way to achieve this? I can't seem to find any way to:
1. Use a "standardized path" variable in the project file's INSTALLS statement. (e.g., my application could use QStandardPaths to initialize the location, but I can't figure out how to access this path from the INSTALLS statement)
2. Save the path to my project's QSettings (.plist, registry, whatever) for later retrieval
That leaves me with creating a custom project file and INSTALLS command for each environment, and then I still can't install to the user's directory because I don't know the user's name when I deploy the make command. It seems as if there must be a better way, but I can't seem to find any documentation for this. Am I just using the wrong keywords in my searches? Thanks in advance!
What standard directory? What type of getting that standard directory?
For instance, you can put such thing in your windows branch of .pro file:
win32 {
APPDATA_DIR = $$system(echo %APPDATA%) # should be %LOCALAPPDATA% as requested
message($$APPDATA_DIR)
}
Just unsure of what exact kind of standartized path you are talking about. QStandardPaths knows many. It makes sense to be more concrete to find the correspondence with concrete OS.
Also somewhat relative reply on mine, on how to check the correspondence with certain variable, etc: Qt .pro file - how to add conditioning on OSX version?
Maybe this class will help you
QStandardPaths documentation
But your problem is still little bit unclear for me.