mirror of
https://github.com/Open-Shell/Open-Shell-Menu.git
synced 2026-04-13 20:28:31 +10:00
Modern settings shell folder
Adds virtual shell folder that contains items representing modern settings parsed from
`%windir%\ImmersiveControlPanel\Settings\AllSystemSettings_{253E530E-387D-4BC2-959D-E6F86122E5F2}.xml`.
It can be accessed via `shell:::{82E749ED-B971-4550-BAF7-06AA2BF7E836}` (in explorer).
Item in folder will open given setting page in `Settings` application.
This commit is contained in:
139
Src/StartMenu/StartMenuHelper/ModernSettings.h
Normal file
139
Src/StartMenu/StartMenuHelper/ModernSettings.h
Normal file
@@ -0,0 +1,139 @@
|
||||
// Modern settings helper
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct Blob
|
||||
{
|
||||
const void* data = nullptr;
|
||||
size_t size = 0;
|
||||
};
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
File(const WCHAR* fileName, DWORD desiredAccess, DWORD shareMode, DWORD creationDisposition = OPEN_EXISTING, DWORD flagsAndAttributes = FILE_ATTRIBUTE_NORMAL)
|
||||
{
|
||||
m_handle = ::CreateFile(fileName, desiredAccess, shareMode, nullptr, creationDisposition, flagsAndAttributes, nullptr);
|
||||
}
|
||||
|
||||
~File()
|
||||
{
|
||||
if (m_handle != INVALID_HANDLE_VALUE)
|
||||
::CloseHandle(m_handle);
|
||||
}
|
||||
|
||||
File(const File&) = delete;
|
||||
File& operator=(const File&) = delete;
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return (m_handle != INVALID_HANDLE_VALUE);
|
||||
}
|
||||
|
||||
operator HANDLE() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
uint64_t size() const
|
||||
{
|
||||
LARGE_INTEGER li = {};
|
||||
return ::GetFileSizeEx(m_handle, &li) ? li.QuadPart : (uint64_t)-1;
|
||||
}
|
||||
|
||||
private:
|
||||
HANDLE m_handle;
|
||||
};
|
||||
|
||||
class MappedFile
|
||||
{
|
||||
public:
|
||||
MappedFile(const WCHAR* fileName) : m_file(fileName, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE)
|
||||
{
|
||||
if (m_file)
|
||||
{
|
||||
auto mapping = ::CreateFileMapping(m_file, nullptr, PAGE_READONLY, 0, 0, nullptr);
|
||||
if (mapping)
|
||||
{
|
||||
m_view.data = ::MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
|
||||
if (m_view.data)
|
||||
m_view.size = (size_t)m_file.size();
|
||||
|
||||
::CloseHandle(mapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~MappedFile()
|
||||
{
|
||||
if (m_view.data)
|
||||
::UnmapViewOfFile(m_view.data);
|
||||
}
|
||||
|
||||
MappedFile(const MappedFile&) = delete;
|
||||
MappedFile& operator=(const MappedFile&) = delete;
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return (m_view.data != nullptr);
|
||||
}
|
||||
|
||||
Blob get() const
|
||||
{
|
||||
return m_view;
|
||||
}
|
||||
|
||||
private:
|
||||
File m_file;
|
||||
Blob m_view;
|
||||
};
|
||||
|
||||
class ModernSettings
|
||||
{
|
||||
public:
|
||||
ModernSettings(const wchar_t* fname);
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return m_settings.size();
|
||||
}
|
||||
|
||||
struct Setting
|
||||
{
|
||||
std::wstring_view fileName;
|
||||
|
||||
std::wstring_view deepLink;
|
||||
std::wstring_view icon;
|
||||
std::wstring_view glyph;
|
||||
|
||||
std::wstring_view pageId;
|
||||
std::wstring_view hostId;
|
||||
std::wstring_view groupId;
|
||||
std::wstring_view settingId;
|
||||
std::wstring_view description;
|
||||
std::wstring_view keywords;
|
||||
|
||||
Setting() = default;
|
||||
Setting(const Blob& blob);
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return !fileName.empty();
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<Setting> enumerate() const;
|
||||
Setting get(const std::wstring_view& name) const;
|
||||
|
||||
private:
|
||||
MappedFile m_storage;
|
||||
std::map<std::wstring_view, Blob> m_settings;
|
||||
};
|
||||
|
||||
// retrieve actual instance of ModernSettings
|
||||
std::shared_ptr<ModernSettings> GetModernSettings();
|
||||
Reference in New Issue
Block a user