# HG changeset patch # User Carl Byington # Date 1403218054 25200 # Node ID 265a4733edcbb38313080f71eb9c69b890a071fd # Parent adf9ca45675bceedeb33765dbec12590d3779896 read deployment.connections on startup for new host entries diff -r adf9ca45675b -r 265a4733edcb deployment.connections --- /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 + diff -r adf9ca45675b -r 265a4733edcb src/com/five_ten_sg/connectbot/HostListActivity.java --- 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(); diff -r adf9ca45675b -r 265a4733edcb src/com/five_ten_sg/connectbot/PubkeyListActivity.java --- 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) diff -r adf9ca45675b -r 265a4733edcb src/com/five_ten_sg/connectbot/transport/TN5250.java --- 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; }