-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWallpaperAppearanceSetting.cs
115 lines (98 loc) · 3.55 KB
/
WallpaperAppearanceSetting.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace AdvancedWindowsAppearence
{
public class WallpaperAppearanceSetting : AppearanceSetting
{
public string Path { get; set; }
public WallpaperStyleRegistrySetting WallpaperStyleSettings { get; private set; }
public WallpaperAppearanceSetting()
{
Path = GetWallpaperPath();
WallpaperStyleSettings = new WallpaperStyleRegistrySetting();
}
string GetWallpaperPath()
{
try
{
return Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop").GetValue("Wallpaper").ToString();
}
catch
{
return "";
}
}
public void SetWallpaper(string path)
{
Path = path;
NotifyPropertyChanged(nameof(Path));
}
public void SaveToRegistry()
{
//save the wallpaper
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
registryKey.SetValue("Wallpaper", Path, RegistryValueKind.String);
registryKey.Close();
//save the wallpaper styles
WallpaperStyleSettings.SaveToRegistry();
}
}
public class WallpaperStyleRegistrySetting: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
internal void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public string[] WallpaperStyles { get; private set; }
public enum WallpaperStyle
{
Center = 0,
Tile = 1,
Stretched = 2,
Fit = 6,
Fill = 10,
Span = 22
}
public WallpaperStyle SelectedWallpaperStyle
{
get => _style;
set
{
_style = value;
NotifyPropertyChanged();
}
}
private WallpaperStyle _style;
internal WallpaperStyleRegistrySetting()
{
BoolRegistrySetting tileWallpaperRegistrySetting = new BoolRegistrySetting("Tile Wallpaper", @"Control Panel\Desktop", "TileWallpaper");
WallpaperStyles = new string[] { "Center", "Tile", "Stretched", "Fit", "Fill", "Span" };
RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", false);
int value = int.Parse(regKey.GetValue("WallpaperStyle", 0).ToString());
regKey.Close();
if(tileWallpaperRegistrySetting.Checked.Value == true)
value = 1;
SelectedWallpaperStyle = (WallpaperStyle)value;
}
internal void SaveToRegistry()
{
//save the tile
RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
if (SelectedWallpaperStyle == WallpaperStyle.Tile)
regKey.SetValue("TileWallpaper", 1, RegistryValueKind.String);
else
regKey.SetValue("TileWallpaper", 0, RegistryValueKind.String);
//save the other styles
regKey.SetValue("WallpaperStyle", (int)SelectedWallpaperStyle, RegistryValueKind.String);
regKey.Close();
}
}
}