Runner: move Launcher to its own folder and simplify dll loading (#4379)

This commit is contained in:
Andrey Nekrasov
2020-06-22 13:01:33 +03:00
committed by GitHub
parent bef14f551e
commit 8c6085b933
5 changed files with 22 additions and 47 deletions

View File

@@ -127,48 +127,27 @@ int runner(bool isProcessElevated)
notifications::register_background_toast_handler();
chdir_current_executable();
// Load Powertoys DLLS
// For now only load known DLLs
// Load Powertoys DLLs
std::wstring baseModuleFolder = L"modules/";
std::unordered_set<std::wstring> known_dlls = {
L"ShortcutGuide.dll",
L"fancyzones.dll",
L"PowerRenameExt.dll",
L"Microsoft.Launcher.dll",
L"ImageResizerExt.dll",
L"powerpreview.dll",
L"KeyboardManager.dll"
const std::array<std::wstring_view, 7> knownModules = {
L"modules/FancyZones/fancyzones.dll",
L"modules/FileExplorerPreview/powerpreview.dll",
L"modules/ImageResizer/ImageResizerExt.dll",
L"modules/KeyboardManager/KeyboardManager.dll",
L"modules/Launcher/Microsoft.Launcher.dll",
L"modules/PowerRename/PowerRenameExt.dll",
L"modules/ShortcutGuide/ShortcutGuide.dll",
};
// TODO(stefan): When all modules get their OutputDir delete this and simplify "search for .dll logic"
std::unordered_set<std::wstring> module_folders = {
L"",
L"FileExplorerPreview/",
L"FancyZones/",
L"ImageResizer/",
L"PowerRename/",
L"ShortcutGuide/",
L"KeyboardManager/"
};
for (std::wstring subfolderName : module_folders)
for (const auto & moduleSubdir : knownModules)
{
for (auto& file : std::filesystem::directory_iterator(baseModuleFolder + subfolderName))
try
{
auto module = load_powertoy(moduleSubdir);
modules().emplace(module->get_name(), std::move(module));
}
catch (...)
{
if (file.path().extension() != L".dll")
continue;
if (known_dlls.find(file.path().filename()) == known_dlls.end())
continue;
try
{
auto module = load_powertoy(file.path().wstring());
modules().emplace(module->get_name(), std::move(module));
}
catch (...)
{
}
}
}
// Start initial powertoys

View File

@@ -7,9 +7,9 @@ std::map<std::wstring, PowertoyModule>& modules()
return modules;
}
PowertoyModule load_powertoy(const std::wstring& filename)
PowertoyModule load_powertoy(const std::wstring_view filename)
{
auto handle = winrt::check_pointer(LoadLibraryW(filename.c_str()));
auto handle = winrt::check_pointer(LoadLibraryW(filename.data()));
auto create = reinterpret_cast<powertoy_create_func>(GetProcAddress(handle, "powertoy_create"));
if (!create)
{

View File

@@ -49,5 +49,5 @@ private:
std::unique_ptr<PowertoyModuleIface, PowertoyModuleDeleter> module;
};
PowertoyModule load_powertoy(const std::wstring& filename);
PowertoyModule load_powertoy(const std::wstring_view filename);
std::map<std::wstring, PowertoyModule>& modules();