• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.QueryValue(value, enabled) == ERROR_SUCCESS)
90       return enabled;
91   }
92   return defaultValue;
93 }
94 
ReadOption(CKey & key,LPCTSTR value,bool & dest)95 static void ReadOption(CKey &key, LPCTSTR value, bool &dest)
96 {
97   bool enabled = false;
98   if (key.QueryValue(value, enabled) == ERROR_SUCCESS)
99     dest = enabled;
100 }
101 
102 /*
103 static void SaveLmOption(LPCTSTR value, bool enabled)
104 {
105   CKey key;
106   key.Create(HKEY_LOCAL_MACHINE, kLM_Path);
107   key.SetValue(value, enabled);
108 }
109 
110 static bool ReadLmOption(LPCTSTR value, bool defaultValue)
111 {
112   CKey key;
113   if (key.Open(HKEY_LOCAL_MACHINE, kLM_Path, KEY_READ) == ERROR_SUCCESS)
114   {
115     bool enabled;
116     if (key.QueryValue(value, enabled) == ERROR_SUCCESS)
117       return enabled;
118   }
119   return defaultValue;
120 }
121 */
122 
Save() const123 void CFmSettings::Save() const
124 {
125   SaveOption(kShowDots, ShowDots);
126   SaveOption(kShowRealFileIcons, ShowRealFileIcons);
127   SaveOption(kFullRow, FullRow);
128   SaveOption(kShowGrid, ShowGrid);
129   SaveOption(kSingleClick, SingleClick);
130   SaveOption(kAlternativeSelection, AlternativeSelection);
131   // SaveOption(kUnderline, Underline);
132 
133   SaveOption(kShowSystemMenu, ShowSystemMenu);
134 }
135 
Load()136 void CFmSettings::Load()
137 {
138   ShowDots = false;
139   ShowRealFileIcons = false;
140   /* if (FullRow == false), we can use mouse click on another columns
141      to select group of files. We need to implement additional
142      way to select files in any column as in Explorer.
143      Then we can enable (FullRow == true) default mode. */
144   // FullRow = true;
145   FullRow = false;
146   ShowGrid = false;
147   SingleClick = false;
148   AlternativeSelection = false;
149   // Underline = false;
150 
151   ShowSystemMenu = false;
152 
153   CKey key;
154   if (key.Open(HKEY_CURRENT_USER, kCU_FMPath, KEY_READ) == ERROR_SUCCESS)
155   {
156     ReadOption(key, kShowDots, ShowDots);
157     ReadOption(key, kShowRealFileIcons, ShowRealFileIcons);
158     ReadOption(key, kFullRow, FullRow);
159     ReadOption(key, kShowGrid, ShowGrid);
160     ReadOption(key, kSingleClick, SingleClick);
161     ReadOption(key, kAlternativeSelection, AlternativeSelection);
162     // ReadOption(key, kUnderline, Underline);
163 
164     ReadOption(key, kShowSystemMenu, ShowSystemMenu );
165   }
166 }
167 
168 
169 // void SaveLockMemoryAdd(bool enable) { SaveLmOption(kLockMemoryAdd, enable); }
170 // bool ReadLockMemoryAdd() { return ReadLmOption(kLockMemoryAdd, true); }
171 
SaveLockMemoryEnable(bool enable)172 void SaveLockMemoryEnable(bool enable) { Save7ZipOption(kLargePages, enable); }
ReadLockMemoryEnable()173 bool ReadLockMemoryEnable() { return Read7ZipOption(kLargePages, false); }
174 
GetFlatViewName(UInt32 panelIndex)175 static CSysString GetFlatViewName(UInt32 panelIndex)
176 {
177   TCHAR panelString[16];
178   ConvertUInt32ToString(panelIndex, panelString);
179   return (CSysString)kFlatViewName + panelString;
180 }
181 
SaveFlatView(UInt32 panelIndex,bool enable)182 void SaveFlatView(UInt32 panelIndex, bool enable) { SaveOption(GetFlatViewName(panelIndex), enable); }
183 
ReadFlatView(UInt32 panelIndex)184 bool ReadFlatView(UInt32 panelIndex)
185 {
186   bool enabled = false;
187   CKey key;
188   if (key.Open(HKEY_CURRENT_USER, kCU_FMPath, KEY_READ) == ERROR_SUCCESS)
189     ReadOption(key, GetFlatViewName(panelIndex), enabled);
190   return enabled;
191 }
192 
193 /*
194 void Save_ShowDeleted(bool enable) { SaveOption(kShowDeletedFiles, enable); }
195 bool Read_ShowDeleted() { return ReadOption(kShowDeletedFiles, false); }
196 */
197