📄 vncoptions.cpp
字号:
// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
//
// This file is part of the VNC system.
//
// The VNC system is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
// TightVNC distribution homepage on the Web: http://www.tightvnc.com/
//
// If the source code for the VNC system is not available from the place
// whence you received this file, check http://www.uk.research.att.com/vnc or contact
// the authors on vnc@uk.research.att.com for information on obtaining it.
// VNCOptions.cpp: implementation of the VNCOptions class.
#include "stdhdrs.h"
#include "vncviewer.h"
#include "VNCOptions.h"
#include "Exception.h"
#include "Htmlhelp.h"
#include "commctrl.h"
#include "AboutBox.h"
VNCOptions::VNCOptions()
{
for (int i = rfbEncodingRaw; i<= LASTENCODING; i++)
m_UseEnc[i] = true;
m_UseEnc[3] = false;
m_ViewOnly = false;
m_FullScreen = false;
m_toolbar = true;
m_historyLimit = 32;
m_skipprompt = false;
m_Use8Bit = false;
m_PreferredEncoding = rfbEncodingTight;
m_SwapMouse = false;
m_Emul3Buttons = true;
m_Emul3Timeout = 100; // milliseconds
m_Emul3Fuzz = 4; // pixels away before emulation is cancelled
m_Shared = true;
m_DeiconifyOnBell = false;
m_DisableClipboard = false;
m_localCursor = DOTCURSOR;
m_FitWindow = false;
m_scaling = false;
m_scale_num = 100;
m_scale_den = 100;
m_display[0] = '\0';
m_host[0] = '\0';
m_port = -1;
m_via_host[0] = '\0';
m_hWindow = 0;
m_kbdname[0] = '\0';
m_kbdSpecified = false;
m_logLevel = 0;
m_logToConsole = false;
m_logToFile = false;
strcpy(m_logFilename ,"vncviewer.log");
m_delay=0;
m_connectionSpecified = false;
m_configSpecified = false;
m_configFilename[0] = '\0';
m_listening = false;
m_listenPort = INCOMING_PORT_OFFSET;
m_restricted = false;
m_useCompressLevel = false;
m_compressLevel = 6;
m_enableJpegCompression = true;
m_jpegQualityLevel = 6;
m_requestShapeUpdates = true;
m_ignoreShapeUpdates = false;
LoadGenOpt();
#ifdef UNDER_CE
m_palmpc = false;
// Check for PalmPC aspect
HDC temp_hdc = GetDC(NULL);
int screen_width = GetDeviceCaps(temp_hdc, HORZRES);
if (screen_width < 320)
{
m_palmpc = true;
}
ReleaseDC(NULL,temp_hdc);
m_slowgdi = false;
#endif
}
VNCOptions& VNCOptions::operator=(VNCOptions& s)
{
for (int i = rfbEncodingRaw; i<= LASTENCODING; i++)
m_UseEnc[i] = s.m_UseEnc[i];
m_ViewOnly = s.m_ViewOnly;
m_FullScreen = s.m_FullScreen;
m_Use8Bit = s.m_Use8Bit;
m_PreferredEncoding = s.m_PreferredEncoding;
m_SwapMouse = s.m_SwapMouse;
m_Emul3Buttons = s.m_Emul3Buttons;
m_Emul3Timeout = s.m_Emul3Timeout;
m_Emul3Fuzz = s.m_Emul3Fuzz; // pixels away before emulation is cancelled
m_Shared = s.m_Shared;
m_DeiconifyOnBell = s.m_DeiconifyOnBell;
m_DisableClipboard = s.m_DisableClipboard;
m_scaling = s.m_scaling;
m_FitWindow = s.m_FitWindow;
m_scale_num = s.m_scale_num;
m_scale_den = s.m_scale_den;
m_localCursor = s.m_localCursor;
m_toolbar = s.m_toolbar;
strcpy(m_display, s.m_display);
strcpy(m_host, s.m_host);
m_port = s.m_port;
m_hWindow = s.m_hWindow;
strcpy(m_kbdname, s.m_kbdname);
m_kbdSpecified = s.m_kbdSpecified;
m_logLevel = s.m_logLevel;
m_logToConsole = s.m_logToConsole;
m_logToFile = s.m_logToFile;
strcpy(m_logFilename, s.m_logFilename);
m_delay = s.m_delay;
m_connectionSpecified = s.m_connectionSpecified;
m_configSpecified = s.m_configSpecified;
strcpy(m_configFilename, s.m_configFilename);
m_listening = s.m_listening;
m_listenPort = s.m_listenPort;
m_restricted = s.m_restricted;
m_useCompressLevel = s.m_useCompressLevel;
m_compressLevel = s.m_compressLevel;
m_enableJpegCompression = s.m_enableJpegCompression;
m_jpegQualityLevel = s.m_jpegQualityLevel;
m_requestShapeUpdates = s.m_requestShapeUpdates;
m_ignoreShapeUpdates = s.m_ignoreShapeUpdates;
#ifdef UNDER_CE
m_palmpc = s.m_palmpc;
m_slowgdi = s.m_slowgdi;
#endif
return *this;
}
VNCOptions::~VNCOptions()
{
}
inline bool SwitchMatch(LPCTSTR arg, LPCTSTR swtch) {
return (arg[0] == '-' || arg[0] == '/') &&
(_tcsicmp(&arg[1], swtch) == 0);
}
static void ArgError(LPTSTR msg) {
MessageBox(NULL, msg, _T("Argument error"),MB_OK | MB_TOPMOST | MB_ICONSTOP);
}
// Greatest common denominator, by Euclid
int gcd(int a, int b) {
if (a < b) return gcd(b, a);
if (b == 0) return a;
return gcd(b, a % b);
}
void VNCOptions::FixScaling() {
if (m_scale_num < 1 || m_scale_den < 1) {
MessageBox(NULL, _T("Invalid scale factor - resetting to normal scale"),
_T("Argument error"),MB_OK | MB_TOPMOST | MB_ICONWARNING);
m_scale_num = 1;
m_scale_den = 1;
m_scaling = false;
}
int g = gcd(m_scale_num, m_scale_den);
m_scale_num /= g;
m_scale_den /= g;
}
void VNCOptions::SetFromCommandLine(LPTSTR szCmdLine) {
// We assume no quoting here.
// Copy the command line - we don't know what might happen to the original
int cmdlinelen = _tcslen(szCmdLine);
if (cmdlinelen == 0) return;
TCHAR CommLine[256] ;
int f = 0;
_tcscpy(CommLine, szCmdLine);
if (_tcsstr( CommLine, "/listen") != NULL ||
_tcsstr( CommLine, "-listen") != NULL) {
LoadOpt(".listen", KEY_VNCVIEWER_HISTORI);
f = 1;
}
TCHAR *cmd = new TCHAR[cmdlinelen + 1];
_tcscpy(cmd, szCmdLine);
// Count the number of spaces
// This may be more than the number of arguments, but that doesn't matter.
int nspaces = 0;
TCHAR *p = cmd;
TCHAR *pos = cmd;
while ( ( pos = _tcschr(p, ' ') ) != NULL ) {
nspaces ++;
p = pos + 1;
}
// Create the array to hold pointers to each bit of string
TCHAR **args = new LPTSTR[nspaces + 1];
// replace spaces with nulls and
// create an array of TCHAR*'s which points to start of each bit.
pos = cmd;
int i = 0;
args[i] = cmd;
bool inquote=false;
for (pos = cmd; *pos != 0; pos++) {
// Arguments are normally separated by spaces, unless there's quoting
if ((*pos == ' ') && !inquote) {
*pos = '\0';
p = pos + 1;
args[++i] = p;
}
if (*pos == '"') {
if (!inquote) { // Are we starting a quoted argument?
args[i] = ++pos; // It starts just after the quote
} else {
*pos = '\0'; // Finish a quoted argument?
}
inquote = !inquote;
}
}
i++;
int j;
for (j = 0; j < i; j++) {
TCHAR phost[256];
if (ParseDisplay(args[j], phost, 255, &m_port) && (f == 0) &&
(_tcsstr( args[j], "/") == NULL))
LoadOpt(args[j], KEY_VNCVIEWER_HISTORI);
}
bool hostGiven = false, portGiven = false;
// take in order.
for (j = 0; j < i; j++) {
if ( SwitchMatch(args[j], _T("help")) ||
SwitchMatch(args[j], _T("?")) ||
SwitchMatch(args[j], _T("h"))) {
ShowHelpBox(_T("TightVNC Usage Help"));
exit(1);
} else if ( SwitchMatch(args[j], _T("listen"))) {
m_listening = true;
if (j+1 < i && args[j+1][0] >= '0' && args[j+1][0] <= '9') {
if (_stscanf(args[j+1], _T("%d"), &m_listenPort) != 1) {
ArgError(_T("Invalid listen port specified"));
continue;
}
j++;
}
} else if ( SwitchMatch(args[j], _T("restricted"))) {
m_restricted = true;
} else if ( SwitchMatch(args[j], _T("viewonly"))) {
m_ViewOnly = true;
} else if ( SwitchMatch(args[j], _T("fullscreen"))) {
m_FullScreen = true;
} else if ( SwitchMatch(args[j], _T("notoolbar"))) {
m_toolbar = false;
} else if ( SwitchMatch(args[j], _T("8bit"))) {
m_Use8Bit = true;
} else if ( SwitchMatch(args[j], _T("shared"))) {
m_Shared = true;
} else if ( SwitchMatch(args[j], _T("noshared"))) {
m_Shared = false;
} else if ( SwitchMatch(args[j], _T("swapmouse"))) {
m_SwapMouse = true;
} else if ( SwitchMatch(args[j], _T("nocursor"))) {
m_localCursor = NOCURSOR;
} else if ( SwitchMatch(args[j], _T("dotcursor"))) {
m_localCursor = DOTCURSOR;
} else if ( SwitchMatch(args[j], _T("smalldotcursor"))) {
m_localCursor = SMALLCURSOR;
} else if ( SwitchMatch(args[j], _T("normalcursor"))) {
m_localCursor= NORMALCURSOR;
} else if ( SwitchMatch(args[j], _T("belldeiconify") )) {
m_DeiconifyOnBell = true;
} else if ( SwitchMatch(args[j], _T("emulate3") )) {
m_Emul3Buttons = true;
} else if ( SwitchMatch(args[j], _T("noemulate3") )) {
m_Emul3Buttons = false;
} else if ( SwitchMatch(args[j], _T("nojpeg") )) {
m_enableJpegCompression = false;
} else if ( SwitchMatch(args[j], _T("nocursorshape") )) {
m_requestShapeUpdates = false;
} else if ( SwitchMatch(args[j], _T("noremotecursor") )) {
m_requestShapeUpdates = true;
m_ignoreShapeUpdates = true;
} else if ( SwitchMatch(args[j], _T("fitwindow") )) {
m_FitWindow = true;
} else if ( SwitchMatch(args[j], _T("scale") )) {
if (++j == i) {
ArgError(_T("No scaling factor specified"));
continue;
}
int numscales = _stscanf(args[j], _T("%d"), &m_scale_num);
if (numscales < 1) {
ArgError(_T("Invalid scaling specified"));
continue;
}
m_scale_den = 100;
} else if ( SwitchMatch(args[j], _T("emulate3timeout") )) {
if (++j == i) {
ArgError(_T("No timeout specified"));
continue;
}
if (_stscanf(args[j], _T("%d"), &m_Emul3Timeout) != 1) {
ArgError(_T("Invalid timeout specified"));
continue;
}
} else if ( SwitchMatch(args[j], _T("emulate3fuzz") )) {
if (++j == i) {
ArgError(_T("No fuzz specified"));
continue;
}
if (_stscanf(args[j], _T("%d"), &m_Emul3Fuzz) != 1) {
ArgError(_T("Invalid fuzz specified"));
continue;
}
} else if ( SwitchMatch(args[j], _T("disableclipboard") )) {
m_DisableClipboard = true;
}
#ifdef UNDER_CE
// Manual setting of palm vs hpc aspect ratio for dialog boxes.
else if ( SwitchMatch(args[j], _T("hpc") )) {
m_palmpc = false;
} else if ( SwitchMatch(args[j], _T("palm") )) {
m_palmpc = true;
} else if ( SwitchMatch(args[j], _T("slow") )) {
m_slowgdi = true;
}
#endif
else if ( SwitchMatch(args[j], _T("delay") )) {
if (++j == i) {
ArgError(_T("No delay specified"));
continue;
}
if (_stscanf(args[j], _T("%d"), &m_delay) != 1) {
ArgError(_T("Invalid delay specified"));
continue;
}
} else if ( SwitchMatch(args[j], _T("loglevel") )) {
if (++j == i) {
ArgError(_T("No loglevel specified"));
continue;
}
if (_stscanf(args[j], _T("%d"), &m_logLevel) != 1) {
ArgError(_T("Invalid loglevel specified"));
continue;
}
} else if ( SwitchMatch(args[j], _T("console") )) {
m_logToConsole = true;
} else if ( SwitchMatch(args[j], _T("logfile") )) {
if (++j == i) {
ArgError(_T("No logfile specified"));
continue;
}
if (_stscanf(args[j], _T("%s"), &m_logFilename) != 1) {
ArgError(_T("Invalid logfile specified"));
continue;
} else {
m_logToFile = true;
}
} else if ( SwitchMatch(args[j], _T("config") )) {
if (++j == i) {
ArgError(_T("No config file specified"));
continue;
}
// The GetPrivateProfile* stuff seems not to like some relative paths
_fullpath(m_configFilename, args[j], _MAX_PATH);
if (_access(m_configFilename, 04)) {
ArgError(_T("Can't open specified config file for reading."));
continue;
} else {
Load(m_configFilename);
m_configSpecified = true;
}
} else if ( SwitchMatch(args[j], _T("via") )) {
if (++j == i) {
ArgError(_T("Host name not specified with -via option"));
continue;
}
if (_tcslen(args[j]) >= sizeof(m_via_host)/sizeof(TCHAR)) {
ArgError(_T("Host name at -via option is too long"));
continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -