Load Windows Svc icon with new icon system

This commit is contained in:
Daniel
2023-12-13 16:25:48 +01:00
parent cf3d4e030f
commit 9c969f9465
3 changed files with 32 additions and 16 deletions

View File

@@ -21,19 +21,7 @@ func FindIcon(ctx context.Context, binName string, homeDir string) (*Icon, error
return nil, nil
}
// Load icon and save it.
data, err := os.ReadFile(iconPath)
if err != nil {
return nil, fmt.Errorf("failed to read icon %s: %w", iconPath, err)
}
filename, err := UpdateProfileIcon(data, filepath.Ext(iconPath))
if err != nil {
return nil, fmt.Errorf("failed to import icon %s: %w", iconPath, err)
}
return &Icon{
Type: IconTypeAPI,
Value: filename,
}, nil
return LoadAndSaveIcon(ctx, iconPath)
}
func search(binName string, homeDir string) (iconPath string, err error) {

View File

@@ -1,6 +1,7 @@
package icons
import (
"context"
"crypto"
"encoding/hex"
"errors"
@@ -78,4 +79,22 @@ func UpdateProfileIcon(data []byte, ext string) (filename string, err error) {
return filename, os.WriteFile(filepath.Join(ProfileIconStoragePath, filename), data, 0o0644) //nolint:gosec
}
// LoadAndSaveIcon loads an icon from disk, updates it in the icon database
// and returns the icon object.
func LoadAndSaveIcon(ctx context.Context, iconPath string) (*Icon, error) {
// Load icon and save it.
data, err := os.ReadFile(iconPath)
if err != nil {
return nil, fmt.Errorf("failed to read icon %s: %w", iconPath, err)
}
filename, err := UpdateProfileIcon(data, filepath.Ext(iconPath))
if err != nil {
return nil, fmt.Errorf("failed to import icon %s: %w", iconPath, err)
}
return &Icon{
Type: IconTypeAPI,
Value: filename,
}, nil
}
// TODO: Clean up icons regularly.