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 bool OpenHKLM(HKEY *key, LPCTSTR relpath = nullptr);
25 static bool OpenHKCU(HKEY *key, LPCTSTR relpath = nullptr);
26 static void CopyFromLMtoCU(HKEY lmKey, HKEY cuKey, LPCTSTR valname);
32 * @brief Initialise options and set default values.
34 * @note Remember default values are what users see first time
35 * using WinMerge and many users never change them. So pick
36 * default values carefully!
38 void Init(COptionsMgr *pOptions)
40 static_cast<CRegOptionsMgr *>(pOptions)->SetRegRootKey(_T("Thingamahoochie\\WinMerge\\"));
42 LANGID LangId = GetUserDefaultLangID();
43 pOptions->InitOption(OPT_SELECTED_LANGUAGE, static_cast<int>(LangId));
45 // Initialise options (name, default value)
46 pOptions->InitOption(OPT_SHOW_UNIQUE_LEFT, true);
47 pOptions->InitOption(OPT_SHOW_UNIQUE_MIDDLE, true);
48 pOptions->InitOption(OPT_SHOW_UNIQUE_RIGHT, true);
49 pOptions->InitOption(OPT_SHOW_DIFFERENT, true);
50 pOptions->InitOption(OPT_SHOW_IDENTICAL, true);
51 pOptions->InitOption(OPT_SHOW_BINARIES, true);
52 pOptions->InitOption(OPT_SHOW_SKIPPED, false);
53 pOptions->InitOption(OPT_SHOW_DIFFERENT_LEFT_ONLY, true);
54 pOptions->InitOption(OPT_SHOW_DIFFERENT_MIDDLE_ONLY, true);
55 pOptions->InitOption(OPT_SHOW_DIFFERENT_RIGHT_ONLY, true);
56 pOptions->InitOption(OPT_SHOW_MISSING_LEFT_ONLY, true);
57 pOptions->InitOption(OPT_SHOW_MISSING_MIDDLE_ONLY, true);
58 pOptions->InitOption(OPT_SHOW_MISSING_RIGHT_ONLY, true);
60 pOptions->InitOption(OPT_SHOW_TOOLBAR, true);
61 pOptions->InitOption(OPT_SHOW_STATUSBAR, true);
62 pOptions->InitOption(OPT_SHOW_TABBAR, true);
63 pOptions->InitOption(OPT_TOOLBAR_SIZE, 0);
64 pOptions->InitOption(OPT_RESIZE_PANES, false);
66 pOptions->InitOption(OPT_SYNTAX_HIGHLIGHT, true);
67 pOptions->InitOption(OPT_WORDWRAP, false);
68 pOptions->InitOption(OPT_VIEW_LINENUMBERS, false);
69 pOptions->InitOption(OPT_VIEW_WHITESPACE, false);
70 pOptions->InitOption(OPT_VIEW_EOL, false);
71 pOptions->InitOption(OPT_SCROLL_TO_FIRST, false);
72 pOptions->InitOption(OPT_SCROLL_TO_FIRST_INLINE_DIFF, false);
73 pOptions->InitOption(OPT_VERIFY_OPEN_PATHS, true);
74 pOptions->InitOption(OPT_AUTO_COMPLETE_SOURCE, (int)1);
75 pOptions->InitOption(OPT_VIEW_FILEMARGIN, false);
76 pOptions->InitOption(OPT_DIFF_CONTEXT, (int)-1);
77 pOptions->InitOption(OPT_INVERT_DIFF_CONTEXT, false);
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);
97 pOptions->InitOption(OPT_DIRVIEW_COLUMN_ORDERS, _T(""));
98 pOptions->InitOption(OPT_DIRVIEW_COLUMN_WIDTHS, _T(""));
99 pOptions->InitOption(OPT_DIRVIEW3_COLUMN_ORDERS, _T(""));
100 pOptions->InitOption(OPT_DIRVIEW3_COLUMN_WIDTHS, _T(""));
102 pOptions->InitOption(OPT_REPORTFILES_REPORTTYPE, 0);
103 pOptions->InitOption(OPT_REPORTFILES_COPYTOCLIPBOARD, false);
104 pOptions->InitOption(OPT_REPORTFILES_INCLUDEFILECMPREPORT, false);
106 pOptions->InitOption(OPT_AUTOMATIC_RESCAN, false);
107 pOptions->InitOption(OPT_ALLOW_MIXED_EOL, false);
108 pOptions->InitOption(OPT_COPY_FULL_LINE, false);
109 pOptions->InitOption(OPT_TAB_SIZE, (int)4);
110 pOptions->InitOption(OPT_TAB_TYPE, (int)0); // 0 means tabs inserted
112 pOptions->InitOption(OPT_EXT_EDITOR_CMD, paths::ConcatPath(env::GetWindowsDirectory(), _T("NOTEPAD.EXE")));
113 pOptions->InitOption(OPT_USE_RECYCLE_BIN, true);
114 pOptions->InitOption(OPT_SINGLE_INSTANCE, false);
115 pOptions->InitOption(OPT_MERGE_MODE, false);
116 // OPT_WORDDIFF_HIGHLIGHT is initialized above
117 pOptions->InitOption(OPT_BREAK_ON_WORDS, false);
118 pOptions->InitOption(OPT_BREAK_TYPE, 1);
120 pOptions->InitOption(OPT_CLOSE_WITH_ESC, 1);
121 pOptions->InitOption(OPT_CLOSE_WITH_OK, false);
122 pOptions->InitOption(OPT_IGNORE_SMALL_FILETIME, false);
123 pOptions->InitOption(OPT_ASK_MULTIWINDOW_CLOSE, false);
124 pOptions->InitOption(OPT_PRESERVE_FILETIMES, false);
125 pOptions->InitOption(OPT_TREE_MODE, true);
127 pOptions->InitOption(OPT_CMP_METHOD, (int)CMP_CONTENT);
128 pOptions->InitOption(OPT_CMP_MOVED_BLOCKS, false);
129 pOptions->InitOption(OPT_CMP_MATCH_SIMILAR_LINES, false);
130 pOptions->InitOption(OPT_CMP_STOP_AFTER_FIRST, false);
131 pOptions->InitOption(OPT_CMP_QUICK_LIMIT, 4 * 1024 * 1024); // 4 Megs
132 pOptions->InitOption(OPT_CMP_BINARY_LIMIT, 64 * 1024 * 1024); // 64 Megs
133 pOptions->InitOption(OPT_CMP_COMPARE_THREADS, -1);
134 pOptions->InitOption(OPT_CMP_WALK_UNIQUE_DIRS, true);
135 pOptions->InitOption(OPT_CMP_IGNORE_REPARSE_POINTS, false);
136 pOptions->InitOption(OPT_CMP_IGNORE_CODEPAGE, false);
137 pOptions->InitOption(OPT_CMP_INCLUDE_SUBDIRS, true);
138 pOptions->InitOption(OPT_CMP_ENABLE_IMGCMP_IN_DIRCMP, false);
140 pOptions->InitOption(OPT_CMP_BIN_FILEPATTERNS, _T("*.bin;*.frx"));
142 pOptions->InitOption(OPT_CMP_CSV_FILEPATTERNS, _T("*.csv"));
143 pOptions->InitOption(OPT_CMP_TSV_FILEPATTERNS, _T("*.tsv"));
144 pOptions->InitOption(OPT_CMP_DSV_FILEPATTERNS, _T(""));
145 pOptions->InitOption(OPT_CMP_DSV_DELIM_CHAR, _T(";"));
146 pOptions->InitOption(OPT_CMP_TBL_ALLOW_NEWLINES_IN_QUOTES, true);
147 pOptions->InitOption(OPT_CMP_TBL_QUOTE_CHAR, _T("\""));
149 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"));
150 pOptions->InitOption(OPT_CMP_IMG_SHOWDIFFERENCES, true);
151 pOptions->InitOption(OPT_CMP_IMG_OVERLAYMOVE, 0);
152 pOptions->InitOption(OPT_CMP_IMG_OVERLAYALPHA, 30);
153 pOptions->InitOption(OPT_CMP_IMG_DRAGGING_MODE, 1);
154 pOptions->InitOption(OPT_CMP_IMG_ZOOM, 1000);
155 pOptions->InitOption(OPT_CMP_IMG_USEBACKCOLOR, true);
156 pOptions->InitOption(OPT_CMP_IMG_BACKCOLOR, 0xFFFFFF);
157 pOptions->InitOption(OPT_CMP_IMG_DIFFBLOCKSIZE, 8);
158 pOptions->InitOption(OPT_CMP_IMG_DIFFCOLORALPHA, 70);
159 pOptions->InitOption(OPT_CMP_IMG_THRESHOLD, 0);
160 pOptions->InitOption(OPT_CMP_IMG_INSERTIONDELETIONDETECTION_MODE, 0);
161 pOptions->InitOption(OPT_CMP_IMG_VECTOR_IMAGE_ZOOM_RATIO, 1000);
162 pOptions->InitOption(OPT_CMP_IMG_OCR_RESULT_TYPE, 0);
164 pOptions->InitOption(OPT_PROJECTS_PATH, _T(""));
165 pOptions->InitOption(OPT_USE_SYSTEM_TEMP_PATH, true);
166 pOptions->InitOption(OPT_CUSTOM_TEMP_PATH, _T(""));
168 pOptions->InitOption(OPT_LINEFILTER_ENABLED, false);
169 pOptions->InitOption(OPT_IGNORED_SUBSTITUTIONS_ENABLED, false);
171 pOptions->InitOption(OPT_FILEFILTER_CURRENT, _T("*.*"));
172 // CMainFrame initializes this when it is empty.
173 pOptions->InitOption(OPT_FILTER_USERPATH, _T(""));
174 if (pOptions->GetString(OPT_FILTER_USERPATH).empty())
175 pOptions->SaveOption(OPT_FILTER_USERPATH, paths::ConcatPath(env::GetMyDocuments(), DefaultRelativeFilterPath));
176 pOptions->InitOption(OPT_FILEFILTER_SHARED, false);
178 pOptions->InitOption(OPT_CP_DEFAULT_MODE, (int)0);
179 pOptions->InitOption(OPT_CP_DEFAULT_CUSTOM, (int)GetACP());
181 if (PRIMARYLANGID(LangId) == LANG_JAPANESE)
182 pOptions->InitOption(OPT_CP_DETECT, (int)(50932 << 16) | 3);
183 else if (LangId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED))
184 pOptions->InitOption(OPT_CP_DETECT, (int)(50936 << 16) | 3);
185 else if (PRIMARYLANGID(LangId) == LANG_KOREAN)
186 pOptions->InitOption(OPT_CP_DETECT, (int)(50949 << 16) | 3);
187 else if (LangId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL))
188 pOptions->InitOption(OPT_CP_DETECT, (int)(50950 << 16) | 3);
190 pOptions->InitOption(OPT_CP_DETECT, (int)(50001 << 16) | 1);
192 pOptions->InitOption(OPT_ARCHIVE_ENABLE, 1); // Enable by default
193 pOptions->InitOption(OPT_ARCHIVE_PROBETYPE, false);
194 pOptions->InitOption(OPT_ARCHIVE_FILTER_INDEX, 1);
196 pOptions->InitOption(OPT_PLUGINS_ENABLED, true);
197 pOptions->InitOption(OPT_PLUGINS_DISABLED_LIST, _T(""));
198 pOptions->InitOption(OPT_PLUGINS_CUSTOM_FILTERS_LIST, _T(""));
199 pOptions->InitOption(OPT_PLUGINS_UNPACKER_MODE, static_cast<int>(PLUGIN_MODE::PLUGIN_MANUAL));
200 pOptions->InitOption(OPT_PLUGINS_PREDIFFER_MODE, static_cast<int>(PLUGIN_MODE::PLUGIN_MANUAL));
201 pOptions->InitOption(OPT_PLUGINS_UNPACK_DONT_CHECK_EXTENSION, false);
203 pOptions->InitOption(OPT_PATCHCREATOR_PATCH_STYLE, 0);
204 pOptions->InitOption(OPT_PATCHCREATOR_CONTEXT_LINES, 0);
205 pOptions->InitOption(OPT_PATCHCREATOR_CASE_SENSITIVE, true);
206 pOptions->InitOption(OPT_PATCHCREATOR_EOL_SENSITIVE, true);
207 pOptions->InitOption(OPT_PATCHCREATOR_IGNORE_BLANK_LINES, false);
208 pOptions->InitOption(OPT_PATCHCREATOR_WHITESPACE, WHITESPACE_COMPARE_ALL);
209 pOptions->InitOption(OPT_PATCHCREATOR_OPEN_TO_EDITOR, false);
210 pOptions->InitOption(OPT_PATCHCREATOR_INCLUDE_CMD_LINE, false);
212 pOptions->InitOption(OPT_TABBAR_AUTO_MAXWIDTH, true);
213 pOptions->InitOption(OPT_ACTIVE_FRAME_MAX, true);
214 pOptions->InitOption(OPT_ACTIVE_PANE, 0);
216 pOptions->InitOption(OPT_MRU_MAX, 9);
218 pOptions->InitOption(OPT_COLOR_SCHEME, _T("Default"));
220 Options::CustomColors::SetDefaults(pOptions);
221 Options::DiffOptions::SetDefaults(pOptions);
222 Options::DiffColors::SetDefaults(pOptions);
223 Options::DirColors::SetDefaults(pOptions);
224 Options::Font::SetDefaults(pOptions);
228 * @brief Copy some HKLM values to HKCU.
229 * The installer sets HKLM values for "all users". This function copies
230 * few of those values for "user" values. E.g. enabling ShellExtension
231 * initially for user is done by this function.
233 void CopyHKLMValues()
237 if (OpenHKLM(&LMKey))
239 if (OpenHKCU(&CUKey))
241 CopyFromLMtoCU(LMKey, CUKey, _T("ContextMenuEnabled"));
242 CopyFromLMtoCU(LMKey, CUKey, _T("Executable"));
247 if (OpenHKLM(&LMKey, _T("Locale")))
249 if (OpenHKCU(&CUKey, _T("Locale")))
251 CopyFromLMtoCU(LMKey, CUKey, _T("LanguageId"));
261 * @brief Open HKLM registry key.
262 * @param [out] key Pointer to open HKLM key.
263 * @param [in] relpath Relative registry path (to WinMerge reg path) to open, or nullptr.
264 * @return true if opening succeeded.
266 static bool OpenHKLM(HKEY *key, LPCTSTR relpath)
268 TCHAR valuename[256];
270 wsprintf(valuename, _T("%s\\%s"), RegDir, relpath);
272 lstrcpy(valuename, RegDir);
273 LONG retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
274 valuename, 0, KEY_READ, key);
275 if (retval == ERROR_SUCCESS)
283 * @brief Open HKCU registry key.
284 * Opens the HKCU key for WinMerge. If the key does not exist, creates one.
285 * @param [out] key Pointer to open HKCU key.
286 * @param [in] relpath Relative registry path (to WinMerge reg path) to open, or nullptr.
287 * @return true if opening succeeded.
289 static bool OpenHKCU(HKEY *key, LPCTSTR relpath)
291 TCHAR valuename[256];
293 wsprintf(valuename, _T("%s\\%s"), RegDir, relpath);
295 lstrcpy(valuename, RegDir);
296 LONG retval = RegOpenKeyEx(HKEY_CURRENT_USER,
297 valuename, 0, KEY_ALL_ACCESS, key);
298 if (retval == ERROR_SUCCESS)
302 else if (retval == ERROR_FILE_NOT_FOUND)
304 retval = RegCreateKeyEx(HKEY_CURRENT_USER,
305 valuename, 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, key, nullptr);
306 if (retval == ERROR_SUCCESS)
313 * @brief Copy value from HKLM to HKCU.
314 * @param [in] lmKey HKLM key from where to copy.
315 * @param [in] cuKey HKCU key to where to copy.
316 * @param [in] valname Name of the value to copy.
318 static void CopyFromLMtoCU(HKEY lmKey, HKEY cuKey, LPCTSTR valname)
321 LONG retval = RegQueryValueEx(cuKey, valname, 0, nullptr, nullptr, &len);
322 if (retval == ERROR_FILE_NOT_FOUND)
324 retval = RegQueryValueEx(lmKey, valname, 0, nullptr, nullptr, &len);
325 if (retval == ERROR_SUCCESS)
328 std::vector<BYTE> buf(len);
329 retval = RegQueryValueEx(lmKey, valname, 0, &type, &buf[0], &len);
330 if (retval == ERROR_SUCCESS)
332 RegSetValueEx(cuKey, valname , 0, type,