Updated FileNode Struct
Added New Field `absolutePath` to FileNode struct. This helps in adding the song to the playlist through the Add Button.
This commit is contained in:
parent
eecb86ed8f
commit
680b41cb6e
@ -1,18 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type FileNode struct {
|
||||
children []FileNode
|
||||
path string
|
||||
parent *FileNode
|
||||
absolutePath string
|
||||
}
|
||||
|
||||
func (f *FileNode) addChildren(path string) {
|
||||
f.children = append(f.children, FileNode{children: make([]FileNode, 0), path: path, parent: f})
|
||||
if f.path != "" {
|
||||
f.children = append(f.children, FileNode{children: make([]FileNode, 0), path: path, parent: f, absolutePath: f.absolutePath + "/" + path})
|
||||
} else {
|
||||
f.children = append(f.children, FileNode{children: make([]FileNode, 0), path: path, parent: f, absolutePath: f.absolutePath + path})
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FileNode) addChildNode(m FileNode) {
|
||||
@ -23,22 +28,22 @@ func (f *FileNode) addChildNode(m FileNode){
|
||||
func generateDirectoryTree(path []string) *FileNode {
|
||||
var head *FileNode = new(FileNode)
|
||||
var head1 *FileNode = head
|
||||
for i := range(path){
|
||||
for i := range path {
|
||||
sepPaths := strings.Split(path[i], "/")
|
||||
for j := range(sepPaths){
|
||||
if(len(head.children) == 0){
|
||||
for j := range sepPaths {
|
||||
if len(head.children) == 0 {
|
||||
head.addChildren(sepPaths[j])
|
||||
head = &(head.children[len(head.children)-1])
|
||||
} else {
|
||||
var headIsChanged = false
|
||||
for k := range(head.children){
|
||||
for k := range head.children {
|
||||
if head.children[k].path == sepPaths[j] {
|
||||
head = &(head.children[k])
|
||||
headIsChanged = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if(!headIsChanged){
|
||||
if !headIsChanged {
|
||||
head.addChildren(sepPaths[j])
|
||||
head = &(head.children[len(head.children)-1])
|
||||
}
|
||||
@ -50,13 +55,14 @@ func generateDirectoryTree(path [] string) *FileNode{
|
||||
}
|
||||
|
||||
func (f FileNode) Print(count int) {
|
||||
if (len(f.children) == 0){
|
||||
if len(f.children) == 0 {
|
||||
return
|
||||
} else {
|
||||
for i := range f.children {
|
||||
for j := 0; j < count; j++ {
|
||||
fmt.Print("---")
|
||||
}; fmt.Println(f.children[i].path)
|
||||
}
|
||||
fmt.Println(f.children[i].absolutePath)
|
||||
f.children[i].Print(count + 1)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user