⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 properties.cpp

📁 teamviewer source code vc++
💻 CPP
📖 第 1 页 / 共 4 页
字号:

	if(IsDlgButtonChecked(hSecurity, IDC_FTRANS_NOQUERY))
		m_pref_Security_EnableFileTransfer = 1;
	else if(IsDlgButtonChecked(hSecurity, IDC_FTRANS_QUERY))
		m_pref_Security_EnableFileTransfer = 2;
	else
		m_pref_Security_EnableFileTransfer = 0;

	m_pref_Security_LockSettings = SendMessage(GetDlgItem(hSecurity, IDC_AFTER_LAST_SESSION), CB_GETCURSEL, 0, 0);
	m_pref_Security_Multiple = SendMessage(GetDlgItem(hSecurity, IDC_SECURITY_MULTIPLE), CB_GETCURSEL, 0, 0);

	m_pref_Security_SingleWindow = IsDlgButtonChecked(hSecurity, IDC_SINGLE_WINDOW);
	GetDlgItemText(hSecurity, IDC_NAME_APPLI, (LPSTR) &m_pref_Security_ShareWindowNamed, MAX_SW_NAMELEN);

	return PSNRET_NOERROR;
}

LONG vncProperties::VerifyHost(HWND hHost)
{
	char pwd[MAXPWLEN+1];
	char pwd2[MAXPWLEN+1];
	BOOL ServerMode = IsDlgButtonChecked(hHost,IDC_SERVER_MODE);
	int len = GetDlgItemText(hHost, IDC_HOST_PASSWORD, (LPSTR) &pwd, MAXPWLEN+1);
	int len2 = GetDlgItemText(hHost, IDC_HOST_PASSWORD2, (LPSTR) &pwd2, MAXPWLEN+1);

	if (len != len2 || strncmp(pwd,pwd2,min(len,len2)) != 0)
	{
		MessageBox(hHost,sz_IDS_PASSWORD_VERIFY_ERROR_TEXT,sz_IDS_NO_PASSWORD_SET_CAPTION,MB_OK|MB_ICONEXCLAMATION);

		
		SecureZeroMemory(&pwd,sizeof(pwd));
		SecureZeroMemory(&pwd2,sizeof(pwd2));

		return PSNRET_INVALID_NOCHANGEPAGE;
	}

	SecureZeroMemory(&pwd,sizeof(pwd));
	SecureZeroMemory(&pwd2,sizeof(pwd2));

	if(ServerMode && len==0)
	{
		MessageBox(hHost,sz_IDS_NO_PASSWORD_SET_TEXT,sz_IDS_NO_PASSWORD_SET_CAPTION,MB_OK|MB_ICONEXCLAMATION);
		return PSNRET_INVALID_NOCHANGEPAGE;
	}

	if (len < 4 && ServerMode)
		ShowWindow(GetDlgItem(hHost,IDC_WARNIN_SIMPLE_PASSWORD),SW_SHOW);
	else
		ShowWindow(GetDlgItem(hHost,IDC_WARNIN_SIMPLE_PASSWORD),SW_HIDE);

	return PSNRET_NOERROR;	
}

void vncProperties::ConvertHTML2CInvitation()
{
	std::string s(m_pref_CustomInvitation_Text);

	int pos = s.find("%0D");
	while (pos > -1)
	{
		s = s.replace(pos,3,"\r\n");
		pos = s.find("%0D");
	}
	pos = s.find("%0A");
	while (pos > -1)
	{
		s = s.replace(pos,3,"");
		pos = s.find("%0A");
	}

	m_pref_CustomInvitation_Text = s;
	
}

void vncProperties::ConvertC2HTMLInvitation()
{
	std::string s(m_pref_CustomInvitation_Text);

	int pos = s.find('\n');
	while (pos > -1)
	{
		s = s.replace(pos,1,"%0A");
		pos = s.find('\n');
	}
	pos = s.find('\r');
	while (pos > -1)
	{
		s = s.replace(pos,1,"%0D");
		pos = s.find('\r');
	}
	int i = s.length();

	m_pref_CustomInvitation_Text = s;
}

LONG vncProperties::ApplyInvitation(HWND hHost)
{
	char s1[MAX_SUBJECT_STRING_LEN+1];
	SecureZeroMemory(&s1,sizeof(s1));

	GetDlgItemText(hHost,IDC_SUBJECTEDIT,s1,sizeof(s1));
	m_pref_CustomInvitation_Subject = s1;

	char s2[MAX_INVITATION_TEXT_LEN+1];
	SecureZeroMemory(&s2,sizeof(s2));
	GetDlgItemText(hHost,IDC_EDITINVITATION,s2,sizeof(s2));
	m_pref_CustomInvitation_Text = s2;
	
	std::string sSubject(m_pref_CustomInvitation_Subject);
	//subject text
	if (sSubject.length() <= 0)
	{
		sSubject = sz_IDS_INVITE;
		int iSubjectPos = sSubject.find("subject=");
		
		if (iSubjectPos >= 0)
		{
			iSubjectPos += 8;

			int iBodyPos = sSubject.find("&body=");
			
			if (iBodyPos < 0)
				iBodyPos = sSubject.length();

			sSubject = sSubject.substr(iSubjectPos,iBodyPos-iSubjectPos);
			
			m_pref_CustomInvitation_Subject = sSubject;		
		
			
			SetDlgItemText(hHost,IDC_SUBJECTEDIT,m_pref_CustomInvitation_Subject.c_str());
		}		
	}
	
	// Text message
	std::string sText(m_pref_CustomInvitation_Text);
	if (sText.length() <= 0)
	{
		if (CroGateway::Instance()->Licensed())
			sText= sz_IDS_INVITE;
		else
			sText = (sz_IDS_INVITE_FREE);
		int iBodyPos = sText.find("body=");
		
		if (iBodyPos >= 0)
		{
			iBodyPos += 5;
	
			sText = sText.substr(iBodyPos,sText.length()-iBodyPos);
			
			m_pref_CustomInvitation_Text = sText;

			ConvertHTML2CInvitation();
			SetDlgItemText(hHost,IDC_EDITINVITATION,m_pref_CustomInvitation_Text.c_str());
			
		}

	}



	ConvertC2HTMLInvitation();
	

	return PSNRET_NOERROR;
}

LONG vncProperties::ApplyHost(HWND hHost)
{
	int ServerMode = IsDlgButtonChecked(hHost,IDC_SERVER_MODE);

	// Save the password
	char pass[MAXPWLEN+1];
	int len = GetDlgItemText(hHost, IDC_HOST_PASSWORD, (LPSTR) &pass, MAXPWLEN+1);
	pass[MAXPWLEN] = '\0';
	vncPasswd::FromText crypt(pass);
	memcpy(m_pref_Host_Passwd, crypt, MAXPWLEN);
	
	ZeroMemory(&pass,sizeof(pass));

	if(!ServerMode)
		m_pref_Host_Autostart = 0;
	else if (IsDlgButtonChecked(hHost, IDC_HOST_AUTOSTART_SERVICE))
		m_pref_Host_Autostart = 2;
	else if (IsDlgButtonChecked(hHost, IDC_HOST_AUTOSTART))
		m_pref_Host_Autostart = 1;
	else
		m_pref_Host_Autostart = 3;

	m_pref_Host_AllowShutdown = !IsDlgButtonChecked(hHost, IDC_HOST_DISABLESHUTDOWN);

	return PSNRET_NOERROR;
}

// Functions to load & save the settings
LONG vncProperties::LoadInt(HKEY key, LPCSTR valname, LONG defval)
{
	LONG pref;
	ULONG type = REG_DWORD;
	ULONG prefsize = sizeof(pref);

	if (RegQueryValueEx(key,
		valname,
		NULL,
		&type,
		(LPBYTE) &pref,
		&prefsize) != ERROR_SUCCESS)
		return defval;

	if (type != REG_DWORD)
		return defval;

	if (prefsize != sizeof(pref))
		return defval;

	return pref;
}

char * vncProperties::LoadString(HKEY key, LPCSTR keyname)
{
	DWORD type = REG_SZ;
	DWORD buflen = 0;
	BYTE *buffer = 0;

	// Get the length of the string
	if (RegQueryValueEx(key,
		keyname,
		NULL,
		&type,
		NULL,
		&buflen) != ERROR_SUCCESS)
		return NULL;

	if (type != REG_SZ || buflen == 0)
		return NULL;
	buffer = new BYTE[buflen];
	if (buffer == 0)
		return NULL;

	// Get the string data
	if (RegQueryValueEx(key,
		keyname,
		NULL,
		&type,
		buffer,
		&buflen) != ERROR_SUCCESS) {
		delete [] buffer;
		return NULL;
	}

	// Verify the type
	if (type != REG_SZ) {
		delete [] buffer;
		return NULL;
	}
	return (char*) buffer;
}

bool vncProperties::LoadString(HKEY key, LPCSTR keyname, char* dest, int maxlen)
{
	char* buffer = LoadString(key, keyname);
	if(buffer != NULL)
	{
		strncpy(dest, buffer, maxlen);
		dest[maxlen-1] = '\0';
		delete [] buffer;
		return true;
	}
	else
	{
		dest[0] = '\0';
		return false;
	}
}

void vncProperties::LoadPassword(HKEY key, char *buffer)
{
	DWORD type = REG_BINARY;
	int slen=MAXPWLEN;
	char inouttext[MAXPWLEN];

	// Retrieve the encrypted password
	if (RegQueryValueEx(key,
		"Password",
		NULL,
		&type,
		(LPBYTE) &inouttext,
		(LPDWORD) &slen) != ERROR_SUCCESS)
		return;

	if (slen > MAXPWLEN)
		return;

	memcpy(buffer, inouttext, MAXPWLEN);
}

void vncProperties::Load()
{
	HKEY hkey;
	char username[255];

	if (m_dlgvisible) {
		vnclog.Print(LL_INTWARN, VNCLOG("service helper invoked while Properties panel displayed"));
		return;
	}
	if(isQuickSupport)
	{
		ApplyPrefs();
		return;
	}

	ResetProperties();

	// Load machine preferences
	// first load settings in HKEY_CURRENT_USER
	// these should not exist unless TeamViewer is installed and used as a user
	// without rights to HKEY_LOCAL_MACHINE
	if (RegOpenKeyEx(HKEY_CURRENT_USER,
					 TV_REGISTRY_KEY,
					 0, KEY_READ, &hkey) == ERROR_SUCCESS)
	{
		vnclog.Print(LL_INTINFO, VNCLOG("Loading machine prefs from HKEY_CURRENT_USER"));
		LoadMachinePrefs(hkey);	
		RegCloseKey(hkey);

		m_Properties_Location = HKEY_CURRENT_USER;
	}
	
	// then load (and overwrite other settings) with
	// properties from HKEY_LOCAL_MACHINE
	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
					 TV_REGISTRY_KEY,
					 0, KEY_READ, &hkey) == ERROR_SUCCESS)
	{
		vnclog.Print(LL_INTINFO, VNCLOG("Loading machine prefs from HKEY_LOCAL_MACHINE"));
		LoadMachinePrefs(hkey);	
		RegCloseKey(hkey);

		m_Properties_Location = HKEY_LOCAL_MACHINE;

	}
	
	vncService::BeginImpersonation();
	// test if we are running either standalone or as a service with an impersonated user
	if (vncService::CurrentUser((char *)&username, sizeof(username)) 
		&& strlen(username) != 0)
	{
		vnclog.Print(LL_INTINFO, VNCLOG("Loading settings for user %s"), username);
		// Load user settings from HKEY_CURRENT_USER
		if (RegOpenKeyEx(HKEY_CURRENT_USER,
						 TV_REGISTRY_KEY,
						 0, KEY_READ, &hkey) == ERROR_SUCCESS)
		{
			LoadUserPrefs(hkey);
			RegCloseKey(hkey);
		}
	}
	else
	{
		vnclog.Print(LL_INTINFO, VNCLOG("Loading user prefs: no user logged on"));	
	}
	vncService::EndImpersonation();

	// Make the loaded settings active.. 
	ApplyPrefs();
}

// load machine specific settings from the selected key
void vncProperties::LoadMachinePrefs(HKEY appkey)
{
	m_pref_General_Logging = (bool)LoadInt(appkey, "Logging", m_pref_General_Logging);

	// security prefs
	m_pref_Security_AdminOnly = LoadInt(appkey, "AllowProperties", m_pref_Security_AdminOnly);
	m_pref_Security_AllowIncoming = (bool)LoadInt(appkey, "IncomingConnections", m_pref_Security_AllowIncoming);
	m_pref_Security_AllowDisableInput = LoadInt(appkey, "LocalInputsDisabled", m_pref_Security_AllowDisableInput);
	m_pref_Security_AllowInput = LoadInt(appkey, "InputsEnabled", m_pref_Security_AllowInput);
	m_pref_Security_EnableFileTransfer = LoadInt(appkey, "FileTransferEnabled", m_pref_Security_EnableFileTransfer);
	m_pref_Security_LockSettings = LoadInt(appkey, "LockSetting", m_pref_Security_LockSettings);
	m_pref_Security_Multiple =  LoadInt(appkey, "ConnectPriority", m_pref_Security_Multiple);
	m_pref_Security_VNC_Compat = LoadInt(appkey, "VNC_Compat", m_pref_Security_VNC_Compat);

	// host mode prefs
	m_pref_Host_Autostart = m_server->AutostartSetting();
	bool use_manual_HostMode = (bool)LoadInt(appkey, "UseHostMode", 0);

	//we define a manual Hostmode (no autostart and no service)
	if (m_pref_Host_Autostart == 0 && use_manual_HostMode)
		m_pref_Host_Autostart = 3;


	m_pref_Host_AllowShutdown = LoadInt(appkey, "AllowShutdown", m_pref_Host_AllowShutdown);
	LoadPassword(appkey, m_pref_Host_Passwd);
	
	vncPasswd::ToText unenc(m_pref_Host_Passwd);
	if (strcmp(unenc,"")==0)
	{
		use_manual_HostMode = false;
		m_pref_Host_Autostart = 0;
	}

}

// save machine specific settings to the selected key
void vncProperties::SaveMachinePrefs(HKEY appkey)
{
	SaveInt(appkey, "Logging", m_pref_General_Logging);

	// security prefs
	SaveInt(appkey, "AllowProperties", m_pref_Security_AdminOnly);
	SaveInt(appkey, "IncomingConnections", m_pref_Security_AllowIncoming);
	SaveInt(appkey, "LocalInputsDisabled", m_pref_Security_AllowDisableInput);
	SaveInt(appkey, "InputsEnabled", m_pref_Security_AllowInput);
	SaveInt(appkey, "FileTransferEnabled", m_pref_Security_EnableFileTransfer);
	SaveInt(appkey, "LockSetting", m_pref_Security_LockSettings);
	SaveInt(appkey, "ConnectPriority", m_pref_Security_Multiple);
	SaveInt(appkey, "VNC_Compat", m_pref_Security_VNC_Compat);

	// host mode prefs
	SaveInt(appkey, "AllowShutdown", m_pref_Host_AllowShutdown);
	SavePassword(appkey, m_pref_Host_Passwd);

	SaveInt(appkey, "UseHostMode", m_pref_Host_Autostart > 0);
	
	
	// Save version number
	SaveString(appkey, "Version", m_server->Version());
}

// load user prefs from the selected key
void vncProperties::LoadUserPrefs(HKEY appkey)
{
	SetConnectionMode((ConnectionMode)LoadInt(appkey, "ConnectionMode", GetConnectionMode()));

	// general prefs
	m_pref_General_UseDynGate = (bool)LoadInt(appkey, "UseDynGate", m_pref_General_UseDynGate);
	LoadString(appkey, "UserIdentity", m_pref_General_Identity, MAXIDENTITYLEN);
	if (isNoSave)
		m_pref_General_ConnectionLogging = false;
	else
		m_pref_General_ConnectionLogging = (bool)LoadInt(appkey, "ConnectionLogging", m_pref_General_ConnectionLogging);

	// remotecontrol prefs
	m_pref_Remote_Quality = LoadInt(appkey, "RemoteControlQuality", m_pref_Remote_Quality);
	m_pref_Remote_Compression = LoadInt(appkey, "RemoteControlCompression", m_pref_Remote_Compression);
	m_pref_Remote_Colors = LoadInt(appkey, "RemoteControlColors", m_pref_Remote_Colors);
	m_pref_Remote_ServerScale = LoadInt(appkey, "RemoteControlServerScale", m_pref_Remote_ServerScale);
	m_pref_Remote_ViewOnly = (bool)LoadInt(appkey, "RemoteControlViewOnly", m_pref_Remote_ViewOnly);
	m_pref_Remote_Wallpaper = (bool)LoadInt(appkey, "RemoteControlWallpaper", m_pref_Remote_Wallpaper);
	m_pref_Remote_DisableInput = (bool)LoadInt(appkey, "RemoteControlDisableInput", m_pref_Remote_DisableInput);
	m_pref_Remote_BlackScreen = (bool)LoadInt(appkey, "RemoteControlBlackScreen", m_pref_Remote_BlackScreen);
	m_pref_Remote_Scaling = (bool)LoadInt(appkey, "RemoteControlScaling", m_pref_Remote_Scaling);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -