📄 generalpage.cpp
字号:
for(long i=0; i< pToolList->Count; i++)
{
IADspToolPtr pTool = pToolList->GetItem(i);
sprintf( szBuffer, "%s",(char *) pTool->Type);
if(!stricmp("Compiler",szBuffer) )
{
strcpy(szBuffer,"-include ");
strcat(szBuffer,header_file);
try
{
// Remove the switch if its already exists.
if(pTool->IsSwitchSet("Debug","AdditionalOptions"))
pTool->RemoveSwitch("Debug","AdditionalOptions",szBuffer);
if(pTool->IsSwitchSet("Release","AdditionalOptions"))
pTool->RemoveSwitch("Release","AdditionalOptions",szBuffer);
}
catch(_com_error err)
{
}
}
}
}
try
{
IADspSourceFilePtr pSrcFile = pProject->AddFile(source_file,"");
pSrcFile = pProject->AddFile(header_file,"");
pSrcFile = pProject->AddFile(g_config_source,"TCP/IP Configuration");
}
catch(_com_error err)
{
}
IADspToolListPtr pToolList = pProject->ToolList;
for(long i=0; i< pToolList->Count; i++)
{
IADspToolPtr pTool = pToolList->GetItem(i);
sprintf( szBuffer, "%s",(char *) pTool->Type);
if(!stricmp("Compiler",szBuffer) )
{
strcpy(szBuffer,"-include ");
strcat(szBuffer,header_file);
try
{
// Remove the switch if its already exists.
if(pTool->IsSwitchSet("Debug","AdditionalOptions"))
pTool->RemoveSwitch("Debug","AdditionalOptions",szBuffer);
if(pTool->IsSwitchSet("Release","AdditionalOptions"))
pTool->RemoveSwitch("Release","AdditionalOptions",szBuffer);
// Add the switch for both release and debug builds
pTool->AddSwitch("Debug","AdditionalOptions",szBuffer);
pTool->AddSwitch("Release","AdditionalOptions",szBuffer);
}
catch(_com_error err)
{
pTool->AddSwitch("Debug","AdditionalOptions",szBuffer);
pTool->AddSwitch("Release","AdditionalOptions",szBuffer);
}
}
}
pApp->Interactive = inter;
free(cfg_source);
free(cfg_header);
}
void GeneralPage::OnButtonSave()
{
char filename[512];
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CStatic *pEdit_ConfigFile = (CStatic*)GetDlgItem(IDC_EDIT_CONFIG_FILE);
pEdit_ConfigFile->GetWindowText(filename,sizeof(filename));
SaveAsFile(filename,true);
}
void GeneralPage::SaveAsFile(char *fname, bool dlgopen)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CButton *pButton_Save;
CStatic *pEdit_ConfigFile;
if (dlgopen) {
pButton_Save = (CButton*)GetDlgItem(IDC_BUTTON_SAVEAS);
pEdit_ConfigFile = (CStatic*)GetDlgItem(IDC_EDIT_CONFIG_FILE);
}
static char *filter = "TCP/IP Configuration file(*.tcp)\x00*.tcp;\x00\x00";
char filename[512];
OPENFILENAME ofn;
bool newfile=false;
memset(&ofn,0, sizeof(ofn));
// Checks for the given file extension. If there is no .tcp extension
// it will append it to the given file.
//
strcpy(filename,fname);
if(filename[0]==0)
{
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFilter = filter;
ofn.lpstrFile = filename;
ofn.nMaxFile = sizeof(filename);
ofn.lpstrTitle = "Save TCP/IP configuration file";
ofn.Flags = OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT;
if(GetSaveFileName(&ofn))
{
CString fname = ofn.lpstrFile;
if(fname.GetLength() > 0)
{
strcpy(filename,ofn.lpstrFile);
}
else
return;
}
else
return;
CheckAndAppendTCPExtension(filename);
newfile = true;
if (dlgopen) SetFileName(filename);
}
strcpy(g_last_configfile,filename);
strcpy(g_config_source,filename);
ConfigHeaderStruct *cfg_header = (ConfigHeaderStruct*)malloc(sizeof(ConfigHeaderStruct));
ConfigSourceStruct *cfg_source = (ConfigSourceStruct*)malloc(sizeof(ConfigSourceStruct));
if(cfg_header == NULL || cfg_source == NULL)
{
MessageBox("Malloc failed","Save",MB_OK);
return;
}
StoreGeneralHeaderData(cfg_header);
g_pIP->StoreIPHeaderData(cfg_header);
g_pTCP->StoreTCPHeaderData(cfg_header);
g_pMEMORY->StoreMemoryHeaderData(cfg_header);
g_pNP0->StoreNIfce0SourceData(&cfg_source->nw_ifces[0]);
g_pNP1->StoreNIfce1SourceData(&cfg_source->nw_ifces[1]);
g_pDEBUG->StoreDebugHeaderData(cfg_header);
StoreConfigHeaderData(filename,cfg_header);
StoreConfigSourceData(filename,cfg_source);
SaveConfigFileIntoRegistry(filename);
g_load_complete_display = false;
//int ret = AfxMessageBox("File Saved", MB_ICONINFORMATION | MB_OK);
g_save = false;
if(cfg_header)
free(cfg_header);
if(cfg_source)
free(cfg_source);
if (dlgopen) pButton_Save->EnableWindow(FALSE);
OnButtonAddproject(); // generate the project files
}
void GeneralPage::InitDefaultGeneralSettings()
{
// Default protocols
m_proto_all = false;
m_proto_tcp = true;
m_proto_udp = true;
m_proto_icmp = false;
m_proto_dhcp = true;
// Default stats
m_stats_all = false;
m_stats_tcp = false;
m_stats_udp = false;
m_stats_ip = false;
m_stats_icmp = false;
m_stats_link = false;
}
void GeneralPage::PopulateGeneralPageSettings()
{
if(m_proto_all == true)
{
CButton *pButton= (CButton*)GetDlgItem(IDC_CHECK_PROTO_ALL);
pButton->SetCheck(TRUE);
OnCheckProtoAll();
}
else
{
CButton *pButton= (CButton*)GetDlgItem(IDC_CHECK_PROTO_ALL);
pButton->SetCheck(FALSE);
// Check TCP
pButton= (CButton*)GetDlgItem(IDC_CHECK_PROTO_TCP);
pButton->EnableWindow();
(m_proto_tcp == true) ? pButton->SetCheck(TRUE) :pButton->SetCheck(FALSE);
// Check UDP
pButton= (CButton*)GetDlgItem(IDC_CHECK_PROTO_UDP);
pButton->EnableWindow();
(m_proto_udp == true) ? pButton->SetCheck(TRUE) :pButton->SetCheck(FALSE);
// Check ICMP
pButton= (CButton*)GetDlgItem(IDC_CHECK_PROTO_ICMP);
pButton->EnableWindow();
(m_proto_icmp == true) ? pButton->SetCheck(TRUE) :pButton->SetCheck(FALSE);
// Check ICMP
pButton= (CButton*)GetDlgItem(IDC_CHECK_PROTO_DHCP);
pButton->EnableWindow();
(m_proto_dhcp == true) ? pButton->SetCheck(TRUE) :pButton->SetCheck(FALSE);
}
if(m_stats_all == true)
{
CButton *pButton= (CButton*)GetDlgItem(IDC_CHECK_ALL_STAT);
pButton->SetCheck(TRUE);
OnCheckAllStat();
}
else
{
CButton *pButton= (CButton*)GetDlgItem(IDC_CHECK_ALL_STAT);
pButton->SetCheck(FALSE);
// Check TCP
pButton= (CButton*)GetDlgItem(IDC_CHECK_TCP_STAT);
pButton->EnableWindow();
(m_stats_tcp == true) ? pButton->SetCheck(TRUE) :pButton->SetCheck(FALSE);
// Check UDP
pButton= (CButton*)GetDlgItem(IDC_CHECK_UDP_STAT);
pButton->EnableWindow();
(m_stats_udp == true) ? pButton->SetCheck(TRUE) :pButton->SetCheck(FALSE);
// Check IP
pButton= (CButton*)GetDlgItem(IDC_CHECK_IP_STAT);
pButton->EnableWindow();
(m_stats_ip == true) ? pButton->SetCheck(TRUE) :pButton->SetCheck(FALSE);
// Check ICMP
pButton= (CButton*)GetDlgItem(IDC_CHECK_ICMP_STAT);
pButton->EnableWindow();
(m_stats_icmp == true) ? pButton->SetCheck(TRUE) :pButton->SetCheck(FALSE);
// Check LINK
pButton= (CButton*)GetDlgItem(IDC_CHECK_LINK_STAT);
pButton->EnableWindow();
(m_stats_link == true) ? pButton->SetCheck(TRUE) :pButton->SetCheck(FALSE);
}
}
void GeneralPage::StoreGeneralHeaderData(ConfigHeaderStruct *cfg_header_struct)
{
if(cfg_header_struct != NULL)
{
cfg_header_struct->proto_all = m_proto_all;
cfg_header_struct->proto_tcp = m_proto_tcp;
cfg_header_struct->proto_udp = m_proto_udp;
cfg_header_struct->proto_icmp = m_proto_icmp;
cfg_header_struct->proto_dhcp = m_proto_dhcp;
cfg_header_struct->stats_all = m_stats_all;
cfg_header_struct->stats_tcp = m_stats_tcp;
cfg_header_struct->stats_udp = m_stats_udp;
cfg_header_struct->stats_ip = m_stats_ip;
cfg_header_struct->stats_icmp = m_stats_icmp;
cfg_header_struct->stats_link = m_stats_link;
}
}
void GeneralPage::LoadGeneralHeaderData(ConfigHeaderStruct *cfg_header_struct)
{
m_proto_all = cfg_header_struct->proto_all;
m_proto_tcp = cfg_header_struct->proto_tcp;
m_proto_udp = cfg_header_struct->proto_udp;
m_proto_icmp = cfg_header_struct->proto_icmp;
m_proto_dhcp = cfg_header_struct->proto_dhcp;
m_stats_all = cfg_header_struct->stats_all;
m_stats_tcp = cfg_header_struct->stats_tcp;
m_stats_udp = cfg_header_struct->stats_udp;
m_stats_ip = cfg_header_struct->stats_ip;
m_stats_icmp = cfg_header_struct->stats_icmp;
m_stats_link = cfg_header_struct->stats_link;
m_multiple_networks = cfg_header_struct->multiple_networks;
}
void GeneralPage::SaveChanges(char *filename)
{
ConfigHeaderStruct *cfg_header = (ConfigHeaderStruct*)malloc(sizeof(ConfigHeaderStruct));
ConfigSourceStruct *cfg_source = (ConfigSourceStruct*)malloc(sizeof(ConfigSourceStruct));
if(cfg_header == NULL || cfg_source == NULL)
{
MessageBox("Malloc failed","Save",MB_OK);
return;
}
StoreGeneralHeaderData(cfg_header);
g_pIP->StoreIPHeaderData(cfg_header);
g_pTCP->StoreTCPHeaderData(cfg_header);
g_pMEMORY->StoreMemoryHeaderData(cfg_header);
g_pNP0->StoreNIfce0SourceData(&cfg_source->nw_ifces[0]);
g_pNP1->StoreNIfce1SourceData(&cfg_source->nw_ifces[1]);
g_pDEBUG->StoreDebugHeaderData(cfg_header);
StoreConfigHeaderData(filename,cfg_header);
StoreConfigSourceData(filename,cfg_source);
SaveConfigFileIntoRegistry(filename);
g_load_complete_display = false;
g_save = false;
free(cfg_header);
free(cfg_source);
}
void GeneralPage::LoadFile(char *filename)
{
ConfigHeaderStruct *cfg_load_header = (ConfigHeaderStruct*)malloc(sizeof(ConfigHeaderStruct));
ConfigSourceStruct *cfg_source = (ConfigSourceStruct*)malloc(sizeof(ConfigSourceStruct));
LoadConfigHeaderData(filename,cfg_load_header);
LoadConfigSourceData(filename,cfg_source);
strcpy(g_config_source,filename);
// Sets the variaous member variable values.
//
LoadGeneralHeaderData(cfg_load_header);
g_pIP->LoadIPHeaderData(cfg_load_header);
g_pTCP->LoadTCPHeaderData(cfg_load_header);
g_pMEMORY->LoadMemoryHeaderData(cfg_load_header);
g_pDEBUG->LoadDebugHeaderData(cfg_load_header);
g_pNP0->LoadNIfce0SourceData(&cfg_source->nw_ifces[0]);
g_pNP1->LoadNIfce1SourceData(&cfg_source->nw_ifces[1]);
// Show them in UI
free(cfg_load_header);
free(cfg_source);
}
void GeneralPage::EnableSaveButton()
{
CButton *pSaveButton = (CButton*)GetDlgItem(IDC_BUTTON_SAVEAS);
if(g_save == true)
pSaveButton->EnableWindow(TRUE);
else
pSaveButton->EnableWindow(FALSE);
}
void GeneralPage::OnChangeEditConfigFile()
{
char filename[512];
CStatic *pEdit_ConfigFile = (CStatic*)GetDlgItem(IDC_EDIT_CONFIG_FILE);
pEdit_ConfigFile->GetWindowText(filename,sizeof(filename));
if(stricmp(filename,""))
{
if(stricmp(g_config_source,filename))
{
CButton *pSaveButton = (CButton*)GetDlgItem(IDC_BUTTON_SAVE);
pSaveButton->EnableWindow(TRUE);
CButton *pButton_GenerateFiles = (CButton*)GetDlgItem(IDC_BUTTON_ADDPROJECT);
pButton_GenerateFiles->EnableWindow(TRUE);
}
}
else
{
CButton *pSaveButton = (CButton*)GetDlgItem(IDC_BUTTON_SAVE);
pSaveButton->EnableWindow(FALSE);
CButton *pButton_GenerateFiles = (CButton*)GetDlgItem(IDC_BUTTON_ADDPROJECT);
pButton_GenerateFiles->EnableWindow(FALSE);
}
}
bool GeneralPage::CheckAndAppendTCPExtension(char *filename)
{
char drive[3];
char directory[512];
char basename[512];
char ext[20];
strcpy(directory,"");
strcpy(drive,"");
strcpy(basename,"");
strcpy(ext,"");
_splitpath(filename,drive,directory,basename,ext);
if(stricmp(filename,"") && !stricmp(ext,""))
{
strcat(filename,".tcp");
}
return true;
}
void GeneralPage::OnButtonSaveas()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SaveAsFile("",true);
}
void GeneralPage::OnOK()
{
CPropertyPage::OnOK();
}
void GeneralPage::OnCancel()
{
CPropertyPage::OnCancel();
}
BOOL GeneralPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
CButton *pSaveAsButton = (CButton*)GetDlgItem(IDC_BUTTON_SAVEAS);
pSaveAsButton->EnableWindow(m_OriginalFile =="");
SetFileName(m_OriginalFile);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void GeneralPage::SetFileName(const char *fname)
{
char tmp[512],disp[512];
CStatic *pEdit_ConfigFile = (CStatic*)GetDlgItem(IDC_EDIT_CONFIG_FILE);
CStatic *pEdit_ConfigFileVis = (CStatic*)GetDlgItem(IDC_EDIT_CONFIG_FILE_VIS);
int len;
char *remf;
int lines = 2;
pEdit_ConfigFile->SetWindowText(fname);
if (fname[0]==0) {
strcpy(disp,"\n *** no file name set ***");
} else {
strcpy(tmp,fname);
disp[0] = 0;
remf = tmp;
while (lines>0) {
char *slash,*start;
char ch;
len = strlen(remf);
if (len<55) break;
start = remf;
slash = remf+55;
while ((slash>start) && (*slash!='\\') && (*slash!='/')) slash--;
if (slash==start) slash = remf+55;
ch = *(slash+1);
*(slash+1) = 0;
strcat(disp,remf);
strcat(disp,"\n");
*(slash+1) = ch;
remf = slash+1;
lines--;
}
strcat(disp,remf);
}
pEdit_ConfigFileVis->SetWindowText(disp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -