1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-22 16:56:16 +00:00

Preparations for caching downloaded files.

This commit is contained in:
Fabian Schlenz 2016-07-14 06:43:44 +02:00
parent ffddfe68d1
commit b4c50a0163
2 changed files with 6 additions and 12 deletions

View File

@ -54,6 +54,7 @@ public abstract class AbstractMediaFileManager {
public abstract String getExtension(); public abstract String getExtension();
public boolean isEmpty() { return isEmpty; } public boolean isEmpty() { return isEmpty; }
public boolean isDownloaded() { return new File(getTargetPathAndFilename()).isFile(); } public boolean isDownloaded() { return new File(getTargetPathAndFilename()).isFile(); }
public boolean isDownloading() { return new File(getTargetPathAndFilename() + ".downloading").isFile(); }
public abstract void download() throws RpcErrorException, IOException; public abstract void download() throws RpcErrorException, IOException;
public static void throwUnexpectedObjectError(Object o) { public static void throwUnexpectedObjectError(Object o) {
throw new RuntimeException("Unexpected " + o.getClass().getName()); throw new RuntimeException("Unexpected " + o.getClass().getName());

View File

@ -47,19 +47,10 @@ public class StickerFileManager extends DocumentFileManager {
public StickerFileManager(TLMessage msg, UserManager user, TelegramClient client) { public StickerFileManager(TLMessage msg, UserManager user, TelegramClient client) {
super(msg, user, client); super(msg, user, client);
} }
/* TLAbsDocument d = ((TLMessageMediaDocument)msg.getMedia()).getDocument();
if (d instanceof TLDocument) {
this.doc = (TLDocument)d;
} else if (d instanceof TLDocumentEmpty) {
this.isEmpty = true;
} else {
throwUnexpectedObjectError(d);
}
}*/
public boolean isSticker() { return true; } public boolean isSticker() { return true; }
public String getTargetFilename() { private String getFilenameBase() {
TLDocumentAttributeSticker sticker = null; TLDocumentAttributeSticker sticker = null;
for(TLAbsDocumentAttribute attr : doc.getAttributes()) { for(TLAbsDocumentAttribute attr : doc.getAttributes()) {
if (attr instanceof TLDocumentAttributeSticker) { if (attr instanceof TLDocumentAttributeSticker) {
@ -75,11 +66,13 @@ public class StickerFileManager extends DocumentFileManager {
} }
file.append("_"); file.append("_");
file.append(sticker.getAlt().hashCode()); file.append(sticker.getAlt().hashCode());
file.append(".");
file.append(getExtension());
return file.toString(); return file.toString();
} }
public String getTargetFilename() {
return getFilenameBase() + "." + getExtension();
}
public String getTargetPath() { public String getTargetPath() {
String path = Config.FILE_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar; String path = Config.FILE_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar;
new File(path).mkdirs(); new File(path).mkdirs();