2024-04-19 03:23:07 +00:00
|
|
|
//go:build dpp
|
|
|
|
// +build dpp
|
|
|
|
|
2024-04-19 05:12:56 +00:00
|
|
|
package dpp
|
2024-04-19 03:23:07 +00:00
|
|
|
|
|
|
|
import (
|
2024-04-19 05:12:56 +00:00
|
|
|
"encoding/json"
|
|
|
|
|
2024-04-19 03:23:07 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/doodads"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/filesystem"
|
2024-04-19 05:12:56 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/levelpack"
|
2024-04-19 05:31:11 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/native"
|
2024-04-19 05:12:56 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/plus"
|
2024-04-19 03:23:07 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/dpp/embedding"
|
|
|
|
"git.kirsle.net/SketchyMaze/dpp/license"
|
2024-04-19 05:12:56 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/dpp/license/levelsigning"
|
2024-04-19 03:23:07 +00:00
|
|
|
)
|
|
|
|
|
2024-04-19 05:12:56 +00:00
|
|
|
type Plugin struct{}
|
|
|
|
|
|
|
|
func (Plugin) LoadFromEmbeddable(filename string, fs filesystem.Embeddable, force bool) (*doodads.Doodad, error) {
|
2024-04-19 03:23:07 +00:00
|
|
|
return embedding.LoadFromEmbeddable(filename, fs, force)
|
|
|
|
}
|
|
|
|
|
2024-04-19 05:12:56 +00:00
|
|
|
func (Plugin) IsRegistered() bool {
|
2024-04-19 03:23:07 +00:00
|
|
|
return license.IsRegistered()
|
|
|
|
}
|
|
|
|
|
2024-04-19 05:12:56 +00:00
|
|
|
func (Plugin) GetRegistration() (plus.Registration, error) {
|
2024-04-19 03:23:07 +00:00
|
|
|
reg, err := license.GetRegistration()
|
2024-04-19 05:12:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return plus.Registration{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return translateLicenseStruct(reg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Plugin) UploadLicenseFile(filename string) (plus.Registration, error) {
|
|
|
|
reg, err := license.UploadLicenseFile(filename)
|
|
|
|
if err != nil {
|
|
|
|
return plus.Registration{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return translateLicenseStruct(reg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hack: to translate JWT token types, easiest is to just encode/decode them (inner jwt.StandardClaims complexity).
|
|
|
|
func translateLicenseStruct(reg license.Registration) (plus.Registration, error) {
|
2024-04-19 05:31:11 +00:00
|
|
|
// Set the DefaultAuthor to the registered user's name.
|
|
|
|
if reg.Name != "" {
|
|
|
|
native.DefaultAuthor = reg.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
// Marshal to JSON and back to cast the type.
|
|
|
|
var (
|
|
|
|
result plus.Registration
|
|
|
|
jsonStr, err = json.Marshal(reg)
|
|
|
|
)
|
2024-04-19 05:12:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return plus.Registration{}, err
|
|
|
|
}
|
|
|
|
err = json.Unmarshal(jsonStr, &result)
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Plugin) IsLevelPackSigned(lp *levelpack.LevelPack) bool {
|
|
|
|
return levelsigning.IsLevelPackSigned(lp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Plugin) IsLevelSigned(lvl *level.Level) bool {
|
|
|
|
return levelsigning.IsLevelSigned(lvl)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Driver = Plugin{}
|
2024-04-19 03:23:07 +00:00
|
|
|
}
|