| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 | package shortcutimport (	"errors"	"path/filepath"	"strings"	"imuslab.com/arozos/mod/common"	"imuslab.com/arozos/mod/filesystem/arozfs")/*	A simple package to better handle shortcuts in ArozOS	Author: tobychui*/func ReadShortcut(shortcutContent []byte) (*arozfs.ShortcutData, error) {	//Split the content of the shortcut files into lines	fileContent := strings.ReplaceAll(strings.TrimSpace(string(shortcutContent)), "\r\n", "\n")	lines := strings.Split(fileContent, "\n")	if len(lines) < 4 {		return nil, errors.New("Corrupted Shortcut File")	}	for i := 0; i < len(lines); i++ {		lines[i] = strings.TrimSpace(lines[i])	}	//Render it as shortcut data	result := arozfs.ShortcutData{		Type: lines[0],		Name: lines[1],		Path: lines[2],		Icon: lines[3],	}	return &result, nil}//Generate the content of a shortcut base the the four important field of shortcut informationfunc GenerateShortcutBytes(shortcutTarget string, shortcutType string, shortcutText string, shortcutIcon string) []byte {	//Check if there are desktop icon. If yes, override icon on module	if shortcutType == "module" && common.FileExists(arozfs.ToSlash(filepath.Join("./web/", filepath.Dir(shortcutIcon), "/desktop_icon.png"))) {		shortcutIcon = arozfs.ToSlash(filepath.Join(filepath.Dir(shortcutIcon), "/desktop_icon.png"))	}	//Clean the shortcut text	shortcutText = arozfs.FilterIllegalCharInFilename(shortcutText, " ")	return []byte(shortcutType + "\n" + shortcutText + "\n" + shortcutTarget + "\n" + shortcutIcon)}
 |