public ThemeSummary ImportTheme(string file) { if (Path.GetExtension(file).Equals(".dll", StringComparison.OrdinalIgnoreCase)) { ThemeSummary theme = this.CreateTheme(); using (MediaCenterTheme mediaCenterTheme = theme.OpenTheme()) { mediaCenterTheme.AddResourceFileDifferences(VmcStudioUtil.BackupFile(Path.Combine(MediaCenterUtil.MediaCenterPath, "ehres.dll")), file); mediaCenterTheme.Save(); } return(theme); } else { string directory = Path.Combine(this.themesPath, Guid.NewGuid().ToString()); string themeFileName = Path.GetFileName(file); string str = Path.Combine(directory, themeFileName); Directory.CreateDirectory(directory); try { File.Copy(file, str); try { Dispatcher dispatcher = System.Windows.Application.Current.Dispatcher; ThemeSummary summary = new ThemeSummary(); Action action = (Action)(() => { summary.BasePath = directory; summary.ThemeFile = themeFileName; summary.Save(); this.themes.Add(summary); }); dispatcher.Invoke((Delegate)action, new object[0]); return(summary); } catch (Exception ex) { Trace.TraceError("Error importing theme {0}: {1}", (object)themeFileName, (object)((object)ex).ToString()); File.Delete(str); throw; } } catch (Exception) { try { Directory.Delete(directory, true); } catch (Exception ex2) { Trace.TraceError("Could not delete failed import ({1}): {0}", (object)((object)ex2).ToString(), (object)directory); } throw; } } }
public static ThemeSummary Load(string path) { String summary_file = ThemeSummary.GetSummaryFilePath(path); if (!File.Exists(summary_file)) { return(null); } ThemeSummary themeSummary = (ThemeSummary) new XmlSerializer(typeof(ThemeSummary)).Deserialize((Stream)File.Open(summary_file, FileMode.Open)); themeSummary.BasePath = path; return(themeSummary); }
public ThemeManager(string themesPath) { if (themesPath == null) { throw new ArgumentNullException(); } this.themesPath = themesPath; this.AppliedThemes = new ObservableCollection <ThemeSummary>(); this.themes = new ObservableCollection <ThemeSummary>(); this.Themes = (IEnumerable <ThemeSummary>) this.themes; try { foreach (string path in Directory.GetDirectories(themesPath)) { try { var theme_summary = ThemeSummary.Load(path); if (theme_summary != null) { this.themes.Add(theme_summary); } } catch (FileNotFoundException) { } } } catch (DirectoryNotFoundException) { } using (MediaCenterLibraryCache centerLibraryCache = new MediaCenterLibraryCache(MediaCenterUtil.MediaCenterPath)) { foreach (ThemeSummary themeSummary1 in ThemeManager.GetAppliedThemes((IResourceLibraryCache)centerLibraryCache)) { ThemeSummary summary = themeSummary1; ThemeSummary themeSummary2 = Enumerable.FirstOrDefault <ThemeSummary>(this.Themes, (Func <ThemeSummary, bool>)(o => o.ID == summary.ID)); if (themeSummary2 != null) { this.AppliedThemes.Add(themeSummary2); } } } this.AppliedThemes.CollectionChanged += (NotifyCollectionChangedEventHandler) delegate { this.IsDirty = true; }; }
public void DeleteTheme(ThemeSummary theme) { this.themes.Remove(theme); Directory.Delete(theme.BasePath, true); }