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 pOptions->InitOption(OPT_TOOLBAR_SIZE, 0);
65 pOptions->InitOption(OPT_RESIZE_PANES, false);
67 pOptions->InitOption(OPT_SYNTAX_HIGHLIGHT, true);
68 pOptions->InitOption(OPT_WORDWRAP, false);
69 pOptions->InitOption(OPT_VIEW_LINENUMBERS, false);
70 pOptions->InitOption(OPT_VIEW_WHITESPACE, false);
71 pOptions->InitOption(OPT_CONNECT_MOVED_BLOCKS, 0);
72 pOptions->InitOption(OPT_SCROLL_TO_FIRST, 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_SPLIT_HORIZONTALLY, false);
78 pOptions->InitOption(OPT_RENDERING_MODE, -1);
79 pOptions->InitOption(OPT_FILE_SIZE_THRESHOLD, 64*1024*1024);
81 pOptions->InitOption(OPT_WORDDIFF_HIGHLIGHT, true);
82 pOptions->InitOption(OPT_BREAK_SEPARATORS, _T(".,:;?[](){}<=>`'!\"#$%&^~\\|@+-*/"));
84 pOptions->InitOption(OPT_BACKUP_FOLDERCMP, false);
85 pOptions->InitOption(OPT_BACKUP_FILECMP, true);
86 pOptions->InitOption(OPT_BACKUP_LOCATION, (int)0);
87 pOptions->InitOption(OPT_BACKUP_GLOBALFOLDER, _T(""));
88 pOptions->InitOption(OPT_BACKUP_ADD_BAK, true);
89 pOptions->InitOption(OPT_BACKUP_ADD_TIME, false);
91 pOptions->InitOption(OPT_DIRVIEW_SORT_COLUMN, (int)-1);
92 pOptions->InitOption(OPT_DIRVIEW_SORT_COLUMN3, (int)-1);
93 pOptions->InitOption(OPT_DIRVIEW_SORT_ASCENDING, true);
94 pOptions->InitOption(OPT_SHOW_SELECT_FILES_AT_STARTUP, false);
95 pOptions->InitOption(OPT_DIRVIEW_EXPAND_SUBDIRS, false);
96 pOptions->InitOption(OPT_DIRVIEW_COLUMN_ORDERS, _T(""));
97 pOptions->InitOption(OPT_DIRVIEW_COLUMN_WIDTHS, _T(""));
98 pOptions->InitOption(OPT_DIRVIEW3_COLUMN_ORDERS, _T(""));
99 pOptions->InitOption(OPT_DIRVIEW3_COLUMN_WIDTHS, _T(""));
101 pOptions->InitOption(OPT_REPORTFILES_REPORTTYPE, 0);
102 pOptions->InitOption(OPT_REPORTFILES_COPYTOCLIPBOARD, false);
103 pOptions->InitOption(OPT_REPORTFILES_INCLUDEFILECMPREPORT, false);
105 pOptions->InitOption(OPT_AUTOMATIC_RESCAN, false);
106 pOptions->InitOption(OPT_ALLOW_MIXED_EOL, false);
107 pOptions->InitOption(OPT_TAB_SIZE, (int)4);
108 pOptions->InitOption(OPT_TAB_TYPE, (int)0); // 0 means tabs inserted
110 pOptions->InitOption(OPT_EXT_EDITOR_CMD, paths::ConcatPath(env::GetWindowsDirectory(), _T("NOTEPAD.EXE")));
111 pOptions->InitOption(OPT_USE_RECYCLE_BIN, true);
112 pOptions->InitOption(OPT_SINGLE_INSTANCE, false);
113 pOptions->InitOption(OPT_MERGE_MODE, false);
114 // OPT_WORDDIFF_HIGHLIGHT is initialized above
115 pOptions->InitOption(OPT_BREAK_ON_WORDS, false);
116 pOptions->InitOption(OPT_BREAK_TYPE, 1);
118 pOptions->InitOption(OPT_CLOSE_WITH_ESC, 1);
119 pOptions->InitOption(OPT_CLOSE_WITH_OK, false);
120 pOptions->InitOption(OPT_IGNORE_SMALL_FILETIME, false);
121 pOptions->InitOption(OPT_ASK_MULTIWINDOW_CLOSE, false);
122 pOptions->InitOption(OPT_PRESERVE_FILETIMES, false);
123 pOptions->InitOption(OPT_TREE_MODE, true);
125 pOptions->InitOption(OPT_CMP_METHOD, (int)CMP_CONTENT);
126 pOptions->InitOption(OPT_CMP_MOVED_BLOCKS, false);
127 pOptions->InitOption(OPT_CMP_MATCH_SIMILAR_LINES, false);
128 pOptions->InitOption(OPT_CMP_STOP_AFTER_FIRST, false);
129 pOptions->InitOption(OPT_CMP_QUICK_LIMIT, 4 * 1024 * 1024); // 4 Megs
130 pOptions->InitOption(OPT_CMP_BINARY_LIMIT, 64 * 1024 * 1024); // 64 Megs
131 pOptions->InitOption(OPT_CMP_COMPARE_THREADS, -1);
132 pOptions->InitOption(OPT_CMP_WALK_UNIQUE_DIRS, true);
133 pOptions->InitOption(OPT_CMP_IGNORE_REPARSE_POINTS, false);
134 pOptions->InitOption(OPT_CMP_IGNORE_CODEPAGE, false);
135 pOptions->InitOption(OPT_CMP_INCLUDE_SUBDIRS, true);
136 pOptions->InitOption(OPT_CMP_ENABLE_IMGCMP_IN_DIRCMP, false);
138 pOptions->InitOption(OPT_CMP_BIN_FILEPATTERNS, _T("*.bin;*.frx"));
140 pOptions->InitOption(OPT_CMP_CSV_FILEPATTERNS, _T("*.csv"));
141 pOptions->InitOption(OPT_CMP_TSV_FILEPATTERNS, _T("*.tsv"));
142 pOptions->InitOption(OPT_CMP_DSV_FILEPATTERNS, _T(""));
143 pOptions->InitOption(OPT_CMP_DSV_DELIM_CHAR, _T(";"));
144 pOptions->InitOption(OPT_CMP_TBL_ALLOW_NEWLINES_IN_QUOTES, true);
145 pOptions->InitOption(OPT_CMP_TBL_QUOTE_CHAR, _T("\""));
147 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"));
148 pOptions->InitOption(OPT_CMP_IMG_SHOWDIFFERENCES, true);
149 pOptions->InitOption(OPT_CMP_IMG_OVERLAYMOVE, 0);
150 pOptions->InitOption(OPT_CMP_IMG_OVERLAYALPHA, 30);
151 pOptions->InitOption(OPT_CMP_IMG_DRAGGING_MODE, 1);
152 pOptions->InitOption(OPT_CMP_IMG_ZOOM, 1000);
153 pOptions->InitOption(OPT_CMP_IMG_USEBACKCOLOR, true);
154 pOptions->InitOption(OPT_CMP_IMG_BACKCOLOR, 0xFFFFFF);
155 pOptions->InitOption(OPT_CMP_IMG_DIFFBLOCKSIZE, 8);
156 pOptions->InitOption(OPT_CMP_IMG_DIFFCOLORALPHA, 70);
157 pOptions->InitOption(OPT_CMP_IMG_THRESHOLD, 0);
158 pOptions->InitOption(OPT_CMP_IMG_INSERTIONDELETIONDETECTION_MODE, 0);
159 pOptions->InitOption(OPT_CMP_IMG_VECTOR_IMAGE_ZOOM_RATIO, 1000);
161 pOptions->InitOption(OPT_PROJECTS_PATH, _T(""));
162 pOptions->InitOption(OPT_USE_SYSTEM_TEMP_PATH, true);
163 pOptions->InitOption(OPT_CUSTOM_TEMP_PATH, _T(""));
165 pOptions->InitOption(OPT_LINEFILTER_ENABLED, false);
166 pOptions->InitOption(OPT_FILEFILTER_CURRENT, _T("*.*"));
167 // CMainFrame initializes this when it is empty.
168 pOptions->InitOption(OPT_FILTER_USERPATH, paths::ConcatPath(env::GetMyDocuments(), DefaultRelativeFilterPath));
169 pOptions->InitOption(OPT_FILEFILTER_SHARED, false);
171 pOptions->InitOption(OPT_CP_DEFAULT_MODE, (int)0);
172 pOptions->InitOption(OPT_CP_DEFAULT_CUSTOM, (int)GetACP());
174 if (PRIMARYLANGID(LangId) == LANG_JAPANESE)
175 pOptions->InitOption(OPT_CP_DETECT, (int)(50932 << 16) | 3);
176 else if (LangId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED))
177 pOptions->InitOption(OPT_CP_DETECT, (int)(50936 << 16) | 3);
178 else if (PRIMARYLANGID(LangId) == LANG_KOREAN)
179 pOptions->InitOption(OPT_CP_DETECT, (int)(50949 << 16) | 3);
180 else if (LangId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL))
181 pOptions->InitOption(OPT_CP_DETECT, (int)(50950 << 16) | 3);
183 pOptions->InitOption(OPT_CP_DETECT, (int)(50001 << 16) | 1);
185 pOptions->InitOption(OPT_ARCHIVE_ENABLE, 1); // Enable by default
186 pOptions->InitOption(OPT_ARCHIVE_PROBETYPE, false);
187 pOptions->InitOption(OPT_ARCHIVE_FILTER_INDEX, 1);
189 pOptions->InitOption(OPT_PLUGINS_ENABLED, true);
190 pOptions->InitOption(OPT_PLUGINS_DISABLED_LIST, _T(""));
191 pOptions->InitOption(OPT_PLUGINS_CUSTOM_FILTERS_LIST, _T(""));
192 pOptions->InitOption(OPT_PLUGINS_UNPACKER_MODE, PLUGIN_MANUAL);
193 pOptions->InitOption(OPT_PLUGINS_PREDIFFER_MODE, PLUGIN_MANUAL);
194 pOptions->InitOption(OPT_PLUGINS_UNPACK_DONT_CHECK_EXTENSION, false);
196 pOptions->InitOption(OPT_PATCHCREATOR_PATCH_STYLE, 0);
197 pOptions->InitOption(OPT_PATCHCREATOR_CONTEXT_LINES, 0);
198 pOptions->InitOption(OPT_PATCHCREATOR_CASE_SENSITIVE, true);
199 pOptions->InitOption(OPT_PATCHCREATOR_EOL_SENSITIVE, true);
200 pOptions->InitOption(OPT_PATCHCREATOR_IGNORE_BLANK_LINES, false);
201 pOptions->InitOption(OPT_PATCHCREATOR_WHITESPACE, WHITESPACE_COMPARE_ALL);
202 pOptions->InitOption(OPT_PATCHCREATOR_OPEN_TO_EDITOR, false);
203 pOptions->InitOption(OPT_PATCHCREATOR_INCLUDE_CMD_LINE, false);
205 pOptions->InitOption(OPT_TABBAR_AUTO_MAXWIDTH, true);
206 pOptions->InitOption(OPT_ACTIVE_FRAME_MAX, true);
207 pOptions->InitOption(OPT_ACTIVE_PANE, 0);
209 pOptions->InitOption(OPT_MRU_MAX, 9);
211 pOptions->InitOption(OPT_COLOR_SCHEME, _T("Default"));
213 Options::CustomColors::SetDefaults(pOptions);
214 Options::DiffOptions::SetDefaults(pOptions);
215 Options::DiffColors::SetDefaults(pOptions);
216 Options::DirColors::SetDefaults(pOptions);
217 Options::Font::SetDefaults(pOptions);
221 * @brief Copy some HKLM values to HKCU.
222 * The installer sets HKLM values for "all users". This function copies
223 * few of those values for "user" values. E.g. enabling ShellExtension
224 * initially for user is done by this function.
226 void CopyHKLMValues()
230 if (OpenHKLM(&LMKey))
232 if (OpenHKCU(&CUKey))
234 CopyFromLMtoCU(LMKey, CUKey, _T("ContextMenuEnabled"));
235 CopyFromLMtoCU(LMKey, CUKey, _T("Executable"));
240 if (OpenHKLM(&LMKey, _T("Locale")))
242 if (OpenHKCU(&CUKey, _T("Locale")))
244 CopyFromLMtoCU(LMKey, CUKey, _T("LanguageId"));
254 * @brief Open HKLM registry key.
255 * @param [out] key Pointer to open HKLM key.
256 * @param [in] relpath Relative registry path (to WinMerge reg path) to open, or nullptr.
257 * @return true if opening succeeded.
259 static bool OpenHKLM(HKEY *key, LPCTSTR relpath)
261 TCHAR valuename[256];
263 wsprintf(valuename, _T("%s\\%s"), RegDir, relpath);
265 lstrcpy(valuename, RegDir);
266 LONG retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
267 valuename, 0, KEY_READ, key);
268 if (retval == ERROR_SUCCESS)
276 * @brief Open HKCU registry key.
277 * Opens the HKCU key for WinMerge. If the key does not exist, creates one.
278 * @param [out] key Pointer to open HKCU key.
279 * @param [in] relpath Relative registry path (to WinMerge reg path) to open, or nullptr.
280 * @return true if opening succeeded.
282 static bool OpenHKCU(HKEY *key, LPCTSTR relpath)
284 TCHAR valuename[256];
286 wsprintf(valuename, _T("%s\\%s"), RegDir, relpath);
288 lstrcpy(valuename, RegDir);
289 LONG retval = RegOpenKeyEx(HKEY_CURRENT_USER,
290 valuename, 0, KEY_ALL_ACCESS, key);
291 if (retval == ERROR_SUCCESS)
295 else if (retval == ERROR_FILE_NOT_FOUND)
297 retval = RegCreateKeyEx(HKEY_CURRENT_USER,
298 valuename, 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, key, nullptr);
299 if (retval == ERROR_SUCCESS)
306 * @brief Copy value from HKLM to HKCU.
307 * @param [in] lmKey HKLM key from where to copy.
308 * @param [in] cuKey HKCU key to where to copy.
309 * @param [in] valname Name of the value to copy.
311 static void CopyFromLMtoCU(HKEY lmKey, HKEY cuKey, LPCTSTR valname)
314 LONG retval = RegQueryValueEx(cuKey, valname, 0, nullptr, nullptr, &len);
315 if (retval == ERROR_FILE_NOT_FOUND)
317 retval = RegQueryValueEx(lmKey, valname, 0, nullptr, nullptr, &len);
318 if (retval == ERROR_SUCCESS)
321 std::vector<BYTE> buf(len);
322 retval = RegQueryValueEx(lmKey, valname, 0, &type, &buf[0], &len);
323 if (retval == ERROR_SUCCESS)
325 RegSetValueEx(cuKey, valname , 0, type,