2 * @file OptionsInit.cpp
4 * @brief Options initialisation.
8 #include "OptionsDef.h"
9 #include "OptionsMgr.h"
10 #include "RegOptionsMgr.h"
11 #include "OptionsDiffOptions.h"
12 #include "OptionsDiffColors.h"
13 #include "OptionsFont.h"
14 #include "DiffWrapper.h" // CMP_CONTENT
15 #include "SourceControl.h"
17 #include "Environment.h"
18 #include "Constants.h"
20 // Functions to copy values set by installer from HKLM to HKCU.
21 static void CopyHKLMValues();
22 static bool OpenHKLM(HKEY *key, LPCTSTR relpath = NULL);
23 static bool OpenHKCU(HKEY *key, LPCTSTR relpath = NULL);
24 static bool IsFirstRun(HKEY key);
25 static void CopyFromLMtoCU(HKEY lmKey, HKEY cuKey, LPCTSTR valname);
26 static void ResetFirstRun(HKEY key);
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 // Copy some values from HKLM to HKCU
43 static_cast<CRegOptionsMgr *>(pOptions)->SetRegRootKey(_T("Thingamahoochie\\WinMerge\\"));
45 LANGID LangId = GetUserDefaultLangID();
46 if (PRIMARYLANGID(LangId) == LANG_JAPANESE)
48 // Default language to Japanese unless installer set it otherwise
49 pOptions->InitOption(OPT_SELECTED_LANGUAGE, 0x411);
53 // Default language to English unless installer set it otherwise
54 pOptions->InitOption(OPT_SELECTED_LANGUAGE, 0x409);
57 // Initialise options (name, default value)
58 pOptions->InitOption(OPT_SHOW_UNIQUE_LEFT, true);
59 pOptions->InitOption(OPT_SHOW_UNIQUE_MIDDLE, true);
60 pOptions->InitOption(OPT_SHOW_UNIQUE_RIGHT, true);
61 pOptions->InitOption(OPT_SHOW_DIFFERENT, true);
62 pOptions->InitOption(OPT_SHOW_IDENTICAL, true);
63 pOptions->InitOption(OPT_SHOW_BINARIES, true);
64 pOptions->InitOption(OPT_SHOW_SKIPPED, false);
66 pOptions->InitOption(OPT_SHOW_TOOLBAR, true);
67 pOptions->InitOption(OPT_SHOW_STATUSBAR, true);
68 pOptions->InitOption(OPT_SHOW_TABBAR, true);
69 pOptions->InitOption(OPT_TOOLBAR_SIZE, GetSystemMetrics(SM_CXSMICON) < 24 ? 0 : 1);
70 pOptions->InitOption(OPT_RESIZE_PANES, false);
72 pOptions->InitOption(OPT_SYNTAX_HIGHLIGHT, true);
73 pOptions->InitOption(OPT_WORDWRAP, false);
74 pOptions->InitOption(OPT_VIEW_LINENUMBERS, false);
75 pOptions->InitOption(OPT_VIEW_WHITESPACE, false);
76 pOptions->InitOption(OPT_CONNECT_MOVED_BLOCKS, 0);
77 pOptions->InitOption(OPT_SCROLL_TO_FIRST, false);
78 pOptions->InitOption(OPT_VERIFY_OPEN_PATHS, true);
79 pOptions->InitOption(OPT_AUTO_COMPLETE_SOURCE, (int)1);
80 pOptions->InitOption(OPT_VIEW_FILEMARGIN, false);
81 pOptions->InitOption(OPT_DIFF_CONTEXT, (int)-1);
82 pOptions->InitOption(OPT_SPLIT_HORIZONTALLY, false);
84 pOptions->InitOption(OPT_WORDDIFF_HIGHLIGHT, true);
85 pOptions->InitOption(OPT_BREAK_SEPARATORS, _T(".,:;?[](){}<>`'!\"#$%&^~\\|@+-*/"));
87 pOptions->InitOption(OPT_BACKUP_FOLDERCMP, false);
88 pOptions->InitOption(OPT_BACKUP_FILECMP, true);
89 pOptions->InitOption(OPT_BACKUP_LOCATION, (int)0);
90 pOptions->InitOption(OPT_BACKUP_GLOBALFOLDER, _T(""));
91 pOptions->InitOption(OPT_BACKUP_ADD_BAK, true);
92 pOptions->InitOption(OPT_BACKUP_ADD_TIME, false);
94 pOptions->InitOption(OPT_DIRVIEW_SORT_COLUMN, (int)-1);
95 pOptions->InitOption(OPT_DIRVIEW_SORT_COLUMN3, (int)-1);
96 pOptions->InitOption(OPT_DIRVIEW_SORT_ASCENDING, true);
97 pOptions->InitOption(OPT_SHOW_SELECT_FILES_AT_STARTUP, false);
98 pOptions->InitOption(OPT_DIRVIEW_EXPAND_SUBDIRS, false);
100 pOptions->InitOption(OPT_AUTOMATIC_RESCAN, false);
101 pOptions->InitOption(OPT_ALLOW_MIXED_EOL, false);
102 pOptions->InitOption(OPT_TAB_SIZE, (int)4);
103 pOptions->InitOption(OPT_TAB_TYPE, (int)0); // 0 means tabs inserted
105 pOptions->InitOption(OPT_EXT_EDITOR_CMD, paths_ConcatPath(env_GetWindowsDirectory(), _T("NOTEPAD.EXE")));
106 pOptions->InitOption(OPT_USE_RECYCLE_BIN, true);
107 pOptions->InitOption(OPT_SINGLE_INSTANCE, false);
108 pOptions->InitOption(OPT_MERGE_MODE, false);
109 // OPT_WORDDIFF_HIGHLIGHT is initialized above
110 pOptions->InitOption(OPT_BREAK_ON_WORDS, false);
111 pOptions->InitOption(OPT_BREAK_TYPE, 1);
113 pOptions->InitOption(OPT_CLOSE_WITH_ESC, true);
114 pOptions->InitOption(OPT_CLOSE_WITH_OK, false);
115 pOptions->InitOption(OPT_IGNORE_SMALL_FILETIME, false);
116 pOptions->InitOption(OPT_ASK_MULTIWINDOW_CLOSE, false);
117 pOptions->InitOption(OPT_PRESERVE_FILETIMES, false);
118 pOptions->InitOption(OPT_TREE_MODE, true);
120 pOptions->InitOption(OPT_CMP_METHOD, (int)CMP_CONTENT);
121 pOptions->InitOption(OPT_CMP_MOVED_BLOCKS, false);
122 pOptions->InitOption(OPT_CMP_MATCH_SIMILAR_LINES, false);
123 pOptions->InitOption(OPT_CMP_STOP_AFTER_FIRST, false);
124 pOptions->InitOption(OPT_CMP_QUICK_LIMIT, 4 * 1024 * 1024); // 4 Megs
125 pOptions->InitOption(OPT_CMP_WALK_UNIQUE_DIRS, false);
126 pOptions->InitOption(OPT_CMP_IGNORE_REPARSE_POINTS, false);
127 pOptions->InitOption(OPT_CMP_IGNORE_CODEPAGE, true);
128 pOptions->InitOption(OPT_CMP_INCLUDE_SUBDIRS, true);
130 pOptions->InitOption(OPT_CMP_BIN_FILEPATTERNS, _T("*.bin;*.frx"));
132 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"));
133 pOptions->InitOption(OPT_CMP_IMG_SHOWDIFFERENCES, true);
134 pOptions->InitOption(OPT_CMP_IMG_OVERLAYMOVE, 0);
135 pOptions->InitOption(OPT_CMP_IMG_OVERLAYALPHA, 30);
136 pOptions->InitOption(OPT_CMP_IMG_ZOOM, 1000);
137 pOptions->InitOption(OPT_CMP_IMG_USEBACKCOLOR, true);
138 pOptions->InitOption(OPT_CMP_IMG_BACKCOLOR, 0xFFFFFF);
139 pOptions->InitOption(OPT_CMP_IMG_DIFFBLOCKSIZE, 8);
140 pOptions->InitOption(OPT_CMP_IMG_DIFFCOLORALPHA, 70);
141 pOptions->InitOption(OPT_CMP_IMG_THRESHOLD, 0);
143 pOptions->InitOption(OPT_PROJECTS_PATH, _T(""));
144 pOptions->InitOption(OPT_USE_SYSTEM_TEMP_PATH, true);
145 pOptions->InitOption(OPT_CUSTOM_TEMP_PATH, _T(""));
147 pOptions->InitOption(OPT_LINEFILTER_ENABLED, false);
148 pOptions->InitOption(OPT_FILEFILTER_CURRENT, _T("*.*"));
149 // CMainFrame initializes this when it is empty.
150 pOptions->InitOption(OPT_FILTER_USERPATH, paths_ConcatPath(env_GetMyDocuments(), DefaultRelativeFilterPath));
151 pOptions->InitOption(OPT_FILEFILTER_SHARED, false);
153 pOptions->InitOption(OPT_CP_DEFAULT_MODE, (int)0);
154 pOptions->InitOption(OPT_CP_DEFAULT_CUSTOM, (int)GetACP());
156 if (PRIMARYLANGID(LangId) == LANG_JAPANESE)
157 pOptions->InitOption(OPT_CP_DETECT, (int)(50932 << 16) | 3);
158 else if (LangId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED))
159 pOptions->InitOption(OPT_CP_DETECT, (int)(50936 << 16) | 3);
160 else if (PRIMARYLANGID(LangId) == LANG_KOREAN)
161 pOptions->InitOption(OPT_CP_DETECT, (int)(50949 << 16) | 3);
162 else if (LangId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL))
163 pOptions->InitOption(OPT_CP_DETECT, (int)(50950 << 16) | 3);
165 pOptions->InitOption(OPT_CP_DETECT, (int)(50001 << 16) | 1);
167 pOptions->InitOption(OPT_VCS_SYSTEM, SourceControl::VCS_NONE);
168 pOptions->InitOption(OPT_VSS_PATH, _T(""));
169 pOptions->InitOption(OPT_VSS_DATABASE, _T(""));
170 pOptions->InitOption(OPT_VSS_PROJECT, _T(""));
171 pOptions->InitOption(OPT_VSS_USER, _T(""));
173 pOptions->InitOption(OPT_ARCHIVE_ENABLE, 1); // Enable by default
174 pOptions->InitOption(OPT_ARCHIVE_PROBETYPE, false);
176 pOptions->InitOption(OPT_PLUGINS_ENABLED, true);
177 pOptions->InitOption(OPT_PLUGINS_DISABLED_LIST, _T(""));
179 pOptions->InitOption(OPT_TABBAR_AUTO_MAXWIDTH, true);
181 pOptions->InitOption(OPT_MRU_MAX, 9);
183 pOptions->InitOption(OPT_CURRENT_VERSION_URL, CurrentVersionURL);
184 pOptions->InitOption(OPT_DOWNLOAD_URL, DownloadUrl);
186 Options::DiffOptions::SetDefaults(pOptions);
187 Options::DiffColors::SetDefaults(pOptions);
188 Options::Font::SetDefaults(pOptions);
194 * @brief Copy some HKLM values to HKCU.
195 * The installer sets HKLM values for "all users". This function copies
196 * few of those values for "user" values. E.g. enabling ShellExtension
197 * initially for user is done by this function.
199 static void CopyHKLMValues()
203 if (OpenHKLM(&LMKey))
205 if (OpenHKCU(&CUKey))
207 CopyFromLMtoCU(LMKey, CUKey, _T("ContextMenuEnabled"));
208 CopyFromLMtoCU(LMKey, CUKey, _T("Executable"));
213 if (OpenHKLM(&LMKey, _T("Locale")))
215 if (OpenHKCU(&CUKey, _T("Locale")))
217 CopyFromLMtoCU(LMKey, CUKey, _T("LanguageId"));
225 * @brief Open HKLM registry key.
226 * @param [out] key Pointer to open HKLM key.
227 * @param [in] relpath Relative registry path (to WinMerge reg path) to open, or NULL.
228 * @return true if opening succeeded.
230 static bool OpenHKLM(HKEY *key, LPCTSTR relpath)
232 TCHAR valuename[256];
234 wsprintf(valuename, _T("%s\\%s"), RegDir, relpath);
236 lstrcpy(valuename, RegDir);
237 LONG retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
238 valuename, 0, KEY_READ, key);
239 if (retval == ERROR_SUCCESS)
247 * @brief Open HKCU registry key.
248 * Opens the HKCU key for WinMerge. If the key does not exist, creates one.
249 * @param [out] key Pointer to open HKCU key.
250 * @param [in] relpath Relative registry path (to WinMerge reg path) to open, or NULL.
251 * @return true if opening succeeded.
253 static bool OpenHKCU(HKEY *key, LPCTSTR relpath)
255 TCHAR valuename[256];
257 wsprintf(valuename, _T("%s\\%s"), RegDir, relpath);
259 lstrcpy(valuename, RegDir);
260 LONG retval = RegOpenKeyEx(HKEY_CURRENT_USER,
261 valuename, 0, KEY_ALL_ACCESS, key);
262 if (retval == ERROR_SUCCESS)
266 else if (retval == ERROR_FILE_NOT_FOUND)
268 retval = RegCreateKeyEx(HKEY_CURRENT_USER,
269 valuename, 0, NULL, 0, KEY_ALL_ACCESS, NULL, key, NULL);
270 if (retval == ERROR_SUCCESS)
277 * @brief Copy value from HKLM to HKCU.
278 * @param [in] lmKey HKLM key from where to copy.
279 * @param [in] cuKey HKCU key to where to copy.
280 * @param [in] valname Name of the value to copy.
282 static void CopyFromLMtoCU(HKEY lmKey, HKEY cuKey, LPCTSTR valname)
285 LONG retval = RegQueryValueEx(cuKey, valname, 0, NULL, NULL, &len);
286 if (retval == ERROR_FILE_NOT_FOUND)
288 retval = RegQueryValueEx(lmKey, valname, 0, NULL, NULL, &len);
289 if (retval == ERROR_SUCCESS)
292 std::vector<BYTE> buf(len);
293 retval = RegQueryValueEx(lmKey, valname, 0, &type, &buf[0], &len);
294 if (retval == ERROR_SUCCESS)
296 RegSetValueEx(cuKey, valname , 0, type,