mirror of
https://github.com/safing/portmaster
synced 2025-04-25 13:29:10 +00:00
Ignore default windows icons
This commit is contained in:
parent
f0bed8f794
commit
a457ac4245
4 changed files with 56 additions and 2 deletions
service/profile
|
@ -100,7 +100,12 @@ func handleGetProfileIcon(ar *api.Request) (data []byte, err error) {
|
|||
|
||||
// Get profile icon.
|
||||
data, err = binmeta.GetProfileIcon(name)
|
||||
if err != nil {
|
||||
switch {
|
||||
case err == nil:
|
||||
// Continue
|
||||
case errors.Is(err, binmeta.IconIgnored):
|
||||
return nil, api.ErrorWithStatus(err, http.StatusNotFound)
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@ import (
|
|||
// Must not be changed once set.
|
||||
var ProfileIconStoragePath = ""
|
||||
|
||||
// IconIgnored is returned when the icon should be ignored.
|
||||
var IconIgnored = errors.New("icon is ignored")
|
||||
|
||||
// GetProfileIcon returns the profile icon with the given ID and extension.
|
||||
func GetProfileIcon(name string) (data []byte, err error) {
|
||||
// Check if enabled.
|
||||
|
@ -26,6 +29,11 @@ func GetProfileIcon(name string) (data []byte, err error) {
|
|||
return nil, errors.New("api icon storage not configured")
|
||||
}
|
||||
|
||||
// Check if icon should be ignored.
|
||||
if IgnoreIcon(name) {
|
||||
return nil, IconIgnored
|
||||
}
|
||||
|
||||
// Build storage path.
|
||||
iconPath := filepath.Clean(
|
||||
filepath.Join(ProfileIconStoragePath, name),
|
||||
|
@ -59,6 +67,11 @@ func UpdateProfileIcon(data []byte, ext string) (filename string, err error) {
|
|||
}
|
||||
sum := hex.EncodeToString(h.Sum(nil))
|
||||
|
||||
// Check if icon should be ignored.
|
||||
if IgnoreIcon(sum) {
|
||||
return "", IconIgnored
|
||||
}
|
||||
|
||||
// Check ext.
|
||||
ext = strings.ToLower(ext)
|
||||
switch ext {
|
||||
|
|
30
service/profile/binmeta/ignore.go
Normal file
30
service/profile/binmeta/ignore.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package binmeta
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ignoreIcons = map[string]struct{}{
|
||||
// Windows Default Icons.
|
||||
"a27898ddfa4e0481b62c69faa196919a738fcade": {},
|
||||
"5a3eea8bcd08b9336ce9c5083f26185164268ee9": {},
|
||||
"573393d6ad238d255b20dc1c1b303c95debe6965": {},
|
||||
"d459b2cb23c27cc31ccab5025533048d5d8301bf": {},
|
||||
"d35a0d91ebfda81df5286f68ec5ddb1d6ad6b850": {},
|
||||
"cc33187385498384f1b648e23be5ef1a2e9f5f71": {},
|
||||
}
|
||||
|
||||
// IgnoreIcon returns whether an icon should be ignored or not.
|
||||
func IgnoreIcon(name string) bool {
|
||||
// Make lower case.
|
||||
name = strings.ToLower(name)
|
||||
// Remove extension.
|
||||
extIndex := strings.Index(name, ".")
|
||||
if extIndex > 0 {
|
||||
name = name[:extIndex]
|
||||
}
|
||||
|
||||
// Check if ID is in list.
|
||||
_, found := ignoreIcons[name]
|
||||
return found
|
||||
}
|
|
@ -515,7 +515,13 @@ func (profile *Profile) updateMetadataFromSystem(ctx context.Context, md Matchin
|
|||
|
||||
// Get binary icon and name.
|
||||
newIcon, newName, err := binmeta.GetIconAndName(ctx, profile.PresentationPath, home)
|
||||
if err != nil {
|
||||
switch {
|
||||
case err == nil:
|
||||
// Continue
|
||||
case errors.Is(err, binmeta.IconIgnored):
|
||||
newIcon = nil
|
||||
// Continue
|
||||
default:
|
||||
log.Warningf("profile: failed to get binary icon/name for %s: %s", profile.PresentationPath, err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue