static int copyFileToPhone_chunkSize = 500000; // see #1004128 static void copyFileToPhone(S localPath, S destPath, bool withContinue) { copyFileToPhone(new File(localPath), destPath, withContinue); } static void copyFileToPhone(File f, S destPath, bool withContinue) { if (!f.isFile()) fail("Not a file: " + f2s(f)); if (destPath.endsWith("/")) destPath += f.getName(); long i = 0; long len = f.length(); DialogIO io = talkTo(gateway(), 4999); try { if (withContinue) { i = parseLong(io.askLoudly(forward("Awareness", "get file * length", destPath))); if (i == len) { print("File fully copied"); ret; } } if (i == 0) io.askLoudly(forward("Awareness", "delete file *", destPath)); for (; i < len; i += copyFileToPhone_chunkSize) { print("[Copying file to phone, " + i + "/" + len + "]"); long j = min(len, i+copyFileToPhone_chunkSize); byte[] data = loadBinaryFileChunk(f, i, toInt(j-i)); S answer = io.ask(forward("Awareness", "write file * bin from * data *", destPath, i, bytesToHex(data))); assertTrue(answer, match("OK", answer)); } } finally { io.close(); } }