mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 12:56:49 +01: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.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Writer;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
@ -167,21 +168,14 @@ public class PBWInstallHandler implements InstallHandler {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
String jsConfigFile = mPBWReader.getJsConfigurationFile();
|
||||
InputStream jsConfigFile = mPBWReader.getInputStreamFile("pebble-js-app.js");
|
||||
|
||||
if (jsConfigFile != null) {
|
||||
outputFile = new File(destDir, app.getUUID().toString() + "_config.js");
|
||||
try {
|
||||
writer = new BufferedWriter(new FileWriter(outputFile));
|
||||
FileUtils.copyStreamToFile(jsConfigFile, outputFile);
|
||||
} catch (IOException 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 int mIconId;
|
||||
private int mFlags;
|
||||
private String jsConfigurationFile = null;
|
||||
|
||||
private JSONObject mAppKeys = null;
|
||||
|
||||
@ -213,20 +212,6 @@ public class PBWReader {
|
||||
e.printStackTrace();
|
||||
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")) {
|
||||
zis.read(buffer, 0, 108);
|
||||
byte[] tmp_buf = new byte[32];
|
||||
@ -342,8 +327,4 @@ public class PBWReader {
|
||||
public JSONObject getAppKeysJSON() {
|
||||
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 {
|
||||
if (uri.getPath().equals(destFile.getPath())) {
|
||||
return;
|
||||
@ -60,14 +70,8 @@ public class FileUtils {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
FileOutputStream fout = new FileOutputStream(destFile);
|
||||
byte[] buf = new byte[4096];
|
||||
while (fin.available() > 0) {
|
||||
int bytes = fin.read(buf);
|
||||
fout.write(buf, 0, bytes);
|
||||
}
|
||||
copyStreamToFile(fin, destFile);
|
||||
fin.close();
|
||||
fout.close();
|
||||
}
|
||||
|
||||
public static String getStringFromFile(File file) throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user