浏览代码

Added update screw up restore logic

Toby Chui 3 年之前
父节点
当前提交
a023f037d4
共有 3 个文件被更改,包括 43 次插入2 次删除
  1. 23 0
      fs.go
  2. 二进制
      launcher.exe
  3. 20 2
      main.go

+ 23 - 0
fs.go

@@ -19,6 +19,29 @@ func restoreConfigs() {
 	restoreIfExists("web/SystemAO/vendor/")
 }
 
+func restoreOldArozOS() {
+	fmt.Println("[LAUNCHER] ArozOS unable to launch. Restoring from backup")
+	if fileExists("arozos.old") {
+		backupfiles, err := filepath.Glob("arozos.old/*")
+		if err != nil {
+			fmt.Println("[LAUNCHER] Unable to restore backup. Exiting.")
+			os.Exit(1)
+		}
+
+		for _, thisBackupFile := range backupfiles {
+			if isDir(thisBackupFile) {
+				cp.Copy(thisBackupFile, "./"+filepath.Base(thisBackupFile))
+			} else {
+				copy(thisBackupFile, "./"+filepath.Base(thisBackupFile))
+			}
+		}
+	} else {
+		fmt.Println("[LAUNCHER] ArozOS backup not found. Exiting.")
+		os.Exit(1)
+	}
+
+}
+
 func restoreIfExists(fileRelPath string) {
 	if fileExists(filepath.Join("arozos.old", fileRelPath)) {
 		if !isDir(filepath.Join("arozos.old", fileRelPath)) {

二进制
launcher.exe


+ 20 - 2
main.go

@@ -48,17 +48,35 @@ func main() {
 		http.ListenAndServe("127.0.0.1:25576", nil)
 	}()
 
+	retryCounter := 0
 	//Start the cmd
 	for {
+		startTime := time.Now().Unix()
 		cmd.Run()
-		fmt.Println("[LAUNCHER] ArozOS Exited. Restarting in 3 seconds... ")
+		endTime := time.Now().Unix()
+		if endTime-startTime < 3 {
+			//Less than 3 seconds, shd be crashed. Add to retry counter
+			fmt.Println("[LAUNCHER] ArozOS Crashed. Restarting in 3 seconds... ")
+			retryCounter++
+		} else {
+			fmt.Println("[LAUNCHER] ArozOS Exited. Restarting in 3 seconds... ")
+		}
+
 		time.Sleep(3 * time.Second)
-		updateIfExists(binaryName)
+
+		if retryCounter > 10 {
+			//Restore from old version of the binary
+			restoreOldArozOS()
+			retryCounter = 0
+		} else {
+			updateIfExists(binaryName)
+		}
 
 		//Rebuild the start paramters
 		cmd = exec.Command(binaryName, os.Args[1:]...)
 		cmd.Stdout = os.Stdout
 		cmd.Stderr = os.Stderr
+
 	}
 
 }