Skip to content

Commit

Permalink
WIP detection of needing to migrate, need for first time user popup
Browse files Browse the repository at this point in the history
  • Loading branch information
budak7273 committed Sep 4, 2024
1 parent fb7ede3 commit 3b74afc
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
55 changes: 55 additions & 0 deletions backend/migration/migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package migration

import (
"errors"
"fmt"
"log/slog"
"os"
)

type migration struct {
smm2Dir string
}

var Migration *migration

func Init() error {
if Migration == nil {
dir, err := os.UserConfigDir()
if err != nil {
return fmt.Errorf("failed to get user home directory for migration check: %w", err)
}
Migration = &migration{}
Migration.smm2Dir = dir + "\\SatisfactoryModManager\\profiles\\"
}
return nil
}

const migrationSuccessMarkerFile = ".smm3_migration_success"

// https://stackoverflow.com/questions/12518876/how-to-check-if-a-file-exists-in-go
func pathExists(path string) bool {
if _, err := os.Stat(path); err == nil {
return true
} else if errors.Is(err, os.ErrNotExist) {
return false
} else {
slog.Warn("Error when checking path exists, so assuming it does not exist: "+path, slog.Any("error", err))
return false
}
}

func (m *migration) NeedsSmm2Migration() bool {
if pathExists(m.smm2Dir) {
return !pathExists(m.smm2Dir + migrationSuccessMarkerFile)
}
return false
}

func (m *migration) MarkSmm2MigrationSuccess() error {
file, err := os.Create(m.smm2Dir + migrationSuccessMarkerFile)
if err != nil {
return fmt.Errorf("failed to create migration success marker file: %w", err)
}
return file.Close()

Check failure on line 54 in backend/migration/migration.go

View workflow job for this annotation

GitHub Actions / lint-backend (ubuntu-latest)

error returned from external package is unwrapped: sig: func (*os.File).Close() error (wrapcheck)

Check failure on line 54 in backend/migration/migration.go

View workflow job for this annotation

GitHub Actions / lint-backend (macos-latest)

error returned from external package is unwrapped: sig: func (*os.File).Close() error (wrapcheck)
}
14 changes: 14 additions & 0 deletions backend/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type settings struct {
CacheDir string `json:"cacheDir,omitempty"`

Debug bool `json:"debug,omitempty"`

NewUserSetupComplete bool `json:"newUserSetupComplete,omitempty"`
}

var Settings = &settings{
Expand Down Expand Up @@ -95,6 +97,18 @@ var Settings = &settings{
LaunchButton: "normal",

Debug: false,

NewUserSetupComplete: false,
}

func (s *settings) GetNewUserSetupComplete() bool {
return s.Debug
}

func (s *settings) SetNewUserSetupComplete(value bool) {
slog.Info("changing NewUserSetupComplete state", slog.Bool("value", value))
s.NewUserSetupComplete = value
_ = SaveSettings()
}

func (s *settings) FavoriteMod(modReference string) (bool, error) {
Expand Down
31 changes: 25 additions & 6 deletions frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import { konami, language, updateCheckMode } from '$lib/store/settingsStore';
import { smmUpdate, smmUpdateReady } from '$lib/store/smmUpdateStore';
import { ExpandMod, UnexpandMod } from '$wailsjs/go/app/app';
import { Environment, EventsOn } from '$wailsjs/runtime';
import { NeedsSmm2Migration } from '$wailsjs/go/migration/migration';
import { GetNewUserSetupComplete } from '$wailsjs/go/settings/settings';
import { Environment, EventsOn, LogError } from '$wailsjs/runtime';

Check warning on line 33 in frontend/src/App.svelte

View workflow job for this annotation

GitHub Actions / lint-frontend

'LogError' is defined but never used. Allowed unused vars must match /^_/u
initializeStores();
initializeModalStore();
Expand Down Expand Up @@ -165,8 +167,7 @@
$error = null;
}
const displayMigrationModal = true; // TODO testing the migrate popup, what should the real condition be?
let displayMigrationModal = false;
$: if (displayMigrationModal) {
modalStore.trigger({
type: 'component',
Expand All @@ -179,9 +180,8 @@
});
}
const firstTimeSetupModal = true; // TODO testing the first time setup popup, what should the real condition be?
$: if (firstTimeSetupModal) {
let displayFirstTimeSetupModal = false;
$: if (displayFirstTimeSetupModal) {
modalStore.trigger({
type: 'component',
component: {
Expand All @@ -193,6 +193,25 @@
});
}
// Order of checks is intentional
// TODO overzealous error checking?
NeedsSmm2Migration().then((needsMigration) => {
if (needsMigration) {
// TODO actually perform profile migration
displayMigrationModal = true;
}
}).catch((err) => {
$error = `failed to check if SMM2 migration is needed: ${err}`;
}).then(() => {
GetNewUserSetupComplete().then((wasSetupCompleted) => {
if (!wasSetupCompleted) {
displayFirstTimeSetupModal = true;
}
}).catch((err) => {
$error = `failed to check if new user setup is needed: ${err}`;
});
});
EventsOn('externalInstallMod', (modReference: string, version: string) => {
if (!modReference) return;
modalStore.trigger({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
import SvgIcon from '$lib/components/SVGIcon.svelte';
import { queueAutoStart } from '$lib/store/settingsStore';
import { SetNewUserSetupComplete } from '$wailsjs/go/settings/settings';
import { BrowserOpenURL } from '$wailsjs/runtime/runtime';
export let parent: { onClose: () => void };
const OpenWelcomeGuide = () => {
BrowserOpenURL('https://docs.ficsit.app/satisfactory-modding/latest/ForUsers/Welcome.html');
};
function onClose() {
SetNewUserSetupComplete(true);
parent.onClose();
}
</script>

<div
Expand Down Expand Up @@ -102,7 +108,7 @@
</p>
</section>
<footer class="card-footer">
<button class="btn" on:click={parent.onClose}>
<button class="btn" on:click={onClose}>
<T defaultValue="Close" keyName="common.close" />
</button>
</footer>
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/satisfactorymodding/SatisfactoryModManager/backend/ficsitcli"
"github.com/satisfactorymodding/SatisfactoryModManager/backend/installfinders/common"
"github.com/satisfactorymodding/SatisfactoryModManager/backend/logging"
"github.com/satisfactorymodding/SatisfactoryModManager/backend/migration"
"github.com/satisfactorymodding/SatisfactoryModManager/backend/settings"
"github.com/satisfactorymodding/SatisfactoryModManager/backend/utils"
"github.com/satisfactorymodding/SatisfactoryModManager/backend/wailsextras"
Expand Down Expand Up @@ -131,6 +132,8 @@ func main() {
startUpdateFound = <-foundOrError
}

migration.Init()

// Create application with options
err = wails.Run(&options.App{
Title: "SatisfactoryModManager",
Expand Down Expand Up @@ -204,6 +207,7 @@ func main() {
autoupdate.Updater,
settings.Settings,
ficsitcli.ServerPicker,
migration.Migration,
},
EnumBind: []interface{}{
common.AllInstallTypes,
Expand Down

0 comments on commit 3b74afc

Please sign in to comment.