-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance.go
54 lines (41 loc) · 954 Bytes
/
instance.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
53
54
package launcher
import (
"errors"
"fmt"
"os"
"path/filepath"
"github.com/brawaru/marct/utils"
)
type Instance struct {
// Path to the instance directory
Path string
TemporalData map[any]any
closed bool
}
const settingsFile = "marct_settings.toml"
func (w *Instance) OpenSettings() (*SettingsFile, error) {
s := NewSettings(filepath.Join(w.Path, filepath.FromSlash(settingsFile)))
if err := s.Read(); err != nil {
if !utils.DoesNotExist(err) {
return nil, fmt.Errorf("failed to read settings: %w", err)
}
}
return s, nil
}
func (w *Instance) Close() error {
if w.closed {
return errors.New("already closed")
}
return nil
}
func OpenInstance(name string) (*Instance, error) {
currentDir, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("failed to get current directory: %w", err)
}
i := &Instance{
Path: filepath.Join(currentDir, name),
TemporalData: make(map[any]any),
}
return i, nil
}