00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "fsEventsMgr.h"
00009 #include "misc.h"
00010
00011 #ifdef _DEBUG
00012 #undef THIS_FILE
00013 static char THIS_FILE[]=__FILE__;
00014 #define new DEBUG_NEW
00015 #endif
00016
00017 fsEventsMgr::fsEventsMgr()
00018 {
00019
00020 }
00021
00022 fsEventsMgr::~fsEventsMgr()
00023 {
00024 clear ();
00025 }
00026
00027 void fsEventsMgr::clear()
00028 {
00029 for (int i = m_vEvents.size () - 1; i >= 0; i--)
00030 delete [] m_vEvents [i].pszEvent;
00031 m_vEvents.clear ();
00032 }
00033
00034 BOOL fsEventsMgr::Save(HANDLE hFile)
00035 {
00036 int cRecs = m_vEvents.size ();
00037 DWORD dw;
00038
00039 if (!WriteFile (hFile, &cRecs, sizeof (cRecs), &dw, NULL))
00040 return FALSE;
00041
00042 for (int i = 0; i < cRecs; i++)
00043 {
00044 fsDescEvent *ev = &m_vEvents [i];
00045
00046 if (!WriteFile (hFile, ev, sizeof (fsDescEvent), &dw, NULL))
00047 return FALSE;
00048
00049 if (!fsSaveStrToFile (ev->pszEvent, hFile))
00050 return FALSE;
00051 }
00052
00053 return TRUE;
00054 }
00055
00056 BOOL fsEventsMgr::Load(HANDLE hFile)
00057 {
00058 int cRecs;
00059 DWORD dw;
00060
00061 m_vEvents.clear ();
00062
00063 if (!ReadFile (hFile, &cRecs, sizeof (cRecs), &dw, NULL) || dw != sizeof (cRecs))
00064 return FALSE;
00065
00066 while (cRecs-- > 0)
00067 {
00068 fsDescEvent ev;
00069
00070 if (!ReadFile (hFile, &ev, sizeof (fsDescEvent), &dw, NULL) || dw != sizeof (fsDescEvent))
00071 {
00072 m_vEvents.clear ();
00073 return FALSE;
00074 }
00075
00076 if (!fsReadStrFromFile (&ev.pszEvent, hFile))
00077 {
00078 m_vEvents.clear ();
00079 return FALSE;
00080 }
00081
00082 m_vEvents.add (ev);
00083 }
00084
00085 return TRUE;
00086 }
00087
00088 UINT fsEventsMgr::GetEventCount()
00089 {
00090 return m_vEvents.size ();
00091 }
00092
00093 fsDescEvent* fsEventsMgr::GetEvent(UINT uIndex)
00094 {
00095 return &m_vEvents [uIndex];
00096 }
00097
00098 void fsEventsMgr::add(fsDescEvent *ev)
00099 {
00100 SYSTEMTIME time;
00101 GetLocalTime (&time);
00102
00103 SystemTimeToFileTime (&time, &ev->timeEvent);
00104
00105 m_vEvents.add (*ev);
00106 }
00107