// $Id$
#include "stdafx.h"
+#include "FileInfo.h"
#include "DiffFileInfo.h"
/**
*/
void DiffFileInfo::Clear()
{
- ctime = 0;
- mtime = 0;
- size = -1;
- version = _T("");
+ FileInfo::Clear();
bVersionChecked = false;
- flags.reset();
codepage = 0;
unicoding = 0;
}
#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
/**
* @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(); }
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
}
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)
}
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)
// $Id$
#include "stdafx.h"
+#include "FileInfo.h"
#include "FileFilterMgr.h"
#include "FileFilterHelper.h"
#include "RegExp.h"
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)
}
}
-/** @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)
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) */
}
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);
+ }
+ }
+}
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;
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);
// 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"
/**
* @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
/**
* @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
}
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);
+}
// 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
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);
#endif // FileFilter_h_included
-
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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();
+}
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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
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);
# End Source File
# Begin Source File
+SOURCE=.\FileInfo.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\FilepathEdit.cpp
# End Source File
# Begin Source File
# End Source File
# Begin Source File
+SOURCE=.\FileInfo.h
+# End Source File
+# Begin Source File
+
SOURCE=.\FilepathEdit.h
# End Source File
# Begin Source File
+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