Skip to content

Commit

Permalink
Merge branch 'master' into error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
budak7273 committed Oct 14, 2024
2 parents a728553 + ad4f421 commit 0875da2
Show file tree
Hide file tree
Showing 30 changed files with 315 additions and 134 deletions.
4 changes: 1 addition & 3 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,4 @@ runs:
shell: bash
run: |
sudo apt update
sudo apt -y install libgtk-3-dev libwebkit2gtk-4.1-dev
sudo apt -y install libwebkit2gtk-4.0-dev # also install 4.0 because it's the default in wails, so any task that runs a go command would require the added tag
sudo apt -y install libgtk-3-dev libwebkit2gtk-4.1-dev patchelf
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
# Apparently only wails build generates the embedded directory
mkdir -p frontend/build
touch frontend/build/.gitkeep
wails generate module
wails generate module -tags webkit2_41
- name: Install dependencies
working-directory: frontend
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ issues:

run:
timeout: 5m
build-tags:
- webkit2_41

linters:
disable-all: true
Expand Down
1 change: 0 additions & 1 deletion backend/app/debug_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ func (a *app) GenerateDebugInfo() (bool, error) {
err = a.ShowInExplorer(filename)
if err != nil {
slog.Error("failed to reveal debug info in file explorer", slog.Any("error", err))
return false, fmt.Errorf("failed to reveal debug info in file explorer: %w", err)
}

return true, nil
Expand Down
9 changes: 8 additions & 1 deletion backend/ficsitcli/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,15 @@ func (f *ficsitCLI) getInstallsToApply() ([]installWithTarget, *cli.Profile, err
var installsUsingProfile []installWithTarget
targetsUsingProfile := make(map[resolver.TargetName]bool)
for _, install := range allInstalls {
meta, ok := f.installationMetadata.Load(install)
if !ok {
continue
}
if meta.State != InstallStateValid {
continue
}
i := f.GetInstallation(install)
if i.Profile == selectedProfile {
if i.Profile == selectedProfile && !i.Vanilla {
platform, err := i.GetPlatform(f.ficsitCli)
if err != nil {
return nil, nil, fmt.Errorf("failed to get platform: %w", err)
Expand Down
6 changes: 6 additions & 0 deletions backend/ficsitcli/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func (f *ficsitCLI) initLocalInstallationsMetadata() error {
return fmt.Errorf("failed to add installation: %w", err)
}
createdNewInstalls = true
} else {
_, profileExists := f.ficsitCli.Profiles.Profiles[ficsitCliInstall.Profile]
if !profileExists {
ficsitCliInstall.Profile = fallbackProfile
createdNewInstalls = true
}
}
f.installationMetadata.Store(install.Path, installationMetadata{
State: InstallStateValid,
Expand Down
8 changes: 8 additions & 0 deletions backend/ficsitcli/profiles.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ficsitcli

import (
"archive/zip"
"bytes"
"encoding/json"
"fmt"
"log/slog"
Expand Down Expand Up @@ -291,6 +293,12 @@ func (f *ficsitCLI) ReadExportedProfileMetadata(file string) (*ExportedProfileMe
var exportedProfile ExportedProfile
err = json.Unmarshal(fileBytes, &exportedProfile)
if err != nil {
_, err = zip.NewReader(bytes.NewReader(fileBytes), int64(len(fileBytes)))
if err == nil {
// SMM2 profile is a zip file, can't import
return nil, fmt.Errorf("profiles exported from SMM2 cannot be loaded in SMM3")
}

l.Error("failed to unmarshal exported profile", slog.Any("error", err))
return nil, fmt.Errorf("failed to parse exported profile: %w", err)
}
Expand Down
14 changes: 12 additions & 2 deletions backend/installfinders/common/helpers.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
package common

import (
"log/slog"
"path/filepath"
"runtime"
"strings"
)

func OsPathEqual(path1, path2 string) bool {
path1 = filepath.Clean(path1)
path2 = filepath.Clean(path2)
path1 = realPath(path1)
path2 = realPath(path2)
if runtime.GOOS == "windows" {
return strings.EqualFold(path1, path2)
}
return path1 == path2
}

func realPath(path string) string {
newPath, err := filepath.EvalSymlinks(path)
if err != nil {
slog.Warn("failed to evaluate symlink, using original path", slog.String("path", path), slog.Any("error", err))
return path
}
return newPath
}

func FindAll(finders ...InstallFinderFunc) ([]*Installation, []error) {
installs := make([]*Installation, 0)
var errors []error
Expand Down
2 changes: 1 addition & 1 deletion backend/installfinders/launchers/epic/epic.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func FindInstallationsEpic(epicManifestsPath string, launcher string, platform c

for _, manifest := range manifests {
manifestName := manifest.Name()
manifestPath := filepath.Join(epicManifestsPath, manifestName)
manifestPath := platform.ProcessPath(filepath.Join(epicManifestsPath, manifestName))

if fileInfo, err := os.Stat(manifestPath); os.IsNotExist(err) || fileInfo.IsDir() {
continue
Expand Down
18 changes: 18 additions & 0 deletions backend/installfinders/launchers/lutris/lutris_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package lutris
import (
"encoding/json"
"fmt"
"os"
"os/exec"
"strings"

"github.com/satisfactorymodding/SatisfactoryModManager/backend/installfinders/common"
"github.com/satisfactorymodding/SatisfactoryModManager/backend/installfinders/launchers"
Expand All @@ -30,7 +32,23 @@ func init() {
func findInstallations(lutrisCmd []string, launcher string) ([]*common.Installation, []error) {
lutrisLjCmd := makeLutrisCmd(lutrisCmd, "-lj")
lutrisLj := exec.Command(lutrisLjCmd[0], lutrisLjCmd[1:]...)
lutrisLj.Env = os.Environ()
lutrisLj.Env = append(lutrisLj.Env, "LUTRIS_SKIP_INIT=1")
if os.Getenv("APPIMAGE") != "" {
// Must clear the APPIMAGE added entries of LD_LIBRARY_PATH, as well as PYTHONHOME and PYTHONPATH
// otherwise lutris will load some appimage libraries and some system libraries, which are incompatible
lutrisLj.Env = append(lutrisLj.Env, "PYTHONHOME=", "PYTHONPATH=")

appdir := os.Getenv("APPDIR")
ldLibraryPathEntries := strings.Split(os.Getenv("LD_LIBRARY_PATH"), ":")
newLdLibraryPathEntries := []string{}
for _, entry := range ldLibraryPathEntries {
if !strings.HasPrefix(entry, appdir) {
newLdLibraryPathEntries = append(newLdLibraryPathEntries, entry)
}
}
lutrisLj.Env = append(lutrisLj.Env, "LD_LIBRARY_PATH="+strings.Join(newLdLibraryPathEntries, ":"))
}
outputBytes, err := lutrisLj.Output()
if err != nil {
return nil, []error{
Expand Down
77 changes: 48 additions & 29 deletions backend/installfinders/launchers/steam/steam.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package steam

import (
"fmt"
"log/slog"
"os"
"path/filepath"
"strconv"
Expand All @@ -17,39 +18,15 @@ func FindInstallationsSteam(steamPath string, launcher string, platform common.L
steamAppsPath := filepath.Join(steamPath, "steamapps")
libraryFoldersManifestPath := platform.ProcessPath(filepath.Join(steamAppsPath, "libraryfolders.vdf"))

libraryFoldersF, err := os.Open(libraryFoldersManifestPath)
rawLibraryFolders, err := getLibraryFoldersFromManifest(libraryFoldersManifestPath)
if err != nil {
return nil, []error{fmt.Errorf("failed to open library folders manifest: %w", err)}
}

parser := vdf.NewParser(libraryFoldersF)
libraryFoldersManifest, err := parser.Parse()
if err != nil {
return nil, []error{fmt.Errorf("failed to parse library folders manifest: %w", err)}
}

var libraryFoldersList map[string]interface{}

if _, ok := libraryFoldersManifest["LibraryFolders"]; ok {
libraryFoldersList = libraryFoldersManifest["LibraryFolders"].(map[string]interface{})
} else if _, ok := libraryFoldersManifest["libraryfolders"]; ok {
libraryFoldersList = libraryFoldersManifest["libraryfolders"].(map[string]interface{})
} else {
return nil, []error{fmt.Errorf("failed to find library folders in manifest")}
}

libraryFolders := []string{
filepath.Clean(steamPath),
return nil, []error{fmt.Errorf("failed to get library folders from manifest: %w", err)}
}

for key, val := range libraryFoldersList {
if _, err := strconv.Atoi(key); err != nil {
continue
}

libraryFolderData := val.(map[string]interface{})
libraryFolder := libraryFolderData["path"].(string)
rawLibraryFolders = append(rawLibraryFolders, filepath.Clean(steamPath))

var libraryFolders []string
for _, libraryFolder := range rawLibraryFolders {
found := false
for _, existingLibraryFolder := range libraryFolders {
if common.OsPathEqual(existingLibraryFolder, libraryFolder) {
Expand Down Expand Up @@ -149,3 +126,45 @@ func FindInstallationsSteam(steamPath string, launcher string, platform common.L

return installs, findErrors
}

func getLibraryFoldersFromManifest(libraryFoldersManifestPath string) ([]string, error) {
libraryFoldersF, err := os.Open(libraryFoldersManifestPath)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, fmt.Errorf("failed to open library folders manifest: %w", err)
}

parser := vdf.NewParser(libraryFoldersF)
libraryFoldersManifest, err := parser.Parse()
if err != nil {
return nil, fmt.Errorf("failed to parse library folders manifest: %w", err)
}

var libraryFoldersList map[string]interface{}

if _, ok := libraryFoldersManifest["LibraryFolders"]; ok {
libraryFoldersList = libraryFoldersManifest["LibraryFolders"].(map[string]interface{})
} else if _, ok := libraryFoldersManifest["libraryfolders"]; ok {
libraryFoldersList = libraryFoldersManifest["libraryfolders"].(map[string]interface{})
} else {
return nil, fmt.Errorf("failed to find library folders in manifest")
}

libraryFolders := make([]string, 0, len(libraryFoldersList))

for key, val := range libraryFoldersList {
if _, err := strconv.Atoi(key); err != nil {
slog.Debug("skipping steam libraryfolders.vdf entry, not array item", slog.String("key", key))
continue
}

libraryFolderData := val.(map[string]interface{})
libraryFolder := libraryFolderData["path"].(string)

libraryFolders = append(libraryFolders, libraryFolder)
}

return libraryFolders, nil
}
19 changes: 15 additions & 4 deletions backend/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ var (
)

type settings struct {
WindowPosition *utils.Position `json:"windowPosition,omitempty"`
Maximized bool `json:"maximized,omitempty"`
WindowPosition *utils.Position `json:"windowPosition,omitempty"`
Maximized bool `json:"maximized,omitempty"`
RestoreWindowPosition bool `json:"restoreWindowPosition"`

UnexpandedSize utils.Size `json:"unexpandedSize,omitempty"`
ExpandedSize utils.Size `json:"expandedSize,omitempty"`
Expand Down Expand Up @@ -71,8 +72,9 @@ type settings struct {
}

var Settings = &settings{
WindowPosition: nil,
Maximized: false,
WindowPosition: nil,
Maximized: false,
RestoreWindowPosition: true,

UnexpandedSize: utils.UnexpandedDefault,
ExpandedSize: utils.ExpandedDefault,
Expand Down Expand Up @@ -102,6 +104,15 @@ var Settings = &settings{
NewUserSetupComplete: false,
}

func (s *settings) GetRestoreWindowPosition() bool {
return s.RestoreWindowPosition
}

func (s *settings) SetRestoreWindowPosition(value bool) {
s.RestoreWindowPosition = value
_ = SaveSettings()
}

func (s *settings) GetNewUserSetupComplete() bool {
return s.NewUserSetupComplete
}
Expand Down
7 changes: 7 additions & 0 deletions backend/settings/smm2settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package settings

import (
"encoding/json"
"errors"
"fmt"
"log/slog"

"github.com/satisfactorymodding/SatisfactoryModManager/backend/utils"
)
Expand Down Expand Up @@ -49,6 +51,11 @@ func readSMM2Settings(data []byte) error {
s := smm2Settings{}
err := json.Unmarshal(data, &s)
if err != nil {
var invalidJSONError *json.SyntaxError
if errors.As(err, &invalidJSONError) {
slog.Warn("invalid SMM2 settings JSON", slog.String("data", string(data)), slog.Any("err", err))
return nil // Ignore error, not much info there anyway
}
return fmt.Errorf("failed to unmarshal SMM2 settings: %w", err)
}

Expand Down
7 changes: 5 additions & 2 deletions build/linux/appimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ chmod +x AppRun
cd "$TMPDIR" || exit

wget https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh
chmod +x "$TMPDIR/linuxdeploy-plugin-gtk.sh"
chmod +x linuxdeploy-plugin-gtk.sh

wget https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gstreamer/master/linuxdeploy-plugin-gstreamer.sh
chmod +x linuxdeploy-plugin-gstreamer.sh

wget -O linuxdeploy.AppImage https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-${ARCH}.AppImage
chmod +x linuxdeploy.AppImage
)

mkdir -p "$(dirname "$OUTPUT")"

LDAI_OUTPUT="$OUTPUT" DEPLOY_GTK_VERSION="3" "$TMPDIR/linuxdeploy.AppImage" --appimage-extract-and-run --appdir "$APPDIR" --plugin gtk --output appimage
LDAI_OUTPUT="$OUTPUT" DEPLOY_GTK_VERSION="3" "$TMPDIR/linuxdeploy.AppImage" --appimage-extract-and-run --appdir "$APPDIR" --plugin gtk --plugin gstreamer --output appimage

rm -rf "$TMPDIR"
rm -rf "$APPDIR"
2 changes: 1 addition & 1 deletion build/windows/installer/project.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ VIAddVersionKey "ProductName" "${INFO_PRODUCTNAME}"
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_ABORTWARNING

!include "smm2.nsh"
!include "utils.nsh"
!include "smm2.nsh"

# Install pages
!define MUI_PAGE_CUSTOMFUNCTION_PRE WelcomePagePre
Expand Down
Loading

0 comments on commit 0875da2

Please sign in to comment.