示例#1
0
 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();
 }
示例#2
0
        protected override void SaveInternal()
        {
            this.themeInfo.ID        = this.ID;
            this.themeInfo.Name      = this.Name;
            this.themeInfo.Author    = this.Author;
            this.themeInfo.Version   = ((object)(this.Version ?? new Version(0, 0))).ToString();
            this.themeInfo.Comments  = this.Comments;
            this.themeInfo.ThemeType = this.ThemeType;
            foreach (IThemeItem themeItem in (Collection <IThemeItem>) this.ThemeItems)
            {
                if (!themeItem.IsLoaded)
                {
                    themeItem.Load();
                }
            }
            this.ZipFile.BeginUpdate();
            foreach (ZipEntry entry in new List <ZipEntry>(Enumerable.OfType <ZipEntry>((IEnumerable)this.ZipFile)))
            {
                this.ZipFile.Delete(entry);
            }
            this.themeItemEntries.Clear();
            this.themeInfo.Fonts  = this.FontsItem;
            this.themeInfo.Colors = this.ColorsItem;
            MemoryStream memoryStream = new MemoryStream();

            new XmlSerializer(typeof(VmcStudioTheme.ThemeInfo)).Serialize((Stream)memoryStream, (object)this.themeInfo);
            this.ZipFile.Add((IStaticDataSource) new ZippedTheme.StreamDataSource((Stream)memoryStream), "Theme.xml");
            if (this.MainScreenshot != null)
            {
                VmcStudioTheme.AddImageResource(this.MainScreenshot, this.ZipFile, "Screenshot.png");
            }
            for (int index = 0; index < this.Screenshots.Count; ++index)
            {
                VmcStudioTheme.AddImageResource(this.Screenshots[index], this.ZipFile, string.Format("Screenshots\\{0}.png", (object)index));
            }
            foreach (ResourceThemeItem resourceThemeItem in Enumerable.OfType <ResourceThemeItem>((IEnumerable)this.ThemeItems))
            {
                string entryName = (string)null;
                if (resourceThemeItem is ImageResourceThemeItem)
                {
                    entryName = VmcStudioTheme.GetResourceZipPath(resourceThemeItem, "Images");
                }
                else if (resourceThemeItem is SoundResourceThemeItem)
                {
                    entryName = VmcStudioTheme.GetResourceZipPath(resourceThemeItem, "Sounds");
                }
                if (entryName == null)
                {
                    throw new Exception("Unknown theme item type - " + (object)resourceThemeItem.GetType());
                }
                this.ZipFile.Add(ZippedTheme.GetResourceThemeItemData(resourceThemeItem), entryName);
            }
            foreach (string fontName in Enumerable.Distinct <string>(Enumerable.Concat <string>(Enumerable.Select <FontClass, string>((IEnumerable <FontClass>) this.themeInfo.Fonts.FontClasses, (Func <FontClass, string>)(fontClass => fontClass.FontFace.FontFamily)), Enumerable.Select <FontOverride, string>(Enumerable.Where <FontOverride>((IEnumerable <FontOverride>) this.themeInfo.Fonts.FontOverrides, (Func <FontOverride, bool>)(fontOverride => fontOverride.FontFace != null)), (Func <FontOverride, string>)(fontOverride => fontOverride.FontFace.FontFamily)))))
            {
                FontFamily fontFamily = this.GetFontFamily(fontName);
                if (fontFamily != null)
                {
                    string file = FontUtil.GetFile(fontFamily);
                    if (file != null)
                    {
                        this.ZipFile.Add(file, "Fonts\\" + Path.GetFileName(file));
                    }
                }
            }
            this.ZipFile.CommitUpdate();
            this.ResetZipFile();
            foreach (IThemeItem themeItem in Enumerable.Where <IThemeItem>((IEnumerable <IThemeItem>) this.ThemeItems, (Func <IThemeItem, bool>)(t => t.IsDirty)))
            {
                themeItem.ClearDirty();
            }
            this.FontsItem.ClearDirty();
            this.ColorsItem.ClearDirty();
            this.IsDirty = false;
        }