OSDN Git Service

PATCH: [ 1489824 ] Better default folder for user filters
authorKimmo Varis <kimmov@gmail.com>
Wed, 17 May 2006 16:15:09 +0000 (16:15 +0000)
committerKimmo Varis <kimmov@gmail.com>
Wed, 17 May 2006 16:15:09 +0000 (16:15 +0000)
Src/Changes.txt
Src/MainFrm.cpp

index 688fabc..73b7453 100644 (file)
@@ -2,6 +2,10 @@ Src\Changes.txt
 Add new items to top.
 (This summarizes all changes to all files under Src, including Src\Languages.)
 
+2006-05-17 Kimmo
+ PATCH: [ 1489824 ] Better default folder for user filters
+  Src: MainFrm.cpp
+
 2006-05-15 Kimmo
  PATCH: [ 1489133 ] Manual: document new filter location(s)
   Docs/Users/Manual: Filters.xml
index 4ddf841..bf92723 100644 (file)
@@ -165,9 +165,24 @@ static UINT indicators[] =
        ID_INDICATOR_SCRL,
 };
 
+/**
+ * @brief Relative (to WinMerge executable ) path to local help file.
+ */
 static const TCHAR DocsPath[] = _T("\\Docs\\WinMerge.chm");
+
+/**
+ * @brief URL to help indes in internet.
+ * We use internet help when local help file is not found (not installed).
+ */
 static const TCHAR DocsURL[] = _T("http://winmerge.org/2.4/manual/index.html");
 
+/**
+ * @brief Default relative path to "My Documents" for private filters.
+ * It is better to use subfolder by default than putting files directly
+ * to "My Folders".
+ */
+static const TCHAR DefaultRelativeFilterPath[] = _T("WinMergeFilters");
+
 /////////////////////////////////////////////////////////////////////////////
 // CMainFrame construction/destruction
 
@@ -212,13 +227,32 @@ CMainFrame::CMainFrame()
        if (m_pSyntaxColors)
                m_pSyntaxColors->Initialize(&m_options);
 
-       // If filter path is not defined, set it to My Documents -folder
+       // Check if filter folder is set, and create it if not
        CString pathMyFolders = m_options.GetString(OPT_FILTER_USERPATH);
        if (pathMyFolders.IsEmpty())
        {
                pathMyFolders = paths_GetMyDocuments(GetSafeHwnd());
-               m_options.SaveOption(OPT_FILTER_USERPATH, pathMyFolders);
-               theApp.m_globalFileFilter.SetFileFilterPath(pathMyFolders);
+               CString pathFilters(pathMyFolders);
+               if (pathFilters.Right(1) != _T("\\"))
+                       pathFilters += _T("\\");
+               pathFilters += DefaultRelativeFilterPath;
+
+               if (!CreateDirectory(pathFilters, NULL))
+               {
+                       // Failed to create a folder, check it didn't already
+                       // exist.
+                       DWORD errCode = GetLastError();
+                       if (errCode != ERROR_ALREADY_EXISTS)
+                       {
+                               // Failed to create a folder for filters, fallback to
+                               // "My Documents"-folder. It is not worth the trouble to
+                               // bother user about this or user more clever solutions.
+                               pathFilters = pathMyFolders;
+                       }
+               }
+
+               m_options.SaveOption(OPT_FILTER_USERPATH, pathFilters);
+               theApp.m_globalFileFilter.SetFileFilterPath(pathFilters);
        }
 }