// UDPAdminTool.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "UDPAdminTool.h" #include "UDPAdminToolDlg.h" #include "util_local.h" //#include "util.hpp" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CUDPAdminToolApp BEGIN_MESSAGE_MAP(CUDPAdminToolApp, CWinApp) //{{AFX_MSG_MAP(CUDPAdminToolApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CUDPAdminToolApp construction CUDPAdminToolApp::CUDPAdminToolApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CUDPAdminToolApp object CUDPAdminToolApp theApp; //#include "util.hpp" ///////////////////////////////////////////////////////////////////////////// // CUDPAdminToolApp initialization // 0~255(max) -> 0~100 int con255(int n, int max) { // 254, 255´Â 100À¸·Î ³ª¿É´Ï´Ù. if(n == 0) return 0; double kk = (max+1)/100.0; // +1À» ÇÏÁö ¾ÊÀ¸¸é, nÀÌ max·Î ¿Ã¶§ °á°ú°ªÀÌ max+1ÀÌ µÇ¾î¹ö¸³´Ï´Ù. return int((n / kk)+1); } // 0~100 -> 0~255(max) int con100(int n, int max) { if(n == 0) return 0; double kk = (max+1)/100.0; return int(n * kk)-1; } void test() { // int table[255]; int max = 999; int i = 0; for(i = 0; i <= max; ++i) { int c100 = con255(i, max); int c255 = con100(c100, max); int re_c100 = con255(c255, max); ASSERT(c100 == re_c100); TRACE3("c100:%d - c255:%d - re_c100:%d\n", c100, c255, re_c100); } } #define PERCENT 1000 int ChangValue(int iSMin, int iSMax, int iTMin, int iTMax, int iValue) { int iPercent, iResult; iPercent = ((iValue - iSMin) * PERCENT) / (iSMax - iSMin); iResult = ((iPercent*(iTMax-iTMin) / PERCENT) + iTMin); return iResult; } int con25511(int n, int max) { return ChangValue(0, max, 0, 100, n); } int con10011(int n, int max) { return ChangValue(0, 100, 0, max, n); } void test11() { // int table[255]; int max = 999; int i = 0; for(i = 0; i <= max; ++i) { int c100 = con25511(i, max); int c255 = con10011(c100, max); int re_c100 = con25511(c255, max); //ASSERT(c100 == re_c100); TRACE3("c100:%d - c255:%d - re_c100:%d\n", c100, c255, re_c100); } } void test_convert_str2bin(); BOOL CUDPAdminToolApp::InitInstance() { InitCommonControls(); // for xp theme AfxInitRichEdit(); // rich edit test_convert_str2bin(); if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } #ifdef _DEBUG // test_util(); // test11(); #endif // registry SetRegistryKey("Cap"); AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #if _MSC_VER <= 1200 #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif #endif #ifdef MULTI bTestMode_ = false; #endif CUDPAdminToolDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; } CString CUDPAdminToolApp::GetSelectDeviceName() { CString name = ""; if(theApp.m_bManual) { name += "M "; } name += info2name(&theApp.m_info); return name; } CString CUDPAdminToolApp::get_fw_path() { // ¹Ýȯ°ªÀº ÆÄÀÏÀÔ´Ï´Ù. return GetProfileString("PATH", "FW", ""); } BOOL CUDPAdminToolApp::set_fw_path(CString path) { // ¼³Á¤°ªÀº ÆÄÀÏ return WriteProfileString("PATH", "FW", path); } CString CUDPAdminToolApp::get_dome_path() { return GetProfileString("PATH", "DOME", ""); } BOOL CUDPAdminToolApp::set_dome_path(CString path) { return WriteProfileString("PATH", "DOME", path); } CString CUDPAdminToolApp::get_web_path() { // ¹Ýȯ°ªÀº µð·ºÅ丮ÀÔ´Ï´Ù. return GetProfileString("PATH", "Web", "c:\\"); } BOOL CUDPAdminToolApp::set_web_path(CString path) // directory¸¦ ÀÎÀÚ·Î ¼³Á¤ÇÕ´Ï´Ù. { // ¼³Á¤°ªÀº µð·ºÅ丮ÀÔ´Ï´Ù. return WriteProfileString("PATH", "Web", path); } CString CUDPAdminToolApp::get_ocx_path() { // ¹Ýȯ°ªÀº ÆÄÀÏ return GetProfileString("PATH", "OCX", "c:\\*.*"); } BOOL CUDPAdminToolApp::set_ocx_path(CString path) // directory¸¦ ÀÎÀÚ·Î ¼³Á¤ÇÕ´Ï´Ù. { return WriteProfileString("PATH", "OCX", path); } CString CUDPAdminToolApp::get_userfile_path() { // ¹Ýȯ°ªÀº ÆÄÀÏ return GetProfileString("PATH", "userfile", "c:\\*.*"); } BOOL CUDPAdminToolApp::set_userfile_path(CString path) // directory¸¦ ÀÎÀÚ·Î ¼³Á¤ÇÕ´Ï´Ù. { return WriteProfileString("PATH", "userfile", path); } CString CUDPAdminToolApp::get_filter() { return GetProfileString("ENV", "filter", ""); } BOOL CUDPAdminToolApp::set_filter(CString filter) { return WriteProfileString("ENV", "filter", filter); } int CUDPAdminToolApp::get_fw_ver() { CString strVer = GetProfileString("VER", "version", ""); int iVer = atoi((LPSTR)(LPCSTR)strVer); return iVer; } BOOL CUDPAdminToolApp::set_fw_ver(int ver) { CString strVer; strVer.Format("%d", ver); return WriteProfileString("VER", "version", strVer); } int CUDPAdminToolApp::get_fw_cond() { CString strCond = GetProfileString("COND", "Firmware", ""); int iCond = atoi((LPSTR)(LPCSTR)strCond); return iCond; } BOOL CUDPAdminToolApp::set_fw_cond(int cond) { CString strCond; strCond.Format("%d", cond); return WriteProfileString("COND", "Firmware", strCond); } CString CUDPAdminToolApp::get_value(CString section, CString entry) { return GetProfileString(section, entry, ""); } BOOL CUDPAdminToolApp::set_value(CString section, CString entry, CString value) { return WriteProfileString(section, entry, value); } BOOL CUDPAdminToolApp::get_login_auto() { int bLogin = GetProfileInt("LOGIN", "auto", 0); return bLogin ? TRUE:FALSE; } BOOL CUDPAdminToolApp::set_login_auto(BOOL bLogin) { return WriteProfileInt("LOGIN", "auto", bLogin); } CString CUDPAdminToolApp::get_login_id() { CString str = GetProfileString("LOGIN", "id", ""); return str; } BOOL CUDPAdminToolApp::set_login_id(CString id) { return WriteProfileString("LOGIN", "id", id); } BOOL CUDPAdminToolApp::get_login_hash(char* out_buf, int* out_size) { int hr; *out_size = 0; CString str = GetProfileString("LOGIN", "hash", ""); if(str.GetLength() != 32) { return FALSE; } unsigned char buf[1024]; int size; hr = convert_str2bin(str, buf, &size); if(hr <= 0) return FALSE; if(size != 16) { return FALSE; } memcpy(out_buf, buf, 16); *out_size = 16; return TRUE; } BOOL CUDPAdminToolApp::set_login_hash(char* buf, int size) { if(size != 16 && size != 0) return FALSE; char str[1024] = {0, }; str[0] = 0; if(size == 0) { return WriteProfileString("LOGIN", "hash", str); } else { ASSERT(buf != NULL); convert_bin2str((unsigned char*)buf, 16, str); return WriteProfileString("LOGIN", "hash", str); } } void CUDPAdminToolApp::clear_login_info() { theApp.set_login_auto(FALSE); theApp.set_login_hash(NULL, 0); }