📄 mydialog2.cpp
字号:
} if (Int != NULL) { if (PrevInt == NULL) Conf->interfaces = Int->next; else PrevInt->next = Int->next; olsrd_cnf_free(Int); } return 0;}static struct olsr_if *AddInterface(struct olsrd_config **Conf, CString Name){ struct olsr_if *Int; Int = (struct olsr_if *)olsrd_cnf_malloc(sizeof (struct olsr_if)); if (Int == NULL) { AfxMessageBox("Cannot allocate memory."); return NULL; } Int->name = (char *)olsrd_cnf_malloc(Name.GetLength() + 1); if (Int->name == NULL) { olsrd_cnf_free(Int); AfxMessageBox("Cannot allocate memory."); return NULL; } ::lstrcpy(Int->name, Name); Int->config = NULL; Int->index = 0; Int->configured = OLSR_FALSE; Int->interf = NULL; Int->cnf = get_default_if_config(); Int->next = (*Conf)->interfaces; (*Conf)->interfaces = Int; return Int;}int MyDialog2::SaveConfigFile(CString PathName, int Real){ struct olsr_if *Int, *PrevInt; struct olsr_msg_params *MsgPar; CString Conv; struct hna4_entry *Hna4, *NewHna4, *PrevHna4; int NumInt = m_InterfaceList.GetItemCount(); int i; CString IntName, IntName2; struct ipc_host *IpcHost; unsigned int Local; PrevInt = NULL; // remove interfaces that we do not want for (Int = Conf->interfaces; Int != NULL; Int = Int->next) { IntName = Int->name; IntName.MakeUpper(); for (i = 0; i < NumInt; i++) if (m_InterfaceList.GetItemText(i, 0).Mid(0, 4) == IntName) break; if (i == NumInt || !m_InterfaceList.GetCheck(i)) { if (PrevInt != NULL) PrevInt->next = Int->next; else Conf->interfaces = Int->next; } } // add missing interfaces for (i = 0; i < NumInt; i++) { if (!m_InterfaceList.GetCheck(i)) continue; IntName2 = m_InterfaceList.GetItemText(i, 0).Mid(0, 4); for (Int = Conf->interfaces; Int != NULL; Int = Int->next) { IntName = Int->name; IntName.MakeUpper(); if (IntName2 == IntName) break; } if (Int == NULL) AddInterface(&Conf, m_InterfaceList.GetItemText(i, 0).Mid(0, 4)); } // add dummy interface, if there aren't any real interfaces if (Conf->interfaces == NULL && Real != 0) AddInterface(&Conf, "GUI"); // per-interface settings for (Int = Conf->interfaces; Int != NULL; Int = Int->next) { MsgPar = &Int->cnf->hello_params; m_HelloInt.GetWindowText(Conv); MsgPar->emission_interval = (float)atof(Conv); m_HelloHold.GetWindowText(Conv); MsgPar->validity_time = (float)atof(Conv); MsgPar = &Int->cnf->tc_params; m_TcInt.GetWindowText(Conv); MsgPar->emission_interval = (float)atof(Conv); m_TcHold.GetWindowText(Conv); MsgPar->validity_time = (float)atof(Conv); MsgPar = &Int->cnf->mid_params; m_MidInt.GetWindowText(Conv); MsgPar->emission_interval = (float)atof(Conv); m_MidHold.GetWindowText(Conv); MsgPar->validity_time = (float)atof(Conv); MsgPar = &Int->cnf->hna_params; m_HnaInt.GetWindowText(Conv); MsgPar->emission_interval = (float)atof(Conv); m_HnaHold.GetWindowText(Conv); MsgPar->validity_time = (float)atof(Conv); } // global settings Conf->debug_level = DebugLevel; m_PollInt.GetWindowText(Conv); Conf->pollrate = (float)atof(Conv); Conf->tc_redundancy = (unsigned char)m_TcRed.GetCurSel(); m_MprCov.GetWindowText(Conv); Conf->mpr_coverage = (unsigned char)atoi(Conv); Conf->use_hysteresis = m_HystCheck.GetCheck() ? OLSR_TRUE : OLSR_FALSE; m_HystScaling.GetWindowText(Conv); Conf->hysteresis_param.scaling = (float)atof(Conv); m_HystThresholdHigh.GetWindowText(Conv); Conf->hysteresis_param.thr_high = (float)atof(Conv); m_HystThresholdLow.GetWindowText(Conv); Conf->hysteresis_param.thr_low = (float)atof(Conv); if (!m_EtxCheck.GetCheck()) Conf->lq_level = 0; else if (m_EtxRadio1.GetCheck()) Conf->lq_level = 1; else Conf->lq_level = 2; if (!m_FishEyeCheck.GetCheck()) Conf->lq_fish = 0; else Conf->lq_fish = 1; m_EtxWindowSize.GetWindowText(Conv); Conf->lq_wsize = atoi(Conv); PrevHna4 = NULL; // check for a default gateway HNA4 entry for (Hna4 = Conf->hna4_entries; Hna4 != NULL; Hna4 = Hna4->next) { if (Hna4->net.v4 == 0 && Hna4->netmask.v4 == 0) break; PrevHna4 = Hna4; } // add default gateway HNA4 entry if (m_InternetCheck.GetCheck() && Hna4 == NULL) { NewHna4 = (struct hna4_entry * ) olsrd_cnf_malloc(sizeof (struct hna4_entry)); if (NewHna4 == NULL) { AfxMessageBox("Cannot allocate memory."); return -1; } NewHna4->net.v4 = 0; NewHna4->netmask.v4 = 0; NewHna4->next = Conf->hna4_entries; Conf->hna4_entries = NewHna4; } // remove default gateway HNA4 entry if (!m_InternetCheck.GetCheck() && Hna4 != NULL) { if (PrevHna4 == NULL) Conf->hna4_entries = Hna4->next; else PrevHna4->next = Hna4->next; olsrd_cnf_free(Hna4); } Local = inet_addr("127.0.0.1"); for (IpcHost = Conf->ipc_hosts; IpcHost != NULL; IpcHost = IpcHost->next) if (IpcHost->host.v4 == Local) break; if (IpcHost == NULL && Real == 0) { IpcHost = (struct ipc_host *) olsrd_cnf_malloc(sizeof (struct ipc_host)); if (IpcHost == NULL) { AfxMessageBox("Cannot allocate memory."); return -1; } IpcHost->host.v4 = Local; IpcHost->next = Conf->ipc_hosts; Conf->ipc_hosts = IpcHost; Conf->ipc_connections++; Conf->open_ipc = OLSR_TRUE; } // write configuration file if (olsrd_write_cnf(Conf, PathName) < 0) return -1; return 0;}void MyDialog2::OnSaveButton(){ CFileDialog FileDialog(FALSE); CString FileName = "Default.olsr"; CString PathName; FileDialog.m_ofn.lpstrFilter = "Configuration file (*.olsr)\0*.olsr\0"; FileDialog.m_ofn.nFilterIndex = 1; FileDialog.m_ofn.lpstrFile = FileName.GetBuffer(500); FileDialog.m_ofn.nMaxFile = 500; if (FileDialog.DoModal() == IDOK) { PathName = FileDialog.GetPathName(); if (SaveConfigFile(PathName, 1) < 0) AfxMessageBox("Cannot save configuration file '" + PathName + "'."); } FileName.ReleaseBuffer();}void MyDialog2::OnOpenButton(){ CFileDialog FileDialog(TRUE); CString FileName = "Default.olsr"; CString PathName; FileDialog.m_ofn.lpstrFilter = "Configuration file (*.olsr)\0*.olsr\0"; FileDialog.m_ofn.nFilterIndex = 1; FileDialog.m_ofn.lpstrFile = FileName.GetBuffer(500); FileDialog.m_ofn.nMaxFile = 500; if (FileDialog.DoModal() == IDOK) { PathName = FileDialog.GetPathName(); if (OpenConfigFile(PathName) < 0) AfxMessageBox("Cannot open configuration file '" + PathName + "'."); } FileName.ReleaseBuffer();}void MyDialog2::OnResetButton() { Reset();}void MyDialog2::OnEtxRadio1() { m_EtxRadio2.SetCheck(FALSE);}void MyDialog2::OnEtxRadio2() { m_EtxRadio1.SetCheck(FALSE);}void MyDialog2::OnKillfocusEtxWinSize() { CString Conv; int WinSize; m_EtxWindowSize.GetWindowText(Conv); WinSize = atoi(Conv); if (WinSize < 3) WinSize = 3; else if (WinSize > 128) WinSize = 128; Conv.Format("%d", WinSize); m_EtxWindowSize.SetWindowText(Conv);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -