From bbf02e29e5967a9f37106e17eb65479b87b86f23 Mon Sep 17 00:00:00 2001 From: Ryan Teal Date: Wed, 3 Jul 2019 18:42:12 +0100 Subject: [PATCH] Fix hacky icon loading method --- .../main/java/gq/cyuubi/lightswitch/NroMeta.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java b/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java index 1a9d2e95..19c65da4 100644 --- a/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java +++ b/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java @@ -1,6 +1,9 @@ package gq.cyuubi.lightswitch; import android.util.Log; +import android.widget.ImageView; + +import com.squareup.picasso.Picasso; import java.io.FileOutputStream; import java.io.IOException; @@ -56,7 +59,7 @@ public class NroMeta { } } - public static String LoadImage(String file, MainActivity context) { + public static void LoadImage(String file, ImageView target, MainActivity context) { try { RandomAccessFile f = new RandomAccessFile(file, "r"); f.seek(0x18); // Skip to NroHeader.size @@ -65,24 +68,24 @@ public class NroMeta { byte[] buffer = new byte[4]; f.read(buffer); if(!(new String(buffer).equals("ASET"))) - return null; + return; f.skipBytes(0x4); long iconOffset = Long.reverseBytes(f.readLong()); long iconSize = Long.reverseBytes(f.readLong()); if(iconOffset == 0 || iconSize == 0) - return null; + return; f.seek(asetOffset + iconOffset); byte[] iconData = new byte[(int)iconSize]; f.read(iconData); new FileOutputStream(context.getFilesDir() + "/tmp.jpg").write(iconData); - return context.getFilesDir() + "/tmp.jpg"; + Picasso.with(context).load(context.getFilesDir() + "/tmp.jpg").into(target); } catch(IOException e) { Log.e("app_process64", "Error while loading ASET: " + e.getMessage()); - return null; + return; } } }