aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2023-12-19 12:28:26 +0100
committerKarsten Heimrich <karsten.heimrich@qt.io>2024-01-08 14:18:09 +0000
commita7259c74555cfae7f124bb5ac48fbe716280bfef (patch)
treeb2232e8d57b2e93fd2cd0894464d9e9a447ce20b
parent318b8219e1ff5cf7e499cad62b2322717230e2ed (diff)
Split Utils class into partial files and introduce Utils.Registry.cs
This commit refactors the Utils class by splitting it into partial files to improve maintainability. The new registry-related code is now located in Utils.Registry.cs, providing better organization and separation of concerns. Change-Id: Ia6bb3bf307c71dd3f1811ab4a955c05a0115fcb8 Reviewed-by: Miguel Costa <miguel.costa@qt.io>
-rw-r--r--QtVsTools.Core/Common/Utils.Registry.cs40
-rw-r--r--QtVsTools.Core/Common/Utils.cs2
-rw-r--r--QtVsTools.Core/QtVsTools.Core.csproj3
3 files changed, 43 insertions, 2 deletions
diff --git a/QtVsTools.Core/Common/Utils.Registry.cs b/QtVsTools.Core/Common/Utils.Registry.cs
new file mode 100644
index 00000000..38173a0f
--- /dev/null
+++ b/QtVsTools.Core/Common/Utils.Registry.cs
@@ -0,0 +1,40 @@
+/**************************************************************************************************
+ Copyright (C) 2023 The Qt Company Ltd.
+ SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+**************************************************************************************************/
+
+using System;
+using Microsoft.Win32;
+
+namespace QtVsTools.Core.Common
+{
+ public static partial class Utils
+ {
+ private static void CopyRegistryKeys(string sourcePath, string destinationPath)
+ {
+ using var sourceKey = Registry.CurrentUser.OpenSubKey(sourcePath);
+ using var destinationKey = Registry.CurrentUser.CreateSubKey(destinationPath);
+
+ // Copy values
+ foreach (var valueName in sourceKey?.GetValueNames() ?? Array.Empty<string>()) {
+ if (sourceKey?.GetValue(valueName) is {} value)
+ destinationKey?.SetValue(valueName, value);
+ }
+
+ // Recursively copy sub keys
+ foreach (var subKeyName in sourceKey?.GetSubKeyNames() ?? Array.Empty<string>()) {
+ var subKeyPath = $"{sourcePath}\\{subKeyName}";
+ CopyRegistryKeys(subKeyPath, $"{destinationPath}\\{subKeyName}");
+ }
+ }
+
+ public static void MoveRegistryKeys(string sourcePath, string destinationPath)
+ {
+ // Copy keys and values
+ CopyRegistryKeys(sourcePath, destinationPath);
+
+ // Delete source keys recursively
+ Registry.CurrentUser.DeleteSubKeyTree(sourcePath, false);
+ }
+ }
+}
diff --git a/QtVsTools.Core/Common/Utils.cs b/QtVsTools.Core/Common/Utils.cs
index 55ee4925..3704de7a 100644
--- a/QtVsTools.Core/Common/Utils.cs
+++ b/QtVsTools.Core/Common/Utils.cs
@@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace QtVsTools.Core.Common
{
- public static class Utils
+ public static partial class Utils
{
public static class ProjectTypes
{
diff --git a/QtVsTools.Core/QtVsTools.Core.csproj b/QtVsTools.Core/QtVsTools.Core.csproj
index 22190705..0aafaf94 100644
--- a/QtVsTools.Core/QtVsTools.Core.csproj
+++ b/QtVsTools.Core/QtVsTools.Core.csproj
@@ -131,13 +131,14 @@
<Compile Include="Common\Json\Serializable.cs" />
<Compile Include="Common\Json\SerializableEnum.cs" />
<Compile Include="Common\Json\Serializer.cs" />
- <Compile Include="Common\Utils.cs" />
<Compile Include="Common\LazyFactory.cs" />
<Compile Include="Common\NativeAPI.cs" />
<Compile Include="Common\PriorityQueue.cs" />
<Compile Include="Common\Prototyped.cs" />
<Compile Include="Common\PunisherQueue.cs" />
<Compile Include="Common\Timestamp.cs" />
+ <Compile Include="Common\Utils.cs" />
+ <Compile Include="Common\Utils.Registry.cs" />
<Compile Include="Common\VsTemplate.cs" />
<Compile Include="CompilerToolWrapper.cs" />
<Compile Include="CxxStream.cs" />