-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWallpaperSettings.cs
139 lines (122 loc) · 4.43 KB
/
WallpaperSettings.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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 WallpaperSettings : INotifyPropertyChanged
{
internal void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public WallpaperAppearanceSetting Wallpaper { get; private set; }
public SlideshowSettings Slideshow { get; private set; }
public ColorAppearanceSetting BackgroundColor { get; private set; }
public WallpaperTypes WallpaperType
{
get => _wallpaperType;
set
{
_wallpaperType = value;
NotifyPropertyChanged();
}
}
internal void CreateDefaultSlideshow()
{
Slideshow = new SlideshowSettings();
string WindowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
if (Directory.Exists(WindowsFolder + @"\Web\Wallpaper\Theme1"))
{
Slideshow.Folder = WindowsFolder + @"\Web\Wallpaper\Theme1";
}
else
{
Slideshow.Folder = WindowsFolder + @"\Web\Wallpaper\Windows";
}
Slideshow.SelectAll();
}
public string[] WallpaperTypesStrings { get; } = new string[] { "Image", "Slideshow", "Color" };
public enum WallpaperTypes
{
Image = 0,
Slideshow = 1,
Color = 2
}
private WallpaperTypes _wallpaperType;
/// <summary>
/// Constructor for the Wallpaper settings
/// </summary>
/// <param name="backgroundColor">color of the wallpaper's background</param>
public WallpaperSettings(ColorAppearanceSetting backgroundColor)
{
BackgroundColor = backgroundColor;
Wallpaper = new WallpaperAppearanceSetting();
UpdateWallpaperType();
if (WallpaperType == WallpaperTypes.Slideshow)
Slideshow = new SlideshowSettings();
}
public event PropertyChangedEventHandler PropertyChanged;
public void UpdateWallpaperType()
{
//if it is solid color
if (String.IsNullOrWhiteSpace(Wallpaper.Path))
{
WallpaperType = WallpaperTypes.Color;
return;
}
//if it is a slideshow
if (Wallpaper.Path.Contains("\\TranscodedWallpaper") && !SlideshowSettings.IsIniEmpty())
{
WallpaperType = WallpaperTypes.Slideshow;
}
//if it is a single image wallpaper
else
{
WallpaperType = WallpaperTypes.Image;
}
}
public void SaveToRegistry()
{
switch (WallpaperType)
{
case WallpaperTypes.Image:
{
Wallpaper.SaveToRegistry();
Slideshow?.DeleteIni();
WindowsInteropServices.Win32Methods.UpdateWallpaper(Wallpaper.Path);
break;
}
case WallpaperTypes.Slideshow:
{
string oldPath = Wallpaper.Path;
try
{
Wallpaper.Path = Environment.SpecialFolder.ApplicationData.ToString() + @"\Microsoft\Windows\Themes\TranscodedWallpaper";
Slideshow.SaveToIni();
}
catch (Exception ex)
{
Wallpaper.Path = oldPath;
throw ex;
}
break;
}
case WallpaperTypes.Color:
{
Wallpaper.Path = "";
Wallpaper.SaveToRegistry();
Slideshow?.DeleteIni();
WindowsInteropServices.Win32Methods.UpdateWallpaper("");
break;
}
}
if(BackgroundColor.IsEdited)
BackgroundColor.SaveToRegistry();
}
}
}