OSDN Git Service

PATCH: [ 1000020 ] Simple project files (no GUI)
authorKimmo Varis <kimmov@gmail.com>
Wed, 4 Aug 2004 10:00:25 +0000 (10:00 +0000)
committerKimmo Varis <kimmov@gmail.com>
Wed, 4 Aug 2004 10:00:25 +0000 (10:00 +0000)
Src/MainFrm.cpp
Src/MainFrm.h
Src/Merge.cpp
Src/Merge.dsp
Src/Merge.h
Src/OpenDlg.cpp
Src/OpenDlg.h
Src/ProjectFile.cpp [new file with mode: 0755]
Src/ProjectFile.h [new file with mode: 0755]
Src/readme.txt

index 4c63053..36e36f5 100644 (file)
@@ -1427,8 +1427,10 @@ BOOL CMainFrame::DoFileOpen(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL*
                dlg.m_strRight = strRight;
                dlg.m_bRecurse = bRecurse;
 
+               if (dwLeftFlags & FFILEOPEN_PROJECT || dwLeftFlags & FFILEOPEN_PROJECT)
+                       dlg.m_bOverwriteRecursive = TRUE; // Use given value, not previously used value
                if (dwLeftFlags & FFILEOPEN_CMDLINE || dwLeftFlags & FFILEOPEN_CMDLINE)
-                       dlg.m_bOverwriteRecursive = TRUE;
+                       dlg.m_bOverwriteRecursive = TRUE; // Use given value, not previously used value
 
                if (dlg.DoModal() != IDOK)
                        return FALSE;
index 3aca91d..b76148e 100644 (file)
@@ -43,6 +43,7 @@ enum
        FFILEOPEN_NOMRU         = 0x0001, /**< Do not add this path to MRU list */
        FFILEOPEN_READONLY      = 0x0002, /**< Open this path as read-only */
        FFILEOPEN_CMDLINE       = 0x0010, /**< Path is read from commandline */
+       FFILEOPEN_PROJECT       = 0x0020, /**< Path is read from project-file */
 };
 
 class CDiffView;
index daab629..afdd90b 100644 (file)
@@ -46,6 +46,7 @@
 #include "FileFilterHelper.h"
 #include "Plugins.h"
 #include "DirScan.h" // for DirScan_InitializeDefaultCodepage
+#include "ProjectFile.h"
 
 #include "MergeEditView.h"
 #ifdef _DEBUG
@@ -224,7 +225,17 @@ BOOL CMergeApp::InitInstance()
        // Split commandline arguments into files & flags & recursive flag
        ParseArgs(pMainFrame, files, nFiles, recurse, dwLeftFlags, dwRightFlags);
 
-       if (nFiles>2)
+       if (LoadProjectFile(files, recurse))
+       {
+               if (!files[0].IsEmpty())
+                       dwLeftFlags |= FFILEOPEN_PROJECT;
+               if (!files[1].IsEmpty())
+                       dwRightFlags |= FFILEOPEN_PROJECT;
+               pMainFrame->m_strSaveAsPath = _T("");
+               pMainFrame->DoFileOpen(files[0], files[1],
+                       dwLeftFlags, dwRightFlags, recurse);
+       }
+       else if (nFiles>2)
        {
                dwLeftFlags |= FFILEOPEN_CMDLINE;
                dwRightFlags |= FFILEOPEN_CMDLINE;
@@ -710,7 +721,7 @@ void CAboutDlg::OnBnClickedOpenContributors()
                // values < 32 are errors (ref to MSDN)
                if ((int)ret < 32)
                {
-                       // Try to open with ssociated application (.rtf)
+                       // Try to open with associated application (.rtf)
                        ret = ShellExecute(m_hWnd, _T("open"), docPath, NULL, NULL, SW_SHOWNORMAL);
                        if ((int)ret < 32)
                        {
@@ -727,3 +738,54 @@ void CAboutDlg::OnBnClickedOpenContributors()
                AfxMessageBox(msg, MB_OK | MB_ICONSTOP);
        }
 }
+
+/** 
+ * @brief Read paths and filter from project file.
+ */
+BOOL CMergeApp::LoadProjectFile(CStringArray & files, BOOL & recursive)
+{
+       CString filterPrefix;
+       CString err;
+       ProjectFile pfile;
+       CString ProjectFileName;
+       CString ext;
+
+       SplitFilename(files[0], NULL, NULL, &ext);
+       if (ext == PROJECTFILE_EXT)
+               ProjectFileName = files[0];
+       else
+       {
+               SplitFilename(files[1], NULL, NULL, &ext);
+               if (ext == PROJECTFILE_EXT)
+                       ProjectFileName = files[1];
+               else
+                       return FALSE;
+       }
+
+       if (!ProjectFileName.IsEmpty())
+       {
+               if (!pfile.Read(ProjectFileName, &err))
+               {
+                       if (!err.IsEmpty())
+                       {
+                               CString msg;
+                               AfxFormatString2(msg, IDS_ERROR_FILEOPEN, ProjectFileName, err);
+                               AfxMessageBox(msg, MB_ICONSTOP);
+                       }
+                       return FALSE;
+               }
+               else
+               {
+                       pfile.GetPaths(files[0], files[1], recursive);
+                       if (pfile.HasFilter())
+                       {
+                               CString filter = pfile.GetFilter();
+                               filter.TrimLeft();
+                               filter.TrimRight();
+                               m_globalFileFilter.SetFilter(filter);
+                       }
+               }
+               return TRUE;
+       }
+       return FALSE;
+}
index 13d1f1d..8240624 100644 (file)
@@ -839,6 +839,10 @@ SOURCE=.\Plugins.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\ProjectFile.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\PropColors.cpp
 # End Source File
 # Begin Source File
@@ -1403,6 +1407,10 @@ SOURCE=.\Plugins.h
 # End Source File
 # Begin Source File
 
+SOURCE=.\ProjectFile.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\PropColors.h
 # End Source File
 # Begin Source File
index 6bb444c..e46efe3 100644 (file)
@@ -82,6 +82,8 @@ protected:
        void InitializeFileFilters();
        void ParseArgs(CMainFrame* pMainFrame, CStringArray & files, UINT & nFiles, BOOL & recurse,
                DWORD & dwLeftFlags, DWORD & dwRightFlags);
+       BOOL LoadProjectFile(CStringArray & files, BOOL & recursive);
+
 
 
        //{{AFX_MSG(CMergeApp)
index 8f7db2e..70c5fc2 100644 (file)
@@ -34,6 +34,7 @@
 #include "SelectUnpackerDlg.h"
 #include "OptionsDef.h"
 #include "MainFrm.h"
+#include "ProjectFile.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -54,11 +55,7 @@ COpenDlg::COpenDlg(CWnd* pParent /*=NULL*/)
        : CDialog(COpenDlg::IDD, pParent)
 {
        //{{AFX_DATA_INIT(COpenDlg)
-       m_strLeft = _T("");
-       m_strRight = _T("");
        m_bRecurse = FALSE;
-       m_strExt = _T("");
-       m_strUnpacker = _T("");
        //}}AFX_DATA_INIT
 
        m_pathsType = DOES_NOT_EXIST;
@@ -111,7 +108,7 @@ END_MESSAGE_MAP()
 void COpenDlg::OnLeftButton()
 {
        CString s;
-       CString sfolder, sname;
+       CString sfolder, sname, sext;
        CString dirSelTag;
        CFileStatus status;
        UpdateData(TRUE); 
@@ -124,11 +121,11 @@ void COpenDlg::OnLeftButton()
                sfolder = GetPathOnly(m_strLeft);
        if (SelectFile(s, sfolder))
        {
-               SplitFilename(s, &sfolder, &sname, 0);
-               if (sname == dirSelTag)
-               {
+               SplitFilename(s, &sfolder, &sname, &sext);
+               if (sext == PROJECTFILE_EXT)
+                       LoadProjectFile(s);
+               else if (sname == dirSelTag)
                        m_strLeft = sfolder + '\\';
-               }
                else
                        m_strLeft = s;
                UpdateData(FALSE);
@@ -142,7 +139,7 @@ void COpenDlg::OnLeftButton()
 void COpenDlg::OnRightButton() 
 {
        CString s;
-       CString sfolder, sname;
+       CString sfolder, sname, sext;
        CString dirSelTag;
        CFileStatus status;
        UpdateData(TRUE);
@@ -155,8 +152,10 @@ void COpenDlg::OnRightButton()
                sfolder = GetPathOnly(m_strRight);
        if (SelectFile(s, sfolder))
        {
-               SplitFilename(s, &sfolder, &sname, 0);
-               if (sname == dirSelTag)
+               SplitFilename(s, &sfolder, &sname, &sext);
+               if (sext == PROJECTFILE_EXT)
+                       LoadProjectFile(s);
+               else if (sname == dirSelTag)
                        m_strRight = sfolder + '\\';
                else
                        m_strRight = s;
@@ -513,3 +512,43 @@ void COpenDlg::CenterToMainFrame()
        SetWindowPos(&CWnd::wndTop, x, y, rectBar.right,
                rectBar.bottom, SWP_NOOWNERZORDER | SWP_NOSIZE );
 }
+
+/** 
+ * @brief Read paths and filter from project file.
+ */
+BOOL COpenDlg::LoadProjectFile(CString path)
+{
+       CString filterPrefix;
+       CString err;
+       ProjectFile pfile;
+
+       VERIFY(filterPrefix.LoadString(IDS_FILTER_PREFIX));
+       if (!pfile.Read(path, &err))
+       {
+               if (!err.IsEmpty())
+               {
+                       CString msg;
+                       AfxFormatString2(msg, IDS_ERROR_FILEOPEN, path, err);
+                       AfxMessageBox(msg, MB_ICONSTOP);
+               }
+               return FALSE;
+       }
+       else
+       {
+               if (pfile.HasLeft())
+                       m_strLeft = pfile.GetLeft();
+               if (pfile.HasRight())
+                       m_strRight = pfile.GetRight();
+               if (pfile.HasFilter())
+               {
+                       m_strExt = pfile.GetFilter();
+                       m_strExt.TrimLeft();
+                       m_strExt.TrimRight();
+                       if (m_strExt[0] != '*')
+                               m_strExt.Insert(0, filterPrefix);
+               }
+               if (pfile.HasSubfolders())
+                       m_bRecurse = (pfile.GetSubfolders() == 1);
+       }
+       return TRUE;
+}
index 89d4d00..cec27b3 100644 (file)
@@ -90,6 +90,7 @@ protected:
        void SetStatus(UINT msgID);
        void SetUnpackerStatus(UINT msgID);
        void CenterToMainFrame();
+       BOOL LoadProjectFile(CString path);
 
        // Generated message map functions
        //{{AFX_MSG(COpenDlg)
diff --git a/Src/ProjectFile.cpp b/Src/ProjectFile.cpp
new file mode 100755 (executable)
index 0000000..6c54752
--- /dev/null
@@ -0,0 +1,195 @@
+/////////////////////////////////////////////////////////////////////////////
+//    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  ProjectFile.cpp
+ *
+ * @brief Implementation file for ProjectFile class
+ */
+// RCS ID line follows -- this is updated by CVS
+// $Id$
+
+#include "stdafx.h"
+#include "ProjectFile.h"
+
+ProjectFile::ProjectFile()
+{
+       m_subfolders = -1;
+}
+
+/** 
+ * @brief Open given path-file and read data from it to member variables.
+ */
+BOOL ProjectFile::Read(LPCTSTR path, CString *sError)
+{
+       ASSERT(sError != NULL);
+       CFile file;
+       CFileException e;
+
+       if (!file.Open(path, CFile::modeRead, &e))
+       {
+               TCHAR szError[1024];
+               e.GetErrorMessage(szError, 1024);
+               *sError = szError;
+               return FALSE;
+       }
+
+       char buf[4096] = {0};
+       TCHAR buf2[4096] = {0};
+       TCHAR tmpPath[MAX_PATH] = {0};
+       UINT bytesRead = file.Read(buf, 4095);
+
+       USES_CONVERSION;
+       _tcsncpy(buf2, A2T(buf), 4096);
+
+       if (_tcsstr(buf2, _T("<?xml")) && _tcsstr(buf2, _T("?>")))
+       {
+               TCHAR *pProject = _tcsstr(buf2, _T("<project>"));
+               
+               if (pProject)
+               {
+                       TCHAR *pPaths = _tcsstr(buf2, _T("<paths>"));
+                       TCHAR *pLeft = _tcsstr(buf2, _T("<left>"));
+                       TCHAR *pRight = _tcsstr(buf2, _T("<right>"));
+                       TCHAR *pFilter = _tcsstr(buf2, _T("<filter>"));
+                       TCHAR *pSubs = _tcsstr(buf2, _T("<subfolders>"));
+
+                       CString subs;
+                       GetVal(pPaths, pLeft, &m_leftFile, _T("<left>"), _T("</left>"), buf2);
+                       GetVal(pPaths, pRight, &m_rightFile, _T("<right>"), _T("</right>"), buf2);
+                       GetVal(pPaths, pFilter, &m_filter, _T("<filter>"), _T("</filter>"), buf2);
+                       if (GetVal(pPaths, pSubs, &subs, _T("<subfolders>"), _T("</subfolders>"), buf2))
+                               m_subfolders = _ttoi(subs);
+               }
+       }
+
+       file.Close();
+
+       return TRUE;
+}
+
+/** 
+ * @brief Save data from member variables to path-file.
+ */
+BOOL ProjectFile::Save(LPCTSTR path)
+{
+       UINT flags = CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite;
+
+       return TRUE;
+}
+
+/** 
+ * @brief Returns if left path is defined.
+ */
+BOOL ProjectFile::HasLeft() const
+{
+       return !m_leftFile.IsEmpty();
+}
+
+/** 
+ * @brief Returns if right path is defined.
+ */
+BOOL ProjectFile::HasRight() const
+{
+       return !m_rightFile.IsEmpty();
+}
+
+/** 
+ * @brief Returns if filter is defined.
+ */
+BOOL ProjectFile::HasFilter() const
+{
+       return !m_filter.IsEmpty();
+}
+
+/** 
+ * @brief Returns if subfolder is included.
+ */
+BOOL ProjectFile::HasSubfolders() const
+{
+       return (m_subfolders != -1);
+}
+
+/** 
+ * @brief Returns left path.
+ */
+CString ProjectFile::GetLeft() const
+{
+       return m_leftFile;
+}
+
+/** 
+ * @brief Returns right path.
+ */
+CString ProjectFile::GetRight() const
+{
+       return m_rightFile;
+}
+
+/** 
+ * @brief Returns filter.
+ */
+CString ProjectFile::GetFilter() const
+{
+       return m_filter;
+}
+
+/** 
+ * @brief Returns subfolder included -setting.
+ */
+int ProjectFile::GetSubfolders() const
+{
+       return m_subfolders;
+}
+
+/** 
+ * @brief Reads one value from XML data.
+ */
+BOOL ProjectFile::GetVal(TCHAR *pPaths, TCHAR *pVal, CString * sval,
+               TCHAR *ptag1, TCHAR *ptag2, TCHAR *pbuf)
+{
+       if (pPaths && pVal && pVal > pPaths)
+       {
+               TCHAR tmpPath[MAX_PATH] = {0};
+               TCHAR *pTagEnd = _tcsstr(pbuf, ptag2);
+               if ((pTagEnd - pVal) < (MAX_PATH * sizeof(TCHAR)))
+               {
+                       pVal += _tcslen(ptag1);
+                       _tcsncpy(tmpPath, pVal, pTagEnd - pVal);
+                       *sval = tmpPath;
+                       return TRUE;
+               }
+       }
+       return FALSE;
+}
+
+/** 
+ * @brief Returns left and right paths and recursive from project file
+ * 
+ * @param [out] sLeft Left path
+ * @param [out] sRight Right path
+ * @param [out] bSubFolders If TRUE subfolders included (recursive compare)
+ */
+void ProjectFile::GetPaths(CString & sLeft, CString & sRight,
+       BOOL & bSubfolders) const
+{
+       if (HasLeft())
+               sLeft = GetLeft();
+       if (HasRight())
+               sRight = GetRight();
+       if (HasSubfolders())
+               bSubfolders = (GetSubfolders() == 1);
+}
diff --git a/Src/ProjectFile.h b/Src/ProjectFile.h
new file mode 100755 (executable)
index 0000000..4aea4ab
--- /dev/null
@@ -0,0 +1,59 @@
+/////////////////////////////////////////////////////////////////////////////
+//    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  ProjectFile.h
+ *
+ * @brief Declaration file ProjectFile class
+ */
+// RCS ID line follows -- this is updated by CVS
+// $Id$
+
+/** @brief File extension for path files */
+const TCHAR PROJECTFILE_EXT[] = _T("WinMerge");
+
+/**
+ * @brief Class for reading paths from project file.
+ */
+class ProjectFile
+{
+public:
+       ProjectFile();
+       BOOL Read(LPCTSTR path, CString *sError);
+       BOOL Save(LPCTSTR path);
+       
+       BOOL HasLeft() const;
+       BOOL HasRight() const;
+       BOOL HasFilter() const;
+       BOOL HasSubfolders() const;
+
+       CString GetLeft() const;
+       CString GetRight() const;
+       CString GetFilter() const;
+       int GetSubfolders() const;
+
+       void GetPaths(CString & sLeft, CString & sRight, BOOL & bSubFolders) const;
+
+protected:
+       BOOL GetVal(TCHAR *pPaths, TCHAR *pVal, CString * sval,
+               TCHAR *ptag1, TCHAR *ptag2, TCHAR *pbuf);
+
+private:
+       CString m_leftFile;
+       CString m_rightFile;
+       CString m_filter;
+       int m_subfolders;
+};
index 44de047..5f981ae 100644 (file)
@@ -6,6 +6,9 @@
   Src: DirView.cpp
  PATCH: [ 1002887 ] Enable Change Pane menuitem for Diff Pane
   Src: MergeDiffDetailView.cpp MergeDoffDetailView.h
+ PATCH: [ 1000020 ] Simple project files (no GUI)
+  Src: MainFrm.cpp MainFrm.h Merge.cpp Merge.dsp Merge.h OpenDlg.cpp OpenDlg.h
+  Src new files: ProjectFile.cpp ProjectFile.h
   
 2004-08-03 Kimmo
  PATCH: [ 1002333 ] Set default filter to *.* when starting WinMerge