AppGlobalF.cpp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "AppGlobalF.h"
  5. #include <inifiles.hpp>
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. //---------------------------------------------------------------------------
  9. String CenterCd = ""; // 지역센터 코드
  10. String CenterId = ""; // 지역센터 아이디
  11. String CenterName = ""; // 지역센터 명칭
  12. int g_nPid = -1; // Application Process ID
  13. String g_sAppDir = ""; // Application Directory
  14. String g_sAppName= ""; // Program name
  15. String g_sCfgDir = ""; // Config File Directory
  16. String g_sLogDir = ""; // Program Log Directory
  17. String g_sTempDir = ""; // Program Temp Directory
  18. String g_sFormsDir = ""; // Program Forms Directory
  19. String g_sLangDir = "";
  20. APP_CONFIG g_AppCfg;
  21. LOG_INFO g_LogCfg;
  22. TITSLog *ITSLog = NULL;
  23. //---------------------------------------------------------------------------
  24. void ActiveProgram()
  25. {
  26. String AClassName = "TFrmVmsCamViewer";
  27. String ATitle = g_AppCfg.sTitle;// + " - Active";
  28. HWND hExeForm = FindWindow(AClassName.c_str(), ATitle.c_str());
  29. if (hExeForm)
  30. {
  31. LOGINFO("Program exit.... Find Ok... Program already running....");
  32. bool bResult = SetWindowPos(hExeForm, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
  33. if (bResult) {
  34. bResult = ShowWindow(hExeForm, SW_RESTORE);
  35. SetForegroundWindow(hExeForm);
  36. }
  37. }
  38. }
  39. //---------------------------------------------------------------------------
  40. bool CheckParamRandKey(String AParam)
  41. {
  42. AParam = Utf8ToAnsi(HTTPDecode(AParam));
  43. String appName = "its.vmscmraviewer://";
  44. if (!AParam.Pos(appName)) {
  45. Application->MessageBox(L"\r\nVMS 영상 모니터링 프로그램 실행 환경이 맞지 않습니다.\r\n프로그램 파라미터 시작 정보를 확인하세요..\r\n",
  46. L"VMS 영상 모니터링 프로그램 실행 오류!!!", MB_OK|MB_ICONERROR);
  47. LOGINFO("Program exit.... Param AppName Error....");
  48. return false;
  49. }
  50. String param = "";
  51. param = StringReplace(AParam, appName, "", TReplaceFlags() << rfReplaceAll);
  52. param = StringReplace(param, "%20", ",", TReplaceFlags() << rfReplaceAll);
  53. String userId = "";
  54. String apiUri = "";
  55. String skinName = "";
  56. TStringList *pStringList = new TStringList;
  57. try {
  58. pStringList->Delimiter = '^';
  59. pStringList->StrictDelimiter = true;
  60. pStringList->DelimitedText = param;
  61. if (pStringList->Count < 2) {
  62. String sMsg = "\r\nVMS 영상 모니터링 프로그램 파라미터 정보가 맞지 않습니다.\r\n파라미터 갯수: " + String(pStringList->Count) + " EA.\r\n";
  63. for (int ii = 0; ii < pStringList->Count; ii++) {
  64. sMsg += pStringList->Strings[ii];
  65. sMsg += "\r\n";
  66. }
  67. Application->MessageBox(sMsg.c_str(), L"VMS 영상 모니터링 프로그램 실행 오류!!!", MB_OK|MB_ICONERROR);
  68. LOGINFO("Program exit.... Param Count Error....");
  69. return false;
  70. }
  71. userId = pStringList->Strings[0];
  72. apiUri = pStringList->Strings[1];
  73. if (pStringList->Count > 2) {
  74. skinName = pStringList->Strings[2];
  75. }
  76. } __finally {
  77. if (pStringList) delete pStringList;
  78. }
  79. if (!apiUri.Pos("http")) {
  80. Application->MessageBox(L"\r\nVMS 영상 모니터링 프로그램 실행 환경이 맞지 않습니다.\r\n프로그램 API 주소 정보를 확인하세요..\r\n",
  81. L"VMS 영상 모니터링 프로그램 실행 오류!!!", MB_OK|MB_ICONERROR);
  82. LOGINFO("Program exit.... Param URI Error....");
  83. return false;
  84. }
  85. g_AppCfg.sUserId = userId;
  86. g_AppCfg.sRestApiUri = apiUri;
  87. if (skinName != "") {
  88. g_AppCfg.sSkinName = skinName;
  89. }
  90. return true;
  91. }
  92. //---------------------------------------------------------------------------
  93. void LoadIcon(TIniFile* AIniFile, String ASection, String& AValue)
  94. {
  95. try {
  96. AValue = AIniFile->ReadString(ASection, "IMAGE", "");
  97. if (AValue == "") {
  98. AValue = "logo.png";
  99. }
  100. AValue = g_sAppDir + "Image\\" + AValue;
  101. if (!FileExists(AValue)) {
  102. AValue = "";
  103. }
  104. }
  105. catch(Exception &e) {
  106. }
  107. }
  108. //---------------------------------------------------------------------------
  109. bool LoadDefaultConfigInfo(String ACfgFile/*=""*/)
  110. {
  111. String sCfgFile;
  112. TIniFile *pIniFile = NULL;
  113. g_AppCfg.sLang = "kr";
  114. String sIniFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".ini");
  115. if (!ACfgFile.IsEmpty())
  116. sIniFile = ACfgFile + ".ini";
  117. sCfgFile = g_sCfgDir + sIniFile;
  118. g_AppCfg.sConfigFile = sCfgFile;
  119. g_AppCfg.AutoLogout.Enabled = false;
  120. g_AppCfg.AutoLogout.IntervalMin = 0;
  121. g_AppCfg.AutoLogout.LogoutExit = false;
  122. g_AppCfg.thr.pThread = NULL;
  123. g_AppCfg.thr.dwThreadId = 0;
  124. g_AppCfg.thr.nHandle = 0;
  125. g_AppCfg.thr.bRunning = false;
  126. g_AppCfg.bAppClose = false;
  127. try {
  128. String sTmp;
  129. pIniFile = new TIniFile(sCfgFile);
  130. g_AppCfg.sTitle = pIniFile->ReadString(g_sAppName, "TITLE", "VMS 영상 모니터링").Trim();
  131. g_AppCfg.sSkinName = pIniFile->ReadString(g_sAppName, "SKIN", "Black").Trim();
  132. g_AppCfg.sLogDay = pIniFile->ReadString(g_sAppName, "LOG", "");
  133. g_AppCfg.bSaveForm = pIniFile->ReadString(g_sAppName, "SAVEFORM", "0").ToIntDef(0) == 1 ? true : false;
  134. String sSqlLog;
  135. g_AppCfg.itsdb.bSqlLog = false;
  136. g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1");
  137. g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE");
  138. g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits");
  139. g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits");
  140. LoadIcon(pIniFile, g_sAppName, g_AppCfg.sEmptyImg);
  141. }
  142. __finally {
  143. if (pIniFile) delete pIniFile;
  144. pIniFile = NULL;
  145. }
  146. return true;
  147. }
  148. //---------------------------------------------------------------------------
  149. /*
  150. * 환경설정 정보를 저장하는 함수.
  151. * arguments
  152. * String : RegisterKey 또는 파일이름
  153. * return
  154. * bool : 실패하면 false
  155. */
  156. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  157. {
  158. String ConfigFile;
  159. TIniFile *pIniFile = NULL;
  160. ConfigFile = sCfgFile;
  161. try
  162. {
  163. pIniFile = new TIniFile(ConfigFile);
  164. if (pIniFile == NULL)
  165. {
  166. return false;
  167. }
  168. pIniFile->WriteString(sTitle, sItem, sValue);
  169. }
  170. catch(...)
  171. {
  172. }
  173. if (pIniFile)
  174. {
  175. pIniFile->Free();
  176. pIniFile = NULL;
  177. }
  178. return true;
  179. }
  180. //---------------------------------------------------------------------------
  181. /*
  182. * 환경설정 정보를 읽어오는 함수.
  183. * arguments
  184. * String : RegisterKey 또는 파일이름
  185. * return
  186. * bool : 실패하면 false
  187. */
  188. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  189. {
  190. bool bRes;
  191. String ConfigFile;
  192. TIniFile *pIniFile = NULL;
  193. bRes = false;
  194. ConfigFile = sCfgFile;
  195. try
  196. {
  197. pIniFile = new TIniFile(ConfigFile);
  198. if (pIniFile == NULL)
  199. {
  200. return bRes;
  201. }
  202. sValue = pIniFile->ReadString(sTitle, sItem, "");
  203. if (sValue != "")
  204. {
  205. bRes = true;
  206. }
  207. }
  208. catch(...)
  209. {
  210. }
  211. if (pIniFile)
  212. {
  213. pIniFile->Free();
  214. pIniFile = NULL;
  215. }
  216. return bRes;
  217. }
  218. //---------------------------------------------------------------------------
  219. void ShowErrorMsg(String ATitle, String AErrMsg)
  220. {
  221. Application->NormalizeTopMosts();
  222. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  223. Application->RestoreTopMosts();
  224. }
  225. //----------------------------------------------------------------------------
  226. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  227. {
  228. ULONG idProc;
  229. GetWindowThreadProcessId( hwnd, &idProc );
  230. return idProc;
  231. }
  232. //----------------------------------------------------------------------------
  233. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  234. {
  235. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  236. while( tempHwnd != NULL )
  237. {
  238. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  239. if( pid == ProcIDFromWnd(tempHwnd) )
  240. return tempHwnd;
  241. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  242. }
  243. return NULL;
  244. }
  245. //----------------------------------------------------------------------------
  246. TColor g_DispColor[MAX_DISPCOLOR];
  247. void APP_InitDisplayColor()
  248. {
  249. g_DispColor[ 0] = Graphics::clBlue;
  250. g_DispColor[ 1] = Graphics::clRed;
  251. g_DispColor[ 2] = Graphics::clLime;
  252. g_DispColor[ 3] = Graphics::clMaroon;
  253. g_DispColor[ 4] = Graphics::clGreen;
  254. g_DispColor[ 5] = Graphics::clMenuHighlight;
  255. g_DispColor[ 6] = Graphics::clBackground;
  256. g_DispColor[ 7] = Graphics::clPurple;
  257. g_DispColor[ 8] = Graphics::clTeal;
  258. g_DispColor[ 9] = Graphics::clYellow;
  259. g_DispColor[10] = Graphics::clFuchsia;
  260. g_DispColor[11] = Graphics::clAqua;
  261. g_DispColor[12] = Graphics::clMoneyGreen;
  262. g_DispColor[13] = Graphics::clSkyBlue;
  263. g_DispColor[14] = Graphics::clRed;
  264. g_DispColor[15] = Graphics::clLime;
  265. g_DispColor[16] = Graphics::clYellow;
  266. g_DispColor[17] = Graphics::clBlue;
  267. g_DispColor[18] = Graphics::clFuchsia;
  268. g_DispColor[19] = Graphics::clAqua;
  269. g_DispColor[20] = Graphics::clMoneyGreen;
  270. g_DispColor[21] = Graphics::clActiveCaption;
  271. }
  272. //---------------------------------------------------------------------------
  273. TColor APP_GetDisplayColor(int ASeq)
  274. {
  275. return g_DispColor[ASeq % MAX_DISPCOLOR];
  276. }
  277. //---------------------------------------------------------------------------