Add collection and history saving

This commit is contained in:
THCFree 2024-10-15 04:22:01 +02:00
parent 8e9d5e90ba
commit 60bafd0870
2 changed files with 32 additions and 0 deletions

View File

@ -32,3 +32,19 @@ func CollectionFromString(content string) (*NML, error) {
return &collection, nil return &collection, nil
} }
func SaveCollectionToFile(collection *NML, filePath string) error {
// Marshal the Collection struct into XML content
content, err := xml.MarshalIndent(collection, "", " ")
if err != nil {
return err
}
// Write the XML content to the file
err = os.WriteFile(filePath, content, 0644)
if err != nil {
return err
}
return nil
}

View File

@ -57,3 +57,19 @@ func IsHistoryFile(path string) bool {
func IsHistoryString(content string) bool { func IsHistoryString(content string) bool {
return strings.Contains(content, "HistoryData") return strings.Contains(content, "HistoryData")
} }
func SaveHistoryToFile(history *NML, filePath string) error {
// Marshal the NML struct into XML content
content, err := xml.MarshalIndent(history, "", " ")
if err != nil {
return err
}
// Write the XML content to the file
err = os.WriteFile(filePath, content, 0644)
if err != nil {
return err
}
return nil
}