install non-APK files
Now that F-Droid repos can handle any kind of file, F-Droid client needs to be able to "install" them. What that actually means depends on what kind of file is. For the vast majority of files, this means copying the file into a standard folder. So "installed" means that the file is present in that standard folder. There could also be a check to make sure the "installed" file is the same size as what is listed in the F-Droid repo index.
Here's some sketch Java code for some of this:
private String getMediaInstalledStatus(final Apk apk) {
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(apk.getUrl());
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String[] mimeType = mimeTypeMap.getMimeTypeFromExtension(fileExtension).split("/");
String topLevelType;
if (mimeType.length == 0) {
topLevelType = "";
} else {
topLevelType = mimeType[0];
}
File path = null;
if ("audio".equals(topLevelType)) {
path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MUSIC);
} else if ("image".equals(topLevelType)) {
path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
} else if ("video".equals(topLevelType)) {
path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MOVIES);
// TODO support OsmAnd map files, other map apps?
} else if (mimeTypeMap.hasExtension("map")) { // OsmAnd map files
} else if (apk.apkName.endsWith(".ota.zip")) { // Over-The-Air update ZIP files
} else {
path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS);
}
Log.i(TAG, "getMediaInstalledStatus " + new File(path, apk.apkName));
if (path != null && new File(path, apk.apkName).isFile()) {
return getString(R.string.app_not_installed);
}
return getString(R.string.app_not_installed);
}