Example #1
0
        private static ThemeSettings TryLoadTheme()
        {
            var invariantTheme = Repository.GetInvariantTheme();

            if (invariantTheme == null)
            {
                // Not good, ColorHelper needs actual InvariantTheme to correctly transform colors.
                // Still not a mission-critical failure, do not raise.
                return(ThemeSettings.Default);
            }

            ThemeId themeId = AppSettings.ThemeId;

            if (string.IsNullOrEmpty(themeId.Name))
            {
                return(new ThemeSettings(Theme.Default, invariantTheme, AppSettings.UseSystemVisualStyle));
            }

            var theme = Repository.GetTheme(themeId);

            if (theme == null || !TryInstallHooks(theme))
            {
                return(new ThemeSettings(Theme.Default, invariantTheme, AppSettings.UseSystemVisualStyle));
            }

            IsDarkTheme = theme.SysColorValues[KnownColor.Window].GetBrightness() < 0.5;

            return(new ThemeSettings(theme, invariantTheme, AppSettings.UseSystemVisualStyle));
        }
 public static string[] GetLessPaths(string sourcePath, ThemeId themeId)
 {
     return(LessAggregation.EnumerateAllItems(sourcePath, "")
            .First(item => IsCssFileForTheme(item.CssFile, themeId))
            .Segments
            .SelectMany(s => s.LessFiles)
            .Select(i => Path.Combine(sourcePath, i))
            .ToArray());
 }
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (Object.ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }


            var other = (VLSurveyTheme)obj;

            //reference types
            if (!Object.Equals(Name, other.Name))
            {
                return(false);
            }
            if (!Object.Equals(RtHtml, other.RtHtml))
            {
                return(false);
            }
            if (!Object.Equals(RtCSS, other.RtCSS))
            {
                return(false);
            }
            if (!Object.Equals(DtHtml, other.DtHtml))
            {
                return(false);
            }
            if (!Object.Equals(DtCSS, other.DtCSS))
            {
                return(false);
            }
            //value types
            if (!ThemeId.Equals(other.ThemeId))
            {
                return(false);
            }
            if (!ClientId.Equals(other.ClientId))
            {
                return(false);
            }
            if (!AttributeFlags.Equals(other.AttributeFlags))
            {
                return(false);
            }

            return(true);
        }
        public void Delete(ThemeId themeId)
        {
            if (themeId.IsBuiltin)
            {
                throw new InvalidOperationException("Only user-defined theme can be deleted");
            }

            var themePath = _themePathProvider.GetThemePath(themeId);

            File.Delete(themePath);
        }
        public void Delete(ThemeId id)
        {
            if (id.IsBuiltin)
            {
                throw new InvalidOperationException("Only user-defined theme can be deleted");
            }

            var path = GetPath(id);

            File.Delete(path);
        }
        public void SettingsAreModified_should_reflect_ThemeId_change(
            ThemeId themeId, string[] themeVariations, bool useSystemVisualStyle)
        {
            AppSettings.ThemeId              = themeId;
            AppSettings.ThemeVariations      = themeVariations;
            AppSettings.UseSystemVisualStyle = useSystemVisualStyle;
            ThemeModule.TestAccessor.ReloadThemeSettings(_context.ThemeRepository);
            _context.Controller.ShowThemeSettings();

            _context.Page.SelectedThemeId = new ThemeId("another_theme", isBuiltin: false);
            _context.Controller.SettingsAreModified.Should().BeTrue();
        }
Example #7
0
 public override bool Equals(Object obj)
 {
     if (obj is Problem ob)
     {
         return(Id.Equals(ob.Id) && CategoryId.Equals(ob.CategoryId) && ThemeId.Equals(ob.ThemeId) && Adress.Equals(ob.Adress) &&
                SourceId.Equals(ob.SourceId) && CreateDate.Equals(ob.CreateDate) && AnswerDate.Equals(ob.AnswerDate) &&
                ProblemText.Equals(ob.ProblemText) && ProblemPhotos.Equals(ob.ProblemPhotos) && AnswerText.Equals(ob.AnswerText) &&
                AnswerPhotos.Equals(ob.AnswerPhotos) && StatusId.Equals(ob.StatusId) && DistrictId.Equals(ob.DistrictId) && ChildID.Equals(ob.ChildID) &&
                ParentID.Equals(ob.ParentID) && IspolnitelName.Equals(ob.IspolnitelName) && IspolnitelId.Equals(ob.IspolnitelId));
     }
     return(false);
 }
        static bool IsCssFileForTheme(LessAggregation.ICssFileInfo cssFile, ThemeId themeId)
        {
            var themeCssFile = cssFile as LessAggregation.ThemeCssFileInfo;

            if (themeCssFile == null)
            {
                return(false);
            }

            return(themeCssFile.ThemeName == themeId.Theme &&
                   themeCssFile.ColorSchemeName == themeId.ColorScheme &&
                   LessRegistry.SizeSchemesEqual(themeCssFile.SizeSchemeName, themeId.SizeScheme));
        }
        public Theme Load(string fileName, ThemeId id)
        {
            if (!TryReadFile(fileName, out string serialized))
            {
                return(null);
            }

            if (!TryParse(fileName, serialized, out var appColors, out var sysColors))
            {
                return(null);
            }

            return(new Theme(appColors, sysColors, id));
        }
Example #10
0
        private string GetPath(ThemeId id)
        {
            if (id.IsBuiltin)
            {
                return(Path.Combine(AppThemesDirectory, id.Name + Extension));
            }

            if (UserThemesDirectory == null)
            {
                throw new InvalidOperationException("There is no directory for custom user themes in portable mode");
            }

            return(Path.Combine(UserThemesDirectory, id.Name + Extension));
        }
Example #11
0
        public override Dictionary <string, string> ToDictionary()
        {
            var parameters = new Dictionary <string, string>();

            parameters.Add("{themeId}", ThemeId.ToString());
            parameters.Add("{consentDisplayType}", ConsentDisplayType.ToString());
            parameters.Add("{division}", "\"" + Division + "\"");
            parameters.Add("{includeSubdomains}", IncludeSubdomains.ToString());

            var vendors = String.Join(", ", Vendors.ToArray());

            parameters.Add("{vendors}", $"{{ 1: [{vendors}] }},");

            return(parameters);
        }
Example #12
0
        private static ThemeSettings LoadThemeSettings()
        {
            Theme invariantTheme;

            try
            {
                invariantTheme = Repository.GetInvariantTheme();
            }
            catch (ThemeException ex)
            {
                // Not good, ColorHelper needs actual InvariantTheme to correctly transform colors.
                MessageBoxes.ShowError(null, $"Failed to load invariant theme: {ex}");
                return(ThemeSettings.Default);
            }

            ThemeId themeId = AppSettings.ThemeId;

            if (string.IsNullOrEmpty(themeId.Name))
            {
                return(CreateFallbackSettings(invariantTheme));
            }

            Theme theme;

            try
            {
                theme = Repository.GetTheme(themeId, AppSettings.ThemeVariations);
            }
            catch (ThemeException ex)
            {
                MessageBoxes.ShowError(null, $"Failed to load {(themeId.IsBuiltin ? "preinstalled" : "user-defined")} theme {themeId.Name}: {ex}");
                return(CreateFallbackSettings(invariantTheme));
            }

            try
            {
                InstallHooks(theme);
            }
            catch (Exception ex)
            {
                MessageBoxes.ShowError(null, $"Failed to install Win32 theming hooks: {ex}");
                return(CreateFallbackSettings(invariantTheme));
            }

            IsDarkTheme = theme.SysColorValues[KnownColor.Window].GetBrightness() < 0.5;

            return(new ThemeSettings(theme, invariantTheme, AppSettings.ThemeVariations, AppSettings.UseSystemVisualStyle));
        }
        public void SettingsAreModified_should_reflect_ThemeVariations_change(
            ThemeId themeId, string[] themeVariations, bool useSystemVisualStyle)
        {
            AppSettings.ThemeId              = themeId;
            AppSettings.ThemeVariations      = themeVariations;
            AppSettings.UseSystemVisualStyle = useSystemVisualStyle;
            ThemeModule.TestAccessor.ReloadThemeSettings(_context.ThemeRepository);

            _context.Controller.ShowThemeSettings();
            _context.Controller.SettingsAreModified.Should().BeFalse();

            _context.Page.SelectedThemeVariations = themeVariations.SequenceEqual(ThemeVariations.None)
                ? new[] { ThemeVariations.Colorblind }
                : ThemeVariations.None;
            _context.Controller.SettingsAreModified.Should().BeTrue();
        }
Example #14
0
        public static ThemeBuilderItem Get(string sourcePath, ThemeId theme, string[] lessPaths)
        {
            var lessParser = new ThemeBuilderLessParser(ThemeBuilderLessFilesReader.ReadPaths(lessPaths));
            var meta       = lessParser.GenerateThemeBuilderMetadata();

            string lessData = ThemeBuilderLessFilesReader.ReadPaths(lessPaths);

            lessData = ImageInliner.InlineImages(lessData, sourcePath);
            lessData = ThemeBuilderLessParser.MinifyLess(lessData);

            return(new ThemeBuilderItem
            {
                Metadata = meta,
                LessTemplate = lessData
            });
        }
Example #15
0
        /// <summary>
        /// Previously all themes were deployed to user data directory.
        /// Now we deploy builtin themes to application directory, leaving user directory for
        /// custom user-defined themes, so built-in themes must be purged from there.
        /// </summary>
        private void MigratePrebuiltThemes()
        {
            // TODO remove this method after 4.0 is released
            foreach (ThemeId id in _themeIds)
            {
                if (!id.IsBuiltin)
                {
                    _repository.Delete(id);
                }
            }

            ThemeId themeId = new ThemeId(AppSettings.ThemeId.Name, isBuiltin: true);

            AppSettings.ThemeId = _themeIds.Contains(themeId)
                ? themeId
                : ThemeId.Default;
        }
Example #16
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ThemeId.Length != 0)
            {
                hash ^= ThemeId.GetHashCode();
            }
            if (ThemeName != 0)
            {
                hash ^= ThemeName.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        public string ResolveCssUrl(string url)
        {
            if (url.EndsWith(_themePathProvider.ThemeExtension, StringComparison.OrdinalIgnoreCase))
            {
                url = url.Substring(0, url.Length - _themePathProvider.ThemeExtension.Length);
            }

            ThemeId id = url.StartsWith(CssVariableUserThemesDirectory)
                ? new ThemeId(url.Substring(CssVariableUserThemesDirectory.Length), isBuiltin: false)
                : new ThemeId(url, isBuiltin: true);

            try
            {
                return(_themePathProvider.GetThemePath(id));
            }
            catch (Exception ex)
            {
                throw new ThemeCssUrlResolverException(ex.Message, ex);
            }
        }
Example #18
0
        /// <exception cref="InvalidOperationException">
        /// Attempt to resolve a custom theme from a %UserAppData% folder in a portable version.
        /// </exception>
        /// <exception cref="FileNotFoundException">Theme does not exist.</exception>
        public string GetThemePath(ThemeId id)
        {
            string path;

            if (id.IsBuiltin)
            {
                path = Path.Combine(AppThemesDirectory, id.Name + ThemeExtension);
            }
            else
            {
                if (UserThemesDirectory is null)
                {
                    throw new InvalidOperationException("Portable mode only supports local themes");
                }

                path = Path.Combine(UserThemesDirectory, id.Name + ThemeExtension);
            }

            return(path);
        }
Example #19
0
        public static void Generate(string sourcePath, ThemeId baseThemeId, string customMetaFilePath, string outputPath)
        {
            var baseThemeBuilderItem = ThemeBuilderItem.Get(sourcePath, baseThemeId, ThemeBuilderLessFilesReader.GetLessPaths(sourcePath, baseThemeId));
            var baseThemeBuilderMeta = baseThemeBuilderItem.Metadata.ToDictionary(item => item.Key, item => item);
            var customThemeMeta      = JsonConvert.DeserializeObject <CustomThemeMeta>(File.ReadAllText(customMetaFilePath));

            var additionalConstants = new StringBuilder();

            if (customThemeMeta.HighlightColor != null)
            {
                foreach (var entry in baseThemeBuilderMeta)
                {
                    var isAccent = entry.Value.PaletteColorOpacity != null;
                    if (isAccent)
                    {
                        additionalConstants.AppendFormat(
                            LESS_VAR_FORMAT,
                            entry.Key,
                            ApplyOpacity(customThemeMeta.HighlightColor, double.Parse(entry.Value.PaletteColorOpacity, CultureInfo.InvariantCulture))
                            );
                    }
                }
            }

            foreach (var item in customThemeMeta.Items)
            {
                additionalConstants.AppendFormat(LESS_VAR_FORMAT, item.Key, item.Value);
            }

            var css = NodeRunner.CompileLess(baseThemeBuilderItem.LessTemplate + additionalConstants);

            var outputDir = Path.GetDirectoryName(outputPath);

            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }

            File.WriteAllText(outputPath, THEME_BUILDER_PROMO + css);
        }
 public Theme LoadTheme(string themeFileName, ThemeId themeId, in IReadOnlyList <string> allowedClasses)
 public void ShowThemeLoadingErrorMessage(ThemeId themeId, string[] variations, Exception ex) =>
 throw new NotImplementedException();
 public Theme Load(string themeFileName, ThemeId themeId, IReadOnlyList <string> variations)
 {
     return(_themeLoader.LoadTheme(themeFileName, themeId, allowedClasses: variations));
 }
        public Theme GetTheme(ThemeId id)
        {
            string path = GetPath(id);

            return(_persistence.Load(path, id));
        }
 private string GetPath(ThemeId id) =>
 Path.Combine(id.IsBuiltin
         ? AppDirectory
         : DataDirectory, id.Name + Extension);
        string PrepareMetadata(List <ThemeBuilderMetadata> metadata, ThemeId theme)
        {
            string writableContent = JsonConvert.SerializeObject(metadata, Formatting.Indented);

            return("ThemeBuilder.__" + theme.FullName.Replace("-", "_") + "_metadata = function(){ return " + writableContent + ";};");
        }
Example #26
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Nickname.Length != 0)
            {
                hash ^= Nickname.GetHashCode();
            }
            if (Level != 0)
            {
                hash ^= Level.GetHashCode();
            }
            if (DistanceWalkedKm != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(DistanceWalkedKm);
            }
            if (MaxHp != 0L)
            {
                hash ^= MaxHp.GetHashCode();
            }
            if (AttackPower != 0L)
            {
                hash ^= AttackPower.GetHashCode();
            }
            if (PlayerTeamId.Length != 0)
            {
                hash ^= PlayerTeamId.GetHashCode();
            }
            if (ProfessionId.Length != 0)
            {
                hash ^= ProfessionId.GetHashCode();
            }
            if (TitleId.Length != 0)
            {
                hash ^= TitleId.GetHashCode();
            }
            hash ^= unlockedTitleIds_.GetHashCode();
            if (ThemeId.Length != 0)
            {
                hash ^= ThemeId.GetHashCode();
            }
            hash ^= unlockedThemeIds_.GetHashCode();
            if (HouseId.Length != 0)
            {
                hash ^= HouseId.GetHashCode();
            }
            if (wand_ != null)
            {
                hash ^= Wand.GetHashCode();
            }
            hash ^= favoriteBadgeIds_.GetHashCode();
            hash ^= unlockedBadgeIds_.GetHashCode();
            hash ^= favoriteTitleIds_.GetHashCode();
            if (FirstName.Length != 0)
            {
                hash ^= FirstName.GetHashCode();
            }
            if (LastName.Length != 0)
            {
                hash ^= LastName.GetHashCode();
            }
            if (ProfileCreationLocation.Length != 0)
            {
                hash ^= ProfileCreationLocation.GetHashCode();
            }
            hash ^= unlockedSelfieAssetIds_.GetHashCode();
            if (TotalSwishSuccessSpell != 0L)
            {
                hash ^= TotalSwishSuccessSpell.GetHashCode();
            }
            hash ^= discoveredPotionsMasterNoteIds_.GetHashCode();
            if (emailOpts_ != null)
            {
                hash ^= EmailOpts.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        public Theme GetTheme(ThemeId themeId, IReadOnlyList <string> variations)
        {
            string themePath = _themePathProvider.GetThemePath(themeId);

            return(_persistence.Load(themePath, themeId, variations));
        }
 public FormattedThemeId(ThemeId themeId)
 {
     ThemeId = themeId;
 }