OSDN Git Service

PATCH: [ 1114360 ] Non-blocking file filter editing
authorKimmo Varis <kimmov@gmail.com>
Thu, 3 Feb 2005 17:21:41 +0000 (17:21 +0000)
committerKimmo Varis <kimmov@gmail.com>
Thu, 3 Feb 2005 17:21:41 +0000 (17:21 +0000)
13 files changed:
Src/DiffFileInfo.cpp
Src/DiffFileInfo.h
Src/DirDoc.cpp
Src/DirViewColItems.cpp
Src/FileFilterHelper.cpp
Src/FileFilterHelper.h
Src/FileFilterMgr.cpp
Src/FileFilterMgr.h
Src/FileInfo.cpp [new file with mode: 0644]
Src/FileInfo.h [new file with mode: 0644]
Src/MainFrm.cpp
Src/Merge.dsp
Src/readme.txt

index 3d7dc32..3f4a0c1 100644 (file)
@@ -23,6 +23,7 @@
 // $Id$
 
 #include "stdafx.h"
+#include "FileInfo.h"
 #include "DiffFileInfo.h"
 
 /**
@@ -66,12 +67,8 @@ void DiffFileInfo::Update(CString sFilePath)
  */
 void DiffFileInfo::Clear()
 {
-       ctime = 0;
-       mtime = 0;
-       size = -1;
-       version = _T("");
+       FileInfo::Clear();
        bVersionChecked = false;
-       flags.reset();
        codepage = 0;
        unicoding = 0;
 }
index 5112748..929aac3 100644 (file)
 #ifndef _DIFF_FILE_INFO_H_INCLUDED
 #define _DIFF_FILE_INFO_H_INCLUDED
 
+#ifndef _FILE_INFO_H_INCLUDED
+#include "FileInfo.h"
+#endif
+
 /**
  * @brief Class for fileflags and coding info.
  */
-struct FileFlags
+struct DiffFileFlags : public FileFlags
 {
        DWORD coding; /**< Coding info for item */
-       DWORD attributes; /**< Fileattributes for item */
-       FileFlags() : coding(0), attributes(0) { }
-       void reset() { attributes = 0; } /// Reset fileattributes
+       DiffFileFlags() : coding(0) { FileFlags(); }
        
        /// Convert flags and coding to string for UI.
        CString toString() const
@@ -75,16 +77,10 @@ struct FileFlags
 /**
  * @brief Information for file
  */
-struct DiffFileInfo
+struct DiffFileInfo : public FileInfo
 {
-       // storing __time_t if MSVC6 (__MSC_VER<1300)
-       // storing __time64_t if MSVC7 (VC.NET)
-       __int64 ctime; /**< time of creation */
-       __int64 mtime;
-       __int64 size; /**< file size in bytes, -1 means file does not exist*/
-       CString version; /**< string of fixed file version, eg, 1.2.3.4 */
        bool bVersionChecked; /**< true if version string is up-to-date */
-       FileFlags flags; /**< file attributes */
+       DiffFileFlags flags; /**< file attributes */
        int codepage; /**< 8bit codepage, if applicable, 0 is unknown or N/A */
        int unicoding; /**< Unicode encoding (ucr::CODESET) */
        DiffFileInfo() { Clear(); }
index cc6b905..9e71f39 100644 (file)
@@ -200,6 +200,8 @@ void CDirDoc::Rescan()
        pf->GetHeaderInterface()->SetActive(0, TRUE);
        pf->GetHeaderInterface()->SetActive(1, TRUE);
 
+       // Make sure filters are up-to-date
+       theApp.m_globalFileFilter.ReloadUpdatedFilters();
        m_pCtxt->m_piFilterGlobal = &theApp.m_globalFileFilter;
 
        // Show active filter name in statusbar
index 6bc63c1..3de5fc1 100644 (file)
@@ -286,7 +286,7 @@ static CString ColBinGet(const CDiffContext *, const void *p)
 }
 static CString ColAttrGet(const CDiffContext *, const void *p)
 {
-       const FileFlags &r = *static_cast<const FileFlags *>(p);
+       const DiffFileFlags &r = *static_cast<const DiffFileFlags *>(p);
        return r.toString();
 }
 static CString ColEncodingGet(const CDiffContext *, const void *p)
@@ -375,8 +375,8 @@ static int ColBinSort(const CDiffContext *, const void *p, const void *q)
 }
 static int ColAttrSort(const CDiffContext *, const void *p, const void *q)
 {
-       const FileFlags &r = *static_cast<const FileFlags *>(p);
-       const FileFlags &s = *static_cast<const FileFlags *>(q);
+       const DiffFileFlags &r = *static_cast<const DiffFileFlags *>(p);
+       const DiffFileFlags &s = *static_cast<const DiffFileFlags *>(q);
        return r.toString().Compare(s.toString());
 }
 static int ColEncodingSort(const CDiffContext *, const void *p, const void *q)
index fcc3f10..05f41dd 100644 (file)
@@ -23,6 +23,7 @@
 // $Id$
 
 #include "stdafx.h"
+#include "FileInfo.h"
 #include "FileFilterMgr.h"
 #include "FileFilterHelper.h"
 #include "RegExp.h"
@@ -136,7 +137,12 @@ void FileFilterHelper::SetMask(LPCTSTR strMask)
        m_rgx.RegComp(regExp);
 }
 
-/** @brief Return TRUE unless we're suppressing this file by filter */
+/**
+ * @brief Check if any of filefilter rules match to filename.
+ *
+ * @param [in] szFileName Filename to test.
+ * @return TRUE unless we're suppressing this file by filter
+ */
 BOOL FileFilterHelper::includeFile(LPCTSTR szFileName)
 {
        if (m_bUseMask)
@@ -159,7 +165,12 @@ BOOL FileFilterHelper::includeFile(LPCTSTR szFileName)
        }
 }
 
-/** @brief Return TRUE unless we're suppressing this directory by filter */
+/**
+ * @brief Check if any of filefilter rules match to directoryname.
+ *
+ * @param [in] szFileName Directoryname to test.
+ * @return TRUE unless we're suppressing this directory by filter
+ */
 BOOL FileFilterHelper::includeDir(LPCTSTR szDirName)
 {
        if (m_bUseMask)
@@ -201,22 +212,6 @@ void FileFilterHelper::EditFileFilter(LPCTSTR szFileFilterPath)
        stInfo.cb = sizeof(STARTUPINFO);
        processSuccess = CreateProcess(NULL, (LPTSTR)(LPCTSTR)cmdLine, NULL,
                NULL, FALSE, 0, NULL, NULL, &stInfo, &prInfo);
-
-       if (processSuccess == TRUE)
-       {
-               // Wait until process closes down
-               WaitForSingleObject(prInfo.hProcess, INFINITE);
-               CloseHandle(prInfo.hThread);
-               CloseHandle(prInfo.hProcess);
-       }
-       
-       // Reload filter after changing it
-       m_fileFilterMgr->ReloadFilterFromDisk(filter);
-
-       // If it was active filter we have to re-set it
-       CString sPath = GetFileFilterPath();
-       if (sPath == szFileFilterPath)
-               SetFileFilterPath(szFileFilterPath);
 }
 
 /** @brief Load in all filter patterns in a directory (unless already in map) */
@@ -325,3 +320,38 @@ BOOL FileFilterHelper::SetFilter(CString filter)
        }
        return TRUE;
 }
+
+/** 
+ * @brief Reloads changed filter files
+ *
+ * Checks if filter file has been modified since it was last time
+ * loaded/reloaded. If file has been modified we reload it.
+ */
+void FileFilterHelper::ReloadUpdatedFilters()
+{
+       FILEFILTER_INFOLIST filters;
+       FileInfo fileInfo;
+       FileInfo *fileInfoStored = NULL;
+       FileFilterInfo * filter = NULL;
+       CString selected;
+
+       GetFileFilters(&filters, selected);
+       for (int i = 0; i < filters.GetSize(); i++)
+       {
+               filter = &filters.GetAt(i);
+               CString path = filter->fullpath;
+               fileInfoStored = &filter->fileinfo;
+
+               fileInfo.Update(path);
+               if (fileInfo.mtime != fileInfoStored->mtime ||
+                       fileInfo.size != fileInfoStored->size)
+               {
+                       // Reload filter after changing it
+                       m_fileFilterMgr->ReloadFilterFromDisk(path);
+
+                       // If it was active filter we have to re-set it
+                       if (path == selected)
+                               SetFileFilterPath(path);
+               }
+       }
+}
index 94c79c6..169fbc6 100644 (file)
@@ -40,6 +40,7 @@ struct FileFilterInfo
        CString name;                   /**< Name of filter */
        CString description;    /**< Description of filter (shown in UI) */
        CString fullpath;               /**< Full path to filter file */
+       FileInfo fileinfo;              /**< For tracking if file has been modified */
 };
 
 typedef CArray<FileFilterInfo, FileFilterInfo> FILEFILTER_INFOLIST;
@@ -68,6 +69,7 @@ public:
        void GetFileFilters(FILEFILTER_INFOLIST * filters, CString & selected) const;
        CString GetFileFilterName(CString filterPath);
        CString GetFileFilterPath(CString filterName);
+       void ReloadUpdatedFilters();
 
        void LoadFileFilterDirPattern(CMap<CString, LPCTSTR, int, int> & patternsLoaded, const CString & sPattern);
 
index d326cae..dce6407 100644 (file)
@@ -7,7 +7,13 @@
 //    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 //    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 /////////////////////////////////////////////////////////////////////////////
-//
+/**
+ *  @file FileFilterMgr.cpp
+ *
+ *  @brief Implementation of FileFilterMgr and supporting routines
+ */ 
+// RCS ID line follows -- this is updated by CVS
+// $Id$
 
 #include "stdafx.h"
 #include "FileFilterMgr.h"
@@ -238,6 +244,10 @@ BOOL TestAgainstRegList(const RegList & reglist, LPCTSTR szTest)
 /**
  * @brief Test given filename against filefilter.
  *
+ * Test filename against active filefilter. If matching rule is found
+ * we must first determine type of rule that matched. If we return FALSE
+ * from this function directory scan marks file as skipped.
+ *
  * @param [in] pFilter Pointer to filefilter
  * @param [in] szFileName Filename to test
  * @return TRUE if file passes the filter
@@ -253,6 +263,10 @@ BOOL FileFilterMgr::TestFileNameAgainstFilter(FileFilter * pFilter, LPCTSTR szFi
 /**
  * @brief Test given directory name against filefilter.
  *
+ * Test directory name against active filefilter. If matching rule is found
+ * we must first determine type of rule that matched. If we return FALSE
+ * from this function directory scan marks file as skipped.
+ *
  * @param [in] pFilter Pointer to filefilter
  * @param [in] szDirName Directory name to test
  * @return TRUE if directory name passes the filter
@@ -330,3 +344,16 @@ void FileFilterMgr::ReloadFilterFromDisk(FileFilter * pfilter)
        }
        m_filters.Add(newfilter);
 }
+
+/**
+ * @brief Reload filter from disk
+ *
+ * Reloads filter from disk. This is done by creating a new one
+ * to substitute for old one.
+ * @param [in] szFullPath Full path to filter file to reload.
+ */
+void FileFilterMgr::ReloadFilterFromDisk(LPCTSTR szFullPath)
+{
+       FileFilter * filter = GetFilterByPath(szFullPath);
+       ReloadFilterFromDisk(filter);
+}
index 5a7b372..0d945fd 100644 (file)
 //    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 //    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 /////////////////////////////////////////////////////////////////////////////
+/**
+ *  @file FileFilterMgr.h
+ *
+ *  @brief Declaration file for FileFilterMgr
+ */ 
+// RCS ID line follows -- this is updated by CVS
+// $Id$
 
 #ifndef FileFilter_h_included
 #define FileFilter_h_included
@@ -38,6 +45,7 @@ public:
        void LoadFromDirectory(LPCTSTR szPattern, LPCTSTR szExt);
        // Reload an edited filter
        void ReloadFilterFromDisk(FileFilter * pfilter);
+       void ReloadFilterFromDisk(LPCTSTR szFullPath);
        // Load a filter from a string
        void LoadFilterString(LPCTSTR szFilterString);
 
@@ -78,4 +86,3 @@ void DeleteRegList(RegList & reglist);
 
 
 #endif // FileFilter_h_included
-
diff --git a/Src/FileInfo.cpp b/Src/FileInfo.cpp
new file mode 100644 (file)
index 0000000..dec2fcc
--- /dev/null
@@ -0,0 +1,74 @@
+/////////////////////////////////////////////////////////////////////////////
+//    License (GPLv2+):
+//    This program is free software; you can redistribute it and/or modify
+//    it under the terms of the GNU General Public License as published by
+//    the Free Software Foundation; either version 2 of the License, or (at
+//    your option) any later version.
+//    
+//    This program is distributed in the hope that it will be useful, but
+//    WITHOUT ANY WARRANTY; without even the implied warranty of
+//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//    GNU General Public License for more details.
+//
+//    You should have received a copy of the GNU General Public License
+//    along with this program; if not, write to the Free Software
+//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+/////////////////////////////////////////////////////////////////////////////
+/** 
+ * @file  FileInfo.cpp
+ *
+ * @brief Implementation for FileInfo routines
+ */
+// RCS ID line follows -- this is updated by CVS
+// $Id$
+
+#include "stdafx.h"
+#include "FileInfo.h"
+
+/**
+ * @brief Convert a FILETIME to a long (standard time)
+ */
+static __int64 FileTimeToInt64(FILETIME & ft)
+{
+       return CTime(ft).GetTime();
+}
+
+/**
+ * @brief Update fileinfo from given file
+ * @param [in] sFilePath Full path to file/directory to update
+ */
+void FileInfo::Update(CString sFilePath)
+{
+       // CFileFind doesn't expose the attributes
+       // CFileStatus doesn't expose 64 bit size
+
+       WIN32_FIND_DATA wfd;
+       HANDLE h = FindFirstFile(sFilePath, &wfd);
+       __int64 mtime64 = 0;
+       size = -1;
+       flags.reset();
+       mtime = 0;
+       if (h != INVALID_HANDLE_VALUE)
+       {
+               mtime64 = FileTimeToInt64(wfd.ftLastWriteTime);
+               flags.attributes = wfd.dwFileAttributes;
+
+               // No size for directory (remains as -1)
+               if ((flags.attributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
+                       size = (wfd.nFileSizeHigh << 32) + wfd.nFileSizeLow;
+               FindClose(h);
+       }
+       mtime = mtime64;
+}
+
+/**
+ * @brief Clears FileInfo data.
+ */
+void FileInfo::Clear()
+{
+       ctime = 0;
+       mtime = 0;
+       size = -1;
+       version.Empty();
+       flags.reset();
+}
diff --git a/Src/FileInfo.h b/Src/FileInfo.h
new file mode 100644 (file)
index 0000000..8d6ee0f
--- /dev/null
@@ -0,0 +1,56 @@
+/////////////////////////////////////////////////////////////////////////////
+//    License (GPLv2+):
+//    This program is free software; you can redistribute it and/or modify
+//    it under the terms of the GNU General Public License as published by
+//    the Free Software Foundation; either version 2 of the License, or
+//    (at your option) any later version.
+//
+//    This program is distributed in the hope that it will be useful, but
+//    WITHOUT ANY WARRANTY; without even the implied warranty of
+//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//    General Public License for more details.
+//
+//    You should have received a copy of the GNU General Public License
+//    along with this program; if not, write to the Free Software
+//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+/////////////////////////////////////////////////////////////////////////////
+/** 
+ * @file  FileInfo.h
+ *
+ * @brief Declaration file for FileInfo
+ */
+// RCS ID line follows -- this is updated by CVS
+// $Id$
+
+#ifndef _FILE_INFO_H_INCLUDED
+#define _FILE_INFO_H_INCLUDED
+
+/**
+ * @brief Class for fileflags.
+ */
+struct FileFlags
+{
+       DWORD attributes; /**< Fileattributes for item */
+       FileFlags() : attributes(0) { }
+       void reset() { attributes = 0; } /// Reset fileattributes
+};
+
+/**
+ * @brief Information for file
+ */
+struct FileInfo
+{
+       // storing __time_t if MSVC6 (__MSC_VER<1300)
+       // storing __time64_t if MSVC7 (VC.NET)
+       __int64 ctime; /**< time of creation */
+       __int64 mtime; /**< time of last modify */
+       __int64 size; /**< file size in bytes, -1 means file does not exist*/
+       CString version; /**< string of fixed file version, eg, 1.2.3.4 */
+       FileFlags flags; /**< file attributes */
+       FileInfo() { Clear(); }
+
+       void Update(CString sFilePath);
+       void Clear();
+};
+
+#endif // _FILE_INFO_H_INCLUDED
index 2f66660..9f4ea20 100644 (file)
@@ -2502,6 +2502,9 @@ void CMainFrame::OnToolsFilters()
        sht.AddPage(&filter);
        sht.m_psh.dwFlags |= PSH_NOAPPLYNOW; // Hide 'Apply' button since we don't need it
 
+       // Make sure all filters are up-to-date
+       theApp.m_globalFileFilter.ReloadUpdatedFilters();
+
        theApp.m_globalFileFilter.GetFileFilters(&fileFilters, selectedFilter);
        fileFiltersDlg.SetFilterArray(&fileFilters);
        fileFiltersDlg.SetSelected(selectedFilter);
index 4b7c222..032f808 100644 (file)
@@ -362,6 +362,10 @@ SOURCE=.\FileFiltersDlg.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\FileInfo.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\FilepathEdit.cpp
 # End Source File
 # Begin Source File
@@ -905,6 +909,10 @@ SOURCE=.\FileFiltersDlg.h
 # End Source File
 # Begin Source File
 
+SOURCE=.\FileInfo.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\FilepathEdit.h
 # End Source File
 # Begin Source File
index 9a9d685..305946a 100644 (file)
@@ -1,3 +1,9 @@
+2005-02-03 Kimmo
+ PATCH: [ 1114360 ] Non-blocking file filter editing
+  Src: DiffFileInfo.cpp DiffFileInfo.h DirDoc.cpp DirViewColItems.cpp FileFilterHelper.cpp
+   FileFilterHelper.h FileFilterMgr.cpp FileFilterMgr.h MainFrm.cpp Merge.dsp
+  Src new files: FileInfo.cpp FileInfo.h
+
 2005-02-02 Kimmo
  BUG: [ 1039592 ] No differences shown after changing EOL options when loading
   Src: MergeDoc.cpp MergeEditView.cpp MergeEditView.h