XFile.cpp
上传用户:kklily621
上传日期:2013-06-25
资源大小:252k
文件大小:17k
开发平台:

Visual C++

  1. //=============================================================================================
  2. /*
  3. 文件: XFile.cpp
  4. 说明:
  5. ---------------------------------------------------
  6. 控管规则文件操作,用来创建、读、写、删除控管规
  7. 则文件以及其它一些辅助操作。
  8. ---------------------------------------------------
  9. 工程: Xfilter 个人防火墙
  10. 作者: 朱雁辉,朱雁冰
  11. 创建日期: 2001/08/03
  12. 网址: http://www.xfilt.com
  13. 电子邮件: xstudio@xfilt.com
  14. 版权所有 (c) 2001-2002 X 工作室
  15. 警告:
  16. ---------------------------------------------------
  17. 本电脑程序受著作权法的保护。未经授权,不能使用
  18. 和修改本软件全部或部分源代码。凡擅自复制、盗用或散
  19. 布此程序或部分程序或者有其它任何越权行为,将遭到民
  20. 事赔偿及刑事的处罚,并将依法以最高刑罚进行追诉。
  21. 凡通过合法途径购买本软件源代码的用户被默认授权
  22. 可以在自己的程序中使用本软件的部分代码,但作者不对
  23. 代码产生的任何后果负责。
  24. 使用了本软件代码的程序只能以可执行文件形式发布,
  25. 未经特别许可,不能将含有本软件源代码的源程序以任何
  26. 形式发布。
  27. ---------------------------------------------------
  28. */
  29. //=============================================================================================
  30. #include "stdafx.h"
  31. //============================================================================================
  32. //Acl file operation
  33. //initialize public function
  34. CAclFile::CAclFile()
  35. {
  36. mAclFile.m_hFile  = NULL;
  37. mpAclDistrustIP = NULL;
  38. mpAclTrustIP = NULL;
  39. mpAclCustomIP = NULL;
  40. mpAcl = NULL;
  41. mAllTime.bWeekDay = 0xFF; //11111111
  42. mAllTime.tStartTime = 0; //00:00
  43. mAllTime.tEndTime = 0; //00:00
  44. InitializeCriticalSection(&gCriticalSectionFile);
  45. }
  46. CAclFile::~CAclFile()
  47. {
  48. CloseAcl();
  49. FreeMemory();
  50. }
  51. //============================================================================================
  52. //private function
  53. void CAclFile::InitDefaultValue()
  54. {
  55. EnterCriticalSection(&gCriticalSectionFile);
  56. {
  57. // Initalize header default value
  58. _tcscpy(mAclHeader.sSignature , ACL_HEADER_SIGNATURE);
  59. mAclHeader.ulTimeOffset = ACL_HEADER_LENTH;
  60. mAclHeader.bMajor = ACL_HEADER_MAJOR;
  61. mAclHeader.bMinor = ACL_HEADER_MINOR;
  62. mAclHeader.uiSerial = ACL_HEADER_SERIAL;
  63. mAclHeader.ulVersion = ACL_HEADER_VERSION;
  64. mAclHeader.bSet = ACL_HEADER_SET;
  65. mAclHeader.uiLogSize = ACL_HEADER_LOG_SIZE;
  66. mAclHeader.bUpdateInterval = ACL_HEADER_UPDATE_INTERVAL;
  67. _tcscpy(mAclHeader.sUserName , ACL_HEADER_USER_NAME);
  68. _tcscpy(mAclHeader.sACode , ACL_HEADER_ACODE);
  69. _tcscpy(mAclHeader.sWebURL , ACL_HEADER_WEB_URL);
  70. _tcscpy(mAclHeader.sCommandURL , ACL_HEADER_COMMAND_URL);
  71. _tcscpy(mAclHeader.sUserRegisterURL , ACL_HEADER_REGISTER_URL);
  72. _tcscpy(mAclHeader.sEmail , ACL_HEADER_EMAIL);
  73. mAclHeader.ulAclCount = ACL_HEADER_INITIALIZE;
  74. mAclHeader.ulAclOffset = ACL_HEADER_INITIALIZE;
  75. mAclHeader.ulCustomIPCount = ACL_HEADER_INITIALIZE;
  76. mAclHeader.ulCustomIPOffset = ACL_HEADER_INITIALIZE;
  77. mAclHeader.ulDistrustIPCount = ACL_HEADER_INITIALIZE;
  78. mAclHeader.ulDistrustIPOffset = ACL_HEADER_INITIALIZE;
  79. mAclHeader.ulHeaderLenth = ACL_HEADER_LENTH;
  80. mAclHeader.ulIntranetIPCount = ACL_HEADER_INTRANET_IP_COUNT;
  81. mAclHeader.ulIntranetIPOffset = ACL_HEADER_LENTH + ACL_TIME_TOTAL_LENTH;
  82. mAclHeader.ulTimeCount = ACL_HEADER_TIME_COUNT;
  83. mAclHeader.ulTrustIPCount = ACL_HEADER_INITIALIZE;
  84. mAclHeader.ulTrustIPOffset = ACL_HEADER_INITIALIZE;
  85. // Initalize intranet IP aria default value
  86. mAclIntranetIP.ulStartIP = ACL_INTRANET_START_IP;
  87. mAclIntranetIP.ulEndIP = ACL_INTRANET_END_IP;
  88. // Initalize time aria default value
  89. mAclTime[0].bWeekDay = ACL_WORK_TIME_WEEK;
  90. mAclTime[0].tStartTime = ACL_WORK_TIME_START;
  91. mAclTime[0].tEndTime = ACL_WORK_TIME_END;
  92. mAclTime[1].bWeekDay = ACL_NONWORK_TIME_WEEK;
  93. mAclTime[1].tStartTime = ACL_NONWORK_TIME_START;
  94. mAclTime[1].tEndTime = ACL_NONWORK_TIME_END;
  95. mAclTime[2].bWeekDay = ACL_WEEK_END_TIME_WEEK;
  96. mAclTime[2].tStartTime = ACL_WEEK_END_TIME_START;
  97. mAclTime[2].tEndTime = ACL_WEEK_END_TIME_END;
  98. mAclTime[3].bWeekDay = ACL_DISTRUST_TIME_WEEK;
  99. mAclTime[3].tStartTime = ACL_DISTRUST_TIME_START;
  100. mAclTime[3].tEndTime = ACL_DISTRUST_TIME_END;
  101. mAclTime[4].bWeekDay = ACL_TRUST_TIME_WEEK;
  102. mAclTime[4].tStartTime = ACL_TRUST_TIME_START;
  103. mAclTime[4].tEndTime = ACL_TRUST_TIME_END;
  104. mAclTime[5].bWeekDay = ACL_CUSTOM_TIME_WEEK;
  105. mAclTime[5].tStartTime = ACL_CUSTOM_TIME_START;
  106. mAclTime[5].tEndTime = ACL_CUSTOM_TIME_END;
  107. }
  108. LeaveCriticalSection(&gCriticalSectionFile);
  109. ODS(_T("XFILE: Success initalize the default value."));
  110. }
  111. int CAclFile::CreateAcl(const TCHAR *sPathName)
  112. {
  113. InitDefaultValue();
  114. return WriteAcl(sPathName);
  115. }
  116. int CAclFile::OpenAcl()
  117. {
  118. int iRet;
  119. if(_taccess(mAppPath + ACL_FILE_NAME, 0) == -1) // file not exists & create
  120. {
  121. ODS(_T("XFILE: Acl file xacl.cfg not exists."));
  122. if((iRet = CreateAcl(mAppPath + ACL_FILE_NAME)) != XERR_SUCCESS)
  123. return iRet;
  124. }
  125. TRY // open file
  126. {
  127. mAclFile.Open( mAppPath + ACL_FILE_NAME,
  128. CFile::modeRead |
  129. CFile::typeBinary | 
  130. CFile::shareDenyWrite
  131. );
  132. ODS(_T("XFILE: Success open the file of xacl.cfg"));
  133. }
  134. CATCH( CFileException, e )
  135. {
  136. ODS(_T("XFILE: Can't open the file of xacl.cfg"));
  137. return XERR_FILE_CAN_NOT_OPEN;
  138. }
  139. END_CATCH
  140. return XERR_SUCCESS;
  141. }
  142. int CAclFile::WriteAcl(const TCHAR *sPathName)
  143. {
  144. CFile FileAcl;
  145. TRY
  146. {
  147. FileAcl.Open( sPathName,
  148. CFile::modeCreate | 
  149. CFile::modeWrite | 
  150. CFile::typeBinary | 
  151. CFile::shareExclusive
  152. );
  153. ODS2(_T("XFILE: Success create the file "),sPathName);
  154. FileAcl.Write(&mAclHeader,ACL_HEADER_LENTH);
  155. FileAcl.Write(&mAclTime,ACL_TIME_TOTAL_LENTH);
  156. FileAcl.Write(&mAclIntranetIP,ACL_IP_LENTH);
  157. if(mAclHeader.ulDistrustIPCount > 0)
  158. FileAcl.WriteHuge(mpAclDistrustIP,mAclHeader.ulDistrustIPCount * ACL_IP_LENTH);
  159. if(mAclHeader.ulTrustIPCount > 0)
  160. FileAcl.WriteHuge(mpAclTrustIP,mAclHeader.ulTrustIPCount * ACL_IP_LENTH);
  161. if(mAclHeader.ulCustomIPCount > 0)
  162. FileAcl.WriteHuge(mpAclCustomIP,mAclHeader.ulCustomIPCount * ACL_IP_LENTH);
  163. if(mAclHeader.ulAclCount > 0)
  164. FileAcl.WriteHuge(mpAcl,mAclHeader.ulAclCount * ACL_ACL_LENTH);
  165. FileAcl.Close();
  166. ODS2(_T("XFILE: Success wrote the data and close "),sPathName);
  167. }
  168. CATCH( CFileException, e )
  169. {
  170. if(FileAcl.m_hFile != NULL)
  171. {
  172. FileAcl.Close();
  173. ODS2(_T("XFILE: Can't write "),sPathName);
  174. }
  175. else
  176. ODS2(_T("XFILE: Can't create "),sPathName);
  177. return XERR_FILE_CREATE_FAILURE;
  178. }
  179. END_CATCH
  180. return XERR_SUCCESS;
  181. }
  182. int CAclFile::AddAclAcl(XACL *pAddAcl, int AddAclCount)
  183. {
  184. if(pAddAcl == NULL || AddAclCount <= 0)
  185. return XERR_INVALID_PARAMETER;
  186. EnterCriticalSection(&gCriticalSectionFile);
  187. {
  188. void *tmpAcl =  malloc(mAclHeader.ulAclCount * ACL_ACL_LENTH);
  189. memcpy (tmpAcl,mpAcl,mAclHeader.ulAclCount * ACL_ACL_LENTH);
  190. free (mpAcl);
  191. mpAcl = new XACL[mAclHeader.ulAclCount + AddAclCount];
  192. memcpy (mpAcl,tmpAcl,mAclHeader.ulAclCount * ACL_ACL_LENTH);
  193. free (tmpAcl);
  194. memcpy( mpAcl + mAclHeader.ulAclCount,
  195. pAddAcl,
  196. AddAclCount * ACL_ACL_LENTH
  197. );
  198. mAclHeader.ulAclCount += AddAclCount;
  199. }
  200. LeaveCriticalSection(&gCriticalSectionFile);
  201. ODS2(_T("XFILE: Success Add ACL, "),mpAcl[mAclHeader.ulAclCount - 1].sApplication);
  202. return XERR_SUCCESS;
  203. }
  204. int CAclFile::AddDistrustIP(XACL_IP *pDistrustIP, int AddCount)
  205. {
  206. DWORD OldTotalLenth = mAclHeader.ulDistrustIPCount * ACL_IP_LENTH;
  207. if(pDistrustIP == NULL || AddCount <= 0)
  208. return XERR_INVALID_PARAMETER;
  209. EnterCriticalSection(&gCriticalSectionFile);
  210. {
  211. void *tmpAcl =  malloc(OldTotalLenth);
  212. memcpy (tmpAcl,mpAclDistrustIP,OldTotalLenth);
  213. free (mpAclDistrustIP);
  214. mpAclDistrustIP = new XACL_IP[mAclHeader.ulDistrustIPCount + AddCount];
  215. memcpy (mpAclDistrustIP,tmpAcl,OldTotalLenth);
  216. free (tmpAcl);
  217. memcpy( mpAclDistrustIP + mAclHeader.ulDistrustIPCount,
  218. pDistrustIP,
  219. AddCount * ACL_IP_LENTH
  220. );
  221. mAclHeader.ulDistrustIPCount += AddCount;
  222. }
  223. LeaveCriticalSection(&gCriticalSectionFile);
  224. ODS2(_T("XFILE: Success Add DistrustIP, "),DIPToSIP(&mpAclDistrustIP[mAclHeader.ulDistrustIPCount - 1].ulStartIP));
  225. return XERR_SUCCESS;
  226. }
  227. int CAclFile::AddTrustIP(XACL_IP *pTrustIP, int AddCount)
  228. {
  229. DWORD OldTotalLenth = mAclHeader.ulTrustIPCount * ACL_IP_LENTH;
  230. if(pTrustIP == NULL || AddCount <= 0)
  231. return XERR_INVALID_PARAMETER;
  232. EnterCriticalSection(&gCriticalSectionFile);
  233. {
  234. void *tmpAcl =  malloc(OldTotalLenth);
  235. memcpy (tmpAcl,mpAclTrustIP,OldTotalLenth);
  236. free (mpAclTrustIP);
  237. mpAclTrustIP = new XACL_IP[mAclHeader.ulTrustIPCount + AddCount];
  238. memcpy (mpAclTrustIP,tmpAcl,OldTotalLenth);
  239. free (tmpAcl);
  240. memcpy( mpAclTrustIP + mAclHeader.ulTrustIPCount,
  241. pTrustIP,
  242. AddCount * ACL_IP_LENTH
  243. );
  244. mAclHeader.ulTrustIPCount += AddCount;
  245. }
  246. LeaveCriticalSection(&gCriticalSectionFile);
  247. ODS2(_T("XFILE: Success Add TrustIP, "),DIPToSIP(&mpAclTrustIP[mAclHeader.ulTrustIPCount - 1].ulStartIP));
  248. return XERR_SUCCESS;
  249. }
  250. int CAclFile::AddCustomIP(XACL_IP *pCustomIP, int AddCount)
  251. {
  252. DWORD OldTotalLenth = mAclHeader.ulCustomIPCount * ACL_IP_LENTH;
  253. if(pCustomIP == NULL || AddCount <= 0)
  254. return XERR_INVALID_PARAMETER;
  255. EnterCriticalSection(&gCriticalSectionFile);
  256. {
  257. void *tmpAcl =  malloc(OldTotalLenth);
  258. memcpy (tmpAcl,mpAclCustomIP,OldTotalLenth);
  259. free (mpAclCustomIP);
  260. mpAclCustomIP = new XACL_IP[mAclHeader.ulCustomIPCount + AddCount];
  261. memcpy (mpAclCustomIP,tmpAcl,OldTotalLenth);
  262. free (tmpAcl);
  263. memcpy( mpAclCustomIP + mAclHeader.ulCustomIPCount,
  264. pCustomIP,
  265. AddCount * ACL_IP_LENTH
  266. );
  267. mAclHeader.ulCustomIPCount += AddCount;
  268. }
  269. LeaveCriticalSection(&gCriticalSectionFile);
  270. ODS2(_T("XFILE: Success Add CustomIP, "),
  271. DIPToSIP(&mpAclCustomIP[mAclHeader.ulCustomIPCount - 1].ulStartIP));
  272. return XERR_SUCCESS;
  273. }
  274. int CAclFile::DelAclIP(XACL_IP *pAclIP, DWORD* pCount, DWORD iIndex)
  275. {
  276. if(pAclIP == NULL || iIndex >= *pCount)
  277. return XERR_INVALID_PARAMETER;
  278. EnterCriticalSection(&gCriticalSectionFile);
  279. {
  280. memcpy(pAclIP + iIndex, pAclIP + iIndex + 1, (*pCount - iIndex) * ACL_IP_LENTH);
  281. *pCount = *pCount - 1 ;
  282. }
  283. LeaveCriticalSection(&gCriticalSectionFile);
  284. ODS(_T("XFILE: Success Del IP aria. "));
  285. return XERR_SUCCESS;
  286. }
  287. int CAclFile::DelAcl(XACL *pAcl, DWORD* pCount, DWORD iIndex)
  288. {
  289. if(pAcl == NULL || iIndex >= *pCount)
  290. return XERR_INVALID_PARAMETER;
  291. EnterCriticalSection(&gCriticalSectionFile);
  292. {
  293. memcpy(pAcl + iIndex, pAcl + iIndex + 1, (*pCount - iIndex) * ACL_ACL_LENTH);
  294. *pCount = *pCount - 1 ;
  295. }
  296. LeaveCriticalSection(&gCriticalSectionFile);
  297. ODS(_T("XFILE: Success Del ACL. "));
  298. return XERR_SUCCESS;
  299. }
  300. //============================================================================================
  301. //Export function
  302. int CAclFile::ReadAcl(BOOL IsDLL, HINSTANCE instance) //main function
  303. {
  304. int iRet = XERR_SUCCESS;
  305. if(IsDLL)
  306. mAppPath = CAclFile::GetAppPath(IsDLL, instance);
  307. else
  308. mAppPath = CAclFile::GetAppPath();
  309. if(mAclFile.m_hFile == NULL && (iRet = OpenAcl()) != XERR_SUCCESS)
  310. return iRet;
  311. TRY
  312. {
  313. FreeMemory();
  314. mAclFile.SeekToBegin();
  315. mAclFile.Read(&mAclHeader,ACL_HEADER_LENTH); //read the header
  316. if(_tcscmp(mAclHeader.sSignature , ACL_HEADER_SIGNATURE) != 0)
  317. {
  318. ODS(_T("XFILE: Invalid signatrue, It's not the XFILTER ACL file."));
  319. CloseAcl();
  320. return XERR_FILE_INVALID_SIGNATURE;
  321. }
  322. mAclFile.Read(&mAclTime,ACL_TIME_TOTAL_LENTH); //read the time aria
  323. mAclFile.Read(&mAclIntranetIP,ACL_IP_LENTH); //read the intranet ip aria
  324. if(mAclHeader.ulDistrustIPCount > 0) //read the distrust ip aria
  325. {
  326. mpAclDistrustIP = new XACL_IP[mAclHeader.ulDistrustIPCount];
  327. mAclFile.ReadHuge(mpAclDistrustIP,ACL_IP_LENTH * mAclHeader.ulDistrustIPCount);
  328. }
  329. if(mAclHeader.ulTrustIPCount > 0) //read the trust ip aria
  330. {
  331. mpAclTrustIP = new XACL_IP[mAclHeader.ulTrustIPCount];
  332. mAclFile.ReadHuge(mpAclTrustIP,ACL_IP_LENTH * mAclHeader.ulTrustIPCount);
  333. }
  334. if(mAclHeader.ulCustomIPCount > 0) //read the custom ip aria
  335. {
  336. mpAclCustomIP = new XACL_IP[mAclHeader.ulCustomIPCount];
  337. mAclFile.ReadHuge(mpAclCustomIP,ACL_IP_LENTH * mAclHeader.ulCustomIPCount);
  338. }
  339. if(mAclHeader.ulAclCount > 0) //read the ACL
  340. {
  341. mpAcl = new XACL[mAclHeader.ulAclCount];
  342. mAclFile.ReadHuge(mpAcl,ACL_ACL_LENTH * mAclHeader.ulAclCount);
  343. }
  344. CloseAcl();
  345. ODS(_T("XFILE: Read xacl.cfg success."));
  346. }
  347. CATCH( CFileException, e )
  348. {
  349. CloseAcl();
  350. ODS(_T("XFILE: Read xacl.cfg error."));
  351. return XERR_FILE_READ_ERROR;
  352. }
  353. END_CATCH
  354. return iRet;
  355. }
  356. int CAclFile::SaveAcl()
  357. {
  358. int iRet;
  359. if((iRet = WriteAcl(mAppPath + ACL_TEMP_FILE_NAME)) != XERR_SUCCESS)
  360. return iRet;
  361. TRY
  362. {
  363. CFile::Remove(mAppPath + ACL_FILE_NAME);
  364. CFile::Rename(mAppPath + ACL_TEMP_FILE_NAME,mAppPath + ACL_FILE_NAME);
  365. ODS(_T("XFILE: Success remove xacl.cfg and rename xacl.tmp to xacl.cfg"));
  366. }
  367. CATCH( CFileException, e )
  368. {
  369. ODS(_T("XFILE: Save error."));
  370. return XERR_FILE_SAVE_ERROR;
  371. }
  372. END_CATCH
  373. return XERR_SUCCESS;
  374. }
  375. void CAclFile::CloseAcl()
  376. {
  377. if(mAclFile.m_hFile != NULL)
  378. {
  379. mAclFile.Close();
  380. mAclFile.m_hFile = NULL;
  381. }
  382. ODS(_T("XFILE: Success close the acl file."));
  383. }
  384. int CAclFile::AddAcl(void *pAddAcl, int AddAclCount, int AclType)
  385. {
  386. switch(AclType)
  387. {
  388. case ACL_TYPE_ACL:
  389. return AddAclAcl((XACL*)pAddAcl,AddAclCount);
  390. case ACL_TYPE_DISTRUST_IP:
  391. return AddDistrustIP((XACL_IP*)pAddAcl,AddAclCount);
  392. case ACL_TYPE_TRUST_IP:
  393. return AddTrustIP((XACL_IP*)pAddAcl,AddAclCount);
  394. case ACL_TYPE_CUSTOM_IP:
  395. return AddCustomIP((XACL_IP*)pAddAcl,AddAclCount);
  396. default:
  397. return XERR_INVALID_PARAMETER;
  398. }
  399. return XERR_SUCCESS;
  400. }
  401. int CAclFile::DelAcl(int iIndex, int AclType)
  402. {
  403. switch(AclType)
  404. {
  405. case ACL_TYPE_ACL:
  406. return DelAcl(mpAcl, &mAclHeader.ulAclCount, iIndex);
  407. case ACL_TYPE_DISTRUST_IP:
  408. return DelAclIP(mpAclDistrustIP, &mAclHeader.ulDistrustIPCount, iIndex);
  409. case ACL_TYPE_TRUST_IP:
  410. return DelAclIP(mpAclTrustIP, &mAclHeader.ulTrustIPCount, iIndex);
  411. case ACL_TYPE_CUSTOM_IP:
  412. return DelAclIP(mpAclCustomIP, &mAclHeader.ulCustomIPCount, iIndex);
  413. default:
  414. return XERR_INVALID_PARAMETER;
  415. }
  416. return XERR_SUCCESS;
  417. }
  418. int CAclFile::FreeMemory()
  419. {
  420. if(mpAcl)
  421. {
  422. free(mpAcl);
  423. mpAcl = NULL;
  424. }
  425. if(mpAclDistrustIP)
  426. {
  427. free(mpAclDistrustIP);
  428. mpAclDistrustIP = NULL;
  429. }
  430. if(mpAclTrustIP)
  431. {
  432. free(mpAclTrustIP);
  433. mpAclTrustIP = NULL;
  434. }
  435. if(mpAclCustomIP)
  436. {
  437. free(mpAclCustomIP);
  438. mpAclCustomIP = NULL;
  439. }
  440. ODS(_T("XFILE: Success free the ACL and IP aria memory."));
  441. return XERR_SUCCESS;
  442. }
  443. CString CAclFile::DIPToSIP(DWORD* pIP)
  444. {
  445. if(pIP == NULL)
  446. return _T("");
  447. CString s;
  448. BYTE *b = (BYTE*)pIP;
  449. s.Format(_T("%d.%d.%d.%d"),b[3],b[2],b[1],b[0]);
  450. return s;
  451. }
  452. /*---------------------------------------------------------------------------------------------
  453. index from 0 start, for example:
  454. index: 0 1 2 3 4 5 6 7
  455. Binary value: 0 0 0 0 0 0 0 0
  456. */
  457. int CAclFile::GetBit(BYTE bit, int index, int count)
  458. {
  459. bit <<= index;
  460. bit >>= (8 - count);
  461. return bit;
  462. }
  463. int CAclFile::SetBit(BYTE* bit, int index, BOOL isTrue)
  464. {
  465. BYTE bOr = 0xFF,bAnd = 0x00;
  466. bOr <<= index;
  467. bOr >>= 7;
  468. bOr <<= (7 - index);
  469. bAnd = ~bOr;
  470. if(isTrue)
  471. *bit = *bit | bOr;
  472. else
  473. *bit = *bit & bAnd;
  474. return 0;
  475. }
  476. //============================================================================================
  477. //static function
  478. CString CAclFile::GetAppPath(BOOL IsDLL, HINSTANCE instance, BOOL IsFullPathName) 
  479. {
  480. TCHAR sFilename[_MAX_PATH];
  481. TCHAR sDrive[_MAX_DRIVE];
  482. TCHAR sDir[_MAX_DIR];
  483. TCHAR sFname[_MAX_FNAME];
  484. TCHAR sExt[_MAX_EXT];
  485. if(IsDLL)
  486. GetModuleFileName(instance, sFilename, _MAX_PATH);
  487. else
  488. GetModuleFileName(AfxGetInstanceHandle(), sFilename, _MAX_PATH);
  489. if(IsFullPathName)
  490. return sFilename;
  491. _tsplitpath(sFilename, sDrive, sDir, sFname, sExt);
  492. CString rVal(CString(sDrive) + CString(sDir));
  493. int nLen = rVal.GetLength();
  494. if (rVal.GetAt(nLen-1) != _T('\'))
  495. rVal += _T("\");
  496. return rVal;
  497. }
  498. CString CAclFile::GetPath(TCHAR *sFilename) 
  499. {
  500. TCHAR sDrive[_MAX_DRIVE];
  501. TCHAR sDir[_MAX_DIR];
  502. TCHAR sFname[_MAX_FNAME];
  503. TCHAR sExt[_MAX_EXT];
  504. _tsplitpath(sFilename, sDrive, sDir, sFname, sExt);
  505. CString rVal(CString(sDrive) + CString(sDir));
  506. int nLen = rVal.GetLength();
  507. if (rVal.GetAt(nLen-1) != _T('\'))
  508. rVal += _T("\");
  509. return rVal;
  510. }  
  511. CString CAclFile::GetName(TCHAR *sFilename) 
  512. {
  513. TCHAR sDrive[_MAX_DRIVE];
  514. TCHAR sDir[_MAX_DIR];
  515. TCHAR sFname[_MAX_FNAME];
  516. TCHAR sExt[_MAX_EXT];
  517. _tsplitpath(sFilename, sDrive, sDir, sFname, sExt);
  518. CString rVal;
  519. rVal.Format(_T("%s%s"), sFname, sExt);
  520. return rVal;
  521. }