mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-10-08 14:09:41 +02:00
Pebble: copy pebble-app-js.js out of the pbw upon installation not upon reading the .pbw
This eliminates the need to copy the whole file into a byte[], and all file size limts are gone.
This commit is contained in:
parent
88982a6174
commit
a3ee3c15fc
@ -13,6 +13,7 @@ import java.io.File;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
@ -167,21 +168,14 @@ public class PBWInstallHandler implements InstallHandler {
|
|||||||
LOG.error(e.getMessage(), e);
|
LOG.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
String jsConfigFile = mPBWReader.getJsConfigurationFile();
|
InputStream jsConfigFile = mPBWReader.getInputStreamFile("pebble-js-app.js");
|
||||||
|
|
||||||
if (jsConfigFile != null) {
|
if (jsConfigFile != null) {
|
||||||
outputFile = new File(destDir, app.getUUID().toString() + "_config.js");
|
outputFile = new File(destDir, app.getUUID().toString() + "_config.js");
|
||||||
try {
|
try {
|
||||||
writer = new BufferedWriter(new FileWriter(outputFile));
|
FileUtils.copyStreamToFile(jsConfigFile, outputFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("Failed to open output file: " + e.getMessage(), e);
|
LOG.error("Failed to open output file: " + e.getMessage(), e);
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
writer.write(jsConfigFile);
|
|
||||||
writer.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.error("Failed to write to output file: " + e.getMessage(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,6 @@ public class PBWReader {
|
|||||||
private short mAppVersion;
|
private short mAppVersion;
|
||||||
private int mIconId;
|
private int mIconId;
|
||||||
private int mFlags;
|
private int mFlags;
|
||||||
private String jsConfigurationFile = null;
|
|
||||||
|
|
||||||
private JSONObject mAppKeys = null;
|
private JSONObject mAppKeys = null;
|
||||||
|
|
||||||
@ -213,20 +212,6 @@ public class PBWReader {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (fileName.equals("pebble-js-app.js")) {
|
|
||||||
LOG.info("Found JS file: app supports configuration.");
|
|
||||||
long bytes = ze.getSize();
|
|
||||||
if (bytes > 65536) {
|
|
||||||
LOG.info("size exceeding 64k, skipping");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
while ((count = zis.read(buffer)) != -1) {
|
|
||||||
baos.write(buffer, 0, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
jsConfigurationFile = baos.toString();
|
|
||||||
} else if (fileName.equals(platformDir + "pebble-app.bin")) {
|
} else if (fileName.equals(platformDir + "pebble-app.bin")) {
|
||||||
zis.read(buffer, 0, 108);
|
zis.read(buffer, 0, 108);
|
||||||
byte[] tmp_buf = new byte[32];
|
byte[] tmp_buf = new byte[32];
|
||||||
@ -342,8 +327,4 @@ public class PBWReader {
|
|||||||
public JSONObject getAppKeysJSON() {
|
public JSONObject getAppKeysJSON() {
|
||||||
return mAppKeys;
|
return mAppKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJsConfigurationFile() {
|
|
||||||
return jsConfigurationFile;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -47,6 +47,16 @@ public class FileUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void copyStreamToFile(InputStream inputStream, File destFile) throws IOException {
|
||||||
|
FileOutputStream fout = new FileOutputStream(destFile);
|
||||||
|
byte[] buf = new byte[4096];
|
||||||
|
while (inputStream.available() > 0) {
|
||||||
|
int bytes = inputStream.read(buf);
|
||||||
|
fout.write(buf, 0, bytes);
|
||||||
|
}
|
||||||
|
fout.close();
|
||||||
|
}
|
||||||
|
|
||||||
public static void copyURItoFile(Context ctx, Uri uri, File destFile) throws IOException {
|
public static void copyURItoFile(Context ctx, Uri uri, File destFile) throws IOException {
|
||||||
if (uri.getPath().equals(destFile.getPath())) {
|
if (uri.getPath().equals(destFile.getPath())) {
|
||||||
return;
|
return;
|
||||||
@ -60,14 +70,8 @@ public class FileUtils {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FileOutputStream fout = new FileOutputStream(destFile);
|
copyStreamToFile(fin, destFile);
|
||||||
byte[] buf = new byte[4096];
|
|
||||||
while (fin.available() > 0) {
|
|
||||||
int bytes = fin.read(buf);
|
|
||||||
fout.write(buf, 0, bytes);
|
|
||||||
}
|
|
||||||
fin.close();
|
fin.close();
|
||||||
fout.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getStringFromFile(File file) throws IOException {
|
public static String getStringFromFile(File file) throws IOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user