@@ -122,29 +122,43 @@ static void AddFileProviders(IServiceCollection services)
122122 {
123123 services . Configure < RazorViewEngineOptions > ( options =>
124124 {
125- try
126- {
127- // load blog themes list from physical file provider
128- var themes = options . FileProviders [ 0 ] . GetDirectoryContents ( "/Views/Blogifier/Themes" ) ;
129-
130- BlogSettings . BlogThemes = new List < SelectListItem > ( ) ;
131- BlogSettings . BlogThemes . Add ( new SelectListItem { Value = "Standard" , Text = "Standard" } ) ;
132-
133- foreach ( var theme in themes )
134- {
135- BlogSettings . BlogThemes . Add ( new SelectListItem {
136- Text = theme . Name ,
137- Value = theme . Name
138- } ) ;
139- }
140- }
141- catch { }
142-
143125 foreach ( var assembly in GetAssemblies ( ) )
144126 {
145127 options . FileProviders . Add ( new EmbeddedFileProvider ( assembly , assembly . GetName ( ) . Name ) ) ;
146128 }
147129 } ) ;
130+
131+ LoadThemes ( ) ;
132+ }
133+ catch { }
134+ }
135+
136+ static void LoadThemes ( )
137+ {
138+ /*
139+ This code relies on Blogifier.Web.csproj to have this line:
140+ <EmbeddedResource Include="Views\Blogifier\**\Single.cshtml" />
141+ We need it to populate list of installed themes when project
142+ deployed precompiled and file system not accessible
143+ */
144+ try
145+ {
146+ var assembly = Assembly . LoadFile ( Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "Blogifier.Web.dll" ) ) ;
147+ var provider = new EmbeddedFileProvider ( assembly , assembly . GetName ( ) . Name ) ;
148+ var resources = provider . GetDirectoryContents ( "/" ) ;
149+
150+ BlogSettings . BlogThemes = new List < SelectListItem > ( ) ;
151+ BlogSettings . BlogThemes . Add ( new SelectListItem { Value = "Standard" , Text = "Standard" } ) ;
152+
153+ foreach ( var rsrc in resources )
154+ {
155+ var theme = rsrc . Name . Replace ( "Views.Blogifier.Themes." , "" ) . Replace ( ".Single.cshtml" , "" ) ;
156+ BlogSettings . BlogThemes . Add ( new SelectListItem
157+ {
158+ Text = theme ,
159+ Value = theme
160+ } ) ;
161+ }
148162 }
149163 catch { }
150164 }
0 commit comments