SupportedPackageType supportedPackageType = determinePackageType(file);
if (supportedPackageType == null) {
return null; // we can't handle this file - it is an unknown/unsupported package type
}
ContentFileInfo fileInfo = ContentFileInfoFactory.createContentFileInfo(file);
String sha256;
try {
sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(file);
} catch (IOException e) {
throw new SyncException("Error digesting file", e);
}
String name = file.getName();
String version = "[sha256=" + sha256 + "]";
String displayVersion = fileInfo.getVersion(null);
String packageTypeName = supportedPackageType.packageTypeName;
String architectureName = supportedPackageType.architectureName;
String resourceTypeName = supportedPackageType.resourceTypeName;
String resourceTypePluginName = supportedPackageType.resourceTypePluginName;
ContentProviderPackageDetailsKey key = new ContentProviderPackageDetailsKey(name, version, packageTypeName,
architectureName, resourceTypeName, resourceTypePluginName);
ContentProviderPackageDetails pkg = new ContentProviderPackageDetails(key);
pkg.setDisplayName(name);
pkg.setFileName(name);
pkg.setFileCreatedDate(file.lastModified());
pkg.setFileSize(file.length());
pkg.setSHA256(sha256);
pkg.setDisplayVersion(displayVersion);
pkg.setLocation(getRelativePath(file));
pkg.setShortDescription(fileInfo.getDescription(null));
return pkg;
}