Skip to content

Commit

Permalink
Fix issue with unsaved contact download
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev4Mod committed Jun 22, 2024
1 parent dcfc7e6 commit 6ba33e6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
12 changes: 6 additions & 6 deletions app/src/main/java/com/wmods/wppenhacer/xposed/core/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) -> {
});
}
}
15 changes: 11 additions & 4 deletions app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
15 changes: 1 addition & 14 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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)
* Fixed issue with unsaved contact download

0 comments on commit 6ba33e6

Please sign in to comment.