123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "AppGlobalF.h"
- #include <inifiles.hpp>
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- //---------------------------------------------------------------------------
- String CenterCd = ""; // 지역센터 코드
- String CenterId = ""; // 지역센터 아이디
- String CenterName = ""; // 지역센터 명칭
- int g_nPid = -1; // Application Process ID
- String g_sAppDir = ""; // Application Directory
- String g_sAppName= ""; // Program name
- String g_sCfgDir = ""; // Config File Directory
- String g_sLogDir = ""; // Program Log Directory
- String g_sTempDir = ""; // Program Temp Directory
- String g_sFormsDir = ""; // Program Forms Directory
- String g_sLangDir = "";
- APP_CONFIG g_AppCfg;
- LOG_INFO g_LogCfg;
- TITSLog *ITSLog = NULL;
- //---------------------------------------------------------------------------
- void ActiveProgram()
- {
- String AClassName = "TFrmVmsCamViewer";
- String ATitle = g_AppCfg.sTitle;// + " - Active";
- HWND hExeForm = FindWindow(AClassName.c_str(), ATitle.c_str());
- if (hExeForm)
- {
- LOGINFO("Program exit.... Find Ok... Program already running....");
- bool bResult = SetWindowPos(hExeForm, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
- if (bResult) {
- bResult = ShowWindow(hExeForm, SW_RESTORE);
- SetForegroundWindow(hExeForm);
- }
- }
- }
- //---------------------------------------------------------------------------
- bool CheckParamRandKey(String AParam)
- {
- AParam = Utf8ToAnsi(HTTPDecode(AParam));
- String appName = "its.vmscmraviewer://";
- if (!AParam.Pos(appName)) {
- Application->MessageBox(L"\r\nVMS 영상 모니터링 프로그램 실행 환경이 맞지 않습니다.\r\n프로그램 파라미터 시작 정보를 확인하세요..\r\n",
- L"VMS 영상 모니터링 프로그램 실행 오류!!!", MB_OK|MB_ICONERROR);
- LOGINFO("Program exit.... Param AppName Error....");
- return false;
- }
- String param = "";
- param = StringReplace(AParam, appName, "", TReplaceFlags() << rfReplaceAll);
- param = StringReplace(param, "%20", ",", TReplaceFlags() << rfReplaceAll);
- String userId = "";
- String apiUri = "";
- String skinName = "";
- TStringList *pStringList = new TStringList;
- try {
- pStringList->Delimiter = '^';
- pStringList->StrictDelimiter = true;
- pStringList->DelimitedText = param;
- if (pStringList->Count < 2) {
- String sMsg = "\r\nVMS 영상 모니터링 프로그램 파라미터 정보가 맞지 않습니다.\r\n파라미터 갯수: " + String(pStringList->Count) + " EA.\r\n";
- for (int ii = 0; ii < pStringList->Count; ii++) {
- sMsg += pStringList->Strings[ii];
- sMsg += "\r\n";
- }
- Application->MessageBox(sMsg.c_str(), L"VMS 영상 모니터링 프로그램 실행 오류!!!", MB_OK|MB_ICONERROR);
- LOGINFO("Program exit.... Param Count Error....");
- return false;
- }
- userId = pStringList->Strings[0];
- apiUri = pStringList->Strings[1];
- if (pStringList->Count > 2) {
- skinName = pStringList->Strings[2];
- }
- } __finally {
- if (pStringList) delete pStringList;
- }
- if (!apiUri.Pos("http")) {
- Application->MessageBox(L"\r\nVMS 영상 모니터링 프로그램 실행 환경이 맞지 않습니다.\r\n프로그램 API 주소 정보를 확인하세요..\r\n",
- L"VMS 영상 모니터링 프로그램 실행 오류!!!", MB_OK|MB_ICONERROR);
- LOGINFO("Program exit.... Param URI Error....");
- return false;
- }
- g_AppCfg.sUserId = userId;
- g_AppCfg.sRestApiUri = apiUri;
- if (skinName != "") {
- g_AppCfg.sSkinName = skinName;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- void LoadIcon(TIniFile* AIniFile, String ASection, String& AValue)
- {
- try {
- AValue = AIniFile->ReadString(ASection, "IMAGE", "");
- if (AValue == "") {
- AValue = "logo.png";
- }
- AValue = g_sAppDir + "Image\\" + AValue;
- if (!FileExists(AValue)) {
- AValue = "";
- }
- }
- catch(Exception &e) {
- }
- }
- //---------------------------------------------------------------------------
- bool LoadDefaultConfigInfo(String ACfgFile/*=""*/)
- {
- String sCfgFile;
- TIniFile *pIniFile = NULL;
- g_AppCfg.sLang = "kr";
- String sIniFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".ini");
- if (!ACfgFile.IsEmpty())
- sIniFile = ACfgFile + ".ini";
- sCfgFile = g_sCfgDir + sIniFile;
- g_AppCfg.sConfigFile = sCfgFile;
- g_AppCfg.AutoLogout.Enabled = false;
- g_AppCfg.AutoLogout.IntervalMin = 0;
- g_AppCfg.AutoLogout.LogoutExit = false;
- g_AppCfg.thr.pThread = NULL;
- g_AppCfg.thr.dwThreadId = 0;
- g_AppCfg.thr.nHandle = 0;
- g_AppCfg.thr.bRunning = false;
- g_AppCfg.bAppClose = false;
- try {
- String sTmp;
- pIniFile = new TIniFile(sCfgFile);
- g_AppCfg.sTitle = pIniFile->ReadString(g_sAppName, "TITLE", "VMS 영상 모니터링").Trim();
- g_AppCfg.sSkinName = pIniFile->ReadString(g_sAppName, "SKIN", "Black").Trim();
- g_AppCfg.sLogDay = pIniFile->ReadString(g_sAppName, "LOG", "");
- g_AppCfg.bSaveForm = pIniFile->ReadString(g_sAppName, "SAVEFORM", "0").ToIntDef(0) == 1 ? true : false;
- String sSqlLog;
- g_AppCfg.itsdb.bSqlLog = false;
- g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1");
- g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE");
- g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits");
- g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits");
- LoadIcon(pIniFile, g_sAppName, g_AppCfg.sEmptyImg);
- }
- __finally {
- if (pIniFile) delete pIniFile;
- pIniFile = NULL;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- /*
- * 환경설정 정보를 저장하는 함수.
- * arguments
- * String : RegisterKey 또는 파일이름
- * return
- * bool : 실패하면 false
- */
- bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
- {
- String ConfigFile;
- TIniFile *pIniFile = NULL;
- ConfigFile = sCfgFile;
- try
- {
- pIniFile = new TIniFile(ConfigFile);
- if (pIniFile == NULL)
- {
- return false;
- }
- pIniFile->WriteString(sTitle, sItem, sValue);
- }
- catch(...)
- {
- }
- if (pIniFile)
- {
- pIniFile->Free();
- pIniFile = NULL;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- /*
- * 환경설정 정보를 읽어오는 함수.
- * arguments
- * String : RegisterKey 또는 파일이름
- * return
- * bool : 실패하면 false
- */
- bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
- {
- bool bRes;
- String ConfigFile;
- TIniFile *pIniFile = NULL;
- bRes = false;
- ConfigFile = sCfgFile;
- try
- {
- pIniFile = new TIniFile(ConfigFile);
- if (pIniFile == NULL)
- {
- return bRes;
- }
- sValue = pIniFile->ReadString(sTitle, sItem, "");
- if (sValue != "")
- {
- bRes = true;
- }
- }
- catch(...)
- {
- }
- if (pIniFile)
- {
- pIniFile->Free();
- pIniFile = NULL;
- }
- return bRes;
- }
- //---------------------------------------------------------------------------
- void ShowErrorMsg(String ATitle, String AErrMsg)
- {
- Application->NormalizeTopMosts();
- Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
- Application->RestoreTopMosts();
- }
- //----------------------------------------------------------------------------
- ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
- {
- ULONG idProc;
- GetWindowThreadProcessId( hwnd, &idProc );
- return idProc;
- }
- //----------------------------------------------------------------------------
- HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
- {
- HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
- while( tempHwnd != NULL )
- {
- if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
- if( pid == ProcIDFromWnd(tempHwnd) )
- return tempHwnd;
- tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
- }
- return NULL;
- }
- //----------------------------------------------------------------------------
- TColor g_DispColor[MAX_DISPCOLOR];
- void APP_InitDisplayColor()
- {
- g_DispColor[ 0] = Graphics::clBlue;
- g_DispColor[ 1] = Graphics::clRed;
- g_DispColor[ 2] = Graphics::clLime;
- g_DispColor[ 3] = Graphics::clMaroon;
- g_DispColor[ 4] = Graphics::clGreen;
- g_DispColor[ 5] = Graphics::clMenuHighlight;
- g_DispColor[ 6] = Graphics::clBackground;
- g_DispColor[ 7] = Graphics::clPurple;
- g_DispColor[ 8] = Graphics::clTeal;
- g_DispColor[ 9] = Graphics::clYellow;
- g_DispColor[10] = Graphics::clFuchsia;
- g_DispColor[11] = Graphics::clAqua;
- g_DispColor[12] = Graphics::clMoneyGreen;
- g_DispColor[13] = Graphics::clSkyBlue;
- g_DispColor[14] = Graphics::clRed;
- g_DispColor[15] = Graphics::clLime;
- g_DispColor[16] = Graphics::clYellow;
- g_DispColor[17] = Graphics::clBlue;
- g_DispColor[18] = Graphics::clFuchsia;
- g_DispColor[19] = Graphics::clAqua;
- g_DispColor[20] = Graphics::clMoneyGreen;
- g_DispColor[21] = Graphics::clActiveCaption;
- }
- //---------------------------------------------------------------------------
- TColor APP_GetDisplayColor(int ASeq)
- {
- return g_DispColor[ASeq % MAX_DISPCOLOR];
- }
- //---------------------------------------------------------------------------
|