Example #1
0
func run(fnamein, fnameico, fnameout string) error {
	manifest, err := binutil.SizedOpen(fnamein)
	if err != nil {
		return fmt.Errorf("Error opening manifest file '%s': %s", fnamein, err)
	}
	defer manifest.Close()

	var icons []ico.ICONDIRENTRY
	var iconsf *os.File
	if fnameico != "" {
		iconsf, err = os.Open(fnameico)
		if err != nil {
			return err
		}
		defer iconsf.Close()
		icons, err = ico.DecodeHeaders(iconsf)
		if err != nil {
			return err
		}
	}

	newid := make(chan uint16)
	go func() {
		for i := uint16(1); ; i++ {
			newid <- i
		}
	}()

	coff := coff.NewRSRC()

	coff.AddResource(RT_MANIFEST, <-newid, manifest)

	if len(icons) > 0 {
		// RT_ICONs
		group := GRPICONDIR{ICONDIR: ico.ICONDIR{
			Reserved: 0, // magic num.
			Type:     1, // magic num.
			Count:    uint16(len(icons)),
		}}
		for _, icon := range icons {
			id := <-newid
			r := io.NewSectionReader(iconsf, int64(icon.ImageOffset), int64(icon.BytesInRes))

			coff.AddResource(RT_ICON, id, r)
			group.Entries = append(group.Entries, GRPICONDIRENTRY{icon.IconDirEntryCommon, id})
		}

		// RT_GROUP_ICON
		coff.AddResource(RT_GROUP_ICON, <-newid, group)
	}

	coff.Freeze()

	return write(coff, fnameout)
}
Example #2
0
// WriteSyso creates a resource file from the version info and optionally an icon
func (vi *VersionInfo) WriteSyso(filename string) error {

	// Channel for generating IDs
	newID := make(chan uint16)
	go func() {
		for i := uint16(1); ; i++ {
			newID <- i
		}
	}()

	// Create a new RSRC section
	coff := coff.NewRSRC()

	// ID 16 is for Version Information
	coff.AddResource(16, 1, sizedReader{&vi.Buffer})

	// If icon is enabled
	if vi.IconPath != "" {
		if err := addIcon(coff, vi.IconPath, newID); err != nil {
			return err
		}
	}

	coff.Freeze()

	// Write to file
	return writeCoff(coff, filename)
}
Example #3
0
func run(fnamein, fnameico, fnameout string) error {
	newid := make(chan uint16)
	go func() {
		for i := uint16(1); ; i++ {
			newid <- i
		}
	}()

	coff := coff.NewRSRC()

	if fnamein != "" {
		manifest, err := binutil.SizedOpen(fnamein)
		if err != nil {
			return fmt.Errorf("Error opening manifest file '%s': %s", fnamein, err)
		}
		defer manifest.Close()

		id := <-newid
		coff.AddResource(RT_MANIFEST, id, manifest)
		fmt.Println("Manifest ID: ", id)
	}
	if fnameico != "" {
		for _, fnameicosingle := range strings.Split(fnameico, ",") {
			err := addicon(coff, fnameicosingle, newid)
			if err != nil {
				return err
			}
		}
	}

	coff.Freeze()

	return write(coff, fnameout)
}