2019-06-01 18:06:44 +00:00
|
|
|
package apple2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/ivanizag/apple2/romdumps"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
internalPrefix = "<internal>/"
|
|
|
|
)
|
|
|
|
|
2019-06-09 21:54:27 +00:00
|
|
|
func isInternalResource(filename string) bool {
|
|
|
|
return strings.HasPrefix(filename, internalPrefix)
|
|
|
|
}
|
|
|
|
|
2019-06-01 18:06:44 +00:00
|
|
|
func loadResource(filename string) []uint8 {
|
|
|
|
var file io.Reader
|
2019-06-09 21:54:27 +00:00
|
|
|
if isInternalResource(filename) {
|
2019-06-01 18:06:44 +00:00
|
|
|
// load from embedded resource
|
|
|
|
resource := strings.TrimPrefix(filename, internalPrefix)
|
|
|
|
resourceFile, err := romdumps.Assets.Open(resource)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer resourceFile.Close()
|
|
|
|
file = resourceFile
|
|
|
|
} else {
|
|
|
|
diskFile, err := os.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer diskFile.Close()
|
|
|
|
file = diskFile
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := ioutil.ReadAll(file)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
}
|