DisplayMagician/HeliosDisplayManagement.Shared/TaskBarSettings.cs
temacdonald a9bb295d1f Renamed app to HeliosPlus namespace and more
Renamed app to HeliosPlus namespace so that the updated
changes don't interfere with HeliosDisplayManagement if
that is also installed. The fact that I've changed so much of
the app means that my changes would be unlikely to be
accepted by Soroush, so I'm best to release this work in a
similar way to other projects like Notepad++, by keeping
the same root name, and adding a plus.
    I've also changed the Shortcut form to put all the games
in a single list to reduce the number of clicks a user has to
do in order for them to create a shortcut. I have begun to
prepare the form so that it will support multiple game
libraries, but now I am at a point that I need to fix the Steam
and Uplay game detection mechanisms so that they report
the correct information for the lv_games list view.
2020-04-23 20:16:16 +12:00

103 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using Microsoft.Win32;
namespace HeliosPlus.Shared
{
public class TaskBarSettings
{
private const string AdvancedSettingsAddress =
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced";
public Tuple<string, int>[] Options { get; set; }
public TaskBarStuckRectangle SingleMonitorStuckRectangle { get; set; }
public static TaskBarSettings GetCurrent()
{
var taskBarOptions = new List<Tuple<string, int>>();
// Get stored integer Taskbar options from the User Registry
try
{
using (var key = Registry.CurrentUser.OpenSubKey(
AdvancedSettingsAddress,
RegistryKeyPermissionCheck.ReadSubTree))
{
if (key != null)
{
foreach (var valueName in key.GetValueNames())
{
try
{
if (!string.IsNullOrWhiteSpace(valueName) && valueName.ToLower().Contains("taskbar"))
{
var value = key.GetValue(valueName, null,
RegistryValueOptions.DoNotExpandEnvironmentNames);
if (value != null && value is int intValue)
{
taskBarOptions.Add(new Tuple<string, int>(valueName, intValue));
}
}
}
catch (Exception)
{
// ignored
}
}
}
}
}
catch (Exception)
{
// ignored
}
if (taskBarOptions.Count == 0)
{
return null;
}
return new TaskBarSettings
{
Options = taskBarOptions.ToArray(),
SingleMonitorStuckRectangle = TaskBarStuckRectangle.GetCurrent()
};
}
public bool Apply()
{
if (SingleMonitorStuckRectangle == null ||
Options.Length == 0)
{
throw new InvalidOperationException();
}
using (var optionsKey = Registry.CurrentUser.OpenSubKey(
AdvancedSettingsAddress,
RegistryKeyPermissionCheck.ReadWriteSubTree))
{
if (optionsKey == null)
{
return false;
}
// Write
foreach (var option in Options)
{
try
{
optionsKey.SetValue(option.Item1, option.Item2);
}
catch (Exception)
{
// ignored
}
}
}
return true;
}
}
}