Mercurial > 510Connectbot
changeset 132:265a4733edcb
read deployment.connections on startup for new host entries
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 19 Jun 2014 15:47:34 -0700 |
parents | adf9ca45675b |
children | b151d3eca95a |
files | deployment.connections src/com/five_ten_sg/connectbot/HostListActivity.java src/com/five_ten_sg/connectbot/PubkeyListActivity.java src/com/five_ten_sg/connectbot/transport/TN5250.java |
diffstat | 4 files changed, 79 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/deployment.connections Thu Jun 19 15:47:34 2014 -0700 @@ -0,0 +1,31 @@ +# +# available keys: +# +# hostkeyalgo +# hostkey +# color +# usekeys +# useauthagent +# postlogin +# pubkeyid +# wantsession +# delkey +# fontsize +# compression +# httpproxy +# encoding +# stayconnected +# wantx11forward +# x11host +# x11port +# monitor +# emulation +# encryption5250 +# library5250 +# menu5250 +# program5250 + + +tn5250://pub1.rzkh.de:23#battleship + encryption5250=NONE +
--- a/src/com/five_ten_sg/connectbot/HostListActivity.java Thu Jun 19 09:57:31 2014 -0700 +++ b/src/com/five_ten_sg/connectbot/HostListActivity.java Thu Jun 19 15:47:34 2014 -0700 @@ -25,6 +25,7 @@ import com.five_ten_sg.connectbot.transport.TransportFactory; import com.five_ten_sg.connectbot.util.HostDatabase; import com.five_ten_sg.connectbot.util.PreferenceConstants; +import java.nio.file.Files; import android.app.Activity; import android.app.AlertDialog; import android.app.ListActivity; @@ -40,6 +41,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Environment; import android.os.Handler; import android.os.IBinder; import android.os.Message; @@ -181,6 +183,7 @@ || Intent.ACTION_PICK.equals(getIntent().getAction()); // connect with hosts database and populate list hostdb = new HostDatabase(this); + createDeploymentHosts(); // build hosts from a deployment text file updateList(); sortedByColor = prefs.getBoolean(PreferenceConstants.SORT_BY_COLOR, false); registerForContextMenu(getListView()); @@ -387,6 +390,46 @@ return true; } + private void createDeploymentHosts() { + try { + String fn = Environment.getExternalStorageDirectory().getAbsolutePath() + + File.separator + "deployment.connections"; + BufferedReader reader = new BufferedReader(new FileReader(fn)); + String line = null; + while ((line = reader.readLine()) != null) { + if (line.length() == 0) continue; // empty + if (line.substring(0,1).equals("#")) continue; // comment + if (!line.contains("://")) continue; // invalid uri + Uri uri = Uri.parse(line); + ContentValues values = null; + while ((line = reader.readLine()).length() > 0) { + String [] parts = line.split("="); + if (parts.length() != 2) continue; + if (values == null) values = new ContentValues(); + values.put(parts[0], parts[1]); + } + HostBean host = TransportFactory.findHost(hostdb, uri); + if (host == null) { + host = TransportFactory.getTransport(uri.getScheme()).createHost(uri); + host.setColor(HostDatabase.COLOR_GRAY); + host.setPubkeyId(HostDatabase.PUBKEYID_ANY); + hostdb.saveHost(host); + } + host = TransportFactory.findHost(hostdb, uri); + if (host == null) continue; + if (values == null) continue; + SQLiteDatabase db = hostdb.getWritableDatabase(); + db.update(HostDatabase.TABLE_HOSTS, values, "_id = ?", new String[] { String.valueOf(host.getId()) }); + db.close(); + } + reader.close(); + Files.delete(fn); + } + catch (Exception e) { + Log.d(TAG, "Deployment scan failed.", e); + } + } + protected void updateList() { if (prefs.getBoolean(PreferenceConstants.SORT_BY_COLOR, false) != sortedByColor) { Editor edit = prefs.edit();
--- a/src/com/five_ten_sg/connectbot/PubkeyListActivity.java Thu Jun 19 09:57:31 2014 -0700 +++ b/src/com/five_ten_sg/connectbot/PubkeyListActivity.java Thu Jun 19 15:47:34 2014 -0700 @@ -543,15 +543,15 @@ errorString = "Error exporting public key"; } - final String sdcard = Environment.getExternalStorageDirectory().toString(); + final String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath(); final EditText fileName = new EditText(PubkeyListActivity.this); fileName.setSingleLine(); if (nickName != null) { if (keyType == KEYTYPE_PRIVATE) - fileName.setText(sdcard + "/" + nickName.trim()); + fileName.setText(sdcard + File.separator + nickName.trim()); else - fileName.setText(sdcard + "/" + nickName.trim() + ".pub"); + fileName.setText(sdcard + File.separator + nickName.trim() + ".pub"); } new AlertDialog.Builder(PubkeyListActivity.this)
--- a/src/com/five_ten_sg/connectbot/transport/TN5250.java Thu Jun 19 09:57:31 2014 -0700 +++ b/src/com/five_ten_sg/connectbot/transport/TN5250.java Thu Jun 19 15:47:34 2014 -0700 @@ -414,12 +414,9 @@ String nickname = uri.getFragment(); if (nickname == null || nickname.length() == 0) { - host.setNickname(getDefaultNickname(host.getUsername(), - host.getHostname(), host.getPort())); + nickname = getDefaultNickname(host.getUsername(), host.getHostname(), host.getPort())); } - else { - host.setNickname(uri.getFragment()); - } + host.setNickname(nickname); return host; }