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

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)

Related

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

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

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.

Read multiple files

I'm new to c++ and am trying to alter the console app code posted below to read multiple files, ideally using a wildcard extension. Can some please give me some pointers..?
http://msdn.microsoft.com/en-us/library/ms916815#odc_wssusageeventlogging_examiningtheusagelogfileformat
-----------Edit-------
What I need is how to change the code above instead of pointing it to a specific [filename.log] point it to a directory name and let it process all the log files in that directory.
--------------Tools-----
Win32 Console Application project in Visual Studio 2010 in C++
[To be run on win 32 bit platform]
Using Win32 APIs you can list the files in a directory by following this example. From there it should be relatively trivial for you to incorporate that code into your application to allow you to process multiple files as requested.
Specifically the FindFirstFile API allows for wildcard when search for files.
If you're willing to use the boost library check out
this post. If you're using something like C++/CLI then there is support in .NET for this as well (I'm assuming for now you're not using C++/CLI). If you specify the tools at your disposal maybe you can get a more directed answer.

SQLite with Android NDK

Is it somehow possible to use SQLite with C++ on an Android phone? I haven't found any documentation around how this could be possible.
Just download the SQLite3 amalgamation source file from:
http://www.sqlite.org/download.html
And then add sqlite3.c to your LOCAL_SRC_FILES variable in Android.mk.
It isn't possible to use the built-in SQLite via NDK (or it wasn't six months ago when I looked into this), that can only be accessed with Java. However it may be possible to link in your own completely separate C++ build of SQLite.
See SQLite Android Bindings http://www.sqlite.org/android/doc/trunk/www/index.wiki which describes how to include sqlite3 for Android targets 15 (4.0.3) and greater. It's copied below.
SQLite Android Bindings
The SQLite library is a core part of the Android environment. Java
applications and content providers access SQLite using the interface
in the android.database.sqlite namespace.
One disadvantage of using Android's built-in SQLite support is that
the application is forced to use the version of SQLite that the
current version of Android happened to ship with. If your application
happens to require a newer version of SQLite, or a build with a custom
extension or VFS installed, you're out of luck.
The code in this project allows an application to use the Android NDK
to build a custom version of SQLite to be shipped with the application
while still continuing to use the standard Java interface.
Normal Usage
Installation
Android API levels 15 (Android 4.0.3) and greater are supported. If
targetting API level 16 or greater, use the default "trunk" branch of
this project. Or, for API level 15, use the "api-level-15" branch. It
is not possible to target an API level lower than 15.
Copy the following files from this project into the equivalent
locations in the application project.
jni/Android.mk
jni/Application.mk
jni/sqlite/* (copy contents of directory recursively)
src/org/sqlite/database/* (copy contents of directory recursively)
Following this, the directory structures should contain
these files.
For API level 15 only, also copy the following:
src/org/sqlite/os/* (copy contents of directory recursively)
Directory "jni/sqlite/" contains copies of the sqlite3.h
and sqlite3.c source files. Between them, they contain the source code
for the SQLite library. If necessary, replace these with the source
for the specific version of SQLite required. If SQLite is to be
compiled with any special pre-processor macros defined, add them to
the "jni/sqlite/Android.mk" file (not jni/Android.mk).
Once the files have been added to the project, run the command
"ndk-build" in the root directory of the project. This compiles the
native code in the jni/ directory (including the custom SQLite
version) to shared libraries that will be deployed to the device along
with the application. Assuming it is successful, unless you modify the
sources or makefiles within the jni/ directory structure, you should
not need to run "ndk-build" again.
Application Programming
The classes that make up the built-in Android SQLite interface reside
in the "android.database.sqlite" namespace. This interface provides
all of the same classes, except within the
"org.sqlite.database.sqlite" namespace. This means that to modify an
application to use the custom version of SQLite, all that is usually
required is to replace all occurrences "android.database.sqlite"
within the source code with "org.sqlite.database.sqlite".
For example,the following:
import android.database.sqlite.SQLiteDatabase;
should be replaced with:
import org.sqlite.database.sqlite.SQLiteDatabase;
As well as replacing all uses of the classes in the android.database.sqlite.*
namespace, the application must also be sure to use the following two:
org.sqlite.database.SQLException
org.sqlite.database.DatabaseErrorHandler
instead of:
android.database.SQLException
android.database.DatabaseErrorHandler
Aside from namespace changes,
there are other differences from the stock Android interface that
applications need to be aware of:
The SQLiteStatement.simpleQueryForBlobFileDescriptor() API is not
available.
The collation sequence "UNICODE" is not available.
The collation sequence "LOCALIZED", which normally changes with the
system's current locale, is always equivalent to SQLite's built in
collation BINARY.
Disclaimer: i have only used this method for standalone executables, not libraries that implement JNI functions. It may work for a .so or not. Also, i'm working with a custom Android device not a phone.
You can use the built in SQLite via NDK but it's more of a hack than something supported. You need to nick sqlite3.h and libsqlite.so from an android source distribution and compile using them. Put sqlite3.h in your application source directory and you need to put the .so somewhere under the out/yourapp directory or build/platform/android-x/arch-arm/usr/lib for the linking step to finish. I have it in both places but i'm not sure which one is really needed.
You will end up linking to the libsqlite.so you provided but the binary will run fine using the system libsqlite.so on a target device.

What is an App Bundle on Mac?

I have a basic C++ applicatin build using g++ and -framework ...
when I run it, I get a :
Working in unbundled mode. You should build a .app wrapper for your Mac OS X applications.
(which is not std::couted by any of my application).
What causes this, and how can I get rid of it?
Thanks!
You need to create a folder structure and place the binary in a special location. For an example with explanation see this Qt page
Mac OS X handles most applications as "bundles". A bundle is a directory structure that groups related files together. Bundles are used for GUI applications, frameworks, and installer packages. These are presented to the user as one file in the Finder. When set up correctly, bundles make for easy deployment. All one needs to do is to archive the application using some preferred method. Users then open the archive and drag the application to wherever they please and are ready to go.
There is something written about this for wxWidgets too
MacOSX introduces a new way of putting together an application. Instead of adding a resource fork to the executable file, you can simply create a special directory (folder). This is the preferred method for OSX.