From 6ba33e6504cf703c9023e8c502946fa6201596c9 Mon Sep 17 00:00:00 2001 From: Dev4Mod Date: Sat, 22 Jun 2024 20:32:21 -0300 Subject: [PATCH] Fix issue with unsaved contact download --- .../com/wmods/wppenhacer/xposed/core/Utils.java | 12 ++++++------ .../com/wmods/wppenhacer/xposed/core/WppCore.java | 15 +++++++++++---- .../xposed/features/media/DownloadViewOnce.java | 5 +++-- .../xposed/features/media/StatusDownload.java | 1 - changelog.txt | 15 +-------------- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/wmods/wppenhacer/xposed/core/Utils.java b/app/src/main/java/com/wmods/wppenhacer/xposed/core/Utils.java index 978fa3f3..c29628fa 100644 --- a/app/src/main/java/com/wmods/wppenhacer/xposed/core/Utils.java +++ b/app/src/main/java/com/wmods/wppenhacer/xposed/core/Utils.java @@ -170,6 +170,7 @@ public static String copyFile(File srcFile, File destFile) { if (read <= 0) { in.close(); out.close(); + Utils.scanFile(destFile); return ""; } out.write(bArr, 0, read); @@ -198,20 +199,19 @@ public static void setToClipboard(String string) { public static String generateName(Object userJid, String fileFormat) { var contactName = WppCore.getContactName(userJid); var number = WppCore.stripJID(WppCore.getRawString(userJid)); - return padronizarNome(contactName) + "_" + number + "_" + new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.getDefault()).format(new Date()) + "." + fileFormat; + return toValidFileName(contactName) + "_" + number + "_" + new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.getDefault()).format(new Date()) + "." + fileFormat; } @NonNull - public static String padronizarNome(@NonNull String nome) { - String nomePadronizado = nome.replaceAll("[^a-zA-Z0-9 _]", ""); - nomePadronizado = nomePadronizado.replace(' ', '_'); - return nomePadronizado; + public static String toValidFileName(@NonNull String input) { + return input.replaceAll("[:\\\\/*\"?|<>']", " "); } public static void scanFile(File file) { MediaScannerConnection.scanFile(Utils.getApplication(), new String[]{file.getAbsolutePath()}, new String[]{MimeTypeUtils.getMimeTypeFromExtension(file.getAbsolutePath())}, - null); + (s, uri) -> { + }); } } diff --git a/app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java b/app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java index d5bf8399..b3a9fd2a 100644 --- a/app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java +++ b/app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java @@ -84,7 +84,6 @@ public static void sendMessage(String number, String message) { } } - public static void Initialize(ClassLoader loader) throws Exception { privPrefs = Utils.getApplication().getSharedPreferences("WaGlobal", Context.MODE_PRIVATE); @@ -184,14 +183,21 @@ public static int getDefaultTheme() { public static String getContactName(Object userJid) { loadDatabase(); if (mWaDatabase == null || userJid == null) return ""; + String name = null; var rawJid = getRawString(userJid); var cursor = mWaDatabase.query("wa_contacts", new String[]{"display_name"}, "jid = ?", new String[]{rawJid}, null, null, null); if (cursor != null && cursor.moveToFirst()) { - var name = cursor.getString(0); + name = cursor.getString(0); cursor.close(); - return name; } - return ""; + if (name == null) { + var cursor2 = mWaDatabase.query("wa_vnames", new String[]{"verified_name"}, "jid = ?", new String[]{rawJid}, null, null, null); + if (cursor2 != null && cursor2.moveToFirst()) { + name = cursor2.getString(0); + cursor2.close(); + } + } + return name == null ? "" : name; } public static Object createUserJid(String rawjid) { @@ -279,6 +285,7 @@ public static Dialog createDialog(Context context) { @Nullable public static Activity getCurrentConversation() { + if (mCurrentActivity == null) return null; Class conversation = XposedHelpers.findClass("com.whatsapp.Conversation", mCurrentActivity.getClassLoader()); if (conversation.isInstance(mCurrentActivity)) return mCurrentActivity; return null; diff --git a/app/src/main/java/com/wmods/wppenhacer/xposed/features/media/DownloadViewOnce.java b/app/src/main/java/com/wmods/wppenhacer/xposed/features/media/DownloadViewOnce.java index 2a1c875b..33591fec 100644 --- a/app/src/main/java/com/wmods/wppenhacer/xposed/features/media/DownloadViewOnce.java +++ b/app/src/main/java/com/wmods/wppenhacer/xposed/features/media/DownloadViewOnce.java @@ -59,8 +59,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { var fileData = XposedHelpers.getObjectField(message, "A01"); var file = (File) ReflectionUtils.getField(fileField, fileData); var dest = Utils.getDestination(prefs, "View Once"); - var userJid = new FMessageWpp(message).getUserJid(); - var name = Utils.generateName(userJid, "jpg"); + var userJid = new FMessageWpp(message).getKey().remoteJid; + var fileExtension = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".") + 1); + var name = Utils.generateName(userJid, fileExtension); var error = Utils.copyFile(file, new File(dest, name)); if (TextUtils.isEmpty(error)) { Utils.showToast(Utils.getApplication().getString(ResId.string.saved_to) + dest, Toast.LENGTH_LONG); diff --git a/app/src/main/java/com/wmods/wppenhacer/xposed/features/media/StatusDownload.java b/app/src/main/java/com/wmods/wppenhacer/xposed/features/media/StatusDownload.java index 32ff5e40..82c93977 100644 --- a/app/src/main/java/com/wmods/wppenhacer/xposed/features/media/StatusDownload.java +++ b/app/src/main/java/com/wmods/wppenhacer/xposed/features/media/StatusDownload.java @@ -84,7 +84,6 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { var name = Utils.generateName(userJid, fileType); var destinationFile = new File(destination, name); var error = Utils.copyFile(file, destinationFile); - Utils.scanFile(destinationFile); if (TextUtils.isEmpty(error)) { Utils.showToast(Utils.getApplication().getString(ResId.string.saved_to) + destinationFile.getAbsolutePath(), Toast.LENGTH_SHORT); log("Saved to: " + destinationFile.getAbsolutePath()); diff --git a/changelog.txt b/changelog.txt index 9cb055ca..32b9419b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,15 +1,2 @@ -[WA ENHANCER] -* Added reset button to settings -* Backups will now have a date in the name -* Fixed errors in backups for the block list(old backups will not be supported) -* All modules have been updated to facilitate maintenance - [STATUS DOWNLOADER | VIEW ONCE DOWNLOADER | PROFILE PICTURE DOWNLOADER] -* The saved file names will now have the user name, phone number and date (Ex: Mary_12345678_20240622-181400.jpg) - -[TASKER] -* Added %name variable to events - -[WHATSAPP] -* Added support for version 2.24.12.78 -* Unsupported versions will no longer be applied to the features (Avoid reporting an unsupported version and downgrading the version) \ No newline at end of file +* Fixed issue with unsaved contact download \ No newline at end of file