1 // RegistryUtils.cpp
2
3 #include "StdAfx.h"
4
5 #include "../../../Common/IntToString.h"
6
7 #include "../../../Windows/Registry.h"
8
9 #include "RegistryUtils.h"
10
11 using namespace NWindows;
12 using namespace NRegistry;
13
14 #define REG_PATH_7Z TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-Zip")
15
16 static LPCTSTR const kCUBasePath = REG_PATH_7Z;
17 static LPCTSTR const kCU_FMPath = REG_PATH_7Z TEXT(STRING_PATH_SEPARATOR) TEXT("FM");
18 // static LPCTSTR const kLM_Path = REG_PATH_7Z TEXT(STRING_PATH_SEPARATOR) TEXT("FM");
19
20 static LPCWSTR const kLangValueName = L"Lang";
21
22 static LPCWSTR const kViewer = L"Viewer";
23 static LPCWSTR const kEditor = L"Editor";
24 static LPCWSTR const kDiff = L"Diff";
25 static LPCWSTR const kVerCtrlPath = L"7vc";
26
27 static LPCTSTR const kShowDots = TEXT("ShowDots");
28 static LPCTSTR const kShowRealFileIcons = TEXT("ShowRealFileIcons");
29 static LPCTSTR const kFullRow = TEXT("FullRow");
30 static LPCTSTR const kShowGrid = TEXT("ShowGrid");
31 static LPCTSTR const kSingleClick = TEXT("SingleClick");
32 static LPCTSTR const kAlternativeSelection = TEXT("AlternativeSelection");
33 // static LPCTSTR const kUnderline = TEXT("Underline");
34
35 static LPCTSTR const kShowSystemMenu = TEXT("ShowSystemMenu");
36
37 // static LPCTSTR const kLockMemoryAdd = TEXT("LockMemoryAdd");
38 static LPCTSTR const kLargePages = TEXT("LargePages");
39
40 static LPCTSTR const kFlatViewName = TEXT("FlatViewArc");
41 // static LPCTSTR const kShowDeletedFiles = TEXT("ShowDeleted");
42
SaveCuString(LPCTSTR keyPath,LPCWSTR valuePath,LPCWSTR value)43 static void SaveCuString(LPCTSTR keyPath, LPCWSTR valuePath, LPCWSTR value)
44 {
45 CKey key;
46 key.Create(HKEY_CURRENT_USER, keyPath);
47 key.SetValue(valuePath, value);
48 }
49
ReadCuString(LPCTSTR keyPath,LPCWSTR valuePath,UString & res)50 static void ReadCuString(LPCTSTR keyPath, LPCWSTR valuePath, UString &res)
51 {
52 res.Empty();
53 CKey key;
54 if (key.Open(HKEY_CURRENT_USER, keyPath, KEY_READ) == ERROR_SUCCESS)
55 key.QueryValue(valuePath, res);
56 }
57
SaveRegLang(const UString & path)58 void SaveRegLang(const UString &path) { SaveCuString(kCUBasePath, kLangValueName, path); }
ReadRegLang(UString & path)59 void ReadRegLang(UString &path) { ReadCuString(kCUBasePath, kLangValueName, path); }
60
SaveRegEditor(bool useEditor,const UString & path)61 void SaveRegEditor(bool useEditor, const UString &path) { SaveCuString(kCU_FMPath, useEditor ? kEditor : kViewer, path); }
ReadRegEditor(bool useEditor,UString & path)62 void ReadRegEditor(bool useEditor, UString &path) { ReadCuString(kCU_FMPath, useEditor ? kEditor : kViewer, path); }
63
SaveRegDiff(const UString & path)64 void SaveRegDiff(const UString &path) { SaveCuString(kCU_FMPath, kDiff, path); }
ReadRegDiff(UString & path)65 void ReadRegDiff(UString &path) { ReadCuString(kCU_FMPath, kDiff, path); }
66
ReadReg_VerCtrlPath(UString & path)67 void ReadReg_VerCtrlPath(UString &path) { ReadCuString(kCU_FMPath, kVerCtrlPath, path); }
68
Save7ZipOption(LPCTSTR value,bool enabled)69 static void Save7ZipOption(LPCTSTR value, bool enabled)
70 {
71 CKey key;
72 key.Create(HKEY_CURRENT_USER, kCUBasePath);
73 key.SetValue(value, enabled);
74 }
75
SaveOption(LPCTSTR value,bool enabled)76 static void SaveOption(LPCTSTR value, bool enabled)
77 {
78 CKey key;
79 key.Create(HKEY_CURRENT_USER, kCU_FMPath);
80 key.SetValue(value, enabled);
81 }
82
Read7ZipOption(LPCTSTR value,bool defaultValue)83 static bool Read7ZipOption(LPCTSTR value, bool defaultValue)
84 {
85 CKey key;
86 if (key.Open(HKEY_CURRENT_USER, kCUBasePath, KEY_READ) == ERROR_SUCCESS)
87 {
88 bool enabled;
89 if (key.GetValue_bool_IfOk(value, enabled) == ERROR_SUCCESS)
90 return enabled;
91 }
92 return defaultValue;
93 }
94
ReadOption(CKey & key,LPCTSTR name,bool & dest)95 static void ReadOption(CKey &key, LPCTSTR name, bool &dest)
96 {
97 key.GetValue_bool_IfOk(name, dest);
98 }
99
100 /*
101 static void SaveLmOption(LPCTSTR value, bool enabled)
102 {
103 CKey key;
104 key.Create(HKEY_LOCAL_MACHINE, kLM_Path);
105 key.SetValue(value, enabled);
106 }
107
108 static bool ReadLmOption(LPCTSTR value, bool defaultValue)
109 {
110 CKey key;
111 if (key.Open(HKEY_LOCAL_MACHINE, kLM_Path, KEY_READ) == ERROR_SUCCESS)
112 {
113 bool enabled;
114 if (key.QueryValue(value, enabled) == ERROR_SUCCESS)
115 return enabled;
116 }
117 return defaultValue;
118 }
119 */
120
Save() const121 void CFmSettings::Save() const
122 {
123 SaveOption(kShowDots, ShowDots);
124 SaveOption(kShowRealFileIcons, ShowRealFileIcons);
125 SaveOption(kFullRow, FullRow);
126 SaveOption(kShowGrid, ShowGrid);
127 SaveOption(kSingleClick, SingleClick);
128 SaveOption(kAlternativeSelection, AlternativeSelection);
129 // SaveOption(kUnderline, Underline);
130
131 SaveOption(kShowSystemMenu, ShowSystemMenu);
132 }
133
Load()134 void CFmSettings::Load()
135 {
136 ShowDots = false;
137 ShowRealFileIcons = false;
138 /* if (FullRow == false), we can use mouse click on another columns
139 to select group of files. We need to implement additional
140 way to select files in any column as in Explorer.
141 Then we can enable (FullRow == true) default mode. */
142 // FullRow = true;
143 FullRow = false;
144 ShowGrid = false;
145 SingleClick = false;
146 AlternativeSelection = false;
147 // Underline = false;
148
149 ShowSystemMenu = false;
150
151 CKey key;
152 if (key.Open(HKEY_CURRENT_USER, kCU_FMPath, KEY_READ) == ERROR_SUCCESS)
153 {
154 ReadOption(key, kShowDots, ShowDots);
155 ReadOption(key, kShowRealFileIcons, ShowRealFileIcons);
156 ReadOption(key, kFullRow, FullRow);
157 ReadOption(key, kShowGrid, ShowGrid);
158 ReadOption(key, kSingleClick, SingleClick);
159 ReadOption(key, kAlternativeSelection, AlternativeSelection);
160 // ReadOption(key, kUnderline, Underline);
161
162 ReadOption(key, kShowSystemMenu, ShowSystemMenu );
163 }
164 }
165
166
167 // void SaveLockMemoryAdd(bool enable) { SaveLmOption(kLockMemoryAdd, enable); }
168 // bool ReadLockMemoryAdd() { return ReadLmOption(kLockMemoryAdd, true); }
169
SaveLockMemoryEnable(bool enable)170 void SaveLockMemoryEnable(bool enable) { Save7ZipOption(kLargePages, enable); }
ReadLockMemoryEnable()171 bool ReadLockMemoryEnable() { return Read7ZipOption(kLargePages, false); }
172
GetFlatViewName(UInt32 panelIndex)173 static CSysString GetFlatViewName(UInt32 panelIndex)
174 {
175 TCHAR panelString[16];
176 ConvertUInt32ToString(panelIndex, panelString);
177 return (CSysString)kFlatViewName + panelString;
178 }
179
SaveFlatView(UInt32 panelIndex,bool enable)180 void SaveFlatView(UInt32 panelIndex, bool enable) { SaveOption(GetFlatViewName(panelIndex), enable); }
181
ReadFlatView(UInt32 panelIndex)182 bool ReadFlatView(UInt32 panelIndex)
183 {
184 bool enabled = false;
185 CKey key;
186 if (key.Open(HKEY_CURRENT_USER, kCU_FMPath, KEY_READ) == ERROR_SUCCESS)
187 ReadOption(key, GetFlatViewName(panelIndex), enabled);
188 return enabled;
189 }
190
191 /*
192 void Save_ShowDeleted(bool enable) { SaveOption(kShowDeletedFiles, enable); }
193 bool Read_ShowDeleted() { return ReadOption(kShowDeletedFiles, false); }
194 */
195