Skip to content

Commit 5f0f88f

Browse files
committed
Issue #39: Converted BitmapCache.h and win32_registry.h
1 parent 038e84f commit 5f0f88f

File tree

8 files changed

+208
-208
lines changed

8 files changed

+208
-208
lines changed

src/BitmapCache.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ namespace shellanything
3535

3636
BitmapCache::~BitmapCache()
3737
{
38-
clear_and_destroy();
38+
ClearAndDestroy();
3939
}
4040

41-
void BitmapCache::clear()
41+
void BitmapCache::Clear()
4242
{
4343
mFiles.clear();
4444
}
4545

46-
void BitmapCache::clear_and_destroy()
46+
void BitmapCache::ClearAndDestroy()
4747
{
4848
//for each files
4949
for (FilenameMap::const_iterator wFilesIterator = mFiles.begin(); wFilesIterator != mFiles.end(); wFilesIterator++)
@@ -65,7 +65,7 @@ namespace shellanything
6565
mFiles.clear();
6666
}
6767

68-
void BitmapCache::reset_counters()
68+
void BitmapCache::ResetCounters()
6969
{
7070
//for each files
7171
for (FilenameMap::iterator wFilesIterator = mFiles.begin(); wFilesIterator != mFiles.end(); wFilesIterator++)
@@ -85,7 +85,7 @@ namespace shellanything
8585
}
8686
}
8787

88-
int BitmapCache::destroy_old_handles()
88+
int BitmapCache::DestroyOldHandles()
8989
{
9090
int num_destroyed = 0;
9191

@@ -168,7 +168,7 @@ namespace shellanything
168168
return num_destroyed;
169169
}
170170

171-
void BitmapCache::add_handle(const std::string & iFilename, const int & iIndex, HBITMAP hBitmap)
171+
void BitmapCache::AddHandle(const std::string & iFilename, const int & iIndex, HBITMAP hBitmap)
172172
{
173173
USAGE usage;
174174
usage.hBitmap = hBitmap;
@@ -177,7 +177,7 @@ namespace shellanything
177177
mFiles[iFilename][iIndex] = usage;
178178
}
179179

180-
HBITMAP BitmapCache::find_handle(const std::string & iFilename, const int & iIndex)
180+
HBITMAP BitmapCache::FindHandle(const std::string & iFilename, const int & iIndex)
181181
{
182182
//search within 1st map level
183183
FilenameMap::iterator wFilesIterator = mFiles.find(iFilename);
@@ -201,7 +201,7 @@ namespace shellanything
201201
return usage.hBitmap;
202202
}
203203

204-
int BitmapCache::get_usage(const std::string & iFilename, const int & iIndex)
204+
int BitmapCache::GetUsage(const std::string & iFilename, const int & iIndex)
205205
{
206206
//search within 1st map level
207207
FilenameMap::iterator wFilesIterator = mFiles.find(iFilename);

src/BitmapCache.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ namespace shellanything
4040

4141
static const HBITMAP INVALID_BITMAP_HANDLE;
4242

43-
void clear();
44-
void clear_and_destroy();
45-
void reset_counters();
46-
int destroy_old_handles();
47-
void add_handle(const std::string & iFilename, const int & iIndex, HBITMAP hBitmap);
48-
HBITMAP find_handle(const std::string & iFilename, const int & iIndex);
49-
int get_usage(const std::string & iFilename, const int & iIndex);
43+
void Clear();
44+
void ClearAndDestroy();
45+
void ResetCounters();
46+
int DestroyOldHandles();
47+
void AddHandle(const std::string & iFilename, const int & iIndex, HBITMAP hBitmap);
48+
HBITMAP FindHandle(const std::string & iFilename, const int & iIndex);
49+
int GetUsage(const std::string & iFilename, const int & iIndex);
5050

5151
private:
5252
// Typedef

src/Icon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace shellanything
7575
if (!file_extension.empty())
7676
{
7777
//try to find the path to the icon module for the given file extension.
78-
win32_registry::REGISTRY_ICON resolved_icon = win32_registry::getFileTypeIcon(file_extension.c_str());
78+
win32_registry::REGISTRY_ICON resolved_icon = win32_registry::GetFileTypeIcon(file_extension.c_str());
7979
if (!resolved_icon.path.empty() && resolved_icon.index != win32_registry::INVALID_ICON_INDEX)
8080
{
8181
//found the icon for the file extension
@@ -89,7 +89,7 @@ namespace shellanything
8989
{
9090
//failed to find a valid icon.
9191
//using the default "unknown" icon
92-
win32_registry::REGISTRY_ICON unknown_file_icon = win32_registry::getUnknownFileTypeIcon();
92+
win32_registry::REGISTRY_ICON unknown_file_icon = win32_registry::GetUnknownFileTypeIcon();
9393
LOG(WARNING) << "Failed to find icon for file extension '" << file_extension << "'. Resolving icon with default icon for unknown file type '" << unknown_file_icon.path << "' with index '" << unknown_file_icon.index << "'";
9494
mPath = unknown_file_icon.path;
9595
mIndex = unknown_file_icon.index;

src/shellext.cpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ std::string GuidToInterfaceName(GUID guid)
153153
bool isFirstApplicationRun(const std::string & name, const std::string & version)
154154
{
155155
std::string key = ra::strings::Format("HKEY_CURRENT_USER\\Software\\%s\\%s", name.c_str(), version.c_str());
156-
if (!win32_registry::createKey(key.c_str(), NULL))
156+
if (!win32_registry::CreateKey(key.c_str(), NULL))
157157
{
158158
// unable to get to the application's key.
159159
// assume it is not the first run.
@@ -165,13 +165,13 @@ bool isFirstApplicationRun(const std::string & name, const std::string & version
165165
// try to read the value
166166
win32_registry::MemoryBuffer value;
167167
win32_registry::REGISTRY_TYPE value_type;
168-
if (!win32_registry::getValue(key.c_str(), FIRST_RUN_VALUE_NAME, value_type, value))
168+
if (!win32_registry::GetValue(key.c_str(), FIRST_RUN_VALUE_NAME, value_type, value))
169169
{
170170
// the registry value is not found.
171171
// assume the application is run for the first time.
172172

173173
// update the flag to "false" for the next call
174-
win32_registry::setValue(key.c_str(), FIRST_RUN_VALUE_NAME, "false"); //don't look at the write result
174+
win32_registry::SetValue(key.c_str(), FIRST_RUN_VALUE_NAME, "false"); //don't look at the write result
175175

176176
return true;
177177
}
@@ -181,7 +181,7 @@ bool isFirstApplicationRun(const std::string & name, const std::string & version
181181
if (first_run)
182182
{
183183
//update the flag to "false"
184-
win32_registry::setValue(key.c_str(), FIRST_RUN_VALUE_NAME, "false"); //don't look at the write result
184+
win32_registry::SetValue(key.c_str(), FIRST_RUN_VALUE_NAME, "false"); //don't look at the write result
185185
}
186186

187187
return first_run;
@@ -329,7 +329,7 @@ void CContextMenu::BuildMenuTree(HMENU hMenu, shellanything::Menu * menu, UINT &
329329

330330
//ask the cache for an existing icon.
331331
//this will identify the icon in the cache as "used" or "active".
332-
HBITMAP hBitmap = m_BitmapCache.find_handle(icon_filename, icon_index);
332+
HBITMAP hBitmap = m_BitmapCache.FindHandle(icon_filename, icon_index);
333333

334334
//if nothing in cache, create a new one
335335
if (hBitmap == shellanything::BitmapCache::INVALID_BITMAP_HANDLE)
@@ -357,7 +357,7 @@ void CContextMenu::BuildMenuTree(HMENU hMenu, shellanything::Menu * menu, UINT &
357357
DestroyIcon(hIconSmall);
358358

359359
//add the bitmap to the cache for future use
360-
m_BitmapCache.add_handle( icon_filename.c_str(), icon_index, hBitmap );
360+
m_BitmapCache.AddHandle( icon_filename.c_str(), icon_index, hBitmap );
361361
}
362362
}
363363

@@ -407,7 +407,7 @@ void CContextMenu::BuildMenuTree(HMENU hMenu)
407407
//https://www.codeproject.com/Questions/1228261/Windows-shell-extension
408408
//
409409
//To prevent running out of bitmap ressource we use the shellanything::BitmapCache class.
410-
//Each bitmap is identified as 'used' in CContextMenu::BuildMenuTree() with 'm_BitmapCache.find_handle()'.
410+
//Each bitmap is identified as 'used' in CContextMenu::BuildMenuTree() with 'm_BitmapCache.FindHandle()'.
411411
//Every 5 times the shell extension popup is displayed, we look for 'unused' bitmap and delete them.
412412
//
413413

@@ -416,10 +416,10 @@ void CContextMenu::BuildMenuTree(HMENU hMenu)
416416
if (m_BuildMenuTreeCount > 0 && (m_BuildMenuTreeCount % 5) == 0)
417417
{
418418
//every 10 calls, refresh the cache
419-
m_BitmapCache.destroy_old_handles();
419+
m_BitmapCache.DestroyOldHandles();
420420

421421
//reset counters
422-
m_BitmapCache.reset_counters();
422+
m_BitmapCache.ResetCounters();
423423
}
424424

425425
//browse through all shellanything menus and build the win32 popup menus
@@ -1101,104 +1101,104 @@ STDAPI DllRegisterServer(void)
11011101
//Register version 1 of our class
11021102
{
11031103
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\%s", class_name_version1);
1104-
if (!win32_registry::createKey(key.c_str(), ShellExtensionDescription))
1104+
if (!win32_registry::CreateKey(key.c_str(), ShellExtensionDescription))
11051105
return E_ACCESSDENIED;
11061106
}
11071107
{
11081108
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\%s.1\\CLSID", ShellExtensionClassName);
1109-
if (!win32_registry::createKey(key.c_str(), guid_str))
1109+
if (!win32_registry::CreateKey(key.c_str(), guid_str))
11101110
return E_ACCESSDENIED;
11111111
}
11121112

11131113
//Register current version of our class
11141114
{
11151115
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\%s", ShellExtensionClassName);
1116-
if (!win32_registry::createKey(key.c_str(), ShellExtensionDescription))
1116+
if (!win32_registry::CreateKey(key.c_str(), ShellExtensionDescription))
11171117
return E_ACCESSDENIED;
11181118
}
11191119
{
11201120
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\%s\\CLSID", ShellExtensionClassName);
1121-
if (!win32_registry::createKey(key.c_str(), guid_str))
1121+
if (!win32_registry::CreateKey(key.c_str(), guid_str))
11221122
return E_ACCESSDENIED;
11231123
}
11241124
{
11251125
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\%s\\CurVer", ShellExtensionClassName);
1126-
if (!win32_registry::createKey(key.c_str(), class_name_version1.c_str()))
1126+
if (!win32_registry::CreateKey(key.c_str(), class_name_version1.c_str()))
11271127
return E_ACCESSDENIED;
11281128
}
11291129

11301130
// Add the CLSID of this DLL to the registry
11311131
{
11321132
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\CLSID\\%s", guid_str);
1133-
if (!win32_registry::createKey(key.c_str(), ShellExtensionDescription))
1133+
if (!win32_registry::CreateKey(key.c_str(), ShellExtensionDescription))
11341134
return E_ACCESSDENIED;
11351135
}
11361136

11371137
// Define the path and parameters of our DLL:
11381138
{
11391139
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\CLSID\\%s\\ProgID", guid_str);
1140-
if (!win32_registry::createKey(key.c_str(), class_name_version1.c_str()))
1140+
if (!win32_registry::CreateKey(key.c_str(), class_name_version1.c_str()))
11411141
return E_ACCESSDENIED;
11421142
}
11431143
{
11441144
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\CLSID\\%s\\VersionIndependentProgID", guid_str);
1145-
if (!win32_registry::createKey(key.c_str(), ShellExtensionClassName))
1145+
if (!win32_registry::CreateKey(key.c_str(), ShellExtensionClassName))
11461146
return E_ACCESSDENIED;
11471147
}
11481148
{
11491149
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\CLSID\\%s\\Programmable", guid_str);
1150-
if (!win32_registry::createKey(key.c_str()))
1150+
if (!win32_registry::CreateKey(key.c_str()))
11511151
return E_ACCESSDENIED;
11521152
}
11531153
{
11541154
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\CLSID\\%s\\InprocServer32", guid_str);
1155-
if (!win32_registry::createKey(key.c_str(), module_path.c_str() ))
1155+
if (!win32_registry::CreateKey(key.c_str(), module_path.c_str() ))
11561156
return E_ACCESSDENIED;
1157-
if (!win32_registry::setValue(key.c_str(), "ThreadingModel", "Apartment"))
1157+
if (!win32_registry::SetValue(key.c_str(), "ThreadingModel", "Apartment"))
11581158
return E_ACCESSDENIED;
11591159
}
11601160

11611161
// Register the shell extension for all the file types
11621162
{
11631163
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\*\\shellex\\ContextMenuHandlers\\%s", ShellExtensionClassName);
1164-
if (!win32_registry::createKey(key.c_str(), guid_str))
1164+
if (!win32_registry::CreateKey(key.c_str(), guid_str))
11651165
return E_ACCESSDENIED;
11661166
}
11671167

11681168
// Register the shell extension for directories
11691169
{
11701170
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\Directory\\shellex\\ContextMenuHandlers\\%s", ShellExtensionClassName);
1171-
if (!win32_registry::createKey(key.c_str(), guid_str))
1171+
if (!win32_registry::CreateKey(key.c_str(), guid_str))
11721172
return E_ACCESSDENIED;
11731173
}
11741174

11751175
// Register the shell extension for folders
11761176
{
11771177
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\Folder\\shellex\\ContextMenuHandlers\\%s", ShellExtensionClassName);
1178-
if (!win32_registry::createKey(key.c_str(), guid_str))
1178+
if (!win32_registry::CreateKey(key.c_str(), guid_str))
11791179
return E_ACCESSDENIED;
11801180
}
11811181

11821182
// Register the shell extension for the desktop or the file explorer's background
11831183
{
11841184
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\Directory\\Background\\ShellEx\\ContextMenuHandlers\\%s", ShellExtensionClassName);
1185-
if (!win32_registry::createKey(key.c_str(), guid_str))
1185+
if (!win32_registry::CreateKey(key.c_str(), guid_str))
11861186
return E_ACCESSDENIED;
11871187
}
11881188

11891189
// Register the shell extension for drives
11901190
{
11911191
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\Drive\\ShellEx\\ContextMenuHandlers\\%s", ShellExtensionClassName);
1192-
if (!win32_registry::createKey(key.c_str(), guid_str))
1192+
if (!win32_registry::CreateKey(key.c_str(), guid_str))
11931193
return E_ACCESSDENIED;
11941194
}
11951195

11961196
// Register the shell extension to the system's approved Shell Extensions
11971197
{
11981198
std::string key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";
1199-
if (!win32_registry::createKey(key.c_str()))
1199+
if (!win32_registry::CreateKey(key.c_str()))
12001200
return E_ACCESSDENIED;
1201-
if (!win32_registry::setValue(key.c_str(), guid_str, ShellExtensionDescription))
1201+
if (!win32_registry::SetValue(key.c_str(), guid_str, ShellExtensionDescription))
12021202
return E_ACCESSDENIED;
12031203
}
12041204

@@ -1223,61 +1223,61 @@ STDAPI DllUnregisterServer(void)
12231223
// Unregister the shell extension from the system's approved Shell Extensions
12241224
{
12251225
std::string key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";
1226-
if (!win32_registry::deleteValue(key.c_str(), guid_str))
1226+
if (!win32_registry::DeleteValue(key.c_str(), guid_str))
12271227
return E_ACCESSDENIED;
12281228
}
12291229

12301230
// Unregister the shell extension for drives
12311231
{
12321232
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\Drive\\shellex\\ContextMenuHandlers\\%s", ShellExtensionClassName);
1233-
if (!win32_registry::deleteKey(key.c_str()))
1233+
if (!win32_registry::DeleteKey(key.c_str()))
12341234
return E_ACCESSDENIED;
12351235
}
12361236

12371237
// Unregister the shell extension for the desktop or the file explorer's background
12381238
{
12391239
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\Directory\\Background\\ShellEx\\ContextMenuHandlers\\%s", ShellExtensionClassName);
1240-
if (!win32_registry::deleteKey(key.c_str()))
1240+
if (!win32_registry::DeleteKey(key.c_str()))
12411241
return E_ACCESSDENIED;
12421242
}
12431243

12441244
// Unregister the shell extension for folders
12451245
{
12461246
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\Folders\\shellex\\ContextMenuHandlers\\%s", ShellExtensionClassName);
1247-
if (!win32_registry::deleteKey(key.c_str()))
1247+
if (!win32_registry::DeleteKey(key.c_str()))
12481248
return E_ACCESSDENIED;
12491249
}
12501250

12511251
// Unregister the shell extension for directories
12521252
{
12531253
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\Directory\\shellex\\ContextMenuHandlers\\%s", ShellExtensionClassName);
1254-
if (!win32_registry::deleteKey(key.c_str()))
1254+
if (!win32_registry::DeleteKey(key.c_str()))
12551255
return E_ACCESSDENIED;
12561256
}
12571257

12581258
// Unregister the shell extension for all the file types
12591259
{
12601260
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\*\\shellex\\ContextMenuHandlers\\%s", ShellExtensionClassName);
1261-
if (!win32_registry::deleteKey(key.c_str()))
1261+
if (!win32_registry::DeleteKey(key.c_str()))
12621262
return E_ACCESSDENIED;
12631263
}
12641264

12651265
// Remove the CLSID of this DLL from the registry
12661266
{
12671267
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\CLSID\\%s", guid_str);
1268-
if (!win32_registry::deleteKey(key.c_str()))
1268+
if (!win32_registry::DeleteKey(key.c_str()))
12691269
return E_ACCESSDENIED;
12701270
}
12711271

12721272
// Unregister current and version 1 of our extension
12731273
{
12741274
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\%s", class_name_version1.c_str());
1275-
if (!win32_registry::deleteKey(key.c_str()))
1275+
if (!win32_registry::DeleteKey(key.c_str()))
12761276
return E_ACCESSDENIED;
12771277
}
12781278
{
12791279
std::string key = ra::strings::Format("HKEY_CLASSES_ROOT\\%s", ShellExtensionClassName);
1280-
if (!win32_registry::deleteKey(key.c_str()))
1280+
if (!win32_registry::DeleteKey(key.c_str()))
12811281
return E_ACCESSDENIED;
12821282
}
12831283

0 commit comments

Comments
 (0)