PowerToys/src/common/utils/registry.h

472 lines
17 KiB
C
Raw Normal View History

2021-10-22 01:02:45 +08:00
#pragma once
#include <Windows.h>
#include <functional>
#include <string>
#include <variant>
#include <vector>
#include <optional>
#include <cassert>
#include <sstream>
2021-10-22 01:02:45 +08:00
#include "../logger/logger.h"
#include "../utils/winapi_error.h"
2021-10-22 01:02:45 +08:00
#include "../version/version.h"
namespace registry
{
namespace install_scope
{
const wchar_t INSTALL_SCOPE_REG_KEY[] = L"Software\\Classes\\powertoys\\";
enum class InstallScope
{
PerMachine = 0,
PerUser,
};
inline const InstallScope get_current_install_scope()
{
// Open HKLM key
HKEY perMachineKey{};
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
INSTALL_SCOPE_REG_KEY,
0,
KEY_READ,
&perMachineKey) != ERROR_SUCCESS)
{
// Open HKCU key
HKEY perUserKey{};
if (RegOpenKeyExW(HKEY_CURRENT_USER,
INSTALL_SCOPE_REG_KEY,
0,
KEY_READ,
&perUserKey) != ERROR_SUCCESS)
{
// both keys are missing
return InstallScope::PerMachine;
}
else
{
DWORD dataSize{};
if (RegGetValueW(
perUserKey,
nullptr,
L"InstallScope",
RRF_RT_REG_SZ,
nullptr,
nullptr,
&dataSize) != ERROR_SUCCESS)
{
// HKCU key is missing
RegCloseKey(perUserKey);
return InstallScope::PerMachine;
}
std::wstring data;
data.resize(dataSize / sizeof(wchar_t));
if (RegGetValueW(
perUserKey,
nullptr,
L"InstallScope",
RRF_RT_REG_SZ,
nullptr,
&data[0],
&dataSize) != ERROR_SUCCESS)
{
// HKCU key is missing
RegCloseKey(perUserKey);
return InstallScope::PerMachine;
}
RegCloseKey(perUserKey);
if (data.contains(L"perUser"))
{
return InstallScope::PerUser;
}
}
}
return InstallScope::PerMachine;
}
}
Registry Preview: complete feature with integration with Settings and the Launcher UX (#23709) * Initial src for Registry Preview Initial collection of files * Update MainWindow.Utilities.cs fixing a few spelling items * Update expect.txt * Update App.xaml.cs * Update MainWindow.Events.cs * Update MainWindow.Utilities.cs * Update MainWindow.xaml.cs * Update expect.txt * Update MainWindow.Events.cs * Rename AddPreviewtoRegfile.reg to AddPreviewToRegfile.reg * Rename RemovePreviewtoRegfile.reg to RemovePreviewToRegfile.reg * Update Resources.resw * Update MainWindow.xaml * Turns on self-contained mode Updates the csproj file to compile the app as self-contained . Includes fixes for code that expected the app to be in an ApplicationContainer. Updates WindowsAppSDK from 1.1.5 to 1.2.230118.102. * Updated to align with StyleCop errors Multiple changes across the codebase that now aligns with StyleCop guidelines. Tested again after the changes, to make sure no new bugs crept in. * Added comments for spell-checker Unclear if this side step should be done or not, but the kxz comes from a GUID and the other three names are constants. * Adding code-custom.dic Comments didn't work; trying a dic file * Added four new terms to expects.txt file Cleaning up attempt to update the spell-checker with dic file and moved it to expects.txt file * Adding one more string Adding one more string for Spell-Check * Adding back egfile Seems this is needed. * Correcting a variable name Seems one of the variable names that changed globally got missed in a XAML file. * Update project to be more PowerToys friendly Tweaking names and output file name to fit better with PowerToys. * First pass at integration into Settings and Launcher This PR is not as large as it seems: - RegistryPreview's source moved around to a "better" directory that makes it look like the whole app changed. It didn't. In fact, I opened it in Beyond Compare and there's not much difference in the RegistryPreview app. - Added RegistryPreviewExt that produces a DLL that the Launcher can run the EXE - Changes to Runner calls the Ext DLL rather than the app - Settings UI got a bunch of changes to enable the Settings page for enable/disable across ViewModels, Views, and string tables. Still todo: - Add "Preview" to .REG files, when the app is enable (and remove it when disabled) - Update the thumbnail-screenshot in the Settings page - Add support for OOBE * Update expect.txt Added REGISTRYPREVIEWEXT for recent changes and corrected an alphabetic sorting error. * Updating project file for Release mode Build failed due to a bad Includes path in Release mode. * Adds REG registration but breaks settings This update will update the HKCU branch of the Registry for REG files: if the app in PowerToys is enabled, it adds a Preview item to the context menu of REG files and disabling in PowerToys removes the menu item. While working on this, I noticed that the application settings were broken, after moving to a self-contained EXE: there must have been old settings from past builds, when it was still using containers and family names. Added TODO's to add a new way to save settings, likely as JSON. * Re-enabled app settings Moved from using ApplicationDataContainer for app settings and now use simple JSON. Also cleaned up handling the scenario where the Launcher send in the PID from PowerToys' main thread. Fixed past spelling errors as well. * Update RegistryPreview.png Captured new screenshot. * Integration into OOBE Integrates new page for Registry Preview into OOBE process. * Removing old comment and unneeded calls Two bits of source removed as they aren't needed any longer Removing a chunk of old commented out code that doesn't make sense anymore. * Merging file from upstream Updating some files due to three merge conflicts from upstream changes and a couple of other changes to keep up. * Update .gitignore Adding two vcxproj files that have local updates for atls.lib locations. * Update Resources.resw Fixing a typo that involved a missing closing tag. * Fix analyzer warnings * Fix CI build * Fix ARM64 build Project file cleanup * Add to installer * expect.txt * Remove unneeded dll * Update MainWindow.xaml.cs Added check for current Theme and adjust TextBox Foreground accordingly. * Update expect.txt Cleaning up merge cruft. * Revert wrong .gitignore changes * Fix ARM installer * Update Brushes for textBox to use Theme based versions Finally figured out how to use the built-in, Theme-aware Brushes for the font colors in the onscreen textBox. Also have it aligning the font color for the hover state. * Align configuration in PowerToys.sln * [installer] Add missing files * Fix bad merge * Fixes for stefansjfw's review Includes: - two new strings for UX localization - adds compatibility section for Windows 10 - fix to only track successful activations - Removes two REG files that were there for examples * Fixes from review from htcfreek Updates: - Fixed an issue where TextBox_TextChanged was firing when you simply opened a file. - Added clamp to prevent files larger than 10MB from being opened. - Added support in the UX to show Keys and Values that are deleted via the file - Added support to specially handle Keys that start with - and Values that have =- in them (delete scenario) - Changed AppBarButton icon for Edit from Rename to NewWindow * Create deleted-folder32.png * Added Registry Preview to GPO * Update expect.txt Updating spellchecker works * Updating Size/Move code for better results - Moved the size/move to the MainWindow layer - Cleaned up the JSON settings handling to avoid an access denied on first run * Improving text handling Changed how special characters are parse, which helps with live entry. * Updates to parsing and other fixes - Renamed the value PNG for parity - Added new error image - Added check that values have " at start and finish. - Added support for a new "ERROR" type for Values - Fixed support for @ versus "@" in values - Fixed bug where Save wasn't activating in all scernarios * Fix signing and versioning * Update src/settings-ui/Settings.UI/ViewModels/RegistryPreviewViewModel.cs Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Apply suggestions from code review Adds Launch button to the settings page. Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update Resources.resw Adding strings for new launch button * Adding new version for GPO Moving to 0.69.0 * More parsing bug fixes - Changes to look for [- instead of -[ for syntax deleting keys (fix for developer's mental hiccup) - Moved [- to top of the decision making stack, as it needs to come before [ - Added new StripEscapedCharacters function for both sides of a Value line - Fixed crashing bug for scenario where no Keys are parsed before a Value * Bug fixes from most recent review. - Dictionary will now be case insensitive when searching for keys - Added tool tips (and strings) to the images of the Keys and Values - Updated delete handling for Keys, so that only the leaf-most node gets marked as deleted; also stops the top most roots from being marked deleted. * Tweaking for @=- Forces the UX to take @=- and treat it as @="" since that's what Registry Editor would do. * Removing unused usings * Updates app description * Update src/gpo/assets/PowerToys.admx Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * cleanup proj file launch process only if module is enabled add process to bugreport process list * Add context menu icon * Update src/modules/registrypreview/RegistryPreviewUI/MainWindow.Utilities.cs Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Use modulesRegistry.h to apply/unapply registry changes * Tweaked window settings Moved the loading of the settings a little later in the initialization code, which gives more time for things to initialize. * Update registry.h Moving the definition out of the detail namespace to the registry name space to fix a compilation issue in RegistryPreviewExt. * Unapply on creation If module is disabled in settings.json, on startup reg entries should be unnaplied. TODO: read m_enabled from settings file on creation * Removing size/move main window Added a TODO comment that responds to the size/position settings that are being saved out in the JSON blob on close as it doesn't always work on every PC, as the MainWindow initializes at different times. * Change to always keep Save As active No reason for this to be disabled, honestly. --------- Co-authored-by: Clint Rutkas <clint@rutkas.com> Co-authored-by: Stefan Markovic <stefan@janeasystems.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com>
2023-03-27 21:21:46 +08:00
template<class>
inline constexpr bool always_false_v = false;
2021-10-22 01:02:45 +08:00
namespace detail
{
struct on_exit
{
std::function<void()> f;
on_exit(std::function<void()> f) :
f{ std::move(f) } {}
~on_exit() { f(); }
};
template<class... Ts>
struct overloaded : Ts...
{
using Ts::operator()...;
};
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
inline const wchar_t* getScopeName(HKEY scope)
{
if (scope == HKEY_LOCAL_MACHINE)
{
return L"HKLM";
}
else if (scope == HKEY_CURRENT_USER)
{
return L"HKCU";
}
else if (scope == HKEY_CLASSES_ROOT)
{
return L"HKCR";
}
else
{
return L"HK??";
}
}
2021-10-22 01:02:45 +08:00
}
2021-10-22 01:02:45 +08:00
struct ValueChange
{
using value_t = std::variant<DWORD, std::wstring>;
static constexpr size_t VALUE_BUFFER_SIZE = 512;
HKEY scope{};
std::wstring path;
std::optional<std::wstring> name; // none == default
value_t value;
bool required = true;
2021-10-22 01:02:45 +08:00
ValueChange(const HKEY scope, std::wstring path, std::optional<std::wstring> name, value_t value, bool required = true) :
scope{ scope }, path{ std::move(path) }, name{ std::move(name) }, value{ std::move(value) }, required{ required }
2021-10-22 01:02:45 +08:00
{
}
std::wstring toString() const
{
using namespace detail;
std::wstring value_str;
std::visit(overloaded{ [&](DWORD value) {
std::wostringstream oss;
oss << value;
value_str = oss.str();
},
[&](const std::wstring& value) { value_str = value; } },
value);
return fmt::format(L"{}\\{}\\{}:{}", detail::getScopeName(scope), path, name ? *name : L"Default", value_str);
}
2021-10-22 01:02:45 +08:00
bool isApplied() const
{
HKEY key{};
if (auto res = RegOpenKeyExW(scope, path.c_str(), 0, KEY_READ, &key); res != ERROR_SUCCESS)
2021-10-22 01:02:45 +08:00
{
Logger::info(L"isApplied of {}: RegOpenKeyExW failed: {}", toString(), get_last_error_or_default(res));
2021-10-22 01:02:45 +08:00
return false;
}
detail::on_exit closeKey{ [key] { RegCloseKey(key); } };
const DWORD expectedType = valueTypeToWinapiType(value);
DWORD retrievedType{};
wchar_t buffer[VALUE_BUFFER_SIZE];
DWORD valueSize = sizeof(buffer);
if (auto res = RegQueryValueExW(key,
name.has_value() ? name->c_str() : nullptr,
0,
&retrievedType,
reinterpret_cast<LPBYTE>(&buffer),
&valueSize);
res != ERROR_SUCCESS)
2021-10-22 01:02:45 +08:00
{
Logger::info(L"isApplied of {}: RegQueryValueExW failed: {}", toString(), get_last_error_or_default(res));
2021-10-22 01:02:45 +08:00
return false;
}
if (expectedType != retrievedType)
{
return false;
}
if (const auto retrievedValue = bufferToValue(buffer, valueSize, retrievedType))
{
return value == retrievedValue;
}
else
{
return false;
}
}
bool apply() const
{
HKEY key{};
if (auto res = RegCreateKeyExW(scope, path.c_str(), 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, &key, nullptr); res !=
ERROR_SUCCESS)
2021-10-22 01:02:45 +08:00
{
Logger::error(L"apply of {}: RegCreateKeyExW failed: {}", toString(), get_last_error_or_default(res));
2021-10-22 01:02:45 +08:00
return false;
}
detail::on_exit closeKey{ [key] { RegCloseKey(key); } };
wchar_t buffer[VALUE_BUFFER_SIZE];
DWORD valueSize;
DWORD valueType;
valueToBuffer(value, buffer, valueSize, valueType);
if (auto res = RegSetValueExW(key,
name.has_value() ? name->c_str() : nullptr,
0,
valueType,
reinterpret_cast<BYTE*>(buffer),
valueSize);
res != ERROR_SUCCESS)
{
Logger::error(L"apply of {}: RegSetValueExW failed: {}", toString(), get_last_error_or_default(res));
return false;
}
return true;
2021-10-22 01:02:45 +08:00
}
bool unApply() const
2021-10-22 01:02:45 +08:00
{
HKEY key{};
if (auto res = RegOpenKeyExW(scope, path.c_str(), 0, KEY_ALL_ACCESS, &key); res != ERROR_SUCCESS)
2021-10-22 01:02:45 +08:00
{
Logger::error(L"unApply of {}: RegOpenKeyExW failed: {}", toString(), get_last_error_or_default(res));
2021-10-22 01:02:45 +08:00
return false;
}
detail::on_exit closeKey{ [key] { RegCloseKey(key); } };
// delete the value itself
if (auto res = RegDeleteKeyValueW(scope, path.c_str(), name.has_value() ? name->c_str() : nullptr); res != ERROR_SUCCESS)
2021-10-22 01:02:45 +08:00
{
Logger::error(L"unApply of {}: RegDeleteKeyValueW failed: {}", toString(), get_last_error_or_default(res));
2021-10-22 01:02:45 +08:00
return false;
}
// Check if the path doesn't contain anything and delete it if so
DWORD nValues = 0;
DWORD maxValueLen = 0;
const auto ok =
RegQueryInfoKeyW(
key, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &nValues, nullptr, &maxValueLen, nullptr, nullptr) ==
ERROR_SUCCESS;
if (ok && (!nValues || !maxValueLen))
{
RegDeleteTreeW(scope, path.c_str());
}
return true;
}
bool requiresElevation() const { return scope == HKEY_LOCAL_MACHINE; }
private:
static DWORD valueTypeToWinapiType(const value_t& v)
{
return std::visit(
[](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, DWORD>)
return REG_DWORD;
else if constexpr (std::is_same_v<T, std::wstring>)
return REG_SZ;
else
static_assert(always_false_v<T>, "support for this registry type is not implemented");
},
v);
}
static void valueToBuffer(const value_t& value, wchar_t buffer[VALUE_BUFFER_SIZE], DWORD& valueSize, DWORD& type)
{
using detail::overloaded;
std::visit(overloaded{ [&](DWORD value) {
*reinterpret_cast<DWORD*>(buffer) = value;
type = REG_DWORD;
valueSize = sizeof(value);
},
[&](const std::wstring& value) {
assert(value.size() < VALUE_BUFFER_SIZE);
value.copy(buffer, value.size());
type = REG_SZ;
valueSize = static_cast<DWORD>(sizeof(wchar_t) * value.size());
} },
value);
}
static std::optional<value_t> bufferToValue(const wchar_t buffer[VALUE_BUFFER_SIZE],
const DWORD valueSize,
const DWORD type)
{
switch (type)
{
case REG_DWORD:
return *reinterpret_cast<const DWORD*>(buffer);
2021-10-22 01:02:45 +08:00
case REG_SZ:
{
if (!valueSize)
{
return std::wstring{};
}
std::wstring result{ buffer, valueSize / sizeof(wchar_t) };
while (result[result.size() - 1] == L'\0')
{
result.resize(result.size() - 1);
}
return result;
}
default:
return std::nullopt;
}
}
};
struct ChangeSet
2021-10-22 01:02:45 +08:00
{
std::vector<ValueChange> changes;
bool isApplied() const
{
for (const auto& c : changes)
{
if (c.required && !c.isApplied())
2021-10-22 01:02:45 +08:00
{
return false;
}
}
return true;
}
bool apply() const
{
bool ok = true;
for (const auto& c : changes)
{
ok = (c.apply()||!c.required) && ok;
2021-10-22 01:02:45 +08:00
}
return ok;
}
bool unApply() const
2021-10-22 01:02:45 +08:00
{
bool ok = true;
for (const auto& c : changes)
{
ok = (c.unApply()||!c.required) && ok;
2021-10-22 01:02:45 +08:00
}
return ok;
}
};
const inline std::wstring DOTNET_COMPONENT_CATEGORY_CLSID = L"{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}";
const inline std::wstring ITHUMBNAIL_PROVIDER_CLSID = L"{E357FCCD-A995-4576-B01F-234630154E96}";
const inline std::wstring IPREVIEW_HANDLER_CLSID = L"{8895b1c6-b41f-4c1c-a562-0d564250836f}";
namespace shellex
{
enum PreviewHandlerType
{
preview,
thumbnail
};
inline registry::ChangeSet generatePreviewHandler(const PreviewHandlerType handlerType,
2021-10-22 01:02:45 +08:00
const bool perUser,
std::wstring handlerClsid,
std::wstring powertoysVersion,
std::wstring fullPathToHandler,
std::wstring className,
std::wstring displayName,
std::vector<std::wstring> fileTypes,
Self-contained .NET (#22217) * dotnet sc * MD preview - C# app - working self-contained * Gcode preview - C# app * DevFiles preview - C# app * Fix passing path with spaces as cmd arg and monacocpp proj file * Pdf preview - C# app * Svg preview - C# app * Fix comment * Gcode thumbnail - C# app TODO: - installer - why IThumbnailProvider and IIntializeWithFile doesn't work? * Pdf thumbnail - C# app TODO: - installer - why IThumbnailProvider and IIntializeWithFile doesn't work? * Pdf thumbnail - C# app TODO: - installer - why IThumbnailProvider and IIntializeWithFile doesn't work? * Fix GcodeThumbnailProviderCpp.vcxproj * Svg thumbnail - C# app TODO: - installer - why IThumbnailProvider and IIntializeWithFile doesn't work? * Fix Svg tests * Thumbnail providers - installer * Self-contained Hosts and FileLocksmith * Fix hardcoded <RuntimeIdentifier> * Remove unneeded files * Try to fix Nuget in PR CI * Prefix new dlls with PowerToys. Sign new dlls and exes * Add new .exe files to ProcessList * ci: debug by listing all env vars * ci: try setting variable in the right ci file * Bring back hardcoded RuntimeIdentifier * ci: Add comment and remove debug action * Remove unneeded lib * [WIP] Platform conditional dotnet files & hardlinks * Cleanup * Update expect.txt * Test fix - ARM installer * Fix uninstall bug * Update docs * Fix failing test * Add dll details * Minor cleanup * Improve resizing * Add some logs * Test fix - release build * Remove InvokeOnControlThread * Test fix: logger initialization * Fix arm64 installer Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Dustin L. Howett <dustin@howett.net>
2022-12-14 20:37:23 +08:00
std::wstring fileKindType = L"")
2021-10-22 01:02:45 +08:00
{
const HKEY scope = perUser ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
std::wstring clsidPath = L"Software\\Classes\\CLSID";
clsidPath += L'\\';
clsidPath += handlerClsid;
std::wstring inprocServerPath = clsidPath;
inprocServerPath += L'\\';
inprocServerPath += L"InprocServer32";
std::wstring assemblyKeyValue;
if (const auto lastDotPos = className.rfind(L'.'); lastDotPos != std::wstring::npos)
{
assemblyKeyValue = L"PowerToys." + className.substr(lastDotPos + 1);
2021-10-22 01:02:45 +08:00
}
else
{
assemblyKeyValue = L"PowerToys." + className;
2021-10-22 01:02:45 +08:00
}
assemblyKeyValue += L", Version=";
assemblyKeyValue += powertoysVersion;
assemblyKeyValue += L", Culture=neutral";
std::wstring versionPath = inprocServerPath;
versionPath += L'\\';
versionPath += powertoysVersion;
using vec_t = std::vector<registry::ValueChange>;
// TODO: verify that we actually need all of those
vec_t changes = { { scope, clsidPath, L"DisplayName", displayName },
{ scope, clsidPath, std::nullopt, className },
{ scope, inprocServerPath, std::nullopt, fullPathToHandler },
{ scope, inprocServerPath, L"Assembly", assemblyKeyValue },
{ scope, inprocServerPath, L"Class", className },
Self-contained .NET (#22217) * dotnet sc * MD preview - C# app - working self-contained * Gcode preview - C# app * DevFiles preview - C# app * Fix passing path with spaces as cmd arg and monacocpp proj file * Pdf preview - C# app * Svg preview - C# app * Fix comment * Gcode thumbnail - C# app TODO: - installer - why IThumbnailProvider and IIntializeWithFile doesn't work? * Pdf thumbnail - C# app TODO: - installer - why IThumbnailProvider and IIntializeWithFile doesn't work? * Pdf thumbnail - C# app TODO: - installer - why IThumbnailProvider and IIntializeWithFile doesn't work? * Fix GcodeThumbnailProviderCpp.vcxproj * Svg thumbnail - C# app TODO: - installer - why IThumbnailProvider and IIntializeWithFile doesn't work? * Fix Svg tests * Thumbnail providers - installer * Self-contained Hosts and FileLocksmith * Fix hardcoded <RuntimeIdentifier> * Remove unneeded files * Try to fix Nuget in PR CI * Prefix new dlls with PowerToys. Sign new dlls and exes * Add new .exe files to ProcessList * ci: debug by listing all env vars * ci: try setting variable in the right ci file * Bring back hardcoded RuntimeIdentifier * ci: Add comment and remove debug action * Remove unneeded lib * [WIP] Platform conditional dotnet files & hardlinks * Cleanup * Update expect.txt * Test fix - ARM installer * Fix uninstall bug * Update docs * Fix failing test * Add dll details * Minor cleanup * Improve resizing * Add some logs * Test fix - release build * Remove InvokeOnControlThread * Test fix: logger initialization * Fix arm64 installer Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Dustin L. Howett <dustin@howett.net>
2022-12-14 20:37:23 +08:00
{ scope, inprocServerPath, L"ThreadingModel", L"Apartment" } };
Preview Handler for developer files (#15138) * Create Readme.md * Update Readme.md * Rebased to master * started integrating * Resolve merge conflict * Fixed merge conflict * Edited expect.txt * Tried implementig interfaces * Push * Push * push * push * Deleted no longer used files * push * push * Thanks @jaimecbernando for helping * can load via url * getting stuff semi stubbed out * full render without passing vars * making sure we clearly label the file was us * push * push * push (does not work) * Push * push * Added file size limit of 3 Kilobyte in standalone App (MoncaoPreview) * Added monacosrc to excludes.txt (spell checker) * Fixed XAMLHost loading issue and changed namespace of Settings.cs * push * Restructred some code in MonacoPreviewHandler (not functional) * MonacoPreview changes: Added maximal file size and error message as values in Settings.cs Increased maxFileSize to 10 KB Renamed variables and formed code according to style guidelines Added many comments Deleted usused code Added unimplemented(?) NavigationStarted method to prevent navigation in WebView Fixed scrollbar issues (Not beautiful, but still better) Removed never seen laoding window Added some debug information as well as some Exceptions. MonacoPreviewHandler Changes: Changed order of code executions (still not usable) * Push * Push * Push * push * Oh my god, it works * Added loading screen and resize * Added some comments, changed variable names and integrated some stuff from MonacoPreview to MonacoPreviewHandler; * Monaco Preview Handler: * Removed accessibilityhelpurl * Made background of loading screen like theme selected * dev tools open now in Debug mode automatically * Fixed error message for too big file size * push * Fixed a tiny bug * Updated a NuGet Pasckage * Removed some to-do points in FileHandler.cs and added them to #14957 * Removed some to-do points in FileHandler.cs and added them to #14957. Supressed a warning and styled a function better in PrebiewHandlerCommon * Fixed 2 comment typos and a font that didn't load. (Sadly his required enable CORS again :( ) * Removed old standalone project * Removed old unused files & rebase to master #1 * Deleted everything from the monaco source code expect the minified version * Push * Added summary of all functions. Restructred/simplified/clarified some code. * Added resources * Update bug_report.yml * Update translation_issue.yml * Update expect.txt * Update ProofOfConcept/MonacoPreview/monacoPreviewHandler/index.html Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com> * Update ProofOfConcept/MonacoPreview/monacoPreviewHandler/MonacoPreviewHandlerControl.cs Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com> * Update ProofOfConcept/MonacoPreview/monacoPreviewHandler/Resources.resx Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com> * Added some additional file types * Added additional file types * Moved to a json file for the available languages and some other changes * Added error message when WebView2 is not installed * Remoing throw error * Update expect.txt * Update excludes.txt * Update excludes.txt * Integrate Monaco preview handler into PowerToys * Update excludes.txt * Ignore .svg extension * Update signing list * Update signing list #2 * Changed monaco string * fix * Fixed wrong JSON field and changed date of Copyright * Added check if WebView is installed * Added error when webview2 is not installed * Increased file size limit to 50kb * Added new file generator for languages.json * Remove unvisible symbol at the beggining of the file * Regenerate resx file * Update MonacoPreviewHandler.csproj * tweaking script to ignore 1.0 check on theme dll * Update src/modules/previewpane/MonacoPreviewHandler/Properties/Resources.resx Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> * Update src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> * Update src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> * Update src/settings-ui/Settings.UI/Strings/en-us/Resources.resw Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> * Update excludes.txt * Update src/modules/previewpane/powerpreview/Resources.resx Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> * Check and install WebView2 if needed * Run spellcheck script * Update ESRPSigning_core.json adding font * Update versionAndSignCheck.ps1 adding fonts to verify * Adding in Monaco usage * Update NOTICE.md * Update ESRPSigning_core.json * expect.txt update * Use Common.UI/ThemeManager.cs * No user facing strings should reference Monaco * Fix build error * monaco devdocs (#15691) * Create update-monaco-editor.md * Update and rename update-monaco-editor.md to readme.md * Update doc/devdocs/modules/powerpreview/monaco/readme.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update doc/devdocs/modules/powerpreview/monaco/readme.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update doc/devdocs/modules/powerpreview/monaco/readme.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update readme.md * Update readme.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Fix WebView installer condition * Using system.text.json * Update ESRPSigning_core.json * Remove Newtonsoft.Json.dll from installer * Revert "WinUI bump (#15707)" This reverts commit b6a207c4b69b797dc5589aebbe162ef1f95fe83f. * Revert "Update Settings.UI.csproj (#15704)" This reverts commit 1a25dacc735621dc62a060fd8e6f52c86a1013cc. Co-authored-by: Clint Rutkas <clint@rutkas.com> Co-authored-by: Aaron Junker <aaron.junker@sus.schulen-stadtsh.ch> Co-authored-by: Clint Rutkas <crutkas@microsoft.com> Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com> Co-authored-by: Stefan Markovic <stefan@janeasystems.com> Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
2022-01-26 04:02:10 +08:00
for (const auto& fileType : fileTypes)
{
std::wstring fileAssociationPath = L"Software\\Classes\\";
fileAssociationPath += fileType;
fileAssociationPath += L"\\shellex\\";
fileAssociationPath += handlerType == PreviewHandlerType::preview ? IPREVIEW_HANDLER_CLSID : ITHUMBNAIL_PROVIDER_CLSID;
changes.push_back({ scope, fileAssociationPath, std::nullopt, handlerClsid });
if (!fileKindType.empty())
{
// Registering a file type as a kind needs to be done at the HKEY_LOCAL_MACHINE level.
// Make it optional as well so that we don't fail registering the handler if we can't write to HKEY_LOCAL_MACHINE.
std::wstring kindMapPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\KindMap";
changes.push_back({ HKEY_LOCAL_MACHINE, kindMapPath, fileType, fileKindType, false});
}
if (handlerType == PreviewHandlerType::preview && fileType == L".reg")
{
// this regfile registry key has precedence over Software\Classes\.reg for .reg files
std::wstring regfilePath = L"Software\\Classes\\regfile\\shellex\\" + IPREVIEW_HANDLER_CLSID + L"\\";
changes.push_back({ scope, regfilePath, std::nullopt, handlerClsid });
}
Preview Handler for developer files (#15138) * Create Readme.md * Update Readme.md * Rebased to master * started integrating * Resolve merge conflict * Fixed merge conflict * Edited expect.txt * Tried implementig interfaces * Push * Push * push * push * Deleted no longer used files * push * push * Thanks @jaimecbernando for helping * can load via url * getting stuff semi stubbed out * full render without passing vars * making sure we clearly label the file was us * push * push * push (does not work) * Push * push * Added file size limit of 3 Kilobyte in standalone App (MoncaoPreview) * Added monacosrc to excludes.txt (spell checker) * Fixed XAMLHost loading issue and changed namespace of Settings.cs * push * Restructred some code in MonacoPreviewHandler (not functional) * MonacoPreview changes: Added maximal file size and error message as values in Settings.cs Increased maxFileSize to 10 KB Renamed variables and formed code according to style guidelines Added many comments Deleted usused code Added unimplemented(?) NavigationStarted method to prevent navigation in WebView Fixed scrollbar issues (Not beautiful, but still better) Removed never seen laoding window Added some debug information as well as some Exceptions. MonacoPreviewHandler Changes: Changed order of code executions (still not usable) * Push * Push * Push * push * Oh my god, it works * Added loading screen and resize * Added some comments, changed variable names and integrated some stuff from MonacoPreview to MonacoPreviewHandler; * Monaco Preview Handler: * Removed accessibilityhelpurl * Made background of loading screen like theme selected * dev tools open now in Debug mode automatically * Fixed error message for too big file size * push * Fixed a tiny bug * Updated a NuGet Pasckage * Removed some to-do points in FileHandler.cs and added them to #14957 * Removed some to-do points in FileHandler.cs and added them to #14957. Supressed a warning and styled a function better in PrebiewHandlerCommon * Fixed 2 comment typos and a font that didn't load. (Sadly his required enable CORS again :( ) * Removed old standalone project * Removed old unused files & rebase to master #1 * Deleted everything from the monaco source code expect the minified version * Push * Added summary of all functions. Restructred/simplified/clarified some code. * Added resources * Update bug_report.yml * Update translation_issue.yml * Update expect.txt * Update ProofOfConcept/MonacoPreview/monacoPreviewHandler/index.html Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com> * Update ProofOfConcept/MonacoPreview/monacoPreviewHandler/MonacoPreviewHandlerControl.cs Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com> * Update ProofOfConcept/MonacoPreview/monacoPreviewHandler/Resources.resx Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com> * Added some additional file types * Added additional file types * Moved to a json file for the available languages and some other changes * Added error message when WebView2 is not installed * Remoing throw error * Update expect.txt * Update excludes.txt * Update excludes.txt * Integrate Monaco preview handler into PowerToys * Update excludes.txt * Ignore .svg extension * Update signing list * Update signing list #2 * Changed monaco string * fix * Fixed wrong JSON field and changed date of Copyright * Added check if WebView is installed * Added error when webview2 is not installed * Increased file size limit to 50kb * Added new file generator for languages.json * Remove unvisible symbol at the beggining of the file * Regenerate resx file * Update MonacoPreviewHandler.csproj * tweaking script to ignore 1.0 check on theme dll * Update src/modules/previewpane/MonacoPreviewHandler/Properties/Resources.resx Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> * Update src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> * Update src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> * Update src/settings-ui/Settings.UI/Strings/en-us/Resources.resw Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> * Update excludes.txt * Update src/modules/previewpane/powerpreview/Resources.resx Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> * Check and install WebView2 if needed * Run spellcheck script * Update ESRPSigning_core.json adding font * Update versionAndSignCheck.ps1 adding fonts to verify * Adding in Monaco usage * Update NOTICE.md * Update ESRPSigning_core.json * expect.txt update * Use Common.UI/ThemeManager.cs * No user facing strings should reference Monaco * Fix build error * monaco devdocs (#15691) * Create update-monaco-editor.md * Update and rename update-monaco-editor.md to readme.md * Update doc/devdocs/modules/powerpreview/monaco/readme.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update doc/devdocs/modules/powerpreview/monaco/readme.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update doc/devdocs/modules/powerpreview/monaco/readme.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update readme.md * Update readme.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Fix WebView installer condition * Using system.text.json * Update ESRPSigning_core.json * Remove Newtonsoft.Json.dll from installer * Revert "WinUI bump (#15707)" This reverts commit b6a207c4b69b797dc5589aebbe162ef1f95fe83f. * Revert "Update Settings.UI.csproj (#15704)" This reverts commit 1a25dacc735621dc62a060fd8e6f52c86a1013cc. Co-authored-by: Clint Rutkas <clint@rutkas.com> Co-authored-by: Aaron Junker <aaron.junker@sus.schulen-stadtsh.ch> Co-authored-by: Clint Rutkas <crutkas@microsoft.com> Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com> Co-authored-by: Stefan Markovic <stefan@janeasystems.com> Co-authored-by: Franky Chen <franky920920+gpg@gmail.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
2022-01-26 04:02:10 +08:00
}
2021-10-22 01:02:45 +08:00
if (handlerType == PreviewHandlerType::preview)
{
const std::wstring previewHostClsid = L"{6d2b5079-2f0b-48dd-ab7f-97cec514d30b}";
const std::wstring previewHandlerListPath = LR"(Software\Microsoft\Windows\CurrentVersion\PreviewHandlers)";
changes.push_back({ scope, clsidPath, L"AppID", previewHostClsid });
changes.push_back({ scope, previewHandlerListPath, handlerClsid, displayName });
}
return registry::ChangeSet{ .changes = std::move(changes) };
2021-10-22 01:02:45 +08:00
}
}
}