From 50439d78fae2828356bfde789ec5c4fd0911ae09 Mon Sep 17 00:00:00 2001 From: Mathias Jonsson Date: Sun, 22 Apr 2018 19:10:30 +0200 Subject: Accept a cfg as an argument as an alt way to start the viewer The user can specify a tigervnc configuration file as an argument to the viewer. Previously the viewer assumed this to be a server, but now we will first check if there is any file matching the given argument. If so, try to load the content of that file, like we normally do. Fixes issue #38. --- java/com/tigervnc/vncviewer/VncViewer.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'java/com') diff --git a/java/com/tigervnc/vncviewer/VncViewer.java b/java/com/tigervnc/vncviewer/VncViewer.java index 566169be..93d3f3be 100644 --- a/java/com/tigervnc/vncviewer/VncViewer.java +++ b/java/com/tigervnc/vncviewer/VncViewer.java @@ -208,6 +208,8 @@ public class VncViewer extends javax.swing.JApplet vncServerName.put(argv[i].toCharArray()).flip(); } + // Check if the server name in reality is a configuration file + potentiallyLoadConfigurationFile(vncServerName); } public static void usage() { @@ -215,6 +217,7 @@ public class VncViewer extends javax.swing.JApplet "[host:displayNum]\n"+ " vncviewer [options/parameters] -listen [port] "+ "[options/parameters]\n"+ + " vncviewer [options/parameters] [.tigervnc file]\n"+ "\n"+ "Options:\n"+ " -log configure logging level\n"+ @@ -277,6 +280,27 @@ public class VncViewer extends javax.swing.JApplet System.exit(1); } + public static void potentiallyLoadConfigurationFile(CharBuffer vncServerName) { + String serverName = vncServerName.toString(); + boolean hasPathSeparator = (serverName.indexOf('/') != -1 || + (serverName.indexOf('\\')) != -1); + + if (hasPathSeparator) { + try { + serverName = loadViewerParameters(vncServerName.toString()); + if (serverName == "") { + vlog.info("Unable to load the server name from given file"); + System.exit(1); + } + vncServerName.clear(); + vncServerName.put(serverName).flip(); + } catch (com.tigervnc.rfb.Exception e) { + vlog.info(e.getMessage()); + System.exit(1); + } + } + } + public static void newViewer() { String cmd = "java -jar "; try { -- cgit v1.2.3