00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "vmsFileRecentList.h"
00009
00010 #ifdef _DEBUG
00011 #undef THIS_FILE
00012 static char THIS_FILE[]=__FILE__;
00013 #define new DEBUG_NEW
00014 #endif
00015
00016 vmsFileRecentList::vmsFileRecentList()
00017 {
00018 m_nMaxEntries = 10;
00019 }
00020
00021 vmsFileRecentList::~vmsFileRecentList()
00022 {
00023
00024 }
00025
00026 void vmsFileRecentList::Add(LPCSTR pszFileDispName, LPCSTR pszFilePathName)
00027 {
00028 _inc_FileInfo fi;
00029 fi.strDispName = pszFileDispName;
00030 fi.strPathName = pszFilePathName;
00031 m_vList.push_back (fi);
00032
00033 bool bNeedDel = true;
00034
00035 for (size_t i = 0; i < m_vList.size () - 1; i++)
00036 {
00037 if (lstrcmp (m_vList [i].strPathName, pszFilePathName) == 0)
00038 {
00039 m_vList.erase (m_vList.begin () + i);
00040 bNeedDel = false;
00041 break;
00042 }
00043 }
00044
00045 if (bNeedDel)
00046 {
00047 if (m_vList.size () > (size_t)m_nMaxEntries)
00048 m_vList.erase (m_vList.begin ());
00049 }
00050 }
00051
00052 BOOL vmsFileRecentList::Save(HANDLE hFile)
00053 {
00054 size_t c = m_vList.size ();
00055
00056 DWORD dw;
00057
00058 if (FALSE == WriteFile (hFile, &c, sizeof (c), &dw, NULL))
00059 return FALSE;
00060
00061 for (size_t i = 0; i < c; i++)
00062 {
00063 if (FALSE == fsSaveStrToFile (get_FileDispName (i), hFile))
00064 return FALSE;
00065
00066 if (FALSE == fsSaveStrToFile (get_FilePathName (i), hFile))
00067 return FALSE;
00068 }
00069
00070 return TRUE;
00071 }
00072
00073 BOOL vmsFileRecentList::Load(HANDLE hFile)
00074 {
00075 Clear ();
00076
00077 size_t c = 0;
00078 DWORD dw;
00079
00080 if (FALSE == ReadFile (hFile, &c, sizeof (c), &dw, NULL))
00081 return FALSE;
00082
00083 for (size_t i = 0; i < c; i++)
00084 {
00085 LPSTR pszDisp, pszPath;
00086
00087 if (FALSE == fsReadStrFromFile (&pszDisp, hFile))
00088 return FALSE;
00089
00090 if (FALSE == fsReadStrFromFile (&pszPath, hFile))
00091 return FALSE;
00092
00093 Add (pszDisp, pszPath);
00094
00095 delete [] pszDisp;
00096 delete [] pszPath;
00097 }
00098
00099 return TRUE;
00100 }
00101
00102 void vmsFileRecentList::Clear()
00103 {
00104 m_vList.clear ();
00105 }
00106
00107 LPCSTR vmsFileRecentList::get_FileDispName(int nIndex) const
00108 {
00109 return m_vList [nIndex].strDispName;
00110 }
00111
00112 LPCSTR vmsFileRecentList::get_FilePathName(int nIndex) const
00113 {
00114 return m_vList [nIndex].strPathName;
00115 }
00116
00117 int vmsFileRecentList::get_Count() const
00118 {
00119 return m_vList.size ();
00120 }