diff --git a/backend/settings/settings.go b/backend/settings/settings.go index cd00b94d..3ddf7778 100644 --- a/backend/settings/settings.go +++ b/backend/settings/settings.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" + psUtilDisk "github.com/shirou/gopsutil/v3/disk" "github.com/spf13/viper" wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime" @@ -328,6 +329,23 @@ func ValidateCacheDir(dir string) error { return nil } +// GetCacheDirDiskSpaceLeft returns the amount of disk space left on the cache directory's disk in bytes +func (s *settings) GetCacheDirDiskSpaceLeft() (uint64, error) { + cacheDir := s.GetCacheDir() + err := ValidateCacheDir(cacheDir) + + if err != nil { + return 0, fmt.Errorf("cache directory to check space on failed to validate: %w", err) + } else { + usage, err := psUtilDisk.Usage(cacheDir) + if err != nil { + return 0, fmt.Errorf("failed to get disk free space: %w", err) + } else { + return usage.Free, nil + } + } +} + func moveCacheDir(newDir string) error { if newDir == viper.GetString("cache-dir") { return nil diff --git a/cspell.json b/cspell.json index b90ee782..9d9a64fa 100644 --- a/cspell.json +++ b/cspell.json @@ -17,6 +17,7 @@ "Maximised", "Minimised", "mircearoata", + "noclose", "Nyan", "smmanager", "smmprofile", diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index a1aa7537..c02d22dc 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -25,12 +25,12 @@ import { getModalStore, initializeModalStore } from '$lib/skeletonExtensions'; import { installs, invalidInstalls, progress } from '$lib/store/ficsitCLIStore'; import { error, expandedMod, siteURL } from '$lib/store/generalStore'; - import { konami, language, updateCheckMode } from '$lib/store/settingsStore'; + import { cacheDir, konami, language, updateCheckMode } from '$lib/store/settingsStore'; import { smmUpdate, smmUpdateReady } from '$lib/store/smmUpdateStore'; import { ExpandMod, UnexpandMod } from '$wailsjs/go/app/app'; import { NeedsSmm2Migration } from '$wailsjs/go/migration/migration'; - import { GetNewUserSetupComplete } from '$wailsjs/go/settings/settings'; - import { Environment, EventsOn, LogError } from '$wailsjs/runtime'; + import { GetCacheDirDiskSpaceLeft, GetNewUserSetupComplete } from '$wailsjs/go/settings/settings'; + import { Environment, EventsOn } from '$wailsjs/runtime'; initializeStores(); initializeModalStore(); @@ -142,11 +142,23 @@ meta: { persistent: true, }, - }); + }); } } } - + + cacheDir.subscribe((cacheDirectory) => { + GetCacheDirDiskSpaceLeft().then((spaceLeftBytes) => { + if (spaceLeftBytes < 10e9) { + const spaceLeftGbReadable = (spaceLeftBytes * 1e-9).toFixed(1); + $error = `The drive your cache directory is on (${cacheDirectory}) is very low on disk space (Only ~${spaceLeftGbReadable} GB left). Please free up some space or move the cache directory to another drive in the Mod Manager Settings.`; + } + }).catch((err) => { + $error = `failed to check cache directory disk space left: ${err}`; + }); + }); + + $: if ($smmUpdateReady && $updateCheckMode === 'ask') { modalStore.trigger({ type: 'component',