Try all supported ABIs for the executable on Android.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4496 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		| @@ -54,36 +54,11 @@ public class MainActivity extends Activity { | ||||
| 		setContentView(R.layout.activity_main); | ||||
|  | ||||
| 		web_view = (WebView)findViewById(R.id.web); | ||||
| 		String arch = System.getProperty("os.arch"); | ||||
| 		Log.w("tildefriends", String.format("getFilesDir() is %s", getFilesDir().toString())); | ||||
| 		Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString())); | ||||
| 		Log.w("tildefriends", String.format("os.arch is %s", arch)); | ||||
|  | ||||
| 		try (ZipInputStream zip = new ZipInputStream(new BufferedInputStream(new FileInputStream(getPackageResourcePath().toString())))) { | ||||
| 			ZipEntry entry = null; | ||||
| 			String lookup = String.format("bin/%s/tildefriends", arch); | ||||
| 			Log.w("tildefriends", "Looking for " + lookup); | ||||
| 			while ((entry = zip.getNextEntry()) != null) { | ||||
| 				if (entry.getName().equals(lookup)) { | ||||
| 					Log.w("tildefriends", "Extracting " + entry.getName()); | ||||
| 					try (FileOutputStream out = new FileOutputStream(getFilesDir().toString().concat("/tildefriends"))) { | ||||
| 						byte[] buffer = new byte[32768]; | ||||
| 						int count; | ||||
| 						while ((count = zip.read(buffer)) != -1) { | ||||
| 							out.write(buffer, 0, count); | ||||
| 						} | ||||
| 						out.close(); | ||||
| 						new File(getFilesDir().toString() + "/tildefriends").setExecutable(true); | ||||
| 					} | ||||
| 				} | ||||
| 				zip.closeEntry(); | ||||
| 			} | ||||
| 		} catch (java.io.FileNotFoundException e) { | ||||
| 			Log.w("tildefriends", "FileNotFoundException extracting executable"); | ||||
| 			Log.w("tildefriends", e.toString()); | ||||
| 		} catch (java.io.IOException e) { | ||||
| 			Log.w("tildefriends", "IOException extracting executable"); | ||||
| 			Log.w("tildefriends", e.toString()); | ||||
| 		if (!extract_executable()) { | ||||
| 			Log.w("tildefriends", "Failed to extract a compatible executable."); | ||||
| 		} | ||||
|  | ||||
| 		String port_file_path = getFilesDir().toString() + "/port.txt"; | ||||
| @@ -198,6 +173,41 @@ public class MainActivity extends Activity { | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	private boolean extract_executable() | ||||
| 	{ | ||||
| 		try (ZipInputStream zip = new ZipInputStream(new BufferedInputStream(new FileInputStream(getPackageResourcePath().toString())))) { | ||||
| 			ZipEntry entry = null; | ||||
| 			for (String abi : android.os.Build.SUPPORTED_ABIS) | ||||
| 			{ | ||||
| 				String lookup = String.format("bin/%s/tildefriends", abi); | ||||
| 				Log.w("tildefriends", "Looking for " + lookup); | ||||
| 				while ((entry = zip.getNextEntry()) != null) { | ||||
| 					if (entry.getName().equals(lookup)) { | ||||
| 						Log.w("tildefriends", "Extracting " + entry.getName()); | ||||
| 						try (FileOutputStream out = new FileOutputStream(getFilesDir().toString().concat("/tildefriends"))) { | ||||
| 							byte[] buffer = new byte[32768]; | ||||
| 							int count; | ||||
| 							while ((count = zip.read(buffer)) != -1) { | ||||
| 								out.write(buffer, 0, count); | ||||
| 							} | ||||
| 							out.close(); | ||||
| 							new File(getFilesDir().toString() + "/tildefriends").setExecutable(true); | ||||
| 							return true; | ||||
| 						} | ||||
| 					} | ||||
| 					zip.closeEntry(); | ||||
| 				} | ||||
| 			} | ||||
| 		} catch (java.io.FileNotFoundException e) { | ||||
| 			Log.w("tildefriends", "FileNotFoundException extracting executable"); | ||||
| 			Log.w("tildefriends", e.toString()); | ||||
| 		} catch (java.io.IOException e) { | ||||
| 			Log.w("tildefriends", "IOException extracting executable"); | ||||
| 			Log.w("tildefriends", e.toString()); | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	protected void onDestroy() | ||||
| 	{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user