#include "StdAfx.h"
|
#include "PathData.h"
|
|
CPathData::CPathData(void)
|
{
|
//»ý¼ºÀÚ ÃʱâÈ
|
InitPathData();
|
|
//µðÆúÆ® °ª
|
m_strDefaultName = _T("DefaultLog");
|
GetModulePath();
|
}
|
|
CPathData::~CPathData(void)
|
{
|
}
|
|
CString CPathData::GetNameFromID(int& LogID)
|
{
|
for(int i = 0; i < LV_FCOUNT; i++)
|
{
|
if( m_nLogID[i] == LogID)
|
return m_strLogName[i];
|
}
|
return m_strDefaultName;
|
}
|
|
CString CPathData::GetPathFromID(int& LogID)
|
{
|
for(int i = 0; i < LV_FCOUNT; i++)
|
{
|
if( m_nLogID[i] == LogID)
|
return m_strLogPath[i];
|
}
|
return m_strDefaultPath;
|
}
|
|
int CPathData::GetIndexFromID(int& LogID)
|
{
|
for(int i = 0; i < LV_FCOUNT; i++)
|
{
|
if( m_nLogID[i] == LogID)
|
return i;
|
}
|
return -1;
|
}
|
|
CString CPathData::GetNameFromIndex(int& Index)
|
{
|
return m_strLogName[Index];
|
}
|
|
CString CPathData::GetPathFromIndex(int& Index)
|
{
|
return m_strLogPath[Index];
|
}
|
|
void CPathData::GetModulePath(void)
|
{
|
TCHAR szBuffer[MAX_PATH];
|
memset(szBuffer,0x00,MAX_PATH*sizeof(TCHAR));
|
|
::GetModuleFileName(NULL,szBuffer,MAX_PATH);
|
|
for(int i = lstrlen(szBuffer) -1; i>=0; --i)
|
{
|
if(szBuffer[i] == '\\')
|
{
|
int j = lstrlen(szBuffer)-1;
|
for(;j>=i;--j)
|
{
|
szBuffer[j] = NULL;
|
}
|
|
if(szBuffer[j] == ';') szBuffer[j+1] = '\\';
|
|
szBuffer[j+1] = '\\';
|
|
m_strDefaultPath = szBuffer;
|
return;
|
}
|
}
|
}
|
bool CPathData::InsertPathData(int& LogID, CString& strName, CString& strPath)
|
{
|
int InsertIndex = GetEmptyIndex();
|
if( InsertIndex == -1)
|
return false;
|
|
m_nLogID[InsertIndex] = LogID;
|
m_strLogName[InsertIndex] = strName;
|
m_strLogPath[InsertIndex] = strPath;
|
return true;
|
}
|
|
int CPathData::GetEmptyIndex(void)
|
{
|
for(int i = 0; i < LV_FCOUNT; i++)
|
{
|
if( m_nLogID[i] == -1)
|
return i;
|
}
|
return -1;
|
}
|
|
bool CPathData::DeletePathData(int& LogID)
|
{
|
int InsertIndex = GetIndexFromID(LogID);
|
if( InsertIndex == -1)
|
return false;
|
|
m_nLogID[InsertIndex] = -1;
|
m_strLogName[InsertIndex] = _T("");
|
m_strLogPath[InsertIndex] = _T("");
|
return true;
|
}
|
|
int CPathData::GetIDFromIndex(int& Index)
|
{
|
if(Index < 0 || Index > LV_FCOUNT) return -1;
|
return m_nLogID[Index];
|
}
|
|
bool CPathData::SetPathData(int& LogID, CString& strName, CString& strPath)
|
{
|
int index = GetIndexFromID(LogID);
|
if( index == -1) return false;
|
SetNameFromIndex(index, strName);
|
SetPathFromIndex(index, strPath);
|
|
return true;
|
|
}
|
|
bool CPathData::SetNameFromIndex(int& index, CString& PathName)
|
{
|
if( index < 0 || index >= LV_FCOUNT)
|
return false;
|
m_strLogName[index] = PathName;
|
return true;
|
}
|
|
bool CPathData::SetPathFromIndex(int& index, CString& strPath)
|
{
|
if( index < 0 || index >= LV_FCOUNT)
|
return false;
|
m_strLogPath[index] = strPath;
|
return true;
|
}
|
|
bool CPathData::ModifyPathData(int& LogID, CString& strPathName, CString& strLogPath)
|
{
|
return SetPathData(LogID, strPathName, strLogPath);
|
}
|
|
void CPathData::InitPathData(void)
|
{
|
for(int i = 0; i < LV_FCOUNT; i++)
|
{
|
m_nLogID[i] = -1;
|
m_strLogPath[i] = _T("");
|
m_strLogName[i] = _T("");
|
}
|
}
|