FreeRDP
Loading...
Searching...
No Matches
com.freerdp.freerdpcore.utils.RDPFileHelper Class Reference

Static Public Member Functions

static void importFrom (InputStream in, BookmarkBase bookmark) throws IOException
 
static String toRdpString (BookmarkBase bookmark)
 

Detailed Description

Definition at line 23 of file RDPFileHelper.java.

Member Function Documentation

◆ importFrom()

static void com.freerdp.freerdpcore.utils.RDPFileHelper.importFrom ( InputStream  in,
BookmarkBase  bookmark 
) throws IOException
inlinestatic

Definition at line 31 of file RDPFileHelper.java.

32 {
33 if (in == null)
34 throw new IOException("null stream");
35
36 byte[] content;
37 try
38 {
39 ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
40 byte[] chunk = new byte[4096];
41 int n;
42 while ((n = in.read(chunk)) != -1)
43 buf.write(chunk, 0, n);
44 content = buf.toByteArray();
45 }
46 finally
47 {
48 in.close();
49 }
50
51 String text;
52 int b0 = content.length > 0 ? (content[0] & 0xFF) : -1;
53 int b1 = content.length > 1 ? (content[1] & 0xFF) : -1;
54 if (b0 == 0xFF && b1 == 0xFE)
55 text = new String(content, 2, content.length - 2, StandardCharsets.UTF_16LE);
56 else if (b0 == 0xFE && b1 == 0xFF)
57 text = new String(content, 2, content.length - 2, StandardCharsets.UTF_16BE);
58 else
59 {
60 text = new String(content, StandardCharsets.UTF_8);
61 if (text.startsWith("\uFEFF"))
62 text = text.substring(1);
63 }
64
65 RDPFileParser p = new RDPFileParser();
66 p.parse(new StringReader(text));
67
68 String s = p.getString("full address");
69 if (s != null)
70 {
71 int colonIdx = s.lastIndexOf(":");
72 if (colonIdx > s.lastIndexOf("]"))
73 {
74 try
75 {
76 bookmark.setPort(Integer.parseInt(s.substring(colonIdx + 1)));
77 }
78 catch (NumberFormatException e)
79 {
80 Log.e(TAG, "Malformed address");
81 }
82 s = s.substring(0, colonIdx);
83 }
84 if (s.startsWith("[") && s.endsWith("]"))
85 s = s.substring(1, s.length() - 1);
86 bookmark.setHostname(s);
87 }
88
89 Integer i = p.getInteger("server port");
90 if (i != null)
91 bookmark.setPort(i);
92
93 s = p.getString("username");
94 if (s != null)
95 bookmark.setUsername(s);
96
97 s = p.getString("domain");
98 if (s != null)
99 bookmark.setDomain(s);
100
101 BookmarkBase.ScreenSettings screen = bookmark.getActiveScreenSettings();
102 Integer w = p.getInteger("desktopwidth");
103 Integer h = p.getInteger("desktopheight");
104 if (w != null && h != null && w > 0 && h > 0)
105 {
106 screen.setWidth(w);
107 screen.setHeight(h);
108 screen.setResolution(BookmarkBase.ScreenSettings.CUSTOM);
109 }
110 i = p.getInteger("session bpp");
111 if (i != null)
112 screen.setColors(i);
113
114 BookmarkBase.PerformanceFlags perf = bookmark.getPerformanceFlags();
115 i = p.getInteger("disable wallpaper");
116 if (i != null)
117 perf.setWallpaper(i == 0);
118 i = p.getInteger("allow font smoothing");
119 if (i != null)
120 perf.setFontSmoothing(i == 1);
121 i = p.getInteger("allow desktop composition");
122 if (i != null)
123 perf.setDesktopComposition(i == 1);
124 i = p.getInteger("disable menu anims");
125 if (i != null)
126 perf.setMenuAnimations(i == 0);
127 i = p.getInteger("disable themes");
128 if (i != null)
129 perf.setTheming(i == 0);
130 i = p.getInteger("disable full window drag");
131 if (i != null)
132 perf.setFullWindowDrag(i == 0);
133
134 BookmarkBase.AdvancedSettings advanced = bookmark.getAdvancedSettings();
135 i = p.getInteger("connect to console");
136 if (i != null)
137 advanced.setConsoleMode(i == 1);
138
139 i = p.getInteger("audiomode");
140 if (i != null && i >= 0 && i <= 2)
141 advanced.setRedirectSound(i);
142 i = p.getInteger("audiocapturemode");
143 if (i != null)
144 advanced.setRedirectMicrophone(i == 1);
145
146 s = p.getString("loadbalanceinfo");
147 if (s != null && !s.isEmpty())
148 advanced.setLoadBalanceInfo(s);
149
150 s = p.getString("remoteapplicationprogram");
151 if (s != null && !s.isEmpty())
152 advanced.setRemoteProgram(s);
153
154 s = p.getString("alternate shell");
155 if (s != null && !s.isEmpty())
156 advanced.setAlternateShell(s);
157
158 s = p.getString("shell working directory");
159 if (s != null && !s.isEmpty())
160 advanced.setWorkDir(s);
161
162 s = p.getString("gatewayhostname");
163 if (s != null && !s.isEmpty())
164 {
165 String gwHost = s;
166 int gwPort = 443;
167 int colonIdx = s.lastIndexOf(":");
168 if (colonIdx > 0)
169 {
170 try
171 {
172 gwPort = Integer.parseInt(s.substring(colonIdx + 1));
173 gwHost = s.substring(0, colonIdx);
174 }
175 catch (NumberFormatException e)
176 {
177 Log.e(TAG, "Malformed gateway port");
178 }
179 }
180 bookmark.getGatewaySettings().setHostname(gwHost);
181 bookmark.getGatewaySettings().setPort(gwPort);
182 bookmark.setEnableGatewaySettings(true);
183 }
184 i = p.getInteger("gatewayusagemethod");
185 if (i != null)
186 bookmark.setEnableGatewaySettings(i == 1 || i == 2);
187
188 i = p.getInteger("redirectprinters");
189 if (i != null)
190 advanced.setRedirectPrinter(i == 1);
191 i = p.getInteger("disableprinterredirection");
192 if (i != null)
193 advanced.setRedirectPrinter(i == 0);
194
195 s = p.getString("pcb");
196 if (s != null && !s.isEmpty())
197 {
198 advanced.setVmConnectMode(true);
199 advanced.setVmConnectGuid(s);
200 }
201 }

◆ toRdpString()

static String com.freerdp.freerdpcore.utils.RDPFileHelper.toRdpString ( BookmarkBase  bookmark)
inlinestatic

Definition at line 203 of file RDPFileHelper.java.

204 {
205 StringBuilder sb = new StringBuilder();
206 BookmarkBase.ScreenSettings screen = bookmark.getActiveScreenSettings();
207 BookmarkBase.PerformanceFlags perf = bookmark.getActivePerformanceFlags();
208 BookmarkBase.AdvancedSettings adv = bookmark.getAdvancedSettings();
209
210 String host = bookmark.getHostname();
211 int port = bookmark.getPort();
212 writeString(sb, "full address", port != 3389 ? host + ":" + port : host);
213
214 String username = bookmark.getUsername();
215 if (!username.isEmpty())
216 writeString(sb, "username", username);
217
218 String domain = bookmark.getDomain();
219 if (!domain.isEmpty())
220 writeString(sb, "domain", domain);
221
222 if (screen.getResolution() == BookmarkBase.ScreenSettings.CUSTOM)
223 {
224 writeInt(sb, "desktopwidth", screen.getWidth());
225 writeInt(sb, "desktopheight", screen.getHeight());
226 }
227 writeInt(sb, "session bpp", screen.getColors());
228
229 writeInt(sb, "disable wallpaper", perf.getWallpaper() ? 0 : 1);
230 writeInt(sb, "allow font smoothing", perf.getFontSmoothing() ? 1 : 0);
231 writeInt(sb, "allow desktop composition", perf.getDesktopComposition() ? 1 : 0);
232 writeInt(sb, "disable menu anims", perf.getMenuAnimations() ? 0 : 1);
233 writeInt(sb, "disable themes", perf.getTheming() ? 0 : 1);
234 writeInt(sb, "disable full window drag", perf.getFullWindowDrag() ? 0 : 1);
235
236 if (adv.getConsoleMode())
237 writeInt(sb, "connect to console", 1);
238
239 int audioMode = adv.getRedirectSound();
240 if (audioMode != 0)
241 writeInt(sb, "audiomode", audioMode);
242
243 if (adv.getRedirectMicrophone())
244 writeInt(sb, "audiocapturemode", 1);
245
246 String lbInfo = adv.getLoadBalanceInfo();
247 if (!lbInfo.isEmpty())
248 writeString(sb, "loadbalanceinfo", lbInfo);
249
250 String remoteApp = adv.getRemoteProgram();
251 if (!remoteApp.isEmpty())
252 {
253 writeString(sb, "remoteapplicationprogram", remoteApp);
254 writeInt(sb, "remoteapplicationmode", 1);
255 }
256
257 String alternateShell = adv.getAlternateShell();
258 if (!alternateShell.isEmpty())
259 writeString(sb, "alternate shell", alternateShell);
260
261 String workDir = adv.getWorkDir();
262 if (!workDir.isEmpty())
263 writeString(sb, "shell working directory", workDir);
264
265 if (bookmark.getEnableGatewaySettings())
266 {
267 BookmarkBase.GatewaySettings gw = bookmark.getGatewaySettings();
268 String gwHost = gw.getHostname();
269 int gwPort = gw.getPort();
270 writeString(sb, "gatewayhostname", gwPort != 443 ? gwHost + ":" + gwPort : gwHost);
271 writeInt(sb, "gatewayusagemethod", 2);
272 }
273
274 if (adv.getVmConnectMode())
275 writeString(sb, "pcb", adv.getVmConnectGuid());
276
277 if (adv.getRedirectPrinter())
278 writeInt(sb, "redirectprinters", 1);
279
280 return sb.toString();
281 }

The documentation for this class was generated from the following file: