DownInfoType.cpp
上传用户:qhonly
上传日期:2013-06-10
资源大小:487k
文件大小:6k
源码类别:

界面编程

开发平台:

Visual C++

  1. #include "StdAfx.h"
  2. #include "downinfotype.h"
  3. #include "RTXmlFile.h"
  4. #include "RTFolder.h"
  5. CDownInfoType::CDownInfoType(void)
  6. {
  7. }
  8. CDownInfoType::~CDownInfoType(void)
  9. {
  10. }
  11. void CDownInfoType::LoadTreeTypeInfo(CTreeCtrl& TreeCtrl, HTREEITEM hParent,UINT Type)
  12. {
  13. DownTypeInfo *pDTI = (DownTypeInfo *)TreeCtrl.GetItemData(hParent);
  14. if(pDTI == NULL)return;
  15. HTREEITEM hChildItem = TreeCtrl.GetChildItem(hParent);
  16. while(hChildItem != NULL)
  17. {
  18. ClearTreeTypeInfoData(TreeCtrl,hChildItem);
  19. TreeCtrl.DeleteItem(hChildItem);
  20. hChildItem = TreeCtrl.GetChildItem(hParent);
  21. }
  22. int layer = pDTI->Layer + 1;
  23. HTREEITEM hItem;
  24. char BaseTypePath[MAX_PATH];
  25. char BaseSavePath[MAX_PATH];
  26. char TypeFile[MAX_PATH];
  27. char find[MAX_PATH];
  28. strcpy(BaseSavePath,pDTI->SavePath);
  29. strcpy(BaseTypePath,pDTI->TypePath);
  30. ZeroMemory(find,MAX_PATH);
  31. strcpy(find,BaseTypePath);
  32. strcat(find,"\*.*");
  33. WIN32_FIND_DATA wfd;
  34. HANDLE hFind = FindFirstFile(find,&wfd);
  35. if(INVALID_HANDLE_VALUE == hFind)return;
  36. do
  37. {
  38. if((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
  39. {
  40. if(wfd.cFileName[0] == '.')continue;
  41. ZeroMemory(TypeFile,MAX_PATH);
  42. strcpy(TypeFile,BaseTypePath);
  43. strcat(TypeFile,"\");
  44. strcat(TypeFile,wfd.cFileName);
  45. pDTI = new DownTypeInfo;
  46. pDTI->Layer = layer;
  47. pDTI->Type = TYPE_DELETE | TYPE_EDIT | TYPE_ADD | Type;
  48. ZeroMemory(pDTI->SavePath,MAX_PATH);
  49. strcpy(pDTI->SavePath,BaseSavePath);
  50. strcat(pDTI->SavePath,"\");
  51. strcat(pDTI->SavePath,wfd.cFileName);
  52. strcpy(pDTI->FileFilter,"*");
  53. strcpy(pDTI->TypePath,TypeFile);
  54. LoadTypeInfo(TypeFile,pDTI);
  55. hItem = TreeCtrl.InsertItem(wfd.cFileName,1,2,hParent);
  56. TreeCtrl.SetItemData(hItem,(DWORD_PTR)pDTI);
  57. LoadTreeTypeInfo(TreeCtrl,hItem);
  58. }
  59. }
  60. while(FindNextFile(hFind,&wfd));
  61. FindClose(hFind);
  62. }
  63. void CDownInfoType::LoadTypeInfo(LPCTSTR lpTypePath,DownTypeInfo* pDTI)
  64. {
  65. char TypeFile[MAX_PATH];
  66. ZeroMemory(TypeFile,MAX_PATH);
  67. strcpy(TypeFile,lpTypePath);
  68. strcat(TypeFile,"\");
  69. strcat(TypeFile,"type.ini");
  70. CRTXmlFile cfgFile;
  71. BOOL bNeedSave = FALSE;
  72. BOOL rtOpen = cfgFile.Open(TypeFile);
  73. CRTXmlItem *pItem = cfgFile.GetItem("TypeInfo");
  74. if(!rtOpen || pItem == NULL)
  75. {
  76. bNeedSave = TRUE;
  77. pItem = new CRTXmlItem("TypeInfo");
  78. pItem->SetKeyValue("SavePath",pDTI->SavePath);
  79. pItem->SetKeyValue("FileFilter",pDTI->FileFilter);
  80. cfgFile.AddItem(pItem);
  81. }
  82. else
  83. {
  84. LPCTSTR lpSavePath = pItem->GetKeyValue("SavePath");
  85. if(lpSavePath == NULL)
  86. {
  87. pItem->SetKeyValue("SavePath",pDTI->SavePath);
  88. bNeedSave = TRUE;
  89. }
  90. else
  91. {
  92. strcpy(pDTI->SavePath,lpSavePath);
  93. }
  94. LPCTSTR lpFileFilter = pItem->GetKeyValue("FileFilter");
  95. if(lpFileFilter == NULL)
  96. {
  97. pItem->SetKeyValue("FileFilter",pDTI->FileFilter);
  98. bNeedSave = TRUE;
  99. }
  100. else
  101. {
  102. strcpy(pDTI->FileFilter,lpFileFilter);
  103. }
  104. }
  105. if(bNeedSave)
  106. {
  107. cfgFile.Save();
  108. }
  109. }
  110. BOOL CDownInfoType::GetTreeTypePath(CTreeCtrl& TreeCtrl,HTREEITEM hItem, char lpBuf[])
  111. {
  112. DownTypeInfo *pDTI = (DownTypeInfo *)TreeCtrl.GetItemData(hItem);
  113. if(pDTI == NULL)return FALSE;
  114. strcpy(lpBuf,pDTI->TypePath);
  115. return TRUE;
  116. }
  117. BOOL CDownInfoType::MoveTreeTypeInfoTo(CTreeCtrl& TreeCtrl, HTREEITEM hSrcItem, HTREEITEM hDestItem,UINT Type)
  118. {
  119. char SrcPath[MAX_PATH];
  120. char DestPath[MAX_PATH];
  121. if(!GetTreeTypePath(TreeCtrl,hSrcItem,SrcPath))return FALSE;
  122. if(!GetTreeTypePath(TreeCtrl,hDestItem,DestPath))return FALSE;
  123. if(!CRTFolder::MoveTo(SrcPath,DestPath))return FALSE;
  124. TreeCtrl.DeleteItem(hSrcItem);
  125. LoadTreeTypeInfo(TreeCtrl,hDestItem,Type);
  126. return TRUE;
  127. }
  128. BOOL CDownInfoType::DeleteTreeTypeInfo(CTreeCtrl& TreeCtrl, HTREEITEM hDeleteItem)
  129. {
  130. char TypePath[MAX_PATH];
  131. if(!GetTreeTypePath(TreeCtrl,hDeleteItem,TypePath))return FALSE;
  132. if(!CRTFolder::DeleteFolder(TypePath))return FALSE;
  133. ClearTreeTypeInfoData(TreeCtrl,hDeleteItem);
  134. TreeCtrl.DeleteItem(hDeleteItem);
  135. return TRUE;
  136. }
  137. void CDownInfoType::ClearTreeTypeInfoData(CTreeCtrl& TreeCtrl, HTREEITEM hItem)
  138. {
  139. if(hItem == NULL)
  140. {
  141. hItem = TreeCtrl.GetRootItem();
  142. }
  143. if(hItem == NULL)return;
  144. DownTypeInfo *pDTI = (DownTypeInfo *)TreeCtrl.GetItemData(hItem);
  145. if(pDTI != NULL)delete pDTI;
  146. hItem = TreeCtrl.GetChildItem(hItem);
  147. while(hItem != NULL)
  148. {
  149. ClearTreeTypeInfoData(TreeCtrl,hItem);
  150. hItem = TreeCtrl.GetNextItem(hItem,TVGN_NEXT);
  151. }
  152. }
  153. BOOL CDownInfoType::SaveTypeInfo(CTreeCtrl& TreeCtrl,HTREEITEM hItem)
  154. {
  155. char TypePath[MAX_PATH];
  156. if(!GetTreeTypePath(TreeCtrl,hItem,TypePath))
  157. return FALSE;
  158. DownTypeInfo *pDTI = (DownTypeInfo*)TreeCtrl.GetItemData(hItem);
  159. if(pDTI == NULL)return FALSE;
  160. return SaveTypeInfo(TypePath,pDTI);
  161. }
  162. BOOL CDownInfoType::SaveTypeInfo(LPCTSTR lpTypePath,DownTypeInfo* pDTI)
  163. {
  164. if(pDTI == NULL)return TRUE;
  165. char TypeFile[MAX_PATH];
  166. ZeroMemory(TypeFile,MAX_PATH);
  167. strcpy(TypeFile,lpTypePath);
  168. strcat(TypeFile,"\");
  169. strcat(TypeFile,"type.ini");
  170. CRTXmlFile cfgFile;
  171. BOOL bNeedSave = TRUE;
  172. BOOL rtOpen = cfgFile.Open(TypeFile);
  173. CRTXmlItem *pItem = cfgFile.GetItem("TypeInfo");
  174. if(!rtOpen || pItem == NULL)
  175. {
  176. pItem = new CRTXmlItem("TypeInfo");
  177. pItem->SetKeyValue("SavePath",pDTI->SavePath);
  178. pItem->SetKeyValue("FileFilter",pDTI->FileFilter);
  179. cfgFile.AddItem(pItem);
  180. }
  181. else
  182. {
  183. pItem->SetKeyValue("SavePath",pDTI->SavePath);
  184. pItem->SetKeyValue("FileFilter",pDTI->FileFilter);
  185. }
  186. if(bNeedSave)
  187. {
  188. cfgFile.Save();
  189. }
  190. return TRUE;
  191. }
  192. UINT CDownInfoType::GetDownInfoType(CTreeCtrl& TreeCtrl, HTREEITEM hItem)
  193. {
  194. DownTypeInfo *pDownInfo = (DownTypeInfo*)TreeCtrl.GetItemData(hItem);
  195. if(pDownInfo == NULL)return 0;
  196. return pDownInfo->Type;
  197. }