Load Windows Svc icon with new icon system
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user