2019-05-24 02:58:46 +00:00
|
|
|
package metadata
|
2019-05-20 04:12:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type License struct {
|
|
|
|
Purchased bool
|
|
|
|
Valid bool
|
|
|
|
Key *string
|
|
|
|
Username *string
|
|
|
|
Company *string
|
|
|
|
}
|
|
|
|
|
|
|
|
const licenseFileName = "license.yml"
|
|
|
|
|
|
|
|
func GetLicense() *License {
|
|
|
|
if !fileExists(licenseFileName) {
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
file := readStorageFile(getPlatformStoragePath(licenseFileName))
|
|
|
|
|
|
|
|
license := new(License)
|
|
|
|
err := yaml.Unmarshal(file, license)
|
|
|
|
|
|
|
|
if err != nil {
|
2019-05-20 04:14:13 +00:00
|
|
|
log.Fatalf("Failed to read license file: %v", err)
|
2019-05-20 04:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return license
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitLicense() {
|
|
|
|
|
|
|
|
license := License{
|
|
|
|
Purchased: false,
|
|
|
|
Valid: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
file, err := yaml.Marshal(license)
|
|
|
|
if err != nil {
|
2019-05-20 04:14:13 +00:00
|
|
|
log.Fatalf("Failed to marshal config file: %v", err)
|
2019-05-20 04:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initStorage()
|
|
|
|
saveStorageFile(file, getPlatformStoragePath(licenseFileName))
|
|
|
|
}
|