Skip to content

Commit

Permalink
Asar Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
thororen1234 committed Jul 19, 2024
2 parents 6d5db15 + 9f8a013 commit d069397
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .idea/Equilot.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 24 additions & 5 deletions github_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io"
"net/http"
"os"
path "path/filepath"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -93,8 +94,21 @@ func InitGithubDownloader() {
Log.Debug("Latest hash is", LatestHash, "Local Install is", Ternary(LatestHash == InstalledHash, "up to date!", "outdated!"))
}()

// either .asar file or directory with main.js file (in DEV)
EquicordFile := EquicordDirectory

stat, err := os.Stat(EquicordFile)
if err != nil {
return
}

// dev
if stat.IsDir() {
EquicordFile = path.Join(EquicordFile, "main.js")
}

// Check hash of installed version if exists
b, err := os.ReadFile(EquicordAsarPath)
b, err := os.ReadFile(EquicordFile)
if err != nil {
return
}
Expand All @@ -116,6 +130,11 @@ func InitGithubDownloader() {
func installLatestBuilds() (retErr error) {
Log.Debug("Installing latest builds...")

if IsDevInstall {
Log.Debug("Skipping due to dev install")
return
}

downloadUrl := ""
for _, ass := range ReleaseData.Assets {
if ass.Name == "desktop.asar" {
Expand All @@ -141,15 +160,15 @@ func installLatestBuilds() (retErr error) {
retErr = err
return
}
out, err := os.OpenFile(EquicordAsarPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
out, err := os.OpenFile(EquicordDirectory, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
Log.Error("Failed to create", EquicordAsarPath+":", err)
Log.Error("Failed to create", EquicordDirectory+":", err)
retErr = err
return
}
read, err := io.Copy(out, res.Body)
if err != nil {
Log.Error("Failed to download to", EquicordAsarPath+":", err)
Log.Error("Failed to download to", EquicordDirectory+":", err)
retErr = err
return
}
Expand All @@ -162,7 +181,7 @@ func installLatestBuilds() (retErr error) {
return
}

_ = FixOwnership(EquicordAsarPath)
_ = FixOwnership(EquicordDirectory)

InstalledHash = LatestHash
return
Expand Down
18 changes: 9 additions & 9 deletions patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

var BaseDir string
var BaseDirErr error
var EquicordAsarPath string
var EquicordDirectory string

func init() {
if dir := os.Getenv("EQUICORD_USER_DATA_DIR"); dir != "" {
Expand All @@ -31,7 +31,7 @@ func init() {
Log.Debug("Using UserConfig")
BaseDir = appdir.New("Equicord").UserConfig()
}
dir := os.Getenv("EQUICORD_ASAR_FILE")
dir := os.Getenv("EQUICORD_DIRECTORY")
if dir == "" {
if !ExistsFile(BaseDir) {
BaseDirErr = os.Mkdir(BaseDir, 0755)
Expand All @@ -43,10 +43,10 @@ func init() {
}
}
if dir != "" {
Log.Debug("Using EQUICORD_ASAR_FILE")
EquicordAsarPath = dir
Log.Debug("Using EQUICORD_DIRECTORY")
EquicordDirectory = dir
} else {
EquicordAsarPath = path.Join(BaseDir, "equicord.asar")
EquicordDirectory = path.Join(BaseDir, "equicord.asar")
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ func patchAppAsar(dir string, isSystemElectron bool) (err error) {
}

Log.Debug("Writing custom app.asar to", appAsar)
if err := WriteAppAsar(appAsar, EquicordAsarPath); err != nil {
if err := WriteAppAsar(appAsar, EquicordDirectory); err != nil {
return err
}

Expand Down Expand Up @@ -149,14 +149,14 @@ func (di *DiscordInstall) patch() error {
}
}

Log.Debug("This is a flatpak. Trying to grant the Flatpak access to", EquicordAsarPath+"...")
Log.Debug("This is a flatpak. Trying to grant the Flatpak access to", EquicordDirectory+"...")

isSystemFlatpak := strings.HasPrefix(di.path, "/var")
var args []string
if !isSystemFlatpak {
args = append(args, "--user")
}
args = append(args, "override", name, "--filesystem="+EquicordAsarPath)
args = append(args, "override", name, "--filesystem="+EquicordDirectory)
fullCmd := "flatpak " + strings.Join(args, " ")

Log.Debug("Running", fullCmd)
Expand All @@ -177,7 +177,7 @@ func (di *DiscordInstall) patch() error {
err = cmd.Run()
}
if err != nil {
return errors.New("Failed to grant Discord Flatpak access to " + EquicordAsarPath + ": " + err.Error())
return errors.New("Failed to grant Discord Flatpak access to " + EquicordDirectory + ": " + err.Error())
}
}
return nil
Expand Down

0 comments on commit d069397

Please sign in to comment.