PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/winxsamp/samples/filesys/RemoveIntermedialFiles/RemoveIntermedialFiles.cpp

http://winx.googlecode.com/
C++ | 153 lines | 90 code | 17 blank | 46 comment | 29 complexity | c06adf2d362ee7050bc3cd5385d69eca MD5 | raw file
  1. /* -------------------------------------------------------------------------
  2. // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE
  3. //
  4. // This file is a part of the WINX Library.
  5. // The use and distribution terms for this software are covered by the
  6. // Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
  7. // which can be found in the file CPL.txt at this distribution. By using
  8. // this software in any fashion, you are agreeing to be bound by the terms
  9. // of this license. You must not remove this notice, or any other, from
  10. // this software.
  11. //
  12. // Module: RemoveIntermedialFiles.cpp
  13. // Creator: xushiwei
  14. // Email: xushiweizh@gmail.com
  15. // Date: 2006-8-18 13:57:28
  16. //
  17. // $Id: RemoveIntermedialFiles.cpp,v 1.8 2006/12/23 09:48:13 xushiwei Exp $
  18. // -----------------------------------------------------------------------*/
  19. #include <winx.h>
  20. // -------------------------------------------------------------------------
  21. #define _EXTS_ALL_DIR \
  22. _T("ncb"), _T("opt"), _T("scc"), _T("suo"), _T("tlh"), NULL
  23. LPCTSTR g_extsAllDir[] = {
  24. _EXTS_ALL_DIR
  25. };
  26. LPCTSTR g_extsDspDir[] = {
  27. _T("aps"), _T("plg"), _T("clw"), _T("dsw"), _T("user"), _T("sln"),
  28. _T("o"), _T("layout"), _T("win"), _T("out"),
  29. _EXTS_ALL_DIR
  30. };
  31. LPCTSTR g_extsObjDir[] = {
  32. _T("obj"), _T("ilk"), _T("pdb"), _T("pch"), _T("sbr"), _T("map"),
  33. _T("exe"), _T("idb"), _T("res"), _T("manifest"), _T("dep"), _T("htm"),
  34. _T("bsc"), _T("lib"), _T("asm"), _T("dll"), _T("exp"), _T("trg"),
  35. _T("o"), _T("out"), _T("awx"),
  36. _EXTS_ALL_DIR
  37. };
  38. inline BOOL CanRemove(LPCTSTR szFileName, LPCTSTR szExts[])
  39. {
  40. if (*szFileName == '.') // generate by cvs, etc
  41. return TRUE;
  42. LPCTSTR szExt = _tcsrchr(szFileName, '.');
  43. if (szExt == NULL)
  44. return FALSE;
  45. ++szExt;
  46. for (UINT i = 0; szExts[i]; ++i) {
  47. if (_tcsicmp(szExts[i], szExt) == 0)
  48. return TRUE;
  49. }
  50. return FALSE;
  51. }
  52. inline void RemoveExts(const winx::CString& strDir, LPCTSTR szExts[])
  53. {
  54. winx::CFindFile finder;
  55. for (BOOL f = finder.FindFile(strDir + _T("\\*.*")); f; f = finder.FindNextFile()) {
  56. if (!finder.IsDirectory()) {
  57. if (CanRemove(finder.m_fd.cFileName, szExts)) {
  58. DeleteFile(finder.GetFilePath());
  59. }
  60. }
  61. }
  62. }
  63. inline void RemovePrivateExts(const winx::CString& strDir)
  64. {
  65. winx::CFindFile finder;
  66. for (BOOL f = finder.FindFile(strDir + _T("\\*_private.*")); f; f = finder.FindNextFile()) {
  67. if (!finder.IsDirectory()) {
  68. LPCTSTR szExt = PathFindExtension(finder.m_fd.cFileName);
  69. if (_tcsicmp(szExt, _T(".h")) == 0 || _tcsicmp(szExt, _T(".rc")) == 0) {
  70. DeleteFile(finder.GetFilePath());
  71. }
  72. }
  73. }
  74. }
  75. inline void RemoveIntermedialFiles(const winx::CString& strDir)
  76. {
  77. winx::CFindFile finder;
  78. BOOL f = finder.FindFile(strDir + _T("\\*.dsp"));
  79. if (!f)
  80. f = finder.FindFile(strDir + _T("\\*.vcproj"));
  81. if (f && !finder.IsDirectory()) {
  82. RemoveExts(strDir, g_extsDspDir);
  83. RemovePrivateExts(strDir);
  84. }
  85. else {
  86. f = finder.FindFile(strDir + _T("\\*.obj"));
  87. if (!f)
  88. f = finder.FindFile(strDir + _T("\\*.o"));
  89. if (f && !finder.IsDirectory())
  90. RemoveExts(strDir, g_extsObjDir);
  91. else {
  92. RemoveExts(strDir, g_extsAllDir);
  93. }
  94. }
  95. for (f = finder.FindFile(strDir + _T("\\*.*")); f; f = finder.FindNextFile()) {
  96. if (finder.IsDirectory() && *finder.m_fd.cFileName != '.') {
  97. RemoveIntermedialFiles(finder.GetFilePath());
  98. }
  99. }
  100. finder.Close();
  101. RemoveDirectory(strDir);
  102. }
  103. // -------------------------------------------------------------------------
  104. // main
  105. CComModule _Module;
  106. void _tmain(int argc, TCHAR* argv[])
  107. {
  108. if (argc <= 1)
  109. return;
  110. RemoveIntermedialFiles(argv[1]);
  111. }
  112. // -------------------------------------------------------------------------
  113. // $Log: RemoveIntermedialFiles.cpp,v $
  114. // Revision 1.8 2006/12/23 09:48:13 xushiwei
  115. // don't remove any files in .svn directory.
  116. //
  117. // Revision 1.7 2006/11/23 06:14:59 xushiwei
  118. // remove .dll etc
  119. //
  120. // Revision 1.6 2006/09/18 05:15:24 xushiwei
  121. // RemoveIntermedialFiles - remove *.bsc, *.lib, *.asm files
  122. //
  123. // Revision 1.5 2006/09/12 00:33:44 xushiwei
  124. // RemoveIntermedialFiles - remove all cvs history files
  125. //
  126. // Revision 1.4 2006/08/26 09:33:26 xushiwei
  127. // vs2005 support
  128. //
  129. // Revision 1.3 2006/08/22 10:36:53 xushiwei
  130. // WINX-Core:
  131. // Property(Bkgrnd, Accel, Layout), MainFrame support
  132. // CommandDispatch, CommandState, Demo: User-defined-control(Subclass, Superclass, SuperDialog)
  133. //
  134. // Revision 1.2 2006/08/21 19:08:20 xushiwei
  135. // RemoveIntermedialFiles tool
  136. //