From 3a615f94aff2dabff407e09485d97add1fe10b5f Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 5 Oct 2016 13:41:11 +0200 Subject: [PATCH] Moved the stickers into the files directory of the individual accounts. Instead of downloading the stickers again, they will be copied from the old location. Closes #25. --- .../mediafilemanager/StickerFileManager.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.java b/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.java index 48d7219..dcc165e 100644 --- a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.java @@ -33,9 +33,16 @@ import com.github.badoualy.telegram.tl.api.upload.TLFile; import com.github.badoualy.telegram.tl.exception.RpcErrorException; import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.IOException; import java.io.File; import java.io.FileOutputStream; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.LinkedList; import java.net.URL; @@ -44,6 +51,8 @@ import java.util.concurrent.TimeoutException; import org.apache.commons.io.FileUtils; public class StickerFileManager extends DocumentFileManager { + private static Logger logger = LoggerFactory.getLogger(StickerFileManager.class); + public StickerFileManager(TLMessage msg, UserManager user, TelegramClient client) { super(msg, user, client); } @@ -74,9 +83,21 @@ public class StickerFileManager extends DocumentFileManager { } public String getTargetPath() { - String path = Config.FILE_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar; + String path = user.getFileBase() + Config.FILE_FILES_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar; new File(path).mkdirs(); return path; + } + + public void download() throws RpcErrorException, IOException { + String old_file = Config.FILE_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar + getTargetFilename(); + + logger.trace("Old filename exists: {}", new File(old_file).exists()); + + if (new File(old_file).exists()) { + Files.copy(Paths.get(old_file), Paths.get(getTargetPathAndFilename()), StandardCopyOption.REPLACE_EXISTING); + return; + } + super.download(); } public String getExtension() { return "webp"; }