using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace JXCMS.Core.Themes
{
public static class ThemeUtil
{
///
/// PC主题
///
public const int PcTheme = 1;
///
/// 手机主题
///
public const int MobileTheme = 2;
///
/// 自适应主题
///
public const int AdaptiveTheme = 3;
///
/// PC主题字段名称
///
public const string PcThemeName = "PcTheme";
///
/// 移动主题字段名称
///
public const string MobileThemeName = "MobileTheme";
public static List ListThemes(string basePath)
{
var themes = Directory.GetDirectories(basePath);
List themeConfigs = new List();
foreach (var theme in themes)
{
var configPath = Path.Combine(theme, "theme.json");
if (File.Exists(configPath))
{
var themeConfig = JsonConvert.DeserializeObject(File.ReadAllText(configPath));
themeConfig.FolderName = Path.GetFileName(theme);
if (themeConfig.ThemeType == MobileTheme)
{
if (TemplateViewLocationExpander.Mode == ThemeChangeMode.Domain || TemplateViewLocationExpander.Mode == ThemeChangeMode.Auto)
{
themeConfigs.Add(themeConfig);
}
}
else
{
themeConfigs.Add(themeConfig);
}
if (themeConfig.FolderName == TemplateViewLocationExpander.PcThemeName)
{
themeConfig.IsUsing = true;
}
else if (themeConfig.FolderName == TemplateViewLocationExpander.MobileThemeName)
{
themeConfig.IsUsing = true;
}
}
}
return themeConfigs;
}
}
}