public IProgressEnabledOperation ImportThemes(IEnumerable <string> files) { ProgressEnabledOperation operation = new ProgressEnabledOperation("Importing themes..."); List <string> fileList = Enumerable.ToList <string>(files); operation.Count = fileList.Count; ThreadPool.QueueUserWorkItem((WaitCallback) delegate { try { for (int currentIndex = 0; currentIndex < fileList.Count; ++currentIndex) { string str = fileList[currentIndex]; operation.OnProgress(string.Format("Importing {0}...", (object)Path.GetFileName(str)), currentIndex); this.ImportTheme(str); } operation.OnCompleted(); } catch (Exception ex) { operation.OnAbandoned(ex); throw; } }); return((IProgressEnabledOperation)operation); }
protected virtual void Apply(MediaCenterLibraryCache readCache, MediaCenterLibraryCache writeCache, ProgressEnabledOperation operation) { try { if (this.Fonts.Count > 0) { operation.OnProgress("Installing fonts...", 0); foreach (string file in Enumerable.Distinct <string>(Enumerable.Select <FontFamily, string>(Enumerable.Where <FontFamily>((IEnumerable <FontFamily>) this.Fonts, (Func <FontFamily, bool>)(f => !Enumerable.Any <FontFamily>((IEnumerable <FontFamily>)System.Windows.Media.Fonts.SystemFontFamilies, (Func <FontFamily, bool>)(o => FontUtil.GetName(f) == FontUtil.GetName(o))))), (Func <FontFamily, string>)(o => FontUtil.GetFile(o))))) { FontUtil.InstallFont(file); } } List <IThemeItem> list = Enumerable.ToList <IThemeItem>(Enumerable.Concat <IThemeItem>((IEnumerable <IThemeItem>) new List <IThemeItem>() { (IThemeItem)this.FontsItem, (IThemeItem)this.ColorsItem }, (IEnumerable <IThemeItem>) this.ThemeItems)); for (int currentIndex = 0; currentIndex < list.Count; ++currentIndex) { IThemeItem themeItem = list[currentIndex]; operation.OnProgress(string.Format("Applying {0}...", (object)themeItem.Name), currentIndex); try { themeItem.Apply(readCache, writeCache); } catch (ThemeApplicationException ex) { Trace.TraceWarning(((object)ex).ToString()); } } } catch (Exception ex) { Trace.TraceError(((object)ex).ToString()); operation.OnAbandoned(ex); throw; } operation.OnCompleted(); }
protected void ApplyThemes(ProgressEnabledOperation operation, bool preserveMenu) { this.OnApplyingThemes(new ApplyThemesEventArgs(operation)); try { MediaCenterLibraryCache readCache = new MediaCenterLibraryCache(VmcStudioUtil.BackupsPath, UnmanagedLibraryAccess.Read); MediaCenterLibraryCache writeCache = new MediaCenterLibraryCache(MediaCenterUtil.MediaCenterPath, UnmanagedLibraryAccess.Write); MemoryLibraryCache memoryLibraryCache = (MemoryLibraryCache)null; if (preserveMenu) { memoryLibraryCache = new MemoryLibraryCache((ushort)1033); using (MediaCenterLibraryCache centerLibraryCache = new MediaCenterLibraryCache()) StartMenuManager.Create((IResourceLibraryCache)centerLibraryCache).Save((IResourceLibraryCache)memoryLibraryCache, true); } readCache.LibraryLoading += (EventHandler <LibraryLoadEventArgs>)((sender, e) => VmcStudioUtil.BackupFile(Path.Combine(MediaCenterUtil.MediaCenterPath, e.FileName))); writeCache.LibraryLoading += (EventHandler <LibraryLoadEventArgs>)((sender, e) => { string local_0 = VmcStudioUtil.BackupFile(Path.Combine(MediaCenterUtil.MediaCenterPath, e.FileName)); string local_1 = Path.Combine(writeCache.SearchPath, e.FileName); VmcStudioUtil.TakeOwnership(local_1); File.Copy(local_0, local_1, true); VmcStudioUtil.TakeOwnership(local_1); }); if (Directory.Exists(VmcStudioUtil.BackupsPath)) { foreach (string path in Directory.GetFiles(VmcStudioUtil.BackupsPath)) { writeCache.LoadLibrary(Path.GetFileName(path)); } } int num = 0; int operationCompleted = 0; Exception applyException = (Exception)null; List <MediaCenterTheme> list1 = Enumerable.ToList <MediaCenterTheme>(Enumerable.Select <ThemeSummary, MediaCenterTheme>((IEnumerable <ThemeSummary>) this.AppliedThemes, (Func <ThemeSummary, MediaCenterTheme>)(o => o.OpenTheme()))); try { List <IDelayedProgressOperation> list2 = new List <IDelayedProgressOperation>(); foreach (MediaCenterTheme mediaCenterTheme in list1) { IDelayedProgressOperation applyOperation = mediaCenterTheme.CreateApplyOperation(readCache, writeCache); num += applyOperation.Count; applyOperation.Progress += (EventHandler <ProgressEventArgs>)((sender, args) => operation.OnProgress(args.Message, args.CurrentIndex + operationCompleted)); applyOperation.Abandoned += (EventHandler <ExceptionEventArgs>)((sender, args) => applyException = args.Exception); list2.Add(applyOperation); } operation.Count = num; using (readCache) { using (writeCache) { foreach (IDelayedProgressOperation progressOperation in list2) { operation.Description = progressOperation.Description; progressOperation.Start(); progressOperation.WaitForCompletion(); if (applyException != null) { throw applyException; } operationCompleted += progressOperation.Count; } if (this.AppliedThemes.Count > 0) { IResource resource = writeCache["ehres.dll"].GetResource("VmcStudio.Themes.xml", (object)23); using (MemoryStream memoryStream = new MemoryStream()) { new XmlSerializer(typeof(ThemeManager.AppliedThemesDocument)).Serialize((Stream)memoryStream, (object)new ThemeManager.AppliedThemesDocument() { AppliedThemes = Enumerable.ToArray <ThemeSummary>((IEnumerable <ThemeSummary>) this.AppliedThemes) }); memoryStream.Flush(); ResourceExtensions.Update(resource, memoryStream.GetBuffer()); } } if (memoryLibraryCache != null) { memoryLibraryCache.ApplyTo((IResourceLibraryCache)writeCache); } } } this.IsDirty = false; } finally { foreach (MediaCenterTheme mediaCenterTheme in list1) { mediaCenterTheme.Dispose(); } } } catch (Exception ex) { Trace.TraceError(((object)ex).ToString()); operation.OnAbandoned(ex); throw; } operation.OnCompleted(); }
protected void ApplyThemes(ProgressEnabledOperation operation, bool preserveMenu) { this.OnApplyingThemes(new ApplyThemesEventArgs(operation)); try { MediaCenterLibraryCache readCache = new MediaCenterLibraryCache(VmcStudioUtil.BackupsPath, UnmanagedLibraryAccess.Read); MediaCenterLibraryCache writeCache = new MediaCenterLibraryCache(MediaCenterUtil.MediaCenterPath, UnmanagedLibraryAccess.Write); MemoryLibraryCache memoryLibraryCache = (MemoryLibraryCache)null; if (preserveMenu) { memoryLibraryCache = new MemoryLibraryCache((ushort)1033); using (MediaCenterLibraryCache centerLibraryCache = new MediaCenterLibraryCache()) StartMenuManager.Create((IResourceLibraryCache)centerLibraryCache).Save((IResourceLibraryCache)memoryLibraryCache, true); } readCache.LibraryLoading += (EventHandler<LibraryLoadEventArgs>)((sender, e) => VmcStudioUtil.BackupFile(Path.Combine(MediaCenterUtil.MediaCenterPath, e.FileName))); writeCache.LibraryLoading += (EventHandler<LibraryLoadEventArgs>)((sender, e) => { string local_0 = VmcStudioUtil.BackupFile(Path.Combine(MediaCenterUtil.MediaCenterPath, e.FileName)); string local_1 = Path.Combine(writeCache.SearchPath, e.FileName); VmcStudioUtil.TakeOwnership(local_1); File.Copy(local_0, local_1, true); VmcStudioUtil.TakeOwnership(local_1); }); if (Directory.Exists(VmcStudioUtil.BackupsPath)) { foreach (string path in Directory.GetFiles(VmcStudioUtil.BackupsPath)) writeCache.LoadLibrary(Path.GetFileName(path)); } int num = 0; int operationCompleted = 0; Exception applyException = (Exception)null; List<MediaCenterTheme> list1 = Enumerable.ToList<MediaCenterTheme>(Enumerable.Select<ThemeSummary, MediaCenterTheme>((IEnumerable<ThemeSummary>)this.AppliedThemes, (Func<ThemeSummary, MediaCenterTheme>)(o => o.OpenTheme()))); try { List<IDelayedProgressOperation> list2 = new List<IDelayedProgressOperation>(); foreach (MediaCenterTheme mediaCenterTheme in list1) { IDelayedProgressOperation applyOperation = mediaCenterTheme.CreateApplyOperation(readCache, writeCache); num += applyOperation.Count; applyOperation.Progress += (EventHandler<ProgressEventArgs>)((sender, args) => operation.OnProgress(args.Message, args.CurrentIndex + operationCompleted)); applyOperation.Abandoned += (EventHandler<ExceptionEventArgs>)((sender, args) => applyException = args.Exception); list2.Add(applyOperation); } operation.Count = num; using (readCache) { using (writeCache) { foreach (IDelayedProgressOperation progressOperation in list2) { operation.Description = progressOperation.Description; progressOperation.Start(); progressOperation.WaitForCompletion(); if (applyException != null) throw applyException; operationCompleted += progressOperation.Count; } if (this.AppliedThemes.Count > 0) { IResource resource = writeCache["ehres.dll"].GetResource("VmcStudio.Themes.xml", (object)23); using (MemoryStream memoryStream = new MemoryStream()) { new XmlSerializer(typeof(ThemeManager.AppliedThemesDocument)).Serialize((Stream)memoryStream, (object)new ThemeManager.AppliedThemesDocument() { AppliedThemes = Enumerable.ToArray<ThemeSummary>((IEnumerable<ThemeSummary>)this.AppliedThemes) }); memoryStream.Flush(); ResourceExtensions.Update(resource, memoryStream.GetBuffer()); } } if (memoryLibraryCache != null) memoryLibraryCache.ApplyTo((IResourceLibraryCache)writeCache); } } this.IsDirty = false; } finally { foreach (MediaCenterTheme mediaCenterTheme in list1) mediaCenterTheme.Dispose(); } } catch (Exception ex) { Trace.TraceError(((object)ex).ToString()); operation.OnAbandoned(ex); throw; } operation.OnCompleted(); }
public IProgressEnabledOperation ImportThemes(IEnumerable<string> files) { ProgressEnabledOperation operation = new ProgressEnabledOperation("Importing themes..."); List<string> fileList = Enumerable.ToList<string>(files); operation.Count = fileList.Count; ThreadPool.QueueUserWorkItem((WaitCallback)delegate { try { for (int currentIndex = 0; currentIndex < fileList.Count; ++currentIndex) { string str = fileList[currentIndex]; operation.OnProgress(string.Format("Importing {0}...", (object)Path.GetFileName(str)), currentIndex); this.ImportTheme(str); } operation.OnCompleted(); } catch (Exception ex) { operation.OnAbandoned(ex); throw; } }); return (IProgressEnabledOperation)operation; }
protected virtual void Apply(MediaCenterLibraryCache readCache, MediaCenterLibraryCache writeCache, ProgressEnabledOperation operation) { try { if (this.Fonts.Count > 0) { operation.OnProgress("Installing fonts...", 0); foreach (string file in Enumerable.Distinct<string>(Enumerable.Select<FontFamily, string>(Enumerable.Where<FontFamily>((IEnumerable<FontFamily>)this.Fonts, (Func<FontFamily, bool>)(f => !Enumerable.Any<FontFamily>((IEnumerable<FontFamily>)System.Windows.Media.Fonts.SystemFontFamilies, (Func<FontFamily, bool>)(o => FontUtil.GetName(f) == FontUtil.GetName(o))))), (Func<FontFamily, string>)(o => FontUtil.GetFile(o))))) FontUtil.InstallFont(file); } List<IThemeItem> list = Enumerable.ToList<IThemeItem>(Enumerable.Concat<IThemeItem>((IEnumerable<IThemeItem>)new List<IThemeItem>() { (IThemeItem) this.FontsItem, (IThemeItem) this.ColorsItem }, (IEnumerable<IThemeItem>)this.ThemeItems)); for (int currentIndex = 0; currentIndex < list.Count; ++currentIndex) { IThemeItem themeItem = list[currentIndex]; operation.OnProgress(string.Format("Applying {0}...", (object)themeItem.Name), currentIndex); try { themeItem.Apply(readCache, writeCache); } catch (ThemeApplicationException ex) { Trace.TraceWarning(((object)ex).ToString()); } } } catch (Exception ex) { Trace.TraceError(((object)ex).ToString()); operation.OnAbandoned(ex); throw; } operation.OnCompleted(); }