VMSCommServer.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /****************************************************************************
  2. * @source : VMSCommSvr.cpp
  3. * @description : VMS 통신 서버
  4. ****************************************************************************
  5. * DATE AUTHOR DESCRIPTION
  6. * --------------------------------------------------------------------------
  7. * 2012/03/09 CYM [100] First Cut
  8. *
  9. ****************************************************************************/
  10. //---------------------------------------------------------------------------
  11. #define COMM_EXCEPTION_MESSAGE 0
  12. //---------------------------------------------------------------------------
  13. #include "AppGlobalF.h"
  14. #include <tchar.h>
  15. //---------------------------------------------------------------------------
  16. USEFORM("FrmMainF.cpp", FrmMain);
  17. USEFORM("DM\DMCOMMF.cpp", DMCOMM); /* TDataModule: File Type */
  18. USEFORM("FRM\FrmVmsLogF.cpp", FrmVmsLog);
  19. USEFORM("FRM\FrmOptionF.cpp", FrmOption);
  20. USEFORM("FRM\FrmVmsInfoF.cpp", FrmVmsInfo);
  21. USEFORM("FRM\FrmSysLogF.cpp", FrmSysLog);
  22. //---------------------------------------------------------------------------
  23. WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
  24. {
  25. DateSeparator = '-';
  26. TimeSeparator = ':';
  27. ShortDateFormat ="yyyy-MM-dd";
  28. ShortTimeFormat = "hh:nn:ss";
  29. LongTimeFormat = "hh:nn:ss";
  30. int nPid = (int)GetCurrentProcessId();
  31. g_sAppDir = ExtractFilePath(Application->ExeName);
  32. g_sAppName = ChangeFileExt(ExtractFileName(Application->ExeName), "");
  33. g_sCfgDir = g_sAppDir + "Cfg\\";
  34. g_sLogDir = g_sAppDir + "Log\\";
  35. g_sTempDir = g_sAppDir + "Temp\\";
  36. g_sImgDir = g_sAppDir + "Image\\";
  37. g_sFtpDir = g_sAppDir + "Ftp\\";
  38. g_sFormDir = g_sAppDir + "Form\\";
  39. ForceDirectories(g_sCfgDir.c_str());
  40. ForceDirectories(g_sLogDir.c_str());
  41. ForceDirectories(g_sTempDir.c_str());
  42. ForceDirectories(g_sImgDir.c_str());
  43. ForceDirectories(g_sFtpDir.c_str());
  44. ForceDirectories(g_sFormDir.c_str());
  45. String sTmpDir = g_sLogDir + "Comm\\";
  46. ForceDirectories(sTmpDir.c_str());
  47. ChDir(g_sAppDir);
  48. g_AppCfg.Clear();
  49. APP_LoadConfigInfo();
  50. /* 환경설정에 저장되어 있는 ftp 디렉토리 */
  51. ForceDirectories(g_sFtpDir.c_str());
  52. ITSLog = new TITSLog(g_sLogDir, g_sAppName, g_AppCfg.sLogDay);
  53. FDbLog = new TITSLog(g_sLogDir + "Db\\", "Database", g_AppCfg.sLogDay);
  54. ITSLog->FLogCfg = g_LogCfg;
  55. FDbLog->FLogCfg = g_LogCfg;
  56. LOGINFO("VMSCommServer Start....");
  57. try
  58. {
  59. AnsiString sPidFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".pid");
  60. AnsiString sMutexName = "HANTE_VMSCommServerYI.lock";
  61. if (SYS_ApplicationSingleInstance(sMutexName, g_sCfgDir+sPidFile))
  62. {
  63. LOGWARN("Program already running. program exit...");
  64. #if 0
  65. int nMsgType = MB_OK|MB_ICONERROR|MB_APPLMODAL;
  66. String sMsgTitle = g_AppCfg.sTitle;
  67. String sMsgError = ExtractFileName(Application->ExeName) + "\r\nProgram is already running.\r\nPlease check the program in the task manager.";
  68. Application->MessageBox(sMsgError.c_str(), sMsgTitle.c_str(), nMsgType);
  69. #endif
  70. return 0;
  71. }
  72. }
  73. catch (Exception &exception)
  74. {
  75. //Application->ShowException(&exception);
  76. return 0;
  77. }
  78. /* allocate memory for system */
  79. if ((g_SysInfo = (SYSTEM_INFORMATION *) malloc(sizeof(SYSTEM_INFORMATION))) == NULL)
  80. {
  81. return 0;
  82. }
  83. memset(g_SysInfo, 0x00, sizeof(SYSTEM_INFORMATION));
  84. try
  85. {
  86. Application->Initialize();
  87. Application->MainFormOnTaskBar = true;
  88. Application->Title = "VMS Communication Server";
  89. Application->CreateForm(__classid(TFrmMain), &FrmMain);
  90. Application->CreateForm(__classid(TDMCOMM), &DMCOMM);
  91. Application->CreateForm(__classid(TFrmVmsLog), &FrmVmsLog);
  92. Application->Run();
  93. }
  94. catch (Exception &exception)
  95. {
  96. #if COMM_EXCEPTION_MESSAGE
  97. Application->ShowException(&exception);
  98. #endif
  99. }
  100. catch (...)
  101. {
  102. #if COMM_EXCEPTION_MESSAGE
  103. try
  104. {
  105. throw Exception("");
  106. }
  107. catch (Exception &exception)
  108. {
  109. Application->ShowException(&exception);
  110. }
  111. #endif
  112. }
  113. //g_Log->WriteLog(LOG_INFO, "VMSCommSvr End...");
  114. LOGINFO("VMSCommServer End....");
  115. /* free memory */
  116. free(g_SysInfo);
  117. return 0;
  118. }
  119. //---------------------------------------------------------------------------