Compare commits
No commits in common. "main" and "1.0.0" have entirely different histories.
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module git.thcfree.dev/THCFree/TraktorNmlUtils
|
module traktorNmlUtils
|
||||||
|
|
||||||
go 1.23.1
|
go 1.23.1
|
||||||
|
|
||||||
|
4
main.go
4
main.go
@ -2,12 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.thcfree.dev/THCFree/TraktorNmlUtils/models/collection"
|
|
||||||
"git.thcfree.dev/THCFree/TraktorNmlUtils/models/history"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"traktorNmlUtils/models/collection"
|
||||||
|
"traktorNmlUtils/models/history"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Most of this code is based on the original python library https://github.com/wolkenarchitekt/traktor-nml-utils/ thus is subject to the same license reference it at LICENSE.txt
|
// Most of this code is based on the original python library https://github.com/wolkenarchitekt/traktor-nml-utils/ thus is subject to the same license reference it at LICENSE.txt
|
||||||
|
@ -22,29 +22,3 @@ func ReadFileAndConvertToCollection(filePath string) (*NML, error) {
|
|||||||
|
|
||||||
return &collection, nil
|
return &collection, nil
|
||||||
}
|
}
|
||||||
func CollectionFromString(content string) (*NML, error) {
|
|
||||||
// Unmarshal the XML content into the Collection struct
|
|
||||||
var collection NML
|
|
||||||
err := xml.Unmarshal([]byte(content), &collection)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -30,22 +30,6 @@ func ReadFileAndConvertToHistory(filePath string) (*NML, error) {
|
|||||||
return nil, errors.New("file is not a history file")
|
return nil, errors.New("file is not a history file")
|
||||||
}
|
}
|
||||||
|
|
||||||
func HistoryFromString(content string) (*NML, error) {
|
|
||||||
// Unmarshal the XML content into the NML struct
|
|
||||||
var nml NML
|
|
||||||
err := xml.Unmarshal([]byte(content), &nml)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the file is a history file based on the content
|
|
||||||
if IsHistoryString(content) {
|
|
||||||
return &nml, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, errors.New("file is not a history file")
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsHistoryFile(path string) bool {
|
func IsHistoryFile(path string) bool {
|
||||||
content, err := os.ReadFile(path)
|
content, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -53,23 +37,3 @@ func IsHistoryFile(path string) bool {
|
|||||||
}
|
}
|
||||||
return strings.Contains(string(content), "HistoryData")
|
return strings.Contains(string(content), "HistoryData")
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user