DlgSettings.cpp
上传用户:gnaf34
上传日期:2022-04-22
资源大小:1657k
文件大小:16k
- // DlgSettings.cpp : implementation file
- //
- #include <string.h>
- #include "stdafx.h"
- #include "BeaconClient.h"
- #include "DlgSettings.h"
- #include "ConfigurePlots.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CString consoleStr;
- char testsFolderPath[MAX_PATH];
- char exeFolderPath[MAX_PATH];
- CString strTmpPath;
- extern CString laG,laA,laU,loG,loA,loU,jiG,jiA,jiU;
- /////////////////////////////////////////////////////////////////////////////
- // CDlgSettings dialog
- CDlgSettings::CDlgSettings(CWnd* pParent /*=NULL*/)
- : CDialog(CDlgSettings::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDlgSettings)
- m_strFolderPath = _T("");
- m_silenceDetection = FALSE;
- m_testSave = FALSE;
- m_Png = FALSE;
- m_Bmp = FALSE;
- //}}AFX_DATA_INIT
- }
- void CDlgSettings::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgSettings)
- DDX_Control(pDX, IDC_AUDIOCODEC, m_audioCodec);
- DDX_Text(pDX, IDC_OUTFILEPATH, m_strFolderPath);
- DDX_Check(pDX, IDC_SILENCEDETECTION, m_silenceDetection);
- DDX_Check(pDX, IDC_TESTSAVE, m_testSave);
- //DDX_Check(pDX, IDC_PNG, m_Png);
- //DDX_Check(pDX, IDC_BMP, m_Bmp);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDlgSettings, CDialog)
- //{{AFX_MSG_MAP(CDlgSettings)
- ON_BN_CLICKED(IDC_APPLYSETTINGS, OnApplysettings)
- ON_BN_CLICKED(IDC_DEFAULTSETTINGS, OnDefaultsettings)
- ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
- ON_BN_CLICKED(IDC_QUALITYMARKERS, OnQualitymarkers)
- ON_EN_KILLFOCUS(IDC_JITTERBUFFER, OnKillfocusJitterbuffer)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgSettings message handlers
- void CDlgSettings::OnApplysettings()
- {
- // TODO: Add your control notification handler code here
- CString folderHolder;
- CString text;
- CWnd* handle;
- FILE *fp;
- int t;
- // int t;
- //Save the file options to the Settings.conf file
- //Get the Path to the folder from where the beaconclient.exe is being executed
- char file[MAX_PATH];
- char exeFilePath[MAX_PATH]; //a string for GetModuleFileName() to store exe Path
- GetModuleFileName( NULL,&exeFilePath[0],sizeof (exeFilePath));
- //Extract path by copying without exe string..
- for(int i=0; i < abs(strlen(exeFilePath)-16); i++){
- file[i] = exeFilePath[i];
- }
- file[i] = ' ';
-
- //strcpy(file,exeFolderPath);
- strcat(file,"S.conf");
- fp = fopen(file,"w");
- //Call_options
- fprintf(fp,"Call_Optionsn");
- t=IsDlgButtonChecked(IDC_FASTSTART);
- fprintf(fp,"FASTSTARTt%dn",t);
- t=IsDlgButtonChecked(IDC_TUNNEL);
- fprintf(fp,"TUNNELt%dn",t);
- t=IsDlgButtonChecked(IDC_SETUP);
- fprintf(fp,"SETUPt%dnn",t);
-
- //Output_File_path
- fprintf(fp,"Output_File_pathn");
- CWnd* pFolder = (CWnd*)GetDlgItem(IDC_OUTFILEPATH);
- pFolder->GetWindowText(folderHolder);
- fprintf(fp,"OUTPUTFILEPATHt%snn",folderHolder);
- strcpy(testsFolderPath,folderHolder);
-
- //Ports
- fprintf(fp,"Ports_Optionsn");
- handle = (CWnd*)GetDlgItem(IDC_TCPBASE);
- handle->GetWindowText(text);
- fprintf(fp,"TCPBASEt%sn",text);
- handle = (CWnd*)GetDlgItem(IDC_TCPMAX);
- handle->GetWindowText(text);
- fprintf(fp,"TCPMAXt%sn",text);
- handle = (CWnd*)GetDlgItem(IDC_UDPBASE);
- handle->GetWindowText(text);
- fprintf(fp,"UDPBASEt%sn",text);
- handle = (CWnd*)GetDlgItem(IDC_UDPMAX);
- handle->GetWindowText(text);
- fprintf(fp,"UDPMAXt%sn",text);
- handle = (CWnd*)GetDlgItem(IDC_RTPBASE);
- handle->GetWindowText(text);
- fprintf(fp,"RTPPBASEt%sn",text);
- handle = (CWnd*)GetDlgItem(IDC_RTPMAX);
- handle->GetWindowText(text);
- fprintf(fp,"RTPMAXt%snn",text);
- //Test Results
- fprintf(fp,"Test_Resultsn");
- t=IsDlgButtonChecked(IDC_TESTSAVE);
- fprintf(fp,"TESTSAVEt%dnn",t);
- // t=IsDlgButtonChecked(IDC_PNG);
- // fprintf(fp,"PNGt%dn",t);
- // t=IsDlgButtonChecked(IDC_BMP);
- // fprintf(fp,"BMPt%dnn",t);
- //Audio options
- fprintf(fp,"Audio_Optionsn");
- t=IsDlgButtonChecked(IDC_SILENCEDETECTION);
- fprintf(fp,"SILENCEDETECTIONt%dn",t);
- handle = (CWnd*)GetDlgItem(IDC_AUDIOCODEC);
- handle->GetWindowText(text);
- fprintf(fp,"AUDIOCODECt%sn",text);
- handle = (CWnd*)GetDlgItem(IDC_JITTERBUFFER);
- handle->GetWindowText(text);
- fprintf(fp,"JITTERBUFFER(ms)t%snn",text);
- //Video options
- fprintf(fp,"Video_Optionsn");
- handle = (CWnd*)GetDlgItem(IDC_VIDEODEVICE);
- handle->GetWindowText(text);
- fprintf(fp,"VIDEODEVICEt%sn",text);
- handle = (CWnd*)GetDlgItem(IDC_FORMAT);
- handle->GetWindowText(text);
- fprintf(fp,"FORMATt%sn",text);
- t=IsDlgButtonChecked(IDC_TRNONE);
- fprintf(fp,"TRNONEt%dn",t);
- t=IsDlgButtonChecked(IDC_TRSMALL);
- fprintf(fp,"TRSMALLt%dn",t);
- t=IsDlgButtonChecked(IDC_TRLARGE);
- fprintf(fp,"TRLARGEt%dnn",t);
- //Configure_QualityMarkers_in plots
- //Configure_options
- fprintf(fp,"Configure_Optionsn");
- fprintf(fp,"LATENCY_GOODt%sn",laG);
- fprintf(fp,"LATENCY_ACCt%sn",laA);
- fprintf(fp,"LATENCY_UNACCt%snn",laU);
- fprintf(fp,"LOSS_GOODt%sn",loG);
- fprintf(fp,"LOSS_ACCt%sn",loA);
- fprintf(fp,"LOSS_UNACCt%snn",loU);
- fprintf(fp,"JITTER_GOODt%sn",jiG);
- fprintf(fp,"JITTER_ACCt%sn",jiA);
- fprintf(fp,"JITTER_UNACCt%snn",jiU);
-
- fclose(fp);
- //It has been saved to the file
-
- //To add "\" to path so that gnuplot understands..
- //Gnuplot understands C:\Beacon and not C:Beacon
- //char *appendSlash;
- //char tmpAppend[MAX_PATH];
- //int jj=0;
-
- //if the last character is not a trailing then add one.
- if(testsFolderPath[abs(strlen(testsFolderPath))-1]=='\'){
- //it is there do nothing.
- }
- else{
- strcat(testsFolderPath,"\");
- }
- SetFldrPath();
- /* appendSlash = testsFolderPath;
- for (int ii=0; ii < abs(strlen(testsFolderPath)); ii++)
- {
- tmpAppend[jj] = testsFolderPath[ii];
- if(*appendSlash == '\')
- {
- jj++;
- tmpAppend[jj] = '\';
- }
- jj++;
- appendSlash++;
- }
- tmpAppend[jj] = ' ';
- strcpy(testsFolderPath,tmpAppend);
- */
- //SetDlgItemText(IDC_OUTFILEPATH,testsFolderPath);
- }
- void CDlgSettings::OnDefaultsettings()
- {
- // TODO: Add your control notification handler code here
-
- char file[MAX_PATH];
- char exeFilePath[MAX_PATH]; //a string for GetModuleFileName() to store exe Path
- GetModuleFileName( NULL,&exeFilePath[0],sizeof (exeFilePath));
- //Extract path by copying without exe string..
- for(int i=0; i < abs(strlen(exeFilePath)-16); i++){
- file[i] = exeFilePath[i];
- }
- file[i] = ' ';
-
- //strcpy(file,exeFolderPath);
- strcat(file,"SD.conf");
-
- SetSettingsFromFile(file);
-
- }
- BOOL CDlgSettings::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CDlgSettings dlg;
-
- char file[MAX_PATH];
- char exeFilePath[MAX_PATH]; //a string for GetModuleFileName() to store exe Path
- GetModuleFileName( NULL,&exeFilePath[0],sizeof (exeFilePath));
- //Extract path by copying without exe string..
- for(int i=0; i < abs(strlen(exeFilePath)-16); i++){
- file[i] = exeFilePath[i];
- }
- file[i] = ' ';
-
- //strcpy(file,exeFolderPath);
- strcat(file,"S.conf");
-
- //Set the settings from file Settings.conf
- SetSettingsFromFile(file);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- //Code to implement "Browse" functionality to set the Test results folder path
- int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
- {
- TCHAR szDir[MAX_PATH];
- switch(uMsg){
- case BFFM_INITIALIZED:
- if (lpData){
- strcpy(szDir, strTmpPath.GetBuffer(strTmpPath.GetLength()));
- SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)szDir);
- }
- break;
- case BFFM_SELCHANGED: {
- if (SHGetPathFromIDList((LPITEMIDLIST) lParam ,szDir)){
- SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir);
- }
- break;
- }
- default:
- break;
- }
-
- return 0;
- }
- BOOL GetFolder(CString* strSelectedFolder,
- const char* lpszTitle,
- const HWND hwndOwner,
- const char* strRootFolder,
- const char* strStartFolder)
- {
- char pszDisplayName[MAX_PATH];
- LPITEMIDLIST lpID;
- BROWSEINFOA bi;
-
- bi.hwndOwner = hwndOwner;
- if (strRootFolder == NULL){
- bi.pidlRoot = NULL;
- }else{
- LPITEMIDLIST pIdl = NULL;
- IShellFolder* pDesktopFolder;
- char szPath[MAX_PATH];
- OLECHAR olePath[MAX_PATH];
- ULONG chEaten;
- ULONG dwAttributes;
- strcpy(szPath, (LPCTSTR)strRootFolder);
- if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
- {
- MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szPath, -1, olePath, MAX_PATH);
- pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, &pIdl, &dwAttributes);
- pDesktopFolder->Release();
- }
- bi.pidlRoot = pIdl;
- }
- bi.pszDisplayName = pszDisplayName;
- bi.lpszTitle = lpszTitle;
- bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
- bi.lpfn = BrowseCallbackProc;
- if (strStartFolder == NULL){
- bi.lParam = FALSE;
- }else{
- strTmpPath.Format("%s", strStartFolder);
- bi.lParam = TRUE;
- }
- bi.iImage = NULL;
- lpID = SHBrowseForFolderA(&bi);
- if (lpID != NULL){
- BOOL b = SHGetPathFromIDList(lpID, pszDisplayName);
- if (b == TRUE){
- strSelectedFolder->Format("%s",pszDisplayName);
- return TRUE;
- }
- }else{
- strSelectedFolder->Empty();
- }
- return FALSE;
- }
- void CDlgSettings::OnBrowse()
- {
- // TODO: Add your control notification handler code here
- CString strFolderPath;
- if (GetFolder(&strFolderPath, "Please choose the folder location to save your H.323 Beacon test session results...", this->m_hWnd, NULL, NULL)){
- if (!strFolderPath.IsEmpty()){
- m_strFolderPath = strFolderPath;
- UpdateData(FALSE);
- }
- }
- }
- void CDlgSettings::SetFldrPath()
- {
- char *appendSlash;
- char tmpAppend[MAX_PATH];
- int jj=0;
- appendSlash = testsFolderPath;
- if(testsFolderPath[abs(strlen(testsFolderPath))-1]=='\'){
- //it is there do nothing.
- }
- else{
- strcat(testsFolderPath,"\");
- }
- //testing if the last word in the directory path is 'Tests'
- int testsexsist=0;
-
- char tempPath[MAX_PATH],*lbone;
- strcpy(tempPath,testsFolderPath);
- //while((last= strtok(tempPath,'\'))!=' '){
- //lbone=last;
- //}
-
- lbone=strstr(tempPath,"Tests");
- if(lbone!=NULL)
- testsexsist=1;
- //add for every ,gnuplot only understands //
- for (int ii=0; ii < abs(strlen(testsFolderPath)); ii++)
- {
- tmpAppend[jj] = testsFolderPath[ii];
- if(*appendSlash == '\')
- {
- jj++;
- tmpAppend[jj] = '\';
- }
- jj++;
- appendSlash++;
- }
- tmpAppend[jj] = ' ';
- strcpy(testsFolderPath,tmpAppend);
- //strcpy(exeFolderPath,testsFolderPath);
- //Add "Tests" string to Path, if testsexsist=0
- if(testsexsist==0){
- strcat(testsFolderPath,"Tests");
- }
- else{
- int len=abs(strlen(testsFolderPath));
- testsFolderPath[len-2]=NULL;
- }
- //SetDlgItemText(IDC_OUTFILEPATH,testsFolderPath);
- }
- void CDlgSettings::SetDefaultTestsFldrPath()
- {
- //Get the Path to the folder from where the beaconclient.exe is being executed
- char exeFilePath[MAX_PATH]; //a string for GetModuleFileName() to store exe Path
- GetModuleFileName( NULL,&exeFilePath[0],sizeof (exeFilePath));
- //Extract path by copying without exe string..
- for(int i=0; i < abs(strlen(exeFilePath)-16); i++){
- testsFolderPath[i] = exeFilePath[i];
- }
- testsFolderPath[i] = ' ';
-
- //To add "\" to path so that gnuplot understands..
- //Gnuplot understands C:\Beacon and not C:Beacon
- char *appendSlash;
- char tmpAppend[MAX_PATH];
- char toDisp[MAX_PATH];
- strcpy(toDisp,testsFolderPath);
- int jj=0;
- appendSlash = testsFolderPath;
- for (int ii=0; ii < abs(strlen(testsFolderPath)); ii++)
- {
- tmpAppend[jj] = testsFolderPath[ii];
- if(*appendSlash == '\')
- {
- jj++;
- tmpAppend[jj] = '\';
- }
- jj++;
- appendSlash++;
- }
- tmpAppend[jj] = ' ';
- strcpy(testsFolderPath,tmpAppend);
- strcpy(exeFolderPath,testsFolderPath);
- //Add "Tests" string to Path
- strcat(testsFolderPath,"Tests");
- strcat(toDisp,"Tests");
- SetDlgItemText(IDC_OUTFILEPATH,toDisp);
- }
-
- void CDlgSettings::SetSettingsFromFile(CString SettingsFile)
- {
-
- CString lp;
- FILE *fp;
- int t=10;
- fp = fopen(SettingsFile,"r");
- //Call Options
- fscanf(fp,"%s",lp); //for CCall_Options
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- t=atoi(lp);
- CheckDlgButton(IDC_FASTSTART,t);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- t=atoi(lp);
- CheckDlgButton(IDC_TUNNEL,t);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- t=atoi(lp);
- CheckDlgButton(IDC_SETUP,t);
-
-
- //Output File Path
- fscanf(fp,"%s",lp);//for Output_File_Path
- fscanf(fp,"%s",lp);
- fseek(fp,sizeof(char),SEEK_CUR);
- //fscanf(fp,"%s ",lp);
- char filepath[MAX_PATH];
- fgets(filepath,MAX_PATH,fp);
- filepath[abs(strlen(filepath))-1]=' ';
- //strcpy((char [])lp,filepath);
- //lp=(LPCSTR)filepath;
- //lp=filepath;
- //MessageBox(lp);
- SetDlgItemText(IDC_OUTFILEPATH,filepath);
-
- if(strcmp(filepath,"default")==0){
- SetDefaultTestsFldrPath();
- }
- else{
- strcpy(testsFolderPath,filepath);
- SetFldrPath();
-
- }
- //Port Options
- fscanf(fp,"%s",lp); //for Ports_Options
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- SetDlgItemText(IDC_TCPBASE, lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- SetDlgItemText(IDC_TCPMAX, lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- SetDlgItemText(IDC_UDPBASE, lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- SetDlgItemText(IDC_UDPMAX, lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- SetDlgItemText(IDC_RTPBASE, lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- SetDlgItemText(IDC_RTPMAX, lp);
-
- //Test Save Results
- fscanf(fp,"%s",lp); //for Test_Save_Results
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- t=atoi(lp);
- CheckDlgButton(IDC_TESTSAVE,t);
- //Audio Options
- fscanf(fp,"%s",lp); //for Audio_options
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- t=atoi(lp);
- CheckDlgButton(IDC_SILENCEDETECTION,t);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- SetDlgItemText(IDC_AUDIOCODEC, lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- SetDlgItemText(IDC_JITTERBUFFER, lp);
-
- //Video Options
- fscanf(fp,"%s",lp); //for Video_options
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- SetDlgItemText(IDC_VIDEODEVICE, lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- SetDlgItemText(IDC_FORMAT, lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- t=atoi(lp);
- if(t==1){
- CheckRadioButton(IDC_TRNONE,IDC_TRLARGE,IDC_TRNONE);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- }
- else{
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- t=atoi(lp);
- if(t==1){
- CheckRadioButton(IDC_TRNONE,IDC_TRLARGE,IDC_TRSMALL);
- }
- else{
- CheckRadioButton(IDC_TRNONE,IDC_TRLARGE,IDC_TRLARGE);
- }
- }
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);//these 2 for the last radio button which we dont read
- fscanf(fp,"%s",lp);//Configure_Plots
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- laG=CString(lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- laA=CString(lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- laU=CString(lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- loG=CString(lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- loA=CString(lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- loU=CString(lp);
-
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- jiG=CString(lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- jiA=CString(lp);
- fscanf(fp,"%s",lp);
- fscanf(fp,"%s",lp);
- jiU=CString(lp);
-
- fclose(fp);
- }
- void CDlgSettings::OnQualitymarkers()
- {
- // TODO: Add your control notification handler code here
-
- CDialog * configDlg = new CConfigurePlots();
- configDlg->Create( IDD_CONFIGURE_PLOTS , NULL );
- configDlg->ModifyStyleEx( 0 , WS_EX_APPWINDOW );
- configDlg->ShowWindow( SW_SHOW );
- }
- void CDlgSettings::OnKillfocusJitterbuffer()
- {
- // TODO: Add your control notification handler code here
- CString lp;
- GetDlgItemText(IDC_JITTERBUFFER, lp);
- int t=atoi(lp);
- if(t<20){
- MessageBox("Jitter Buffer should have a value between 20ms to 1s");
- SetDlgItemText(IDC_JITTERBUFFER, "20");
- }
- else if (t>1000){
- MessageBox("Jitter Buffer should have a value between 20ms to 1s");
- SetDlgItemText(IDC_JITTERBUFFER, "20");
- }
- }