shortcut.go 760 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package shortcut
  2. import (
  3. "errors"
  4. "strings"
  5. "imuslab.com/arozos/mod/filesystem/arozfs"
  6. )
  7. /*
  8. A simple package to better handle shortcuts in ArozOS
  9. Author: tobychui
  10. */
  11. func ReadShortcut(shortcutContent []byte) (*arozfs.ShortcutData, error) {
  12. //Split the content of the shortcut files into lines
  13. fileContent := strings.ReplaceAll(strings.TrimSpace(string(shortcutContent)), "\r\n", "\n")
  14. lines := strings.Split(fileContent, "\n")
  15. if len(lines) < 4 {
  16. return nil, errors.New("Corrupted Shortcut File")
  17. }
  18. for i := 0; i < len(lines); i++ {
  19. lines[i] = strings.TrimSpace(lines[i])
  20. }
  21. //Render it as shortcut data
  22. result := arozfs.ShortcutData{
  23. Type: lines[0],
  24. Name: lines[1],
  25. Path: lines[2],
  26. Icon: lines[3],
  27. }
  28. return &result, nil
  29. }