Skip to content

Commit

Permalink
Update to internal testing build v2.015
Browse files Browse the repository at this point in the history
Big updates to File Manager interface and remove some of the wallpaper pack to reduce webpack size
(Also a new dark theme as well if you are interested into not white theme)
  • Loading branch information
tobychui committed Mar 29, 2023
1 parent 5eb222e commit caa3b38
Show file tree
Hide file tree
Showing 81 changed files with 22,074 additions and 34,593 deletions.
17 changes: 10 additions & 7 deletions src/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,25 @@ The functions in this section handle file listing and its icon locations.
func desktop_initUserFolderStructure(username string) {
//Call to filesystem for creating user file struture at root dir
userinfo, _ := userHandler.GetUserInfoFromUsername(username)
homedir, err := userinfo.GetHomeDirectory()
userfsh, err := userinfo.GetHomeFileSystemHandler()
if err != nil {
systemWideLogger.PrintAndLog("Desktop", "Unable to initiate user desktop folder", err)
return
}

if !fs.FileExists(filepath.Join(homedir, "Desktop")) {
userFsa := userfsh.FileSystemAbstraction
userDesktopPath, _ := userFsa.VirtualPathToRealPath("user:/Desktop", userinfo.Username)
if !userFsa.FileExists(userDesktopPath) {
//Desktop directory not exists. Create one and copy a template desktop
os.MkdirAll(homedir+"Desktop", 0755)
userFsa.MkdirAll(userDesktopPath, 0755)

//Copy template file from system folder if exists
templateFolder := "./system/desktop/template/"
if fs.FileExists(templateFolder) {
templateFiles, _ := filepath.Glob(templateFolder + "*")
for _, tfile := range templateFiles {
input, _ := os.ReadFile(tfile)
os.WriteFile(homedir+"Desktop/"+filepath.Base(tfile), input, 0755)
userFsa.WriteFile(arozfs.ToSlash(filepath.Join(userDesktopPath, filepath.Base(tfile))), input, 0755)
}
}
}
Expand Down Expand Up @@ -346,7 +349,7 @@ func setDesktopLocationFromPath(filename string, username string, x int, y int)
//Parse the location to json
jsonstring, err := json.Marshal(newLocation)
if err != nil {
log.Println("[Desktop] Unable to parse new file location on desktop for file: " + path)
systemWideLogger.PrintAndLog("Desktop", "Unable to parse new file location on desktop for file: "+path, err)
return err
}

Expand Down Expand Up @@ -474,7 +477,7 @@ func desktop_theme_handler(w http.ResponseWriter, r *http.Request) {
//List all the currnet themes in the list
themes, err := filepath.Glob("web/img/desktop/bg/*")
if err != nil {
log.Println("[Desktop] Unable to search bg from destkop image root. Are you sure the web data folder exists?")
systemWideLogger.PrintAndLog("Desktop", "Unable to search bg from destkop image root. Are you sure the web data folder exists?", err)
return
}
//Prase the results to json array
Expand Down Expand Up @@ -513,7 +516,7 @@ func desktop_theme_handler(w http.ResponseWriter, r *http.Request) {
//Return the results as JSON string
jsonString, err := json.Marshal(desktopThemeList)
if err != nil {
log.Println("[Desktop] Marshal desktop wallpaper list error: " + err.Error())
systemWideLogger.PrintAndLog("Desktop", "Unable to render desktop wallpaper list", err)
utils.SendJSONResponse(w, string("[]"))
return
}
Expand Down
99 changes: 40 additions & 59 deletions src/file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func FileSystemInit() {
Version: "1.0",
StartDir: "SystemAO/file_system/file_explorer.html",
SupportFW: true,
InitFWSize: []int{1080, 580},
InitFWSize: []int{1075, 600},
LaunchFWDir: "SystemAO/file_system/file_explorer.html",
SupportEmb: false,
})
Expand Down Expand Up @@ -519,9 +519,6 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
if msg == "done" {
//Start the merging process
break
} else {
//Unknown operations

}
} else if mt == 2 {
//File block. Save it to tmp folder
Expand Down Expand Up @@ -631,7 +628,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
return
}

for _, filesrc := range chunkName {
for counter, filesrc := range chunkName {
var srcChunkReader arozfs.File
if isHugeFile {
srcChunkReader, err = fshAbs.Open(filesrc)
Expand All @@ -644,7 +641,9 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
c.WriteMessage(1, []byte(`{\"error\":\"Failed to open Source Chunk\"}`))
return
}

io.Copy(out, srcChunkReader)

srcChunkReader.Close()

//Delete file immediately to save space
Expand All @@ -654,6 +653,9 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
os.Remove(filesrc)
}

//Write to websocket for the percentage of upload is written fro tmp to dest
moveProg := strconv.Itoa(int(math.Round(float64(counter)/float64(len(chunkName))*100))) + "%"
c.WriteMessage(1, []byte(`{\"move\":\"`+moveProg+`"}`))
}

out.Close()
Expand Down Expand Up @@ -2257,7 +2259,7 @@ func system_fs_removeUserPreferences(username string) {
}

func system_fs_listDrives(w http.ResponseWriter, r *http.Request) {
if authAgent.CheckAuth(r) == false {
if !authAgent.CheckAuth(r) {
utils.SendErrorResponse(w, "User not logged in")
return
}
Expand Down Expand Up @@ -2370,49 +2372,21 @@ func system_fs_listRoot(w http.ResponseWriter, r *http.Request) {
You can also pass in normal path for globing if you are not sure.
*/

func system_fs_specialGlob(path string) ([]string, error) {
//Quick fix for foldername containing -] issue
path = strings.ReplaceAll(path, "[", "[[]")
files, err := filepath.Glob(path)
if err != nil {
return []string{}, err
}

if strings.Contains(path, "[") == true || strings.Contains(path, "]") == true {
if len(files) == 0 {
//Handle reverse check. Replace all [ and ] with *
newSearchPath := strings.ReplaceAll(path, "[", "?")
newSearchPath = strings.ReplaceAll(newSearchPath, "]", "?")
//Scan with all the similar structure except [ and ]
tmpFilelist, _ := filepath.Glob(newSearchPath)
for _, file := range tmpFilelist {
file = filepath.ToSlash(file)
if strings.Contains(file, filepath.ToSlash(filepath.Dir(path))) {
files = append(files, file)
}
}
}
}
//Convert all filepaths to slash
for i := 0; i < len(files); i++ {
files[i] = filepath.ToSlash(files[i])
}
return files, nil
}

func system_fs_specialURIDecode(inputPath string) string {
inputPath = strings.ReplaceAll(inputPath, "+", "{{plus_sign}}")
inputPath, _ = url.QueryUnescape(inputPath)
inputPath = strings.ReplaceAll(inputPath, "{{plus_sign}}", "+")
return inputPath
}

/*
func system_fs_specialURIEncode(inputPath string) string {
inputPath = strings.ReplaceAll(inputPath, " ", "{{space_sign}}")
inputPath, _ = url.QueryUnescape(inputPath)
inputPath = strings.ReplaceAll(inputPath, "{{space_sign}}", "%20")
return inputPath
}
*/

// Handle file properties request
func system_fs_getFileProperties(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -2576,13 +2550,15 @@ func system_fs_handleList(w http.ResponseWriter, r *http.Request) {
}
if !fshAbs.FileExists(realpath) {
//Path not exists
userRoot, _ := fshAbs.VirtualPathToRealPath("", userinfo.Username)
if filepath.Clean(realpath) == filepath.Clean(userRoot) {
userRoot, _ := fshAbs.VirtualPathToRealPath("/", userinfo.Username)
if filepath.Clean(realpath) == filepath.Clean(userRoot) || realpath == "" {
//Initiate user folder (Initiaed in user object)
userinfo.GetHomeDirectory()
} else if !strings.Contains(filepath.ToSlash(filepath.Clean(currentDir)), "/") {
//User root not created. Create the root folder
os.MkdirAll(filepath.Clean(realpath), 0775)
err = fshAbs.MkdirAll(userRoot, 0775)
if err != nil {
systemWideLogger.PrintAndLog("File System", "Unable to create user root on "+fsh.UUID+": "+err.Error(), nil)
utils.SendErrorResponse(w, "Unable to create user root folder due to file system error")
return
}
} else {
//Folder not exists
systemWideLogger.PrintAndLog("File System", "Requested path: "+realpath+" does not exists", nil)
Expand All @@ -2598,7 +2574,7 @@ func system_fs_handleList(w http.ResponseWriter, r *http.Request) {

files, err := fshAbs.ReadDir(realpath)
if err != nil {
utils.SendErrorResponse(w, "Readdir Failed: "+err.Error())
utils.SendErrorResponse(w, "Readdir Failed: "+strings.ReplaceAll(err.Error(), "\\", "/"))
systemWideLogger.PrintAndLog("File System", "Unable to read dir: "+err.Error(), err)
return
}
Expand Down Expand Up @@ -2707,23 +2683,24 @@ func system_fs_handleDirHash(w http.ResponseWriter, r *http.Request) {
}

//Get a list of files in this directory
currentDir = filepath.ToSlash(filepath.Clean(rpath)) + "/"
/*
filesInDir, err := fshAbs.Glob(currentDir + "*")
if err != nil {
utils.SendErrorResponse(w, err.Error())
return
}
currentDir = filepath.ToSlash(filepath.Clean(rpath)) + "/"
filenames := []string{}
for _, file := range filesInDir {
if len(filepath.Base(file)) > 0 && string([]rune(filepath.Base(file))[0]) != "." {
//Ignore hidden files
filenames = append(filenames, filepath.Base(file))
filesInDir, err := fshAbs.Glob(currentDir + "*")
if err != nil {
utils.SendErrorResponse(w, err.Error())
return
}
}
filenames := []string{}
for _, file := range filesInDir {
if len(filepath.Base(file)) > 0 && string([]rune(filepath.Base(file))[0]) != "." {
//Ignore hidden files
filenames = append(filenames, filepath.Base(file))
}
}
*/
finfos, err := fshAbs.ReadDir(rpath)
if err != nil {
Expand Down Expand Up @@ -3108,7 +3085,7 @@ func system_fs_handleFolderSortModePreference(w http.ResponseWriter, r *http.Req
return
}

if !utils.StringInArray([]string{"default", "reverse", "smallToLarge", "largeToSmall", "mostRecent", "leastRecent"}, sortMode) {
if !utils.StringInArray(fssort.ValidSortModes, sortMode) {
utils.SendErrorResponse(w, "Not supported sort mode: "+sortMode)
return
}
Expand Down Expand Up @@ -3137,6 +3114,10 @@ func system_fs_handleFilePermission(w http.ResponseWriter, r *http.Request) {
}

fsh, subpath, err := GetFSHandlerSubpathFromVpath(file)
if err != nil {
utils.SendErrorResponse(w, err.Error())
return
}
fshAbs := fsh.FileSystemAbstraction
rpath, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
if err != nil {
Expand Down Expand Up @@ -3184,13 +3165,13 @@ func system_fs_handleFilePermission(w http.ResponseWriter, r *http.Request) {
//Always ok as this is owned by the user
} else if fsh.Hierarchy == "public" {
//Require admin
if userinfo.IsAdmin() == false {
if !userinfo.IsAdmin() {
utils.SendErrorResponse(w, "Permission Denied")
return
}
} else {
//Not implemeneted. Require admin
if userinfo.IsAdmin() == false {
if !userinfo.IsAdmin() {
utils.SendErrorResponse(w, "Permission Denied")
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var subserviceBasePort = 12810 //Next subservice port

// =========== SYSTEM BUILD INFORMATION ==============
var build_version = "development" //System build flag, this can be either {development / production / stable}
var internal_version = "0.2.013" //Internal build version, [fork_id].[major_release_no].[minor_release_no]
var internal_version = "0.2.015" //Internal build version, [fork_id].[major_release_no].[minor_release_no]
var deviceUUID string //The device uuid of this host
var deviceVendor = "IMUSLAB.INC" //Vendor of the system
var deviceVendorURL = "http://imuslab.com" //Vendor contact information
Expand Down
26 changes: 25 additions & 1 deletion src/mod/filesystem/fssort/fssort.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type sortBufferedStructure struct {
ModTime int64
}

var ValidSortModes = []string{"default", "reverse", "smallToLarge", "largeToSmall", "mostRecent", "leastRecent", "smart", "fileTypeAsce", "fileTypeDesc"}

/*
Quick utilties to sort file list according to different modes
*/
Expand Down Expand Up @@ -60,6 +62,28 @@ func SortFileList(filelistRealpath []string, fileInfos []fs.FileInfo, sortMode s
sort.Slice(parsedFilelist, func(i, j int) bool { return parsedFilelist[i].ModTime < parsedFilelist[j].ModTime })
} else if sortMode == "smart" {
parsedFilelist = SortNaturalFilelist(parsedFilelist)
} else if sortMode == "fileTypeAsce" {
sort.Slice(parsedFilelist, func(i, j int) bool {
exti := filepath.Ext(parsedFilelist[i].Filename)
extj := filepath.Ext(parsedFilelist[j].Filename)

exti = strings.TrimPrefix(exti, ".")
extj = strings.TrimPrefix(extj, ".")

return exti < extj

})
} else if sortMode == "fileTypeDesc" {
sort.Slice(parsedFilelist, func(i, j int) bool {
exti := filepath.Ext(parsedFilelist[i].Filename)
extj := filepath.Ext(parsedFilelist[j].Filename)

exti = strings.TrimPrefix(exti, ".")
extj = strings.TrimPrefix(extj, ".")

return exti > extj

})
}

results := []string{}
Expand Down Expand Up @@ -96,7 +120,7 @@ func SortDirEntryList(dirEntries []fs.DirEntry, sortMode string) []fs.DirEntry {
}

func SortModeIsSupported(sortMode string) bool {
return contains(sortMode, []string{"default", "reverse", "smallToLarge", "largeToSmall", "mostRecent", "leastRecent", "smart"})
return contains(sortMode, ValidSortModes)
}

func contains(item string, slice []string) bool {
Expand Down
11 changes: 7 additions & 4 deletions src/mod/user/directoryHandler.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package user

import (
"errors"
"os"
"path/filepath"

fs "imuslab.com/arozos/mod/filesystem"
"imuslab.com/arozos/mod/utils"
)

/*
func (u *User) GetHomeDirectory() (string, error) {
//Return the realpath of the user home directory
for _, dir := range u.HomeDirectories.Storages {
Expand All @@ -22,6 +19,12 @@ func (u *User) GetHomeDirectory() (string, error) {
return "", errors.New("User root not found. Is this a permission group instead of a real user?")
}
*/

//Get the user home file system handler, aka user:/
func (u *User) GetHomeFileSystemHandler() (*fs.FileSystemHandler, error) {
return getHandlerFromID(u.HomeDirectories.Storages, "user")
}

//Get all user Acessible file system handlers (ignore special fsh like backups)
func (u *User) GetAllAccessibleFileSystemHandler() []*fs.FileSystemHandler {
Expand Down
2 changes: 1 addition & 1 deletion src/system.info.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func SystemInfoInit() {
http.HandleFunc("/system/info/getArOZInfo", infoServer.GetArOZInfo)

//Router to handle login background image loading
http.HandleFunc("/system/info/wallpaper", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/system/info/wallpaper.jpg", func(w http.ResponseWriter, r *http.Request) {
imgsrc := filepath.Join(vendorResRoot, "auth_bg.jpg")
if !fs.FileExists(imgsrc) {
imgsrc = "./web/img/public/auth_bg.jpg"
Expand Down
7 changes: 1 addition & 6 deletions src/web/MDEditor/mde.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,7 @@
}

function closeThisWindow(){
if (!ao_module_virtualDesktop){
window.close('','_parent','');
window.location.href = ao_root + "SystemAO/closeTabInsturction.html";
return;
}
parent.closeFwProcess(ao_module_windowID);
ao_module_closeHandler();
}
</script>
</body>
Expand Down
Binary file modified src/web/OfficeViewer/img/desktop_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/web/OfficeViewer/img/desktop_icon.psd
Binary file not shown.
Binary file modified src/web/OfficeViewer/img/module_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/web/OfficeViewer/img/module_icon.psd
Binary file not shown.
Binary file modified src/web/OfficeViewer/img/small_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/web/OfficeViewer/img/small_icon.psd
Binary file not shown.
Loading

0 comments on commit caa3b38

Please sign in to comment.