import scala.util.control.Breaks;
-object Setup {
- private final val TAG = "Setup";
- private val BREAK = new Breaks;
- import BREAK.{breakable, break};
-
- def setup(ctx: Context) {
- val bindir = ctx.getDir("bin", MODE_WORLD_READABLE);
- val assets = ctx.getAssets;
-
- val abis =
- try { classOf[Build].getField("SUPPORTED_ABIS").get(null).asInstanceOf[Array[String]] }
- catch {
- case _: NoSuchFieldException => Array(CPU_ABI, CPU_ABI2) flatMap {
- case null | "" => None
- case s => Some(s)
- }
- };
-
- Log.d(TAG, s"abis = ${abis.mkString(", ")}");
- Log.d(TAG, s"assets: ${assets.list("bin").mkString(", ")}");
-
- for (abi <- abis) {
- val binsrc = s"bin/$abi";
- for (base <- assets.list(binsrc)) {
- val prog = new File(bindir, base);
- if (!prog.exists) try {
- Log.d(TAG, s"creating $prog...");
- val in = assets.open(s"$binsrc/$base");
- Log.d(TAG, "opened source...");
- val out = new FileOutputStream(prog);
- Log.d(TAG, "opened target...");
- val buf = new Array[Byte](4096);
- breakable {
- while (true) {
- val n = in.read(buf);
- Log.d(TAG, s"read $n bytes...");
- if (n <= 0) break;
- out.write(buf, 0, n);
- }
- }
- in.close();
- out.close();
- Log.d(TAG, "set permissions...");
- if (!prog.setReadable(true, false) ||
- !prog.setExecutable(true, false))
- throw new IOException("failed to set program permissions");
- } catch {
- case exc: IOException =>
- Log.wtf(TAG, "fuck, failed to create prog", exc);
- }
- }
- }
- Log.d(TAG, "all OK");
- }
-}
object ToyActivity {
private final val TAG = "ToyActivity";
override protected def onCreate(joy: Bundle) {
super.onCreate(joy);
- Setup.setup(this);
+ app.setup(this);
setContentView(R.layout.toy);
Log.d(TAG, s"created ${this}");
}