Improve finding windows exe icon
This commit is contained in:
@@ -63,29 +63,6 @@ func getIconAndNamefromRSS(ctx context.Context, binPath string) (png []byte, nam
|
||||
// return true
|
||||
// })
|
||||
|
||||
// Get first icon.
|
||||
var (
|
||||
icon *winres.Icon
|
||||
iconErr error
|
||||
)
|
||||
rss.WalkType(winres.RT_GROUP_ICON, func(resID winres.Identifier, langID uint16, _ []byte) bool {
|
||||
icon, iconErr = rss.GetIconTranslation(resID, langID)
|
||||
return iconErr != nil
|
||||
})
|
||||
if iconErr != nil {
|
||||
return nil, "", fmt.Errorf("failed to get icon: %w", err)
|
||||
}
|
||||
// Convert icon.
|
||||
icoBuf := &bytes.Buffer{}
|
||||
err = icon.SaveICO(icoBuf)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("failed to save ico: %w", err)
|
||||
}
|
||||
png, err = ConvertICOtoPNG(icoBuf.Bytes())
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("failed to convert ico to png: %w", err)
|
||||
}
|
||||
|
||||
// Get name from version record.
|
||||
var (
|
||||
versionInfo *version.Info
|
||||
@@ -111,5 +88,31 @@ func getIconAndNamefromRSS(ctx context.Context, binPath string) (png []byte, nam
|
||||
})
|
||||
name = cleanFileDescription(name)
|
||||
|
||||
// Get first icon.
|
||||
var (
|
||||
icon *winres.Icon
|
||||
iconErr error
|
||||
)
|
||||
rss.WalkType(winres.RT_GROUP_ICON, func(resID winres.Identifier, langID uint16, _ []byte) bool {
|
||||
icon, iconErr = rss.GetIconTranslation(resID, langID)
|
||||
return iconErr != nil
|
||||
})
|
||||
if iconErr != nil {
|
||||
return nil, name, fmt.Errorf("failed to get icon: %w", err)
|
||||
}
|
||||
if icon == nil {
|
||||
return nil, name, errors.New("no icon in resources")
|
||||
}
|
||||
// Convert icon, if it exists.
|
||||
icoBuf := &bytes.Buffer{}
|
||||
err = icon.SaveICO(icoBuf)
|
||||
if err != nil {
|
||||
return nil, name, fmt.Errorf("failed to save ico: %w", err)
|
||||
}
|
||||
png, err = ConvertICOtoPNG(icoBuf.Bytes())
|
||||
if err != nil {
|
||||
return nil, name, fmt.Errorf("failed to convert ico to png: %w", err)
|
||||
}
|
||||
|
||||
return png, name, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user