1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-23 01:06:17 +00:00

Don't die with NPEs if a MediaFileManager tries to download an Empty media thing.

This commit is contained in:
Fabian Schlenz 2016-07-11 06:34:16 +02:00
parent 468c5517dd
commit 71150a36d2
2 changed files with 11 additions and 3 deletions

View File

@ -68,10 +68,14 @@ public class DocumentFileManager extends AbstractMediaFileManager {
return sticker!=null; return sticker!=null;
} }
public int getSize() { return doc.getSize(); } public int getSize() {
if (doc != null) return doc.getSize();
return 0;
}
public String getExtension() { public String getExtension() {
if (extension != null) return extension; if (extension != null) return extension;
if (doc == null) return "empty";
String ext = null; String ext = null;
String original_filename = null; String original_filename = null;
for(TLAbsDocumentAttribute attr : doc.getAttributes()) { for(TLAbsDocumentAttribute attr : doc.getAttributes()) {
@ -92,8 +96,10 @@ public class DocumentFileManager extends AbstractMediaFileManager {
} }
public void download() throws RpcErrorException, IOException { public void download() throws RpcErrorException, IOException {
if (doc!=null) {
DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), doc.getDcId(), doc.getId(), doc.getAccessHash()); DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), doc.getDcId(), doc.getId(), doc.getAccessHash());
} }
}
public String getLetter() { return "d"; } public String getLetter() { return "d"; }
public String getName() { return "document"; } public String getName() { return "document"; }

View File

@ -70,12 +70,14 @@ public class PhotoFileManager extends AbstractMediaFileManager {
} }
public int getSize() { public int getSize() {
return size.getSize(); if (size!=null) return size.getSize();
return 0;
} }
public String getExtension() { return "jpg"; } public String getExtension() { return "jpg"; }
public void download() throws RpcErrorException, IOException { public void download() throws RpcErrorException, IOException {
if (isEmpty) return;
TLFileLocation loc = (TLFileLocation) size.getLocation(); TLFileLocation loc = (TLFileLocation) size.getLocation();
DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), loc.getVolumeId(), loc.getLocalId(), loc.getSecret()); DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), loc.getVolumeId(), loc.getLocalId(), loc.getSecret());
} }