Skip to content

Commit b48b1e6

Browse files
authored
Bundled themes inside of the app (#7616)
1 parent b732071 commit b48b1e6

26 files changed

+1862
-130
lines changed

src/Files/Constants.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ public static class ResourceFilePaths
163163
public const string PreviewPaneDetailsPropertiesJsonPath = @"ms-appx:///Resources/PreviewPanePropertiesInformation.json";
164164
}
165165

166-
public static class OptionalPackages
167-
{
168-
public const string ThemesOptionalPackagesName = "49306atecsolution.ThemesforFiles";
169-
}
170-
171166
public static class Filesystem
172167
{
173168
public const int ExtendedAsciiCodePage = 437;

src/Files/Files.csproj

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,86 @@
11031103
<Generator>MSBuild:Compile</Generator>
11041104
<SubType>Designer</SubType>
11051105
</ApplicationDefinition>
1106+
<Content Include="Themes\Acrylic.xaml">
1107+
<Generator>MSBuild:Compile</Generator>
1108+
<SubType>Designer</SubType>
1109+
</Content>
1110+
<Content Include="Themes\Black Pixel.xaml">
1111+
<Generator>MSBuild:Compile</Generator>
1112+
<SubType>Designer</SubType>
1113+
</Content>
1114+
<Content Include="Themes\Blue Acrylic.xaml">
1115+
<Generator>MSBuild:Compile</Generator>
1116+
<SubType>Designer</SubType>
1117+
</Content>
1118+
<Content Include="Themes\Bound to be Blue.xaml">
1119+
<Generator>MSBuild:Compile</Generator>
1120+
<SubType>Designer</SubType>
1121+
</Content>
1122+
<Content Include="Themes\Bronze.xaml">
1123+
<Generator>MSBuild:Compile</Generator>
1124+
<SubType>Designer</SubType>
1125+
</Content>
1126+
<Content Include="Themes\Burgundy.xaml">
1127+
<Generator>MSBuild:Compile</Generator>
1128+
<SubType>Designer</SubType>
1129+
</Content>
1130+
<Content Include="Themes\Deep Sea.xaml">
1131+
<Generator>MSBuild:Compile</Generator>
1132+
<SubType>Designer</SubType>
1133+
</Content>
1134+
<Content Include="Themes\Discord.xaml">
1135+
<Generator>MSBuild:Compile</Generator>
1136+
<SubType>Designer</SubType>
1137+
</Content>
1138+
<Content Include="Themes\Dracula.xaml">
1139+
<Generator>MSBuild:Compile</Generator>
1140+
<SubType>Designer</SubType>
1141+
</Content>
1142+
<Content Include="Themes\Glass.xaml">
1143+
<Generator>MSBuild:Compile</Generator>
1144+
<SubType>Designer</SubType>
1145+
</Content>
1146+
<Content Include="Themes\Green Grass.xaml">
1147+
<Generator>MSBuild:Compile</Generator>
1148+
<SubType>Designer</SubType>
1149+
</Content>
1150+
<Content Include="Themes\Lavender.xaml">
1151+
<Generator>MSBuild:Compile</Generator>
1152+
<SubType>Designer</SubType>
1153+
</Content>
1154+
<Content Include="Themes\Leaf Green.xaml">
1155+
<Generator>MSBuild:Compile</Generator>
1156+
<SubType>Designer</SubType>
1157+
</Content>
1158+
<Content Include="Themes\Luxury Red.xaml">
1159+
<Generator>MSBuild:Compile</Generator>
1160+
<SubType>Designer</SubType>
1161+
</Content>
1162+
<Content Include="Themes\Magentistic.xaml">
1163+
<Generator>MSBuild:Compile</Generator>
1164+
<SubType>Designer</SubType>
1165+
</Content>
1166+
<Content Include="Themes\Mica Imitation.xaml">
1167+
<Generator>MSBuild:Compile</Generator>
1168+
<SubType>Designer</SubType>
1169+
</Content>
1170+
<Content Include="Themes\Middle Blue.xaml">
1171+
<Generator>MSBuild:Compile</Generator>
1172+
<SubType>Designer</SubType>
1173+
</Content>
1174+
<Content Include="Themes\Red Wave.xaml">
1175+
<Generator>MSBuild:Compile</Generator>
1176+
<SubType>Designer</SubType>
1177+
</Content>
1178+
<Content Include="Themes\Solarized.xaml">
1179+
<Generator>MSBuild:Compile</Generator>
1180+
<SubType>Designer</SubType>
1181+
</Content>
1182+
<Content Include="Themes\Turquoise.xaml">
1183+
<Generator>MSBuild:Compile</Generator>
1184+
<SubType>Designer</SubType>
1185+
</Content>
11061186
<Page Include="Dialogs\BitlockerDialog.xaml">
11071187
<Generator>MSBuild:Compile</Generator>
11081188
<SubType>Designer</SubType>
@@ -1143,6 +1223,10 @@
11431223
<SubType>Designer</SubType>
11441224
<Generator>MSBuild:Compile</Generator>
11451225
</Page>
1226+
<Content Include="Themes\Nord.xaml">
1227+
<Generator>MSBuild:Compile</Generator>
1228+
<SubType>Designer</SubType>
1229+
</Content>
11461230
<Page Include="UserControls\ColoredIcon.xaml">
11471231
<SubType>Designer</SubType>
11481232
<Generator>MSBuild:Compile</Generator>

src/Files/Helpers/ExternalResourcesHelper.cs

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5+
using System.IO;
56
using System.Linq;
67
using System.Threading.Tasks;
78
using Windows.Storage;
@@ -21,32 +22,15 @@ public class ExternalResourcesHelper
2122
};
2223

2324
public StorageFolder ThemeFolder { get; set; }
24-
public StorageFolder OptionalPackageThemesFolder { get; set; }
25+
public StorageFolder ImportedThemesFolder { get; set; }
2526

2627
public string CurrentThemeResources { get; set; }
2728

2829
public async Task LoadSelectedTheme()
2930
{
30-
if (App.OptionalPackageManager.TryGetOptionalPackage(Constants.OptionalPackages.ThemesOptionalPackagesName, out var package))
31-
{
32-
Debug.WriteLine(package.InstalledLocation.Path);
33-
OptionalPackageThemesFolder = package.InstalledLocation;
34-
}
35-
36-
ThemeFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Themes", CreationCollisionOption.OpenIfExists);
37-
38-
// This is used to migrate to the new theme setting
39-
// It can be removed in a future update
40-
if (ApplicationData.Current.LocalSettings.Values.TryGetValue("PathToThemeFile", out var path))
41-
{
42-
var pathStr = path as string;
43-
App.AppSettings.SelectedTheme = new AppTheme()
44-
{
45-
Name = pathStr.Replace(".xaml", "", StringComparison.Ordinal),
46-
Path = pathStr,
47-
};
48-
ApplicationData.Current.LocalSettings.Values.Remove("PathToThemeFile");
49-
}
31+
StorageFolder appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
32+
ThemeFolder = await appInstalledFolder.GetFolderAsync("Themes");
33+
ImportedThemesFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Themes", CreationCollisionOption.OpenIfExists);
5034

5135
if (App.AppSettings.SelectedTheme.Path != null)
5236
{
@@ -59,19 +43,15 @@ public async Task LoadOtherThemesAsync()
5943
try
6044
{
6145
await AddThemesAsync(ThemeFolder);
62-
63-
if (OptionalPackageThemesFolder != null)
64-
{
65-
await AddThemesAsync(OptionalPackageThemesFolder, true);
66-
}
46+
await AddThemesAsync(ImportedThemesFolder);
6747
}
6848
catch (Exception)
6949
{
7050
Debug.WriteLine($"Error loading themes");
7151
}
7252
}
7353

74-
private async Task AddThemesAsync(StorageFolder folder, bool isOptionalPackage = false)
54+
private async Task AddThemesAsync(StorageFolder folder)
7555
{
7656
foreach (var file in (await folder.GetFilesAsync()).Where(x => x.FileType == ".xaml"))
7757
{
@@ -80,7 +60,6 @@ private async Task AddThemesAsync(StorageFolder folder, bool isOptionalPackage =
8060
Name = file.Name.Replace(".xaml", "", StringComparison.Ordinal),
8161
Path = file.Name,
8262
AbsolutePath = file.Path,
83-
IsFromOptionalPackage = isOptionalPackage
8463
});
8564
}
8665
}
@@ -111,21 +90,16 @@ public async Task<ResourceDictionary> TryLoadResourceDictionary(AppTheme theme)
11190
{
11291
return null;
11392
}
114-
if (theme.IsFromOptionalPackage)
93+
94+
if (theme.AbsolutePath.Contains(ImportedThemesFolder.Path))
11595
{
116-
if (OptionalPackageThemesFolder != null)
117-
{
118-
file = await OptionalPackageThemesFolder.GetFileAsync(theme.Path);
119-
}
120-
else
121-
{
122-
return null;
123-
}
96+
file = await ImportedThemesFolder.GetFileAsync(theme.Path);
12497
}
12598
else
12699
{
127100
file = await ThemeFolder.GetFileAsync(theme.Path);
128101
}
102+
129103
var code = await FileIO.ReadTextAsync(file);
130104
var xaml = XamlReader.Load(code) as ResourceDictionary;
131105
xaml.Add("CustomThemeID", theme.Key);
@@ -164,7 +138,6 @@ public class AppTheme
164138
public string Name { get; set; }
165139
public string Path { get; set; }
166140
public string AbsolutePath { get; set; }
167-
public bool IsFromOptionalPackage { get; set; }
168-
public string Key => $"{Name}-{IsFromOptionalPackage}";
141+
public string Key => $"{Name}";
169142
}
170143
}

0 commit comments

Comments
 (0)