1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package main
- import (
- "errors"
- "fmt"
- "io"
- "os"
- "path/filepath"
- "runtime"
- )
- //Auto detect and execute the correct binary
- func autoDetectExecutable() string {
- if runtime.GOOS == "windows" {
- if fileExists("arozos.exe") {
- return "arozos.exe"
- }
- } else {
- if fileExists("arozos") {
- return "arozos"
- }
- }
- //Not build from source. Look for release binary names
- binaryExecPath := "arozos_" + runtime.GOOS + "_" + runtime.GOARCH
- if runtime.GOOS == "windows" {
- binaryExecPath += ".exe"
- }
- if fileExists(binaryExecPath) {
- return binaryExecPath
- } else {
- fmt.Println("[LAUNCHER] Unable to detect ArozOS start binary")
- os.Exit(1)
- return ""
- }
- }
- func getUpdateBinaryFilename() (string, error) {
- updateFiles, err := filepath.Glob("./updates/*")
- if err != nil {
- return "", err
- }
- for _, thisFile := range updateFiles {
- if !isDir(thisFile) && filepath.Ext(thisFile) != ".gz" {
- //This might be the file
- return thisFile, nil
- }
- }
- return "", errors.New("file not found")
- }
- func copy(src, dst string) (int64, error) {
- sourceFileStat, err := os.Stat(src)
- if err != nil {
- return 0, err
- }
- if !sourceFileStat.Mode().IsRegular() {
- return 0, errors.New("invalid file")
- }
- source, err := os.Open(src)
- if err != nil {
- return 0, err
- }
- defer source.Close()
- destination, err := os.Create(dst)
- if err != nil {
- return 0, err
- }
- defer destination.Close()
- nBytes, err := io.Copy(destination, source)
- return nBytes, err
- }
- func isDir(path string) bool {
- fileInfo, err := os.Stat(path)
- if err != nil {
- return false
- }
- return fileInfo.IsDir()
- }
- func fileExists(name string) bool {
- _, err := os.Stat(name)
- if err == nil {
- return true
- }
- if errors.Is(err, os.ErrNotExist) {
- return false
- }
- return false
- }
|