Ver código fonte

Added stupid man auto tar.gz unzip logic

Toby Chui 3 anos atrás
pai
commit
06b181edc7
3 arquivos alterados com 100 adições e 4 exclusões
  1. 68 0
      mod/filesystem/fileOpr.go
  2. 22 0
      startup.go
  3. 10 4
      web/desktop.system

+ 68 - 0
mod/filesystem/fileOpr.go

@@ -12,8 +12,10 @@ package filesystem
 */
 
 import (
+	"archive/tar"
 	"archive/zip"
 	"compress/flate"
+	"compress/gzip"
 	"errors"
 	"fmt"
 	"io"
@@ -751,3 +753,69 @@ func IsDir(path string) bool {
 	}
 	return false
 }
+
+//Unzip tar.gz file
+func ExtractTarGzipFile(filename string, outfile string) error {
+	f, err := os.Open(filename)
+	if err != nil {
+		return err
+	}
+
+	err = ExtractTarGzipByStream(filepath.Clean(outfile), f, true)
+	if err != nil {
+		return err
+	}
+
+	return f.Close()
+}
+func ExtractTarGzipByStream(basedir string, gzipStream io.Reader, onErrorResumeNext bool) error {
+	uncompressedStream, err := gzip.NewReader(gzipStream)
+	if err != nil {
+		return err
+	}
+
+	tarReader := tar.NewReader(uncompressedStream)
+
+	for {
+		header, err := tarReader.Next()
+
+		if err == io.EOF {
+			break
+		}
+
+		if err != nil {
+			return err
+		}
+
+		switch header.Typeflag {
+		case tar.TypeDir:
+			err := os.Mkdir(header.Name, 0755)
+			if err != nil {
+				if !onErrorResumeNext {
+					return err
+				}
+
+			}
+		case tar.TypeReg:
+			outFile, err := os.Create(filepath.Join(basedir, header.Name))
+			if err != nil {
+				if !onErrorResumeNext {
+					return err
+				}
+			}
+			_, err = io.Copy(outFile, tarReader)
+			if err != nil {
+				if !onErrorResumeNext {
+					return err
+				}
+			}
+			outFile.Close()
+
+		default:
+			//Unknown filetype, continue
+
+		}
+
+	}
+	return nil
+}

+ 22 - 0
startup.go

@@ -7,12 +7,34 @@ package main
 
 import (
 	"fmt"
+	"log"
+	"os"
 
 	db "imuslab.com/arozos/mod/database"
+	"imuslab.com/arozos/mod/filesystem"
 )
 
 func RunStartup() {
 	//1. Initiate the main system database
+
+	//Check if system or web both not exists and web.tar.gz exists. Unzip it for the user
+	if (!fileExists("system/") || !fileExists("web/")) && fileExists("./web.tar.gz") {
+		log.Println("Unzipping system critical files from archive")
+		extErr := filesystem.ExtractTarGzipFile("./web.tar.gz", "./")
+		if extErr != nil {
+			//Extract failed
+			fmt.Println("▒▒ ERROR: UNABLE TO EXTRACT CRITICAL SYSTEM FOLDERS ▒▒")
+			fmt.Println(extErr)
+			panic("Unable to extract content from web.tar.gz to fix the missing system / web folder. Please unzip the web.tar.gz manually.")
+		}
+
+		//Extract success
+		extErr = os.Remove("./web.tar.gz")
+		if extErr != nil {
+			log.Println("Unable to remove web.tar.gz: ", extErr)
+		}
+	}
+
 	if !fileExists("system/") {
 		fmt.Println("▒▒ ERROR: SYSTEM FOLDER NOT FOUND ▒▒")
 		panic("This error occurs because the system folder is missing. Please follow the installation guide and don't just download a binary and run it.")

+ 10 - 4
web/desktop.system

@@ -1226,10 +1226,7 @@
                     alert(data.error);
                 }else{
                     userInfo = data;
-                    if (data.IsAdmin == false){
-                        //Hide the power buttons
-                        $(".hardware").hide();
-                    }
+                   
 
                     //Update the user tag
                     $("#username").text(userInfo.Username);
@@ -1238,6 +1235,14 @@
                     if (data.UserIcon !== ""){
                         $(".usericon").attr("src",data.UserIcon);
                     }
+
+                    if (data.IsAdmin == false){
+                        //Hide the power buttons
+                        $(".hardware").hide();
+                    }else{
+                        //User is admin. Add admin icon
+                        $("#username").append(` <i style="color: #52c9ff" class="protect icon themed text"></i>`);
+                    }
                 }
             });
         }
@@ -6261,6 +6266,7 @@
             $("#listMenu").find(".searchBar").css("border-bottom", "2px solid " + newThemeColor);
             $("#volumebar").css("background-color", newThemeColor);
             $("#brightnessbar").css("background-color", newThemeColor);
+            $(".themed.text").css("color", newThemeColor);
 
             //Connection lost notification css
             $("#connectionLost").find(".ts.card").css("background-color", hexToRgbA(newThemeColor, 0.5));