|
6 | 6 | #include "FileFilterHelper.h"
|
7 | 7 | #include "FolderCmp.h"
|
8 | 8 | #include "DirScan.h"
|
| 9 | +#include "paths.h" |
9 | 10 | #include <iostream>
|
10 | 11 | #include <Poco/Thread.h>
|
11 | 12 | #ifdef _MSC_VER
|
12 | 13 | #include <crtdbg.h>
|
13 | 14 | #endif
|
14 | 15 |
|
| 16 | +std::vector<std::wstring> ParseQuotedArgs(const std::wstring& input) |
| 17 | +{ |
| 18 | + std::vector<std::wstring> tokens; |
| 19 | + std::wstring current; |
| 20 | + bool inQuotes = false; |
| 21 | + |
| 22 | + for (size_t i = 0; i < input.length(); ++i) |
| 23 | + { |
| 24 | + wchar_t ch = input[i]; |
| 25 | + if (ch == L'"') |
| 26 | + { |
| 27 | + inQuotes = !inQuotes; |
| 28 | + if (!inQuotes && !current.empty()) |
| 29 | + { |
| 30 | + tokens.push_back(current); |
| 31 | + current.clear(); |
| 32 | + } |
| 33 | + } |
| 34 | + else if (iswspace(ch) && !inQuotes) |
| 35 | + { |
| 36 | + if (!current.empty()) |
| 37 | + { |
| 38 | + tokens.push_back(current); |
| 39 | + current.clear(); |
| 40 | + } |
| 41 | + } |
| 42 | + else |
| 43 | + { |
| 44 | + current += ch; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + if (!current.empty()) |
| 49 | + tokens.push_back(current); |
| 50 | + |
| 51 | + return tokens; |
| 52 | +} |
| 53 | + |
15 | 54 | int main()
|
16 | 55 | {
|
17 | 56 | #ifdef _MSC_VER
|
18 | 57 | _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
|
19 | 58 | #endif
|
20 |
| - CompareStats cmpstats(2); |
21 | 59 |
|
| 60 | + int dm = CMP_CONTENT; // Default compare method |
| 61 | + PathContext paths(_T(""), _T("")); // Default empty paths |
22 | 62 | FileFilterHelper filter;
|
23 | 63 | filter.UseMask(true);
|
24 |
| -// filter.SetMask(_T("*.cpp;*.c;*.h;*.vcproj;*.vcxproj")); |
25 | 64 | filter.SetMask(_T("*.*"));
|
26 | 65 |
|
27 |
| - CDiffContext ctx( |
28 |
| - PathContext(_T("c:/windows"), _T("c:/windows")), |
29 |
| - CMP_CONTENT); |
| 66 | + std::wcout << L"WinMerge folder comparison test tool\n"; |
| 67 | + std::wcout << L"Type 'h' for help.\n"; |
30 | 68 |
|
31 |
| - DIFFOPTIONS options = {0}; |
32 |
| - options.nIgnoreWhitespace = false; |
33 |
| - options.bIgnoreBlankLines = false; |
34 |
| - options.bFilterCommentsLines = false; |
35 |
| - options.bIgnoreCase = false; |
36 |
| - options.bIgnoreEol = false; |
| 69 | + std::wstring cmd; |
| 70 | + while (true) |
| 71 | + { |
| 72 | + std::wcout << L"> "; |
| 73 | + std::getline(std::wcin, cmd); |
| 74 | + if (cmd.empty()) |
| 75 | + continue; |
37 | 76 |
|
38 |
| - ctx.InitDiffItemList(); |
39 |
| - //ctx.CreateCompareOptions(CMP_CONTENT, options); |
40 |
| - ctx.CreateCompareOptions(CMP_DATE, options); |
| 77 | + if (cmd[0] == L'q') |
| 78 | + { |
| 79 | + break; |
| 80 | + } |
| 81 | + if (cmd[0] == L'h') |
| 82 | + { |
| 83 | + std::wcout << L"\nAvailable commands:\n"; |
| 84 | + std::wcout << L" p <left-path> <right-path> : Set folder paths to compare\n"; |
| 85 | + std::wcout << L" f <filter-mask> : Set file mask filter (e.g., *.c;*.h)\n"; |
| 86 | + std::wcout << L" m <compare-method> : Set compare method (FullContents, Date, etc.)\n"; |
| 87 | + std::wcout << L" c : Start folder comparison\n"; |
| 88 | + std::wcout << L" q : Quit the program\n"; |
| 89 | + std::wcout << L" h : Show this help message\n\n"; |
| 90 | + } |
| 91 | + else if (cmd[0] == L'p') // Set path |
| 92 | + { |
| 93 | + std::vector<std::wstring> args = ParseQuotedArgs(cmd.substr(2)); |
| 94 | + if (args.size() == 2 || args.size() == 3) |
| 95 | + { |
| 96 | + paths = PathContext(args); |
| 97 | + } |
| 98 | + else |
| 99 | + { |
| 100 | + std::wcout << L"Usage: p \"left_path\" \"right_path\"\n"; |
| 101 | + } |
| 102 | + } |
| 103 | + else if (cmd[0] == L'f') // Set file mask |
| 104 | + { |
| 105 | + std::wstring mask = cmd.substr(2); |
| 106 | + filter.SetMask(mask.c_str()); |
| 107 | + } |
| 108 | + else if (cmd[0] == L'm') // Set method |
| 109 | + { |
| 110 | + std::wstring method = cmd.substr(2); |
| 111 | + if (method == L"FullContents") dm = CMP_CONTENT; |
| 112 | + else if (method == L"QuickContents") dm = CMP_QUICK_CONTENT; |
| 113 | + else if (method == L"BinaryContents") dm = CMP_BINARY_CONTENT; |
| 114 | + else if (method == L"Date") dm = CMP_DATE; |
| 115 | + else if (method == L"DateSize") dm = CMP_DATE_SIZE; |
| 116 | + else if (method == L"Size") dm = CMP_SIZE; |
| 117 | + else { |
| 118 | + std::wcout << L"Unknown compare method\n"; |
| 119 | + continue; |
| 120 | + } |
| 121 | + } |
| 122 | + else if (cmd[0] == L'c') // Compare |
| 123 | + { |
| 124 | + CompareStats cmpstats(paths.GetSize()); |
41 | 125 |
|
42 |
| - ctx.m_iGuessEncodingType = 0;//(50001 << 16) + 2; |
43 |
| - ctx.m_bIgnoreSmallTimeDiff = true; |
44 |
| - ctx.m_bStopAfterFirstDiff = false; |
45 |
| - ctx.m_nQuickCompareLimit = 4 * 1024 * 1024; |
46 |
| - ctx.m_bPluginsEnabled = false; |
47 |
| - ctx.m_bWalkUniques = true; |
48 |
| - ctx.m_pCompareStats = &cmpstats; |
49 |
| - ctx.m_bRecursive = true; |
50 |
| - ctx.m_piFilterGlobal = &filter; |
| 126 | + CDiffContext ctx(paths, dm); |
51 | 127 |
|
52 |
| - // Folder names to compare are in the compare context |
53 |
| - CDiffThread diffThread; |
54 |
| - diffThread.SetContext(&ctx); |
55 |
| - diffThread.SetCollectFunction([](DiffFuncStruct* myStruct) { |
56 |
| - bool casesensitive = false; |
57 |
| - int depth = myStruct->context->m_bRecursive ? -1 : 0; |
58 |
| - PathContext paths = myStruct->context->GetNormalizedPaths(); |
59 |
| - String subdir[3] = { _T(""), _T(""), _T("") }; // blank to start at roots specified in diff context |
60 |
| - // Build results list (except delaying file comparisons until below) |
61 |
| - DirScan_GetItems(paths, subdir, myStruct, |
62 |
| - casesensitive, depth, nullptr, myStruct->context->m_bWalkUniques); |
63 |
| - }); |
64 |
| - diffThread.SetCompareFunction([](DiffFuncStruct* myStruct) { |
65 |
| - DirScan_CompareItems(myStruct, nullptr); |
66 |
| - }); |
67 |
| - diffThread.CompareDirectories(); |
| 128 | + DIFFOPTIONS options = {0}; |
| 129 | + options.nIgnoreWhitespace = false; |
| 130 | + options.bIgnoreBlankLines = false; |
| 131 | + options.bFilterCommentsLines = false; |
| 132 | + options.bIgnoreCase = false; |
| 133 | + options.bIgnoreEol = false; |
| 134 | + |
| 135 | + ctx.InitDiffItemList(); |
| 136 | + ctx.CreateCompareOptions(dm, options); |
| 137 | + ctx.m_iGuessEncodingType = 0; |
| 138 | + ctx.m_bIgnoreSmallTimeDiff = true; |
| 139 | + ctx.m_bStopAfterFirstDiff = false; |
| 140 | + ctx.m_nQuickCompareLimit = 4 * 1024 * 1024; |
| 141 | + ctx.m_bPluginsEnabled = false; |
| 142 | + ctx.m_bWalkUniques = true; |
| 143 | + ctx.m_pCompareStats = &cmpstats; |
| 144 | + ctx.m_bRecursive = true; |
| 145 | + ctx.m_piFilterGlobal = &filter; |
68 | 146 |
|
69 |
| - while (diffThread.GetThreadState() != CDiffThread::THREAD_COMPLETED) |
70 |
| - { |
71 |
| - Poco::Thread::sleep(200); |
72 |
| - std::cout << cmpstats.GetComparedItems() << std::endl; |
73 |
| - } |
| 147 | + CDiffThread diffThread; |
| 148 | + diffThread.SetContext(&ctx); |
| 149 | + diffThread.SetCollectFunction([](DiffFuncStruct* myStruct) { |
| 150 | + bool casesensitive = false; |
| 151 | + int depth = myStruct->context->m_bRecursive ? -1 : 0; |
| 152 | + PathContext paths = myStruct->context->GetNormalizedPaths(); |
| 153 | + String subdir[3] = { _T(""), _T(""), _T("") }; |
| 154 | + DirScan_GetItems(paths, subdir, myStruct, |
| 155 | + casesensitive, depth, nullptr, myStruct->context->m_bWalkUniques); |
| 156 | + }); |
| 157 | + diffThread.SetCompareFunction([](DiffFuncStruct* myStruct) { |
| 158 | + DirScan_CompareItems(myStruct, nullptr); |
| 159 | + }); |
| 160 | + diffThread.CompareDirectories(); |
74 | 161 |
|
75 |
| - DIFFITEM *pos = ctx.GetFirstDiffPosition(); |
76 |
| - while (pos) |
77 |
| - { |
78 |
| - DIFFITEM& di = ctx.GetNextDiffRefPosition(pos); |
79 |
| - if (ctx.m_piFilterGlobal->includeFile(di.diffFileInfo[0].filename, di.diffFileInfo[1].filename)) |
| 162 | + while (diffThread.GetThreadState() != CDiffThread::THREAD_COMPLETED) |
| 163 | + { |
| 164 | + Poco::Thread::sleep(200); |
| 165 | + std::wcout << L"Comparing " << cmpstats.GetComparedItems() << L" items...\r"; |
| 166 | + } |
| 167 | + std::wcout << L"\nComparison completed.\n"; |
| 168 | + |
| 169 | + DIFFITEM* pos = ctx.GetFirstDiffPosition(); |
| 170 | + while (pos) |
| 171 | + { |
| 172 | + DIFFITEM& di = ctx.GetNextDiffRefPosition(pos); |
| 173 | + if ((paths.GetSize() == 2 && ctx.m_piFilterGlobal->includeFile( |
| 174 | + paths::ConcatPath(di.diffFileInfo[0].path, di.diffFileInfo[0].filename), |
| 175 | + paths::ConcatPath(di.diffFileInfo[1].path, di.diffFileInfo[1].filename)) |
| 176 | + || |
| 177 | + (paths.GetSize() == 3 && ctx.m_piFilterGlobal->includeFile( |
| 178 | + paths::ConcatPath(di.diffFileInfo[0].path, di.diffFileInfo[0].filename), |
| 179 | + paths::ConcatPath(di.diffFileInfo[1].path, di.diffFileInfo[1].filename), |
| 180 | + paths::ConcatPath(di.diffFileInfo[1].path, di.diffFileInfo[2].filename))))) |
| 181 | + { |
| 182 | + FolderCmp folderCmp(&ctx); |
| 183 | + folderCmp.prepAndCompareFiles(di); |
| 184 | + if (di.diffcode.isResultDiff()) |
| 185 | + std::wcout << di.diffFileInfo[0].filename << L": " << L"Different" << std::endl; |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + else |
80 | 190 | {
|
81 |
| - FolderCmp folderCmp(&ctx); |
82 |
| - folderCmp.prepAndCompareFiles(di); |
83 |
| -#ifdef _UNICODE |
84 |
| -// std::wcout << di.diffFileInfo[0].filename << ":" << di.diffcode.isResultDiff() << std::endl; |
85 |
| -#else |
86 |
| -// std::cout << di.diffFileInfo[0].filename << ":" << di.diffcode.isResultDiff() << std::endl; |
87 |
| -#endif |
| 191 | + std::wcout << L"Unknown command: " << cmd << std::endl; |
88 | 192 | }
|
89 |
| - |
90 | 193 | }
|
91 | 194 |
|
92 | 195 | return 0;
|
|
0 commit comments