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

📄 cfg.cpp

📁 飞鸽传书 可以在局域网上应用一些关于文件传输的 高速且有效
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				if (SendOrder[cnt] == SendOrder[cnt2])
					break;
			if (cnt2 != MAX_SENDWIDTH)
				break;
		}
		if (cnt != MAX_SENDWIDTH)
			for (cnt=0; cnt < MAX_SENDWIDTH; cnt++)
				SendOrder[cnt] = cnt;

		reg.GetInt(SENDXDIFF_STR, &SendXdiff);
		reg.GetInt(SENDYDIFF_STR, &SendYdiff);
		reg.GetInt(SENDMIDYDIFF_STR, &SendMidYdiff);
		reg.GetInt(SENDSAVEPOS_STR, &SendSavePos);
		reg.GetInt(SENDXPOS_STR, &SendXpos);
		reg.GetInt(SENDYPOS_STR, &SendYpos);

		reg.GetInt(RECVXDIFF_STR, &RecvXdiff);
		reg.GetInt(RECVYDIFF_STR, &RecvYdiff);
		reg.GetInt(RECVSAVEPOS_STR, &RecvSavePos);
		reg.GetInt(RECVXPOS_STR, &RecvXpos);
		reg.GetInt(RECVYPOS_STR, &RecvYpos);
		reg.CloseKey();
	}

	if (reg.CreateKey(FONT_STR) == TRUE)
	{
		ReadFontRegistry(&reg, SENDEDITFONT_STR, &SendEditFont);
		ReadFontRegistry(&reg, SENDLISTFONT_STR, &SendListFont);
		ReadFontRegistry(&reg, RECVHEADFONT_STR, &RecvHeadFont);
		ReadFontRegistry(&reg, RECVEDITFONT_STR, &RecvEditFont);
		reg.CloseKey();
	}

	if (reg.CreateKey(BROADCAST_STR) == TRUE)
	{
		int		cnt = 0;
		while (1)
		{
			wsprintf(buf, "%d", cnt++);
			if (reg.GetStr(buf, val, sizeof(val)) != TRUE)
				break;
			broadcastList.SetHostRaw(val, (ResolveOpt & RS_REALTIME) ? 0 : ResolveAddr(val));
		}
		reg.CloseKey();
	}

	for (cnt=0; DefaultUrlProtocol[cnt] != NULL; cnt++)
	{
		UrlObj *obj = new UrlObj;
		strncpyz(obj->protocol, DefaultUrlProtocol[cnt], sizeof(obj->protocol));
		*obj->program = 0;
		urlList.AddObj(obj);
	}

	if (reg.CreateKey(CLICKABLEURL_STR) == TRUE)
	{
		for (cnt = 0; reg.EnumValue(cnt, buf, sizeof(buf)) == TRUE || reg.EnumKey(cnt, buf, sizeof(buf)) == TRUE; cnt++)
		{
			for (UrlObj *obj = (UrlObj *)urlList.TopObj(); obj != NULL; obj = (UrlObj *)urlList.NextObj(obj))
				if (stricmp(obj->protocol, buf) == 0)
					break;

			if (obj == NULL)
			{
				obj = new UrlObj;
				urlList.AddObj(obj);
			}
			strncpyz(obj->protocol, buf, sizeof(obj->protocol));
			reg.GetStr(buf, obj->program, sizeof(obj->program));
		}
		reg.CloseKey();
	}

	if (reg.CreateKey(PRIORITY_STR) == TRUE)
	{
		reg.GetInt(PRIORITYMAX_STR, &PriorityMax);
		reg.GetInt(PRIORITYREJECT_STR, &PriorityReject);
#if 0
		PrioritySound = new char *[PriorityMax];
		for (int cnt=0; cnt < PriorityMax; cnt++)
		{
			wsprintf(buf, "%d", cnt);

			if (reg.CreateKey(buf) == TRUE)
			{
				if (reg.GetStr(PRIORITYSOUND_STR, buf, sizeof(buf)) == TRUE && *buf != '\0')
					PrioritySound[cnt] = strdup(buf);
				reg.CloseKey();
			}
		}
#endif
		reg.CloseKey();
	}

	if (reg.CreateKey(HOSTINFO_STR) == TRUE)
	{
		int		cnt = 0, priority;
		Host	*host;
		time_t	default_time = Time() - KeepHostTime / 2;	// 90 擔
		BOOL	rewriteFlg = FALSE;

		priorityHosts.Enable(THosts::NAME, TRUE);
		fileHosts.Enable(THosts::NAME_ADDR, TRUE);
		for (cnt = 0; reg.EnumValue(cnt, buf, sizeof(buf)) == TRUE || reg.EnumKey(cnt, buf, sizeof(buf)) == TRUE; cnt++)
		{
			if (reg.OpenKey(buf) != TRUE)
				break;
			if (reg.GetInt(PRIORITY_STR, &priority) != TRUE || priority == DEFAULT_PRIORITY)
				rewriteFlg = TRUE;
			else {
				host = new Host;
				host->priority = priority;
				reg.GetStr(USERNAME_STR, host->hostSub.userName, MAX_NAMEBUF);
				reg.GetStr(HOSTNAME_STR, host->hostSub.hostName, MAX_NAMEBUF);
				reg.GetLong(IPADDR_STR, (long *)&host->hostSub.addr);
				reg.GetInt(PORTNO_STR, &host->hostSub.portNo);
				reg.GetStr(NICKNAME_STR, host->nickName, MAX_NAMEBUF);
				reg.GetStr(GROUPNAME_STR, host->groupName, MAX_NAMEBUF);
				if (reg.GetLong(UPDATETIME_STR, &host->updateTime) != TRUE)
					host->updateTime = default_time;
				priorityHosts.AddHost(host);
			}
			reg.CloseKey();
		}
		reg.CloseKey();
		if (rewriteFlg)
			WriteRegistry(CFG_HOSTINFO|CFG_DELHOST);
	}

	if (reg.OpenKey(DEBUG_STR) == TRUE)	// 媽僶乕僕儑儞儗僕僗僩儕嶍彍
	{
		reg.CloseKey();
		reg.DeleteChildTree();
	}
	if (reg.GetStr(NULL, buf, sizeof(buf)) != TRUE || strcmp(buf, GetVerionStr()))
	{
		reg.CloseKey();		// close top appreg
		WriteRegistry();
	}

	return	TRUE;
}

BOOL Cfg::ReadFontRegistry(TRegistry *reg, char *key, LOGFONT *font)
{
	if (reg->CreateKey(key) == TRUE)
	{
		int		tmp = 0;

		reg->GetInt(HEIGHT_STR, &tmp);			font->lfHeight = tmp;
		reg->GetInt(WIDTH_STR, &tmp);			font->lfWidth = tmp;
		reg->GetInt(ESCAPEMENT_STR, &tmp);		font->lfEscapement = tmp;
		reg->GetInt(ORIENTATION_STR, &tmp);		font->lfOrientation = tmp;
		reg->GetInt(WEIGHT_STR, &tmp);			font->lfWeight = tmp;
		reg->GetInt(ITALIC_STR, &tmp);			font->lfItalic = (BYTE)tmp;
		reg->GetInt(UNDERLINE_STR, &tmp);		font->lfUnderline = (BYTE)tmp;
		reg->GetInt(STRIKEOUT_STR, &tmp);		font->lfStrikeOut = (BYTE)tmp;
		reg->GetInt(CHARSET_STR, &tmp);			font->lfCharSet = (BYTE)tmp;
		reg->GetInt(OUTPRECISION_STR, &tmp);	font->lfOutPrecision = (BYTE)tmp;
		reg->GetInt(CLIPPRECISION_STR, &tmp);	font->lfClipPrecision = (BYTE)tmp;
		reg->GetInt(QUALITY_STR, &tmp);			font->lfQuality = (BYTE)tmp;
		reg->GetInt(PITCHANDFAMILY_STR, &tmp);	font->lfPitchAndFamily = (BYTE)tmp;
		reg->GetStr(FACENAME_STR, font->lfFaceName, sizeof(font->lfFaceName));
		reg->CloseKey();
	}
	return	TRUE;
}


BOOL Cfg::WriteRegistry(int ctl_flg)
{
	char	buf[MAX_LISTBUF], val[MAX_LISTBUF];

	GetRegName(buf, nicAddr, portNo);
	TRegistry	reg(HS_TOOLS, buf);

	if (ctl_flg & CFG_GENERAL)
	{
		reg.SetStr(NULL, GetVerionStr());
		reg.SetInt(NOBEEP_STR, NoBeep);
		reg.SetInt(LISTGET_STR, ListGet);
		reg.SetInt(LISTGETMSEC_STR, (int)ListGetMSec);
		reg.SetInt(RETRYMSEC_STR, (int)RetryMSec);
		reg.SetInt(RETRYMAX_STR, (int)RetryMax);
		reg.SetInt(IsWinNT() ? RECVMAXNT_STR : RECVMAX95_STR, (int)RecvMax);
		reg.SetInt(NOERASE_STR, NoErase);
		reg.SetInt(DEBUG_STR, Debug);
		reg.SetInt(NOPOPUPCHECK_STR, NoPopupCheck);
		reg.SetInt(OPENCHECK_STR, OpenCheck);
		reg.SetInt(ALLOWSENDLIST_STR, AllowSendList);
		reg.SetInt(FILETRANSOPT_STR, fileTransOpt);
		reg.SetInt(RESOLVEOPT_STR, ResolveOpt);
		reg.SetInt(VIEWMAX_STR, ViewMax);
		reg.SetInt(TRANSMAX_STR, TransMax);
		reg.SetInt(TCPBUFMAX_STR, TcpbufMax);
	}

	if (ctl_flg & CFG_ABSENCE)
	{
		reg.SetInt(ABSENCESAVE_STR, AbsenceSave);
		reg.SetInt(ABSENCECHECK_STR, AbsenceCheck);
		reg.SetInt(ABSENCEMAX_STR, AbsenceMax);
		if (reg.CreateKey(ABSENCESTR_STR) == TRUE)
		{
			for (int cnt=0; cnt < AbsenceMax; cnt++)
			{
				char	key[MAX_PATH];
				wsprintf(key, "%s%d", ABSENCESTR_STR, cnt);
				reg.SetStr(key, AbsenceStr[cnt]);
				wsprintf(key, "%s%d", ABSENCEHEAD_STR, cnt);
				reg.SetStr(key, AbsenceHead[cnt]);
			}
		}
		reg.CloseKey();
	}

	if (ctl_flg & CFG_GENERAL)
	{
		reg.SetStr(PASSWORD_STR, PasswordStr);
		reg.SetInt(PASSWDLOGCHECK_STR, PasswdLogCheck);
		reg.SetInt(DELAYTIME_STR, DelayTime);
		reg.SetInt(QUOTECHECK_STR, QuoteCheck);
		reg.SetInt(SECRETCHECK_STR, SecretCheck);
		reg.SetInt(IPADDRCHECK_STR, IPAddrCheck);
		reg.SetInt(ONECLICKPOPUP_STR, OneClickPopup);
		reg.SetInt(ABNORMALBTN_STR, AbnormalButton);
		reg.SetInt(DIALUPCHECK_STR, DialUpCheck);
		reg.SetInt(NICKNAMECHECK_STR, NickNameCheck);
		reg.SetInt(ABSENCENONPOPUP_STR, AbsenceNonPopup);
		reg.SetStr(NICKNAMESTR_STR, NickNameStr);
		reg.SetStr(GROUPNAMESTR_STR, GroupNameStr);
		reg.SetStr(LANG_STR, Lang);
		reg.SetLong(SORT_STR, Sort);
		reg.SetInt(UPDATETIME_STR, UpdateTime);
		reg.SetInt(KEEPHOSTTIME_STR, KeepHostTime);
		reg.SetInt(MSGMINIMIZE_STR, MsgMinimize);
		reg.SetInt(EXTENDENTRY_STR, ExtendEntry);
		reg.SetInt(CONTROLIME_STR, ControlIME);
		reg.SetInt(GLIDLINE_STR, GlidLineCheck);
		reg.SetInt(COLUMNITEMS_STR, ColumnItems);
		reg.SetStr(QUOTESTR_STR, QuoteStr);
		if (reg.CreateKey(HOTKEY_STR) == TRUE)
		{
			reg.SetInt(HOTKEYCHECK_STR, HotKeyCheck);
			reg.SetInt(HOTKEYMODIFY_STR, HotKeyModify);
			reg.SetInt(HOTKEYSEND_STR, HotKeySend);
			reg.SetInt(HOTKEYRECV_STR, HotKeyRecv);
			reg.SetInt(HOTKEYMISC_STR, HotKeyMisc);
			reg.CloseKey();
		}
		reg.SetInt(LOGCHECK_STR, LogCheck);
		reg.SetStr(LOGFILE_STR, LogFile);
		reg.SetStr(SOUNDFILE_STR, SoundFile);
		reg.SetStr(ICON_STR, IconFile);
		reg.SetStr(REVICON_STR, RevIconFile);
		reg.SetStr(LASTOPEN_STR, lastOpenDir);
		reg.SetStr(LASTSAVE_STR, lastSaveDir);
	}

	if ((ctl_flg & CFG_WINSIZE) && reg.CreateKey(WINSIZE_STR) == TRUE)
	{
		reg.SetInt(SENDNICKNAME_STR, SendWidth[SW_NICKNAME]);
		reg.SetInt(SENDUSERNAME_STR, SendWidth[SW_USER]);
		reg.SetInt(SENDABSENCE_STR, SendWidth[SW_ABSENCE]);
		reg.SetInt(SENDPRIORITY_STR, SendWidth[SW_PRIORITY]);
		reg.SetInt(SENDGROUPNAME_STR, SendWidth[SW_GROUP]);
		reg.SetInt(SENDHOSTNAME_STR, SendWidth[SW_HOST]);
		reg.SetInt(SENDIPADDR_STR, SendWidth[SW_IPADDR]);

		if (reg.CreateKey(SENDORDER_STR) == TRUE)
		{
			for (int cnt=0; cnt < MAX_SENDWIDTH; cnt++)
			{
				wsprintf(buf, "%d", cnt);
				reg.SetInt(buf, SendOrder[cnt]);
			}
			reg.CloseKey();
		}

		reg.SetInt(SENDXDIFF_STR, SendXdiff);
		reg.SetInt(SENDYDIFF_STR, SendYdiff);
		reg.SetInt(SENDMIDYDIFF_STR, SendMidYdiff);
		reg.SetInt(SENDSAVEPOS_STR, SendSavePos);
		reg.SetInt(SENDXPOS_STR, SendXpos);
		reg.SetInt(SENDYPOS_STR, SendYpos);

		reg.SetInt(RECVXDIFF_STR, RecvXdiff);
		reg.SetInt(RECVYDIFF_STR, RecvYdiff);
		reg.SetInt(RECVSAVEPOS_STR, RecvSavePos);
		reg.SetInt(RECVXPOS_STR, RecvXpos);
		reg.SetInt(RECVYPOS_STR, RecvYpos);

		reg.CloseKey();
	}

	if ((ctl_flg & CFG_FONT) && reg.CreateKey(FONT_STR) == TRUE)
	{
		WriteFontRegistry(&reg, SENDEDITFONT_STR, &SendEditFont);
		WriteFontRegistry(&reg, SENDLISTFONT_STR, &SendListFont);
		WriteFontRegistry(&reg, RECVHEADFONT_STR, &RecvHeadFont);
		WriteFontRegistry(&reg, RECVEDITFONT_STR, &RecvEditFont);
		reg.CloseKey();
	}

	if ((ctl_flg & CFG_BROADCAST) && reg.CreateKey(BROADCAST_STR) == TRUE)
	{
		int		cnt = 0;
		for (TBroadcastObj *obj=broadcastList.Top(); obj; obj=broadcastList.Next(obj))
		{
			wsprintf(buf, "%d", cnt++);
			reg.SetStr(buf, obj->Host());
		}
		while (1)
		{
			wsprintf(buf, "%d", cnt++);
			if (reg.GetStr(buf, val, sizeof(val)) != TRUE)
				break;
			if (reg.DeleteValue(buf) != TRUE)
				break;
		}
		reg.CloseKey();
	}

	if (ctl_flg & CFG_CLICKURL)
	{
		reg.SetInt(DEFAULTURL_STR, DefaultUrl);
		reg.SetInt(SHELLEXEC_STR, ShellExec);
		if (reg.CreateKey(CLICKABLEURL_STR) == TRUE)
		{

			for (UrlObj *obj = (UrlObj *)urlList.TopObj(); obj != NULL; obj = (UrlObj *)urlList.NextObj(obj))
				reg.SetStr(obj->protocol, obj->program);
			reg.CloseKey();
		}
	}

	if ((ctl_flg & CFG_PRIORITY) && reg.CreateKey(PRIORITY_STR) == TRUE)
	{
		reg.SetInt(PRIORITYMAX_STR, PriorityMax);
		reg.SetInt(PRIORITYREJECT_STR, PriorityReject);
#if 0
		for (int cnt=0; cnt < PriorityMax; cnt++)
		{
			wsprintf(buf, "%d", cnt);

			if (reg.CreateKey(buf) == TRUE)
			{
				reg.SetStr(PRIORITYSOUND_STR, PrioritySound[cnt] ? PrioritySound[cnt] : "");
				reg.CloseKey();
			}
		}
#endif
		reg.CloseKey();
	}

	if ((ctl_flg & CFG_HOSTINFO) && reg.CreateKey(HOSTINFO_STR) == TRUE)
	{
		int cnt;
		time_t	now_time = Time();

		if (ctl_flg & CFG_DELHOST)
			reg.DeleteChildTree();

		for (cnt=0; cnt < priorityHosts.HostCnt(); cnt++)
		{
			Host	*host = priorityHosts.GetHost(cnt);
			wsprintf(buf, "%s:%s", host->hostSub.userName, host->hostSub.hostName);
			if (host->updateTime + KeepHostTime < now_time || host->priority == DEFAULT_PRIORITY)
			{
				if (ctl_flg & CFG_DELCHLDHOST)
					reg.DeleteChildTree(buf);
			}
			else if (reg.CreateKey(buf) == TRUE)
			{
				reg.SetStr(USERNAME_STR, host->hostSub.userName);
				reg.SetStr(HOSTNAME_STR, host->hostSub.hostName);
				reg.SetLong(IPADDR_STR, host->hostSub.addr);
				reg.SetInt(PORTNO_STR, host->hostSub.portNo);
				reg.SetStr(NICKNAME_STR, host->nickName);
				reg.SetStr(GROUPNAME_STR, host->groupName);
				reg.SetInt(PRIORITY_STR, host->priority);
				reg.SetLong(UPDATETIME_STR, host->updateTime);
				reg.CloseKey();
			}
		}
		reg.CloseKey();
	}

	if ((ctl_flg & CFG_FINDHIST) && reg.CreateKey(FINDSTR_STR) == TRUE)
	{
		reg.SetInt(FINDMAX_STR, FindMax);
		reg.SetInt(FINDALL_STR, FindAll);
		for (int cnt=0; cnt < FindMax; cnt++)
		{
			char	key[MAX_PATH];
			wsprintf(key, "%d", cnt);
			reg.SetStr(key, FindStr[cnt]);
		}
		reg.CloseKey();
	}

	return	TRUE;
}


BOOL Cfg::WriteFontRegistry(TRegistry *reg, char *key, LOGFONT *font)
{
	if (reg->CreateKey(key) == TRUE)
	{
		reg->SetInt(HEIGHT_STR, (int)font->lfHeight);
		reg->SetInt(WIDTH_STR, (int)font->lfWidth);
		reg->SetInt(ESCAPEMENT_STR, (int)font->lfEscapement);
		reg->SetInt(ORIENTATION_STR, (int)font->lfOrientation);
		reg->SetInt(WEIGHT_STR, (int)font->lfWeight);
		reg->SetInt(ITALIC_STR, (int)font->lfItalic);
		reg->SetInt(UNDERLINE_STR, (int)font->lfUnderline);
		reg->SetInt(STRIKEOUT_STR, (int)font->lfStrikeOut);
		reg->SetInt(CHARSET_STR, (int)font->lfCharSet);
		reg->SetInt(OUTPRECISION_STR, (int)font->lfOutPrecision);
		reg->SetInt(CLIPPRECISION_STR, (int)font->lfClipPrecision);
		reg->SetInt(QUALITY_STR, (int)font->lfQuality);
		reg->SetInt(PITCHANDFAMILY_STR, (int)font->lfPitchAndFamily);
		reg->SetStr(FACENAME_STR, font->lfFaceName);
		reg->CloseKey();
	}
	return	TRUE;
}

void Cfg::GetRegName(char *buf, ULONG nic_addr, int port_no)
{
	buf += wsprintf(buf, "%s", IPMSG_MSGSTR);
	if (port_no != IPMSG_DEFAULT_PORT)
		buf += wsprintf(buf, "%d", port_no);
	if (nic_addr)
		buf += wsprintf(buf, "_%s", inet_ntoa(*(in_addr *)&nic_addr));
}

⌨️ 快捷键说明

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