From e01a596bc0ab0ee76ea532ae3fbd0cdc5efda1e3 Mon Sep 17 00:00:00 2001 From: Hong Chen Date: Mon, 12 Mar 2018 11:01:58 -0700 Subject: [PATCH] wait on retrying oms connectivity --- .../lrstudios/android/pachi/PachiEngine.java | 65 ++++++++++--------- .../games/ego/lib/ui/NewGameActivity.java | 20 ++++++ 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/net/lrstudios/android/pachi/PachiEngine.java b/app/src/main/java/net/lrstudios/android/pachi/PachiEngine.java index ed471b1..10acc84 100644 --- a/app/src/main/java/net/lrstudios/android/pachi/PachiEngine.java +++ b/app/src/main/java/net/lrstudios/android/pachi/PachiEngine.java @@ -73,43 +73,44 @@ protected File getEngineFile() { File file = new File(dir, "pachi"); Context _context = GtpBoardActivity.actionContext; - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context); - int version = prefs.getInt(PREF_KEY_VERSION, 0); - if (version < EXE_VERSION) { - if (file.exists()) - file.delete(); - InputStream inputStream = null; - OutputStream outputStream = null; - try { - outputStream = new BufferedOutputStream(new FileOutputStream(file), 4096); - inputStream = new BufferedInputStream(_context.getResources().openRawResource(R.raw.pachi), 4096); - Utils.copyStream(inputStream, outputStream, 4096); - - extractRawResToFile(R.raw.libcaffe, dir,"libcaffe.so"); - extractRawResToFile(R.raw.golast19, dir,"golast19.prototxt"); - extractRawResToFile(R.raw.golast, dir, "golast.trained"); + try { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context); + int version = prefs.getInt(PREF_KEY_VERSION, 0); + if (version < EXE_VERSION) { + if (file.exists()) + file.delete(); + InputStream inputStream = null; + OutputStream outputStream = null; try { - //file.setExecutable(true); TODO test this instead of chmod - new ProcessBuilder("chmod", "744", file.getAbsolutePath()).start().waitFor(); - SharedPreferences.Editor editor = prefs.edit(); - editor.putInt(PREF_KEY_VERSION, EXE_VERSION); - editor.commit(); - } - catch (IOException e) { - e.printStackTrace(); - } - catch (InterruptedException e) { + outputStream = new BufferedOutputStream(new FileOutputStream(file), 4096); + inputStream = new BufferedInputStream(_context.getResources().openRawResource(R.raw.pachi), 4096); + Utils.copyStream(inputStream, outputStream, 4096); + + extractRawResToFile(R.raw.libcaffe, dir, "libcaffe.so"); + extractRawResToFile(R.raw.golast19, dir, "golast19.prototxt"); + extractRawResToFile(R.raw.golast, dir, "golast.trained"); + + try { + //file.setExecutable(true); TODO test this instead of chmod + new ProcessBuilder("chmod", "744", file.getAbsolutePath()).start().waitFor(); + SharedPreferences.Editor editor = prefs.edit(); + editor.putInt(PREF_KEY_VERSION, EXE_VERSION); + editor.commit(); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } catch (IOException e) { e.printStackTrace(); + } finally { + Utils.closeObject(inputStream); + Utils.closeObject(outputStream); } } - catch (IOException e) { // TODO handle file extracting errors - e.printStackTrace(); - } - finally { - Utils.closeObject(inputStream); - Utils.closeObject(outputStream); - } + } catch (RuntimeException e){ + // fine to continue with the pre-installed engine bits on the cloud node } return file; diff --git a/elygo-lib/src/main/java/lrstudios/games/ego/lib/ui/NewGameActivity.java b/elygo-lib/src/main/java/lrstudios/games/ego/lib/ui/NewGameActivity.java index 10910d4..1dc9d13 100644 --- a/elygo-lib/src/main/java/lrstudios/games/ego/lib/ui/NewGameActivity.java +++ b/elygo-lib/src/main/java/lrstudios/games/ego/lib/ui/NewGameActivity.java @@ -30,13 +30,17 @@ import android.widget.EditText; import android.widget.RadioGroup; import android.widget.Spinner; +import android.widget.Toast; + import lrstudios.games.ego.lib.GoBoard; import lrstudios.games.ego.lib.IntentGameInfo; import lrstudios.games.ego.lib.R; import lrstudios.games.ego.lib.UpdatePrefsTask; import lrstudios.util.android.ui.BetterFragmentActivity; +import sapphire.kernel.common.GlobalKernelReferences; import sapphire.kernel.server.KernelServerImpl; +import sapphire.oms.OMSServer; /** * Allows to start a game against a bot. @@ -145,6 +149,14 @@ else if (colorPos == 1) String ipLocal = getWifiIPAddress(); KernelServerImpl.main(new String[]{ipLocal, "22344", omsHost, "22343"}); + OMSServer oms = GlobalKernelReferences.nodeServer.oms; + if (oms == null) { + Toast.makeText( + this, + "Cannot connect to OMS. Please check your network connectivity and ensure OMS is available, and try again.", + Toast.LENGTH_LONG).show(); + return; + } intent = new Intent(NewGameActivity.this, GtpBoardActivity.class); intent.putExtra(GtpBoardActivity.INTENT_GTP_BOT_CLASS, getBotClass()); @@ -163,6 +175,14 @@ else if (id == R.id.btn_play_continue) { String ipLocal = getWifiIPAddress(); KernelServerImpl.main(new String[]{ipLocal, "22344", omsHost, "22343"}); + OMSServer oms = GlobalKernelReferences.nodeServer.oms; + if (oms == null) { + Toast.makeText( + this, + "Cannot connect to OMS. Please check your network connectivity and ensure OMS is available, and try again.", + Toast.LENGTH_LONG).show(); + return; + } intent = new Intent(NewGameActivity.this, GtpBoardActivity.class); intent.putExtra(GtpBoardActivity.INTENT_PLAY_RESTORE, true);