From 60bafd0870acc0935ab39019b3c26169524a7e01 Mon Sep 17 00:00:00 2001 From: THCFree Date: Tue, 15 Oct 2024 04:22:01 +0200 Subject: [PATCH] Add collection and history saving --- models/collection/CollectionHandler.go | 16 ++++++++++++++++ models/history/HistoryHandler.go | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/models/collection/CollectionHandler.go b/models/collection/CollectionHandler.go index dfeb923..399d0e3 100644 --- a/models/collection/CollectionHandler.go +++ b/models/collection/CollectionHandler.go @@ -32,3 +32,19 @@ func CollectionFromString(content string) (*NML, error) { 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 +} diff --git a/models/history/HistoryHandler.go b/models/history/HistoryHandler.go index 8824ecd..a5e866a 100644 --- a/models/history/HistoryHandler.go +++ b/models/history/HistoryHandler.go @@ -57,3 +57,19 @@ func IsHistoryFile(path string) bool { func IsHistoryString(content string) bool { 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 +}