From 0d8672d5fb8937a57e1c369a9bc187eb31b88312 Mon Sep 17 00:00:00 2001 From: mircearoata Date: Sat, 8 Jun 2024 20:55:05 +0200 Subject: [PATCH] Add custom remote names --- backend/ficsitcli/metadata.go | 18 +++++++++++++-- backend/ficsitcli/remote_servers.go | 17 +++++++++++++- backend/settings/settings.go | 4 ++++ .../components/modals/ServerManager.svelte | 22 ++++++++++++++++--- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/backend/ficsitcli/metadata.go b/backend/ficsitcli/metadata.go index 3eecc09b..48b2fd3d 100644 --- a/backend/ficsitcli/metadata.go +++ b/backend/ficsitcli/metadata.go @@ -1,6 +1,8 @@ package ficsitcli import ( + "crypto/sha256" + "encoding/hex" "errors" "fmt" "log/slog" @@ -13,6 +15,7 @@ import ( "github.com/satisfactorymodding/SatisfactoryModManager/backend/installfinders" "github.com/satisfactorymodding/SatisfactoryModManager/backend/installfinders/common" + "github.com/satisfactorymodding/SatisfactoryModManager/backend/settings" ) func (f *ficsitCLI) initLocalInstallationsMetadata() error { @@ -161,18 +164,29 @@ func (f *ficsitCLI) getRemoteServerMetadata(installation *cli.Installation) (*co branch := common.BranchEarlyAccess // TODO: Do we have a way to detect this for remote installs? + remoteName := settings.Settings.RemoteNames[remoteKey(installation.Path)] + + if remoteName == "" { + remoteName = f.GetNextRemoteLauncherName() + } + return &common.Installation{ Path: installation.Path, Type: installType, Location: common.LocationTypeRemote, Branch: branch, Version: gameVersion, - Launcher: f.getNextRemoteLauncherName(), + Launcher: remoteName, SavedPath: path.Join(installation.BasePath(), "FactoryGame", "Saved"), }, nil } -func (f *ficsitCLI) getNextRemoteLauncherName() string { +func remoteKey(path string) string { + hash := sha256.Sum256([]byte(path)) + return hex.EncodeToString(hash[:]) +} + +func (f *ficsitCLI) GetNextRemoteLauncherName() string { existingNumbers := make(map[int]bool) for _, install := range f.GetRemoteInstallations() { metadata, ok := f.installationMetadata.Load(install) diff --git a/backend/ficsitcli/remote_servers.go b/backend/ficsitcli/remote_servers.go index c20ad5e9..db5b4798 100644 --- a/backend/ficsitcli/remote_servers.go +++ b/backend/ficsitcli/remote_servers.go @@ -5,6 +5,7 @@ import ( "log/slog" "github.com/satisfactorymodding/SatisfactoryModManager/backend/installfinders/common" + "github.com/satisfactorymodding/SatisfactoryModManager/backend/settings" ) func (f *ficsitCLI) GetRemoteInstallations() []string { @@ -22,7 +23,7 @@ func (f *ficsitCLI) GetRemoteInstallations() []string { return paths } -func (f *ficsitCLI) AddRemoteServer(path string) error { +func (f *ficsitCLI) AddRemoteServer(path string, name string) error { if f.ficsitCli.Installations.GetInstallation(path) != nil { return fmt.Errorf("installation already exists") } @@ -38,11 +39,20 @@ func (f *ficsitCLI) AddRemoteServer(path string) error { l.Error("failed to save installations", slog.Any("error", err)) } + if name != "" { + settings.Settings.RemoteNames[remoteKey(installation.Path)] = name + } + meta, err := f.getRemoteServerMetadata(installation) if err != nil { + if name != "" { + delete(settings.Settings.RemoteNames, remoteKey(installation.Path)) + } return fmt.Errorf("failed to get remote server metadata: %w", err) } + _ = settings.SaveSettings() + f.installationMetadata.Store(path, installationMetadata{ State: InstallStateValid, Info: meta, @@ -73,6 +83,11 @@ func (f *ficsitCLI) RemoveRemoteServer(path string) error { slog.Error("failed to save installations", slog.Any("error", err)) } f.installationMetadata.Delete(path) + + delete(settings.Settings.RemoteNames, remoteKey(path)) + _ = settings.SaveSettings() + f.EmitGlobals() + return nil } diff --git a/backend/settings/settings.go b/backend/settings/settings.go index 2ad2c6ce..1b5b259b 100644 --- a/backend/settings/settings.go +++ b/backend/settings/settings.go @@ -46,6 +46,8 @@ type settings struct { FavoriteMods []string `json:"favoriteMods,omitempty"` ModFilters SavedModFilters `json:"modFilters,omitempty"` + RemoteNames map[string]string `json:"remoteNames,omitempty"` + QueueAutoStart bool `json:"queueAutoStart"` IgnoredUpdates map[string][]string `json:"ignoredUpdates,omitempty"` UpdateCheckMode UpdateCheckMode `json:"updateCheckMode,omitempty"` @@ -80,6 +82,8 @@ var Settings = &settings{ Filter: "Compatible", }, + RemoteNames: map[string]string{}, + QueueAutoStart: true, IgnoredUpdates: map[string][]string{}, UpdateCheckMode: UpdateOnLaunch, diff --git a/frontend/src/lib/components/modals/ServerManager.svelte b/frontend/src/lib/components/modals/ServerManager.svelte index 53b83964..9f9b705a 100644 --- a/frontend/src/lib/components/modals/ServerManager.svelte +++ b/frontend/src/lib/components/modals/ServerManager.svelte @@ -10,7 +10,7 @@ import Tooltip from '$lib/components/Tooltip.svelte'; import { type PopupSettings, popup } from '$lib/skeletonExtensions'; import { installsMetadata, remoteServers } from '$lib/store/ficsitCLIStore'; - import { AddRemoteServer, FetchRemoteServerMetadata, RemoveRemoteServer } from '$wailsjs/go/ficsitcli/ficsitCLI'; + import { AddRemoteServer, FetchRemoteServerMetadata, GetNextRemoteLauncherName, RemoveRemoteServer } from '$wailsjs/go/ficsitcli/ficsitCLI'; import { ficsitcli } from '$wailsjs/go/models'; export let parent: { onClose: () => void }; @@ -48,6 +48,9 @@ let newServerPath = ''; let err = ''; + let defaultRemoteName = ''; + let remoteName = ''; + let advancedMode = false; let addInProgress = false; @@ -106,7 +109,7 @@ try { err = ''; addInProgress = true; - await AddRemoteServer(fullInstallPath); + await AddRemoteServer(fullInstallPath, remoteName); newServerUsername = ''; newServerPassword = ''; newServerHost = ''; @@ -143,6 +146,13 @@ return `remote-server-warning-${install}`; } + $: { + remoteServers; + (async () => { + defaultRemoteName = await GetNextRemoteLauncherName(); + })(); + } + $: installWarningPopups = $remoteServers.map((i) => [i, { event: 'hover', target: installWarningPopupId(i), @@ -164,6 +174,7 @@ {#each $remoteServers as remoteServer} + {$installsMetadata[remoteServer].info?.launcher} {remoteServer} {#if $installsMetadata[remoteServer]?.state === ficsitcli.InstallState.VALID} @@ -304,8 +315,13 @@ /> {/if} +