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"; }