2 * @file OptionsInit.cpp
4 * @brief Options initialisation.
9 #include "OptionsDef.h"
10 #include "OptionsMgr.h"
11 #include "RegOptionsMgr.h"
12 #include "OptionsCustomColors.h"
13 #include "OptionsDiffOptions.h"
14 #include "OptionsDiffColors.h"
15 #include "OptionsDirColors.h"
16 #include "OptionsFont.h"
17 #include "DiffWrapper.h" // CMP_CONTENT
19 #include "Environment.h"
20 #include "FileTransform.h"
21 #include "Constants.h"
23 // Functions to copy values set by installer from HKLM to HKCU.
24 static void CopyHKLMValues();
25 static bool OpenHKLM(HKEY *key, LPCTSTR relpath = nullptr);
26 static bool OpenHKCU(HKEY *key, LPCTSTR relpath = nullptr);
27 static void CopyFromLMtoCU(HKEY lmKey, HKEY cuKey, LPCTSTR valname);
33 * @brief Initialise options and set default values.
35 * @note Remember default values are what users see first time
36 * using WinMerge and many users never change them. So pick
37 * default values carefully!
39 void Init(COptionsMgr *pOptions)
41 static_cast<CRegOptionsMgr *>(pOptions)->SetRegRootKey(_T("Thingamahoochie\\WinMerge\\"));
43 LANGID LangId = GetUserDefaultLangID();
44 pOptions->InitOption(OPT_SELECTED_LANGUAGE, static_cast<int>(LangId));
46 // Initialise options (name, default value)
47 pOptions->InitOption(OPT_SHOW_UNIQUE_LEFT, true);
48 pOptions->InitOption(OPT_SHOW_UNIQUE_MIDDLE, true);
49 pOptions->InitOption(OPT_SHOW_UNIQUE_RIGHT, true);
50 pOptions->InitOption(OPT_SHOW_DIFFERENT, true);
51 pOptions->InitOption(OPT_SHOW_IDENTICAL, true);
52 pOptions->InitOption(OPT_SHOW_BINARIES, true);
53 pOptions->InitOption(OPT_SHOW_SKIPPED, false);
54 pOptions->InitOption(OPT_SHOW_DIFFERENT_LEFT_ONLY, true);
55 pOptions->InitOption(OPT_SHOW_DIFFERENT_MIDDLE_ONLY, true);
56 pOptions->InitOption(OPT_SHOW_DIFFERENT_RIGHT_ONLY, true);
57 pOptions->InitOption(OPT_SHOW_MISSING_LEFT_ONLY, true);
58 pOptions->InitOption(OPT_SHOW_MISSING_MIDDLE_ONLY, true);
59 pOptions->InitOption(OPT_SHOW_MISSING_RIGHT_ONLY, true);
61 pOptions->InitOption(OPT_SHOW_TOOLBAR, true);
62 pOptions->InitOption(OPT_SHOW_STATUSBAR, true);
63 pOptions->InitOption(OPT_SHOW_TABBAR, true);
64 const int cxsmicon = GetSystemMetrics(SM_CXSMICON);
65 pOptions->InitOption(OPT_TOOLBAR_SIZE, (cxsmicon < 28) ? 0 : (cxsmicon < 40 ? 1 : 2));
66 pOptions->InitOption(OPT_RESIZE_PANES, false);
68 pOptions->InitOption(OPT_SYNTAX_HIGHLIGHT, true);
69 pOptions->InitOption(OPT_WORDWRAP, false);
70 pOptions->InitOption(OPT_VIEW_LINENUMBERS, false);
71 pOptions->InitOption(OPT_VIEW_WHITESPACE, false);
72 pOptions->InitOption(OPT_CONNECT_MOVED_BLOCKS, 0);
73 pOptions->InitOption(OPT_SCROLL_TO_FIRST, false);
74 pOptions->InitOption(OPT_VERIFY_OPEN_PATHS, true);
75 pOptions->InitOption(OPT_AUTO_COMPLETE_SOURCE, (int)1);
76 pOptions->InitOption(OPT_VIEW_FILEMARGIN, false);
77 pOptions->InitOption(OPT_DIFF_CONTEXT, (int)-1);
78 pOptions->InitOption(OPT_SPLIT_HORIZONTALLY, false);
79 pOptions->InitOption(OPT_RENDERING_MODE, -1);
80 pOptions->InitOption(OPT_FILE_SIZE_THRESHOLD, 64*1024*1024);
82 pOptions->InitOption(OPT_WORDDIFF_HIGHLIGHT, true);
83 pOptions->InitOption(OPT_BREAK_SEPARATORS, _T(".,:;?[](){}<=>`'!\"#$%&^~\\|@+-*/"));
85 pOptions->InitOption(OPT_BACKUP_FOLDERCMP, false);
86 pOptions->InitOption(OPT_BACKUP_FILECMP, true);
87 pOptions->InitOption(OPT_BACKUP_LOCATION, (int)0);
88 pOptions->InitOption(OPT_BACKUP_GLOBALFOLDER, _T(""));
89 pOptions->InitOption(OPT_BACKUP_ADD_BAK, true);
90 pOptions->InitOption(OPT_BACKUP_ADD_TIME, false);
92 pOptions->InitOption(OPT_DIRVIEW_SORT_COLUMN, (int)-1);
93 pOptions->InitOption(OPT_DIRVIEW_SORT_COLUMN3, (int)-1);
94 pOptions->InitOption(OPT_DIRVIEW_SORT_ASCENDING, true);
95 pOptions->InitOption(OPT_SHOW_SELECT_FILES_AT_STARTUP, false);
96 pOptions->InitOption(OPT_DIRVIEW_EXPAND_SUBDIRS, false);
98 pOptions->InitOption(OPT_REPORTFILES_REPORTTYPE, 0);
99 pOptions->InitOption(OPT_REPORTFILES_COPYTOCLIPBOARD, false);
100 pOptions->InitOption(OPT_REPORTFILES_INCLUDEFILECMPREPORT, false);
102 pOptions->InitOption(OPT_AUTOMATIC_RESCAN, false);
103 pOptions->InitOption(OPT_ALLOW_MIXED_EOL, false);
104 pOptions->InitOption(OPT_TAB_SIZE, (int)4);
105 pOptions->InitOption(OPT_TAB_TYPE, (int)0); // 0 means tabs inserted
107 pOptions->InitOption(OPT_EXT_EDITOR_CMD, paths::ConcatPath(env::GetWindowsDirectory(), _T("NOTEPAD.EXE")));
108 pOptions->InitOption(OPT_USE_RECYCLE_BIN, true);
109 pOptions->InitOption(OPT_SINGLE_INSTANCE, false);
110 pOptions->InitOption(OPT_MERGE_MODE, false);
111 // OPT_WORDDIFF_HIGHLIGHT is initialized above
112 pOptions->InitOption(OPT_BREAK_ON_WORDS, false);
113 pOptions->InitOption(OPT_BREAK_TYPE, 1);
115 pOptions->InitOption(OPT_CLOSE_WITH_ESC, 1);
116 pOptions->InitOption(OPT_CLOSE_WITH_OK, false);
117 pOptions->InitOption(OPT_IGNORE_SMALL_FILETIME, false);
118 pOptions->InitOption(OPT_ASK_MULTIWINDOW_CLOSE, false);
119 pOptions->InitOption(OPT_PRESERVE_FILETIMES, false);
120 pOptions->InitOption(OPT_TREE_MODE, true);
122 pOptions->InitOption(OPT_CMP_METHOD, (int)CMP_CONTENT);
123 pOptions->InitOption(OPT_CMP_MOVED_BLOCKS, false);
124 pOptions->InitOption(OPT_CMP_MATCH_SIMILAR_LINES, false);
125 pOptions->InitOption(OPT_CMP_STOP_AFTER_FIRST, false);
126 pOptions->InitOption(OPT_CMP_QUICK_LIMIT, 4 * 1024 * 1024); // 4 Megs
127 pOptions->InitOption(OPT_CMP_BINARY_LIMIT, 64 * 1024 * 1024); // 64 Megs
128 pOptions->InitOption(OPT_CMP_COMPARE_THREADS, -1);
129 pOptions->InitOption(OPT_CMP_WALK_UNIQUE_DIRS, true);
130 pOptions->InitOption(OPT_CMP_IGNORE_REPARSE_POINTS, false);
131 pOptions->InitOption(OPT_CMP_IGNORE_CODEPAGE, false);
132 pOptions->InitOption(OPT_CMP_INCLUDE_SUBDIRS, true);
133 pOptions->InitOption(OPT_CMP_ENABLE_IMGCMP_IN_DIRCMP, false);
135 pOptions->InitOption(OPT_CMP_BIN_FILEPATTERNS, _T("*.bin;*.frx"));
137 pOptions->InitOption(OPT_CMP_CSV_FILEPATTERNS, _T("*.csv"));
138 pOptions->InitOption(OPT_CMP_TSV_FILEPATTERNS, _T("*.tsv"));
139 pOptions->InitOption(OPT_CMP_DSV_FILEPATTERNS, _T(""));
140 pOptions->InitOption(OPT_CMP_DSV_DELIM_CHAR, _T(";"));
141 pOptions->InitOption(OPT_CMP_TBL_ALLOW_NEWLINES_IN_QUOTES, true);
142 pOptions->InitOption(OPT_CMP_TBL_QUOTE_CHAR, _T("\""));
144 pOptions->InitOption(OPT_CMP_IMG_FILEPATTERNS, _T("*.bmp;*.cut;*.dds;*.exr;*.g3;*.gif;*.hdr;*.ico;*.iff;*.lbm;*.j2k;*.j2c;*.jng;*.jp2;*.jpg;*.jif;*.jpeg;*.jpe;*.jxr;*.wdp;*.hdp;*.koa;*.mng;*.pcd;*.pcx;*.pfm;*.pct;*.pict;*.pic;*.png;*.pbm;*.pgm;*.ppm;*.psd;*.ras;*.sgi;*.rgb;*.rgba;*.bw;*.tga;*.targa;*.tif;*.tiff;*.wap;*.wbmp;*.wbm;*.webp;*.xbm;*.xpm"));
145 pOptions->InitOption(OPT_CMP_IMG_SHOWDIFFERENCES, true);
146 pOptions->InitOption(OPT_CMP_IMG_OVERLAYMOVE, 0);
147 pOptions->InitOption(OPT_CMP_IMG_OVERLAYALPHA, 30);
148 pOptions->InitOption(OPT_CMP_IMG_DRAGGING_MODE, 1);
149 pOptions->InitOption(OPT_CMP_IMG_ZOOM, 1000);
150 pOptions->InitOption(OPT_CMP_IMG_USEBACKCOLOR, true);
151 pOptions->InitOption(OPT_CMP_IMG_BACKCOLOR, 0xFFFFFF);
152 pOptions->InitOption(OPT_CMP_IMG_DIFFBLOCKSIZE, 8);
153 pOptions->InitOption(OPT_CMP_IMG_DIFFCOLORALPHA, 70);
154 pOptions->InitOption(OPT_CMP_IMG_THRESHOLD, 0);
155 pOptions->InitOption(OPT_CMP_IMG_INSERTIONDELETIONDETECTION_MODE, 0);
156 pOptions->InitOption(OPT_CMP_IMG_VECTOR_IMAGE_ZOOM_RATIO, 1000);
158 pOptions->InitOption(OPT_PROJECTS_PATH, _T(""));
159 pOptions->InitOption(OPT_USE_SYSTEM_TEMP_PATH, true);
160 pOptions->InitOption(OPT_CUSTOM_TEMP_PATH, _T(""));
162 pOptions->InitOption(OPT_LINEFILTER_ENABLED, false);
163 pOptions->InitOption(OPT_FILEFILTER_CURRENT, _T("*.*"));
164 // CMainFrame initializes this when it is empty.
165 pOptions->InitOption(OPT_FILTER_USERPATH, paths::ConcatPath(env::GetMyDocuments(), DefaultRelativeFilterPath));
166 pOptions->InitOption(OPT_FILEFILTER_SHARED, false);
168 pOptions->InitOption(OPT_CP_DEFAULT_MODE, (int)0);
169 pOptions->InitOption(OPT_CP_DEFAULT_CUSTOM, (int)GetACP());
171 if (PRIMARYLANGID(LangId) == LANG_JAPANESE)
172 pOptions->InitOption(OPT_CP_DETECT, (int)(50932 << 16) | 3);
173 else if (LangId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED))
174 pOptions->InitOption(OPT_CP_DETECT, (int)(50936 << 16) | 3);
175 else if (PRIMARYLANGID(LangId) == LANG_KOREAN)
176 pOptions->InitOption(OPT_CP_DETECT, (int)(50949 << 16) | 3);
177 else if (LangId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL))
178 pOptions->InitOption(OPT_CP_DETECT, (int)(50950 << 16) | 3);
180 pOptions->InitOption(OPT_CP_DETECT, (int)(50001 << 16) | 1);
182 pOptions->InitOption(OPT_ARCHIVE_ENABLE, 1); // Enable by default
183 pOptions->InitOption(OPT_ARCHIVE_PROBETYPE, false);
184 pOptions->InitOption(OPT_ARCHIVE_FILTER_INDEX, 1);
186 pOptions->InitOption(OPT_PLUGINS_ENABLED, true);
187 pOptions->InitOption(OPT_PLUGINS_DISABLED_LIST, _T(""));
188 pOptions->InitOption(OPT_PLUGINS_CUSTOM_FILTERS_LIST, _T(""));
189 pOptions->InitOption(OPT_PLUGINS_UNPACKER_MODE, PLUGIN_MANUAL);
190 pOptions->InitOption(OPT_PLUGINS_PREDIFFER_MODE, PLUGIN_MANUAL);
191 pOptions->InitOption(OPT_PLUGINS_UNPACK_DONT_CHECK_EXTENSION, false);
193 pOptions->InitOption(OPT_PATCHCREATOR_PATCH_STYLE, 0);
194 pOptions->InitOption(OPT_PATCHCREATOR_CONTEXT_LINES, 0);
195 pOptions->InitOption(OPT_PATCHCREATOR_CASE_SENSITIVE, true);
196 pOptions->InitOption(OPT_PATCHCREATOR_EOL_SENSITIVE, true);
197 pOptions->InitOption(OPT_PATCHCREATOR_IGNORE_BLANK_LINES, false);
198 pOptions->InitOption(OPT_PATCHCREATOR_WHITESPACE, WHITESPACE_COMPARE_ALL);
199 pOptions->InitOption(OPT_PATCHCREATOR_OPEN_TO_EDITOR, false);
200 pOptions->InitOption(OPT_PATCHCREATOR_INCLUDE_CMD_LINE, false);
202 pOptions->InitOption(OPT_TABBAR_AUTO_MAXWIDTH, true);
203 pOptions->InitOption(OPT_ACTIVE_FRAME_MAX, true);
204 pOptions->InitOption(OPT_ACTIVE_PANE, 0);
206 pOptions->InitOption(OPT_MRU_MAX, 9);
208 pOptions->InitOption(OPT_COLOR_SCHEME, _T("Default"));
210 Options::CustomColors::SetDefaults(pOptions);
211 Options::DiffOptions::SetDefaults(pOptions);
212 Options::DiffColors::SetDefaults(pOptions);
213 Options::DirColors::SetDefaults(pOptions);
214 Options::Font::SetDefaults(pOptions);
218 * @brief Copy some HKLM values to HKCU.
219 * The installer sets HKLM values for "all users". This function copies
220 * few of those values for "user" values. E.g. enabling ShellExtension
221 * initially for user is done by this function.
223 void CopyHKLMValues()
227 if (OpenHKLM(&LMKey))
229 if (OpenHKCU(&CUKey))
231 CopyFromLMtoCU(LMKey, CUKey, _T("ContextMenuEnabled"));
232 CopyFromLMtoCU(LMKey, CUKey, _T("Executable"));
237 if (OpenHKLM(&LMKey, _T("Locale")))
239 if (OpenHKCU(&CUKey, _T("Locale")))
241 CopyFromLMtoCU(LMKey, CUKey, _T("LanguageId"));
251 * @brief Open HKLM registry key.
252 * @param [out] key Pointer to open HKLM key.
253 * @param [in] relpath Relative registry path (to WinMerge reg path) to open, or nullptr.
254 * @return true if opening succeeded.
256 static bool OpenHKLM(HKEY *key, LPCTSTR relpath)
258 TCHAR valuename[256];
260 wsprintf(valuename, _T("%s\\%s"), RegDir, relpath);
262 lstrcpy(valuename, RegDir);
263 LONG retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
264 valuename, 0, KEY_READ, key);
265 if (retval == ERROR_SUCCESS)
273 * @brief Open HKCU registry key.
274 * Opens the HKCU key for WinMerge. If the key does not exist, creates one.
275 * @param [out] key Pointer to open HKCU key.
276 * @param [in] relpath Relative registry path (to WinMerge reg path) to open, or nullptr.
277 * @return true if opening succeeded.
279 static bool OpenHKCU(HKEY *key, LPCTSTR relpath)
281 TCHAR valuename[256];
283 wsprintf(valuename, _T("%s\\%s"), RegDir, relpath);
285 lstrcpy(valuename, RegDir);
286 LONG retval = RegOpenKeyEx(HKEY_CURRENT_USER,
287 valuename, 0, KEY_ALL_ACCESS, key);
288 if (retval == ERROR_SUCCESS)
292 else if (retval == ERROR_FILE_NOT_FOUND)
294 retval = RegCreateKeyEx(HKEY_CURRENT_USER,
295 valuename, 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, key, nullptr);
296 if (retval == ERROR_SUCCESS)
303 * @brief Copy value from HKLM to HKCU.
304 * @param [in] lmKey HKLM key from where to copy.
305 * @param [in] cuKey HKCU key to where to copy.
306 * @param [in] valname Name of the value to copy.
308 static void CopyFromLMtoCU(HKEY lmKey, HKEY cuKey, LPCTSTR valname)
311 LONG retval = RegQueryValueEx(cuKey, valname, 0, nullptr, nullptr, &len);
312 if (retval == ERROR_FILE_NOT_FOUND)
314 retval = RegQueryValueEx(lmKey, valname, 0, nullptr, nullptr, &len);
315 if (retval == ERROR_SUCCESS)
318 std::vector<BYTE> buf(len);
319 retval = RegQueryValueEx(lmKey, valname, 0, &type, &buf[0], &len);
320 if (retval == ERROR_SUCCESS)
322 RegSetValueEx(cuKey, valname , 0, type,