Skip to content

Commit bf00d99

Browse files
committed
Created new interface IIconResolutionService and a default implementation LegacyIconResolutionService.
1 parent 98373af commit bf00d99

10 files changed

Lines changed: 248 additions & 0 deletions

File tree

src/core/App.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ namespace shellanything
137137
return mRandom;
138138
}
139139

140+
void App::SetIconResolutionService(IIconResolutionService* instance)
141+
{
142+
mIconResolutionService = instance;
143+
}
144+
145+
IIconResolutionService* App::GetIconResolutionService()
146+
{
147+
return mIconResolutionService;
148+
}
149+
140150
bool App::IsTestingEnvironment()
141151
{
142152
std::string process_path = ra::process::GetCurrentProcessPath();

src/core/App.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "IClipboardService.h"
3131
#include "IKeyboardService.h"
3232
#include "IRandomService.h"
33+
#include "IIconResolutionService.h"
3334

3435
#include <string>
3536

@@ -144,6 +145,21 @@ namespace shellanything
144145
/// <returns>Returns a pointer of the instance that is currently set. Returns NULL if no service is set.</returns>
145146
IRandomService* GetRandomService();
146147

148+
/// <summary>
149+
/// Set the current application icon resolution service.
150+
/// </summary>
151+
/// <remarks>
152+
/// If a service instance is already set, the caller must properly destroy the old instance.
153+
/// </remarks>
154+
/// <param name="instance">A valid instance of a the service.</param>
155+
void SetIconResolutionService(IIconResolutionService* instance);
156+
157+
/// <summary>
158+
/// Get the current application random service.
159+
/// </summary>
160+
/// <returns>Returns a pointer of the instance that is currently set. Returns NULL if no service is set.</returns>
161+
IIconResolutionService* GetIconResolutionService();
162+
147163
/// <summary>
148164
/// Test if application is loaded in a test environment (main's tests executable).
149165
/// </summary>
@@ -199,6 +215,7 @@ namespace shellanything
199215
IClipboardService* mClipboard;
200216
IKeyboardService* mKeyboard;
201217
IRandomService* mRandom;
218+
IIconResolutionService* mIconResolutionService;
202219
};
203220

204221

src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(SHELLANYTHING_CORE_HEADER_FILES ""
1818
${CMAKE_SOURCE_DIR}/src/core/Environment.h
1919
${CMAKE_SOURCE_DIR}/src/core/Icon.h
2020
${CMAKE_SOURCE_DIR}/src/core/IObject.h
21+
${CMAKE_SOURCE_DIR}/src/core/IIconResolutionService.h
2122
${CMAKE_SOURCE_DIR}/src/core/IKeyboardService.h
2223
${CMAKE_SOURCE_DIR}/src/core/ILiveProperty.h
2324
${CMAKE_SOURCE_DIR}/src/core/IClipboardService.h
@@ -62,6 +63,7 @@ add_library(sa.core SHARED
6263
IAttributeValidator.cpp
6364
Icon.cpp
6465
IObject.cpp
66+
IIconResolutionService.cpp
6567
IKeyboardService.cpp
6668
ILiveProperty.cpp
6769
IClipboardService.cpp
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**********************************************************************************
2+
* MIT License
3+
*
4+
* Copyright (c) 2018 Antoine Beauchamp
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*********************************************************************************/
24+
25+
#include "IIconResolutionService.h"
26+
27+
namespace shellanything
28+
{
29+
30+
IIconResolutionService::IIconResolutionService()
31+
{
32+
}
33+
34+
IIconResolutionService::~IIconResolutionService()
35+
{
36+
}
37+
38+
} //namespace shellanything

src/core/IIconResolutionService.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**********************************************************************************
2+
* MIT License
3+
*
4+
* Copyright (c) 2018 Antoine Beauchamp
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*********************************************************************************/
24+
25+
#ifndef SA_IICON_RESOLUTION_SERVICE_H
26+
#define SA_IICON_RESOLUTION_SERVICE_H
27+
28+
#include "shellanything/export.h"
29+
#include "shellanything/config.h"
30+
#include "Icon.h"
31+
32+
#include <stdint.h>
33+
34+
namespace shellanything
35+
{
36+
/// <summary>
37+
/// Abstract icon resolution service class.
38+
/// Used to decouple the core from the operating system.
39+
/// </summary>
40+
class SHELLANYTHING_EXPORT IIconResolutionService
41+
{
42+
public:
43+
IIconResolutionService();
44+
virtual ~IIconResolutionService();
45+
46+
private:
47+
// Disable and copy constructor, dtor and copy operator
48+
IIconResolutionService(const IIconResolutionService&);
49+
IIconResolutionService& operator=(const IIconResolutionService&);
50+
public:
51+
52+
/// <summary>
53+
/// Resolve an icon's file extension to the system icon for this file extension.
54+
/// </summary>
55+
/// <param name="icon">The icon that have its fileextension's attribute set to resolve.</param>
56+
/// <returns>Returns true if the operation is successful. Returns false otherwise.</returns>
57+
virtual bool ResolveFileExtensionIcon(Icon & icon) = 0;
58+
59+
};
60+
61+
} //namespace shellanything
62+
63+
#endif //SA_IICON_RESOLUTION_SERVICE_H

src/shellextension/dllmain.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "WindowsClipboardService.h"
4040
#include "WindowsKeyboardService.h"
4141
#include "PcgRandomService.h"
42+
#include "LegacyIconResolutionService.h"
4243

4344
#include "shellanything/version.h"
4445
#include "shellanything/config.h"
@@ -55,6 +56,7 @@ shellanything::IRegistryService* registry_service = NULL;
5556
shellanything::IClipboardService* clipboard_service = NULL;
5657
shellanything::IKeyboardService* keyboard_service = NULL;
5758
shellanything::IRandomService* random_service = NULL;
59+
shellanything::IIconResolutionService* icon_resolution_service = NULL;
5860

5961
class CShellAnythingModule : public ATL::CAtlDllModuleT< CShellAnythingModule >
6062
{
@@ -198,6 +200,10 @@ extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpRe
198200
random_service = new shellanything::PcgRandomService();
199201
app.SetRandomService(random_service);
200202

203+
// Setup an active icon resolution service in ShellAnything's core.
204+
icon_resolution_service = new shellanything::LegacyIconResolutionService();
205+
app.SetIconResolutionService(icon_resolution_service);
206+
201207
// Setup and starting application
202208
app.Start();
203209

@@ -218,11 +224,13 @@ extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpRe
218224
delete clipboard_service;
219225
delete registry_service;
220226
delete logger_service;
227+
delete icon_resolution_service;
221228
random_service = NULL;
222229
keyboard_service = NULL;
223230
clipboard_service = NULL;
224231
registry_service = NULL;
225232
logger_service = NULL;
233+
icon_resolution_service = NULL;
226234
}
227235
}
228236

src/tests/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "WindowsClipboardService.h"
5151
#include "TestKeyboardService.h"
5252
#include "PcgRandomService.h"
53+
#include "LegacyIconResolutionService.h"
5354
#include "ConfigManager.h"
5455

5556
using namespace ra;
@@ -147,6 +148,10 @@ int main(int argc, char** argv)
147148
shellanything::IRandomService* random_service = new shellanything::PcgRandomService();
148149
app.SetRandomService(random_service);
149150

151+
// Setup an active icon resolution service in ShellAnything's core.
152+
shellanything::IIconResolutionService* icon_resolution_service = new shellanything::LegacyIconResolutionService();
153+
app.SetIconResolutionService(icon_resolution_service);
154+
150155
//Issue #60 - Unit tests cannot execute from installation directory.
151156
//Create log directory under the current executable.
152157
//When running tests from a developer environment, the log directory is expected to have write access.
@@ -208,11 +213,13 @@ int main(int argc, char** argv)
208213
delete clipboard_service;
209214
delete registry_service;
210215
delete logger_service;
216+
delete icon_resolution_service;
211217
random_service = NULL;
212218
keyboard_service = NULL;
213219
clipboard_service = NULL;
214220
registry_service = NULL;
215221
logger_service = NULL;
222+
icon_resolution_service = NULL;
216223

217224
return wResult; // returns 0 if all the tests are successful, or 1 otherwise
218225
}

src/windows/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
add_library(sa.windows SHARED
22
dllmain.cpp
3+
LegacyIconResolutionService.cpp
4+
LegacyIconResolutionService.h
35
Win32Clipboard.cpp
46
Win32Clipboard.h
57
WindowsClipboardService.cpp
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**********************************************************************************
2+
* MIT License
3+
*
4+
* Copyright (c) 2018 Antoine Beauchamp
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*********************************************************************************/
24+
25+
#include "LegacyIconResolutionService.h"
26+
27+
namespace shellanything
28+
{
29+
LegacyIconResolutionService::LegacyIconResolutionService()
30+
{
31+
}
32+
33+
LegacyIconResolutionService::~LegacyIconResolutionService()
34+
{
35+
}
36+
37+
bool LegacyIconResolutionService::ResolveFileExtensionIcon(Icon& icon)
38+
{
39+
return false;
40+
}
41+
42+
} //namespace shellanything
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**********************************************************************************
2+
* MIT License
3+
*
4+
* Copyright (c) 2018 Antoine Beauchamp
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*********************************************************************************/
24+
25+
#ifndef SA_LEGACY_ICON_RESOLUTION_SERVICE_H
26+
#define SA_LEGACY_ICON_RESOLUTION_SERVICE_H
27+
28+
#include "sa_windows_export.h"
29+
#include "IIconResolutionService.h"
30+
31+
namespace shellanything
32+
{
33+
/// <summary>
34+
/// Legacy implementation class of IIconResolutionService that resolved by browsing Windows Registry.
35+
/// </summary>
36+
class SA_WINDOWS_EXPORT LegacyIconResolutionService : public virtual IIconResolutionService
37+
{
38+
public:
39+
LegacyIconResolutionService();
40+
virtual ~LegacyIconResolutionService();
41+
42+
private:
43+
// Disable and copy constructor, dtor and copy operator
44+
LegacyIconResolutionService(const LegacyIconResolutionService&);
45+
LegacyIconResolutionService& operator=(const LegacyIconResolutionService&);
46+
public:
47+
48+
/// <summary>
49+
/// Resolve an icon's file extension to the system icon for this file extension.
50+
/// </summary>
51+
/// <param name="icon">The icon that have its fileextension's attribute set to resolve.</param>
52+
/// <returns>Returns true if the operation is successful. Returns false otherwise.</returns>
53+
virtual bool ResolveFileExtensionIcon(Icon& icon);
54+
55+
};
56+
57+
} //namespace shellanything
58+
59+
#endif //SA_LEGACY_ICON_RESOLUTION_SERVICE_H

0 commit comments

Comments
 (0)