-
Notifications
You must be signed in to change notification settings - Fork 2
/
image.go
52 lines (46 loc) · 838 Bytes
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package mvm
import (
"fmt"
"io/ioutil"
"os"
)
func SetupDefault() {
b := MakeBlueprint("root")
s := MakeShell(nil, nil)
b.instances[s] = true
s.object = MakeMachine(b)
TheVM.root = s
var x float64
for _, o := range Objects {
f := b.AddFrame()
Copy(o, f, s)
f.pos.X = x
x += f.size.X + margin
}
}
var FileName string = "mvm.img"
func LoadImage() error {
byte_slice, err := ioutil.ReadFile(FileName)
if err != nil {
fmt.Printf("'%s' not found - loading the default VM image\n", FileName)
SetupDefault()
return nil
}
ble, err := Unflatten(byte_slice)
if err != nil {
return err
}
TheVM = ble.(*VM)
return nil
}
func SaveImage() error {
bytes, err := Flatten(TheVM)
if err != nil {
return err
}
err = ioutil.WriteFile(FileName, bytes, os.ModePerm)
if err != nil {
return err
}
return nil
}