Skip to content

Commit b40faaa

Browse files
committed
Fix download of not fully downloaded media
1 parent 956b9fe commit b40faaa

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

app/src/main/java/com/wmods/wppenhacer/xposed/core/components/FMessageWpp.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import androidx.annotation.Nullable;
55

66
import com.wmods.wppenhacer.xposed.core.WppCore;
7+
import com.wmods.wppenhacer.xposed.core.db.MessageStore;
78
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
89
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
910

@@ -163,8 +164,12 @@ public File getMediaFile() {
163164
if (field.getType().isPrimitive()) continue;
164165
var fileField = ReflectionUtils.getFieldByType(field.getType(), File.class);
165166
if (fileField != null) {
166-
var mediaFile = ReflectionUtils.getObjectField(field, fmessage);
167-
return (File) fileField.get(mediaFile);
167+
var mediaObject = ReflectionUtils.getObjectField(field, fmessage);
168+
var mediaFile = (File) fileField.get(mediaObject);
169+
if (mediaFile != null) return mediaFile;
170+
var filePath = MessageStore.getInstance().getMediaFromID(getRowId());
171+
if (filePath == null) return null;
172+
return new File(filePath);
168173
}
169174
}
170175
} catch (Exception e) {

app/src/main/java/com/wmods/wppenhacer/xposed/features/media/DownloadViewOnce.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
7373
item.setOnMenuItemClickListener(item1 -> {
7474
try {
7575
var file = fMessage.getMediaFile();
76+
if (file == null) {
77+
Utils.showToast(Utils.getApplication().getString(ResId.string.download_not_available), 1);
78+
return true;
79+
}
7680
downloadFile(fMessage.getKey().remoteJid, file);
7781
} catch (Exception e) {
7882
Utils.showToast(e.getMessage(), Toast.LENGTH_LONG);
@@ -99,6 +103,10 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
99103
var fmessageObj = WppCore.getFMessageFromKey(keyMessageObj);
100104
var fmessage = new FMessageWpp(fmessageObj);
101105
var file = fmessage.getMediaFile();
106+
if (file == null) {
107+
Utils.showToast(Utils.getApplication().getString(ResId.string.download_not_available), 1);
108+
return;
109+
}
102110
var userJid = fmessage.getKey().remoteJid;
103111
try {
104112
downloadFile(userJid, file);

app/src/main/java/com/wmods/wppenhacer/xposed/features/media/StatusDownload.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Collections;
2626

2727
import de.robv.android.xposed.XSharedPreferences;
28-
import de.robv.android.xposed.XposedHelpers;
2928

3029
public class StatusDownload extends Feature {
3130

@@ -89,6 +88,10 @@ private void sharedStatus(FMessageWpp fMessageWpp) {
8988
return;
9089
}
9190
var file = fMessageWpp.getMediaFile();
91+
if (file == null) {
92+
Utils.showToast(Utils.getApplication().getString(ResId.string.download_not_available), 1);
93+
return;
94+
}
9295
Intent intent = new Intent();
9396
var clazz = Unobfuscator.getClassByName("MediaComposerActivity", classLoader);
9497
intent.setClassName(Utils.getApplication().getPackageName(), clazz.getName());
@@ -104,6 +107,10 @@ private void sharedStatus(FMessageWpp fMessageWpp) {
104107
private void downloadFile(FMessageWpp fMessage) {
105108
try {
106109
var file = fMessage.getMediaFile();
110+
if (file == null) {
111+
Utils.showToast(Utils.getApplication().getString(ResId.string.download_not_available), 1);
112+
return;
113+
}
107114
var userJid = fMessage.getUserJid();
108115
var fileType = file.getName().substring(file.getName().lastIndexOf(".") + 1);
109116
var destination = getStatusDestination(file);

app/src/main/java/com/wmods/wppenhacer/xposed/utils/ResId.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public static class string {
103103
public static int download_folder_permission;
104104
public static int no_contact_with_custom_privacy;
105105
public static int select_contacts;
106+
public static int download_not_available;
106107
}
107108

108109
public static class array {

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,5 @@
415415
<string name="disable_the_proximity_sensor_sum">Disable Screen off on proximity sensor to the whole WhatsApp</string>
416416
<string name="disable_status_in_the_profile_photo">Disable Status in the profile photo</string>
417417
<string name="disable_status_in_the_profile_photo_sum">Disables the circle that appears in the profile photo of each contact when there is new status</string>
418+
<string name="download_not_available">Download not available or media has not been fully downloaded</string>
418419
</resources>

0 commit comments

Comments
 (0)