|
@@ -2,10 +2,9 @@ package shortcut
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
- "io/ioutil"
|
|
|
"strings"
|
|
|
|
|
|
- "imuslab.com/arozos/mod/common"
|
|
|
+ "imuslab.com/arozos/mod/filesystem/arozfs"
|
|
|
)
|
|
|
|
|
|
/*
|
|
@@ -14,43 +13,26 @@ import (
|
|
|
Author: tobychui
|
|
|
*/
|
|
|
|
|
|
-//A shortcut representing struct
|
|
|
-type ShortcutData struct {
|
|
|
- Type string //The type of shortcut
|
|
|
- Name string //The name of the shortcut
|
|
|
- Path string //The path of shortcut
|
|
|
- Icon string //The icon of shortcut
|
|
|
-}
|
|
|
+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")
|
|
|
+ }
|
|
|
|
|
|
-func ReadShortcut(shortcutFile string) (*ShortcutData, error) {
|
|
|
- if common.FileExists(shortcutFile) {
|
|
|
- content, err := ioutil.ReadFile(shortcutFile)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- //Split the content of the shortcut files into lines
|
|
|
- fileContent := strings.ReplaceAll(strings.TrimSpace(string(content)), "\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 := ShortcutData{
|
|
|
- Type: lines[0],
|
|
|
- Name: lines[1],
|
|
|
- Path: lines[2],
|
|
|
- Icon: lines[3],
|
|
|
- }
|
|
|
-
|
|
|
- return &result, nil
|
|
|
- } else {
|
|
|
- return nil, errors.New("File not exists.")
|
|
|
+ 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
|
|
|
}
|