How to get the ios document/library path through Qt5? - c++

I used find my ios app's document/library path by going up starts from QApplication::applicationDirPath().
However from iOS 7/8, the bundle path is moved away from data path.
So how can I get my app's writable paths through Qt C++ only? Is there a correct way that packed with Qt?
I don't want to write on APPROOT's document. And I understand that I can write objective-c codes to find the path.
So my app is installed at:
/var/mobile/Containers/Bundle/Application/XXXX/
What I want to get is
/var/mobile/Containers/Data/Application/YYYY/Documents
/var/mobile/Containers/Data/Application/YYYY/Library
note that the bundle's long id (the XXXX) is different from Data's (the YYYY)

If you need to take the document or any other standard library directories path, use QStandardPaths from Qt5:
QStandardPaths::AppDataLocation
For other paths consider to read the official Qt docs about QStandardPaths

Related

Access iPhone's sandbox Document folder from standard C++ code

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)

Get the config folder of a third-party Click-Once application

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.

How to specify a standard directory in a Qt project file

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.

File path of .exe File in windows 7

I am working in a C++ project. I need to obtain the path of a installed software. (Eg. skype.exe) Is there any way to find the path via C++ coding or via Widows command prompt
Depends what you are needing it for, and how generic you want it.
You can use GetEnvironmentVariable to get the PATH variable, and search these paths.
You can use the App Paths registry key, as Gabe says. See also...
Usually there are pretty clear application-specific ways to find the path via the registry. Either via the HKLM/Software key or Uninstall. Careful with localization and hard-coding application names...
If you are just trying to launch the app, ShellExecute doesn't need the full path, it works almost like the "run" dialog box in the start menu.
It's in the App Paths registry key. For skype.exe you would look in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\skype.exe
You can call the standard Win32 API RegQueryValue to read it.

Find out the mime type and associated applications with Qt

How can I find out a mime-type or content-type of a given file?
I cannot use the suffix because the file could be renamed.
Possible additions would be categorizing them as jpg, gif, png and so on are image files and can be opened by editing applications, which has been set in the OS.
Thank you in advance.
What platform? On *nix, you should refer to how the program file does it, which is based on a few heuristics including checks of the first few bytes of a file (many file formats start with a fixed header, including many image formats).
If you're on Windows, the *nix file command is probably still instructive, even if you can't reuse its code as directly. There may also be some better solution in the Windows APIs (I'm not a Windows programmer).
This could help, it is with C# but I think you can get the idea.
http://kseesharp.blogspot.com/2008/04/c-get-mimetype-from-file-name.html
You can use some sort of class for acccesing Windows Registry from qt or using the Windows API directly from qt.
I am not a qt programmer.
You can't, not from within Qt.
However, if all you want is to show a file with the correct application, you can use QDesktopServices::openUrl(), which wraps open (Windows/OSX) and xdg-open (Unix). The URL may also be a local file (in that case, use QUrl::fromLocalFile() to construct the URL).
For categorizing image files. For Qt and just only for image files.
QByteArray imageFormat = QImageReader::imageFormat(fileName); //Where fileName - path to your file
Further mapping imageFormat to mime-type is not complicable
It doesn't look like Qt offers that capability yet. However, you may want to look into the libmagic library which does what the file and other similar commands do. Assuming the library is maintained properly it will include new MIME types as time passes. From what I can tell it is part of the file tool suite. Under a Debian system do something like this:
sudo apt-get install libmagic-dev
to get the development library and use #include to make use of it.