Skip to content

A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.

[Fix] steam move game (#6168)

Drackrath11a1a69a8682
diff --git a/public/locales/en/gamepage.json b/public/locales/en/gamepage.json
index d0c868030..379277876 100644
--- a/public/locales/en/gamepage.json
+++ b/public/locales/en/gamepage.json
@@ -11,7 +11,18 @@
"move": {
"message": "This can take a long time, are you sure?",
"path": "Choose where you want to move",
- "steamMessage": "Steam's Storage Manager will open to move this game to another drive. Heroic refreshes when it's done.",
+ "steam-close": "Close Steam if it is running. It only starts again if it was running.",
+ "steam-confirm": "Move",
+ "steam-destination": "Destination",
+ "steam-duplicate": {
+ "keep-destination": "Keep destination copy",
+ "keep-source": "Keep current copy",
+ "message": "{{game}} is already installed in the destination library:\n{{destination}}\n\nWhich copy do you want to keep? The other one is deleted.",
+ "title": "Game already installed"
+ },
+ "steam-no-destination": "There is no other Steam library folder to move this game to. Add a drive in Steam first.",
+ "steam-source": "Current location",
+ "steam-warning": "Be aware that this can take a long time. Steam must be closed during the move.",
"title": "Move Game Installation"
},
"no": "NO",
@@ -424,7 +435,8 @@
"installing": "Installing",
"launching": "Launching",
"moving": "Moving Installation, please wait",
- "moving-files": "Moving file '{{file}}': {{percent}}%",
+ "moving-preparing": "Preparing",
+ "moving-short": "Moving",
"notinstalled": "This game is not installed",
"notSupported": "Not supported",
"notSupportedGame": "Not Supported",
diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json
index e63c91ea5..d5856e730 100644
--- a/public/locales/en/translation.json
+++ b/public/locales/en/translation.json
@@ -119,6 +119,7 @@
"running": "Steam is running. Close Steam and try again, or restart Steam once to let Heroic manage shortcuts while Steam is running.",
"running-gamemode": "A one-time Steam restart is required before Heroic can manage Steam shortcuts on this device. Restart Steam and try again."
},
+ "steam-move-no-library": "Choose a Steam library folder to move the game to.",
"steam-running": "Steam is running. Close Steam, then try again.",
"title": "Error",
"uncaught-exception": {
diff --git a/src/backend/main.ts b/src/backend/main.ts
index b67656011..86f9c0ff5 100644
--- a/src/backend/main.ts
+++ b/src/backend/main.ts
@@ -6,7 +6,14 @@ import {
} from './images_cache'
import { fetchLastestReleases } from './utils/releases'
import { getControllerBatteries } from './utils/controller_battery'
-import { DiskSpaceData, StatusPromise, WineInstallation } from 'common/types'
+import {
+ DiskSpaceData,
+ MoveGameOutcome,
+ StatusPromise,
+ WineInstallation
+} from 'common/types'
+import { isDuplicateInstallError } from 'backend/storeManagers/steam/utils'
+import type { InstallResult } from 'common/types/game_manager'
import { runnerCapabilities } from 'common/runnerCapabilities'
import * as path from 'path'
import {
@@ -1114,7 +1121,10 @@ addHandler('repair', async (event, appName, runner) => {
addHandler(
'moveInstall',
- async (event, { appName, path, runner }): Promise<void> => {
+ async (
+ event,
+ { appName, path, runner, restartSteam, unify }
+ ): Promise<MoveGameOutcome> => {
sendGameStatusUpdate({
appName,
runner,
@@ -1127,6 +1137,7 @@ addHandler(
notify({ title, body: i18next.t('notify.moving', 'Moving game') })
let validNewPath = true
+ const outcome: MoveGameOutcome = {}
const onMoveError = (error: string) => {
notify({
@@ -1160,14 +1171,24 @@ addHandler(
}
if (validNewPath) {
- const moveRes = await libraryManagerMap[runner]
+ const moveRes: InstallResult = await libraryManagerMap[runner]
.getGame(appName)
- .moveInstall(path)
- if (moveRes.status === 'error') {
+ .moveInstall(path, { restartSteam, unify })
+ if (
+ moveRes.status === 'error' &&
+ runner === 'steam' &&
+ // A retry already chose; fail then.
+ !unify &&
+ isDuplicateInstallError(moveRes.error, moveRes.kind)
+ ) {
+ // Not a failure: the frontend asks which copy to keep.
+ outcome.duplicate = true
+ } else if (moveRes.status === 'error') {
onMoveError(moveRes.error!)
}
if (moveRes.status === 'done') {
+ outcome.warnings = moveRes.warnings
notify({ title, body: i18next.t('notify.moved') })
logInfo(`Finished moving ${appName} to ${path}.`, LogPrefix.Backend)
}
@@ -1178,6 +1199,7 @@ addHandler(
runner,
status: 'done'
})
+ return outcome
}
)
diff --git a/src/backend/storeManagers/steam/__tests__/utils.test.ts b/src/backend/storeManagers/steam/__tests__/utils.test.ts
index d9e57b136..b95e26d64 100644
--- a/src/backend/storeManagers/steam/__tests__/utils.test.ts
+++ b/src/backend/storeManagers/steam/__tests__/utils.test.ts
@@ -1,5 +1,9 @@
import { AureliaError } from '../aurelia'
-import { isSteamRunningError, reportSteamRunning } from '../utils'
+import {
+ isDuplicateInstallError,
+ isSteamRunningError,
+ reportSteamRunning
+} from '../utils'
import { showDialogBoxModalAuto } from 'backend/dialog/dialog'
jest.mock('backend/launcher', () => ({ callRunner: jest.fn() }))
@@ -37,6 +41,24 @@ describe('isSteamRunningError', () => {
})
})
+describe('isDuplicateInstallError', () => {
+ it('matches the typed kind', () => {
+ expect(isDuplicateInstallError('anything', 'already_installed')).toBe(true)
+ })
+
+ it('falls back to the text', () => {
+ expect(
+ isDuplicateInstallError(
+ 'app 7 is already installed in /mnt/games. Re-run with --unify'
+ )
+ ).toBe(true)
+ })
+
+ it('ignores other failures', () => {
+ expect(isDuplicateInstallError('disk full', 'disk_full')).toBe(false)
+ })
+})
+
describe('reportSteamRunning', () => {
beforeEach(() => jest.mocked(showDialogBoxModalAuto).mockClear())
diff --git a/src/backend/storeManagers/steam/aurelia_types.ts b/src/backend/storeManagers/steam/aurelia_types.ts
index 86ae05126..0d031cc0a 100644
--- a/src/backend/storeManagers/steam/aurelia_types.ts
+++ b/src/backend/storeManagers/steam/aurelia_types.ts
@@ -287,3 +287,13 @@ export interface AureliaAccount {
email?: string
email_validated?: boolean
}
+
+/** Final line of `aurelia move --json`. */
+export interface AureliaMoveResult {
+ status: 'moved'
+ library: string
+ /** Where the Proton prefix lives after the move, if the game has one. */
+ prefix_path?: string | null
+ /** Notes the user should see, e.g. a destination without symlink support. */
+ warnings?: string[]
+}
diff --git a/src/backend/storeManagers/steam/games.ts b/src/backend/storeManagers/steam/games.ts
index 20b42b9de..6bbefe0e1 100644
--- a/src/backend/storeManagers/steam/games.ts
+++ b/src/backend/storeManagers/steam/games.ts
@@ -11,9 +11,11 @@ import {
ExecResult,
InstallArgs,
LaunchOption,
+ MoveUnify,
Status,
CloudSyncResult
} from 'common/types'
+import { sendProgressUpdate } from 'backend/utils'
import {
logError,
logInfo,
@@ -78,7 +80,8 @@ import type {
AureliaCloudConflict,
AureliaCloudSyncResponse,
AureliaLaunchTarget,
- AureliaLaunchTargetsResponse
+ AureliaLaunchTargetsResponse,
+ AureliaMoveResult
} from './aurelia_types'
import type {
SteamCloudFile,
@@ -550,7 +553,8 @@ export default class SteamGame implements Game {
private async runStreamingCommand(
commandParts: string[],
status: Status,
- logType: 'install' | 'update' | 'repair'
+ logType: 'install' | 'update' | 'repair',
+ onResult?: (result: unknown) => void
): Promise<InstallResult> {
const logWriter = await createGameLogWriter(this.id, 'steam', logType)
const res = await libraryManagerMap['steam'].runRunnerCommand(
@@ -567,7 +571,7 @@ export default class SteamGame implements Game {
return { status: 'abort' }
}
try {
- parseAureliaJson(res)
+ onResult?.(parseAureliaJson(res))
} catch (error) {
// Paused or stopped, not failed.
if (
@@ -583,7 +587,11 @@ export default class SteamGame implements Game {
? res.error
: describeError(error)
logError([`Failed to ${status} ${this.id}`, message], LogPrefix.Steam)
- return { status: 'error', error: message }
+ return {
+ status: 'error',
+ error: message,
+ kind: error instanceof AureliaError ? error.kind : undefined
+ }
}
return { status: 'done' }
}
@@ -1240,7 +1248,10 @@ export default class SteamGame implements Game {
return true
}
- async moveInstall(newInstallPath: string): Promise<InstallResult> {
+ async moveInstall(
+ newInstallPath: string,
+ options?: { restartSteam?: boolean; unify?: MoveUnify }
+ ): Promise<InstallResult> {
if (!isSteamSupported()) {
return { status: 'error', error: STEAM_UNSUPPORTED }
}
@@ -1251,15 +1262,57 @@ export default class SteamGame implements Game {
LogPrefix.Steam
)
+ // Aurelia moves between Steam libraries only.
+ if (!newInstallPath) {
+ return {
+ status: 'error',
+ error: t(
+ 'box.error.steam-move-no-library',
+ 'Choose a Steam library folder to move the game to.'
+ )
+ }
+ }
+
+ // Clear progress left from an earlier install, so the page shows
+ // "Preparing" until the copy reports its own.
+ sendProgressUpdate({
+ appName: this.id,
+ runner: 'steam',
+ status: 'moving',
+ progress: { eta: '' }
+ })
+
+ let warnings: string[] = []
+ // A duplicate install comes back as an error the caller turns into a question.
const result = await this.runStreamingCommand(
- ['move', this.id, newInstallPath],
+ [
+ 'move',
+ this.id,
+ newInstallPath,
+ // Aurelia stops Steam and starts it again afterwards.
+ ...(options?.restartSteam ? ['--restart-steam'] : []),
+ // Which copy wins when the game is installed in both libraries.
+ ...(options?.unify ? [`--unify=${options.unify}`] : [])
+ ],
'moving',
- 'update'
+ 'update',
+ (moved) => {
+ warnings = (moved as AureliaMoveResult | null)?.warnings ?? []
+ }
)
if (result.status === 'done') {
await libraryManagerMap['steam'].refresh()
sendFrontendMessage('refreshLibrary', 'steam')
+ // E.g. a library that cannot hold symlinks keeps the Proton prefix elsewhere.
+ if (warnings.length) {
+ logWarning(
+ [`Moved ${this.id} with warnings:`, ...warnings],
+ LogPrefix.Steam
+ )
+ // Frontend shows them.
+ return { ...result, warnings }
+ }
}
if (result.status === 'error' && isSteamRunningError(result.error)) {
return { status: 'error', error: steamRunningMessage() }
diff --git a/src/backend/storeManagers/steam/utils.ts b/src/backend/storeManagers/steam/utils.ts
index 795f43637..f6a74b1ee 100644
--- a/src/backend/storeManagers/steam/utils.ts
+++ b/src/backend/storeManagers/steam/utils.ts
@@ -29,6 +29,18 @@ export function isSteamRunningError(error: unknown): boolean {
return text.includes('Steam is running')
}
+/** Aurelia found a second install in the destination library. */
+export function isDuplicateInstallError(
+ error: unknown,
+ kind?: string
+): boolean {
+ // Typed since Aurelia v0.5.3.
+ if (kind === 'already_installed') return true
+ // Text fallback for older binaries.
+ const text = error instanceof Error ? error.message : String(error)
+ return text.includes('already installed in')
+}
+
export function steamRunningMessage(): string {
return t(
'box.error.steam-running',
diff --git a/src/common/types.ts b/src/common/types.ts
index 1cb741852..c9e11af65 100644
--- a/src/common/types.ts
+++ b/src/common/types.ts
@@ -849,6 +849,21 @@ export interface MoveGameArgs {
appName: string
path: string
runner: Runner
+ /** Steam only: close a running Steam for the move and start it again after. */
+ restartSteam?: boolean
+ /** Steam only: which copy to keep when the destination has one too. */
+ unify?: MoveUnify
+}
+
+/** `destination`: delete the copy being moved. `source`: replace the other one. */
+export type MoveUnify = 'destination' | 'source'
+
+/** Steam move result for the frontend. */
+export interface MoveGameOutcome {
+ /** Already installed at the destination. */
+ duplicate?: boolean
+ /** Notes from a finished move. */
+ warnings?: string[]
}
export interface DiskSpaceData {
diff --git a/src/common/types/game_manager.ts b/src/common/types/game_manager.ts
index 47182f697..734559f90 100644
--- a/src/common/types/game_manager.ts
+++ b/src/common/types/game_manager.ts
@@ -7,6 +7,7 @@ import {
InstallArgs,
InstallInfo,
LaunchOption,
+ MoveUnify,
GOGAchievement,
CloudSyncResult
} from 'common/types'
@@ -16,6 +17,10 @@ import type LogWriter from 'backend/logger/log_writer'
export interface InstallResult {
status: 'done' | 'error' | 'abort'
error?: string
+ /** Aurelia's error type, e.g. `disk_full`. */
+ kind?: string
+ /** Steam move notes for the user. */
+ warnings?: string[]
}
export type RemoveArgs = {
@@ -43,7 +48,10 @@ export interface Game {
args?: string[],
skipVersionCheck?: boolean
) => Promise<boolean>
- moveInstall: (newInstallPath: string) => Promise<InstallResult>
+ moveInstall: (
+ newInstallPath: string,
+ options?: { restartSteam?: boolean; unify?: MoveUnify }
+ ) => Promise<InstallResult>
repair: () => Promise<ExecResult>
syncSaves: (
arg: string,
diff --git a/src/common/types/ipc.ts b/src/common/types/ipc.ts
index c8dc287d4..a8217bf8e 100644
--- a/src/common/types/ipc.ts
+++ b/src/common/types/ipc.ts
@@ -30,6 +30,7 @@ import type {
LaunchOption,
LaunchParams,
MoveGameArgs,
+ MoveGameOutcome,
RecentGame,
Release,
Runner,
@@ -347,7 +348,7 @@ interface AsyncIPCFunctions {
shoudlRemoveSetting: boolean
) => Promise<void>
repair: (appName: string, runner: Runner) => Promise<void>
- moveInstall: (args: MoveGameArgs) => Promise<void>
+ moveInstall: (args: MoveGameArgs) => Promise<MoveGameOutcome>
importGame: (args: ImportGameArgs) => StatusPromise
updateGame: (args: UpdateParams) => Promise<void>
changeInstallPath: (args: MoveGameArgs) => Promise<void>
diff --git a/src/frontend/components/UI/SelectField/index.css b/src/frontend/components/UI/SelectField/index.css
index e7cbf5b82..7fa704bbc 100644
--- a/src/frontend/components/UI/SelectField/index.css
+++ b/src/frontend/components/UI/SelectField/index.css
@@ -128,6 +128,14 @@
cursor: not-allowed;
}
+/* MUI's disabled text is unreadable */
+.selectFieldWrapper .MuiOutlinedInput-root.Mui-disabled,
+.selectFieldWrapper .MuiSelect-select.Mui-disabled {
+ color: var(--text-secondary);
+ -webkit-text-fill-color: var(--text-secondary);
+ cursor: not-allowed;
+}
+
.selectFieldWrapper.small select {
width: clamp(150px, 10rem, 372px);
}
diff --git a/src/frontend/components/UI/Sidebar/components/CurrentDownload/index.tsx b/src/frontend/components/UI/Sidebar/components/CurrentDownload/index.tsx
index 60422425b..16837ffe2 100644
--- a/src/frontend/components/UI/Sidebar/components/CurrentDownload/index.tsx
+++ b/src/frontend/components/UI/Sidebar/components/CurrentDownload/index.tsx
@@ -16,12 +16,15 @@ type Props = {
appName: string
runner: Runner
state?: DownloadManagerState
+ /** A game being moved, not a download-queue entry. */
+ moving?: boolean
}
export default React.memo(function CurrentDownload({
appName,
runner,
- state
+ state,
+ moving = false
}: Props) {
const [progress] = hasProgress(appName, runner)
const liveProgress = useInstallProgress((s) => s[`${appName}_${runner}`])
@@ -57,6 +60,9 @@ export default React.memo(function CurrentDownload({
if (isPreparing) {
return t('status.preparing', 'Preparing…')
}
+ if (moving) {
+ return t('gamepage:status.moving-short', 'Moving')
+ }
return progress.percent && progress.percent > 98
? t('status.processing', 'Processing files, please wait')
: t('status.installing', 'Installing')
@@ -67,7 +73,10 @@ export default React.memo(function CurrentDownload({
}
return (
- <Link to={`/download-manager`} className="currentDownload">
+ <Link
+ to={moving ? `/gamepage/${runner}/${appName}` : `/download-manager`}
+ className="currentDownload"
+ >
<span className="statusIcon" title={`${getStatus()} - ${gameTitle}`}>
<Badge
badgeContent={`${Math.round(progress.percent ?? 0)}%`}
diff --git a/src/frontend/components/UI/Sidebar/index.tsx b/src/frontend/components/UI/Sidebar/index.tsx
index 7814667f7..8103fd089 100644
--- a/src/frontend/components/UI/Sidebar/index.tsx
+++ b/src/frontend/components/UI/Sidebar/index.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useRef, useState } from 'react'
+import React, { useContext, useEffect, useRef, useState } from 'react'
import CurrentDownload from './components/CurrentDownload'
import SidebarLinks from './components/SidebarLinks'
@@ -9,6 +9,7 @@ import { DMQueueElement, DownloadManagerState } from 'common/types'
import HeroicIcon from 'frontend/assets/heroic-icon.svg?react'
import { useNavigate } from 'react-router-dom'
+import ContextProvider from 'frontend/state/ContextProvider'
import { WebviewTag } from 'electron'
const defaultWidth = 240
@@ -28,6 +29,13 @@ export default React.memo(function Sidebar() {
const navigate = useNavigate()
+ // A Steam move reports progress but is not in the download queue; show it in
+ // the same spot when nothing is downloading.
+ const { libraryStatus } = useContext(ContextProvider)
+ const movingGame = libraryStatus.find(
+ (game) => game.status === 'moving' && game.runner === 'steam'
+ )
+
useEffect(() => {
window.api
.getDMQueueInformation()
@@ -160,6 +168,14 @@ export default React.memo(function Sidebar() {
state={dmState}
/>
)}
+ {!currentDMElement && movingGame?.runner && (
+ <CurrentDownload
+ key={`moving-${movingGame.appName}`}
+ appName={movingGame.appName}
+ runner={movingGame.runner}
+ moving
+ />
+ )}
</div>
<HeroicVersion />
<div className="resizer" onMouseDown={handleDragStart} />
diff --git a/src/frontend/screens/Game/GamePage/components/GameStatus.tsx b/src/frontend/screens/Game/GamePage/components/GameStatus.tsx
index 55004e5d2..7452a1434 100644
--- a/src/frontend/screens/Game/GamePage/components/GameStatus.tsx
+++ b/src/frontend/screens/Game/GamePage/components/GameStatus.tsx
@@ -21,7 +21,7 @@ const GameStatus = ({ gameInfo, progress }: Props) => {
notAvailable?: boolean,
statusContext?: string
): React.ReactNode {
- const { eta, bytes, percent, file } = progress
+ const { eta, bytes, percent } = progress
if (runner === 'gog' && is.notInstallable) {
return t(
@@ -56,15 +56,18 @@ const GameStatus = ({ gameInfo, progress }: Props) => {
}
if (is.moving) {
- if (file && percent !== undefined) {
- return t(
- 'status.moving-files',
- `Moving file '{{file}}': {{percent}}%`,
- { file, percent: percent.toFixed(0) }
- )
+ // Same shape as an install: amount done and time left, next to the bar.
+ if (percent !== undefined && bytes) {
+ return `${t('status.moving-short', 'Moving')} ${bytes}${
+ eta ? ` \u00b7 ETA ${eta}` : ''
+ }`
}
- return `${t('status.moving', 'Moving Installation, please wait')} ...`
+ // Steam: sizing the install and closing Steam come before the copy.
+ // Other stores report no progress, so they keep the long-running text.
+ return runner === 'steam'
+ ? `${t('status.moving-preparing', 'Preparing')} ...`
+ : `${t('status.moving', 'Moving Installation, please wait')} ...`
}
const currentProgress =
@@ -112,7 +115,13 @@ const GameStatus = ({ gameInfo, progress }: Props) => {
is.notAvailable,
statusContext
)
- const showProgress = is.installing || is.updating
+ const moveHasProgress = progress.percent !== undefined && !!progress.bytes
+ // A Steam move shows the animated "preparing" bar until the copy reports.
+ const preparingMove = is.moving && runner === 'steam' && !moveHasProgress
+ const showProgress =
+ is.installing ||
+ is.updating ||
+ (is.moving && (moveHasProgress || preparingMove))
if (!label && !showProgress) {
return null
@@ -122,12 +131,16 @@ const GameStatus = ({ gameInfo, progress }: Props) => {
<div className="gameStatus">
{showProgress && (
<ProgressBar
- tone="success"
+ tone={preparingMove ? 'warning' : 'success'}
size="md"
showValue
className="installProgress"
- value={getProgress(progress)}
- label={t('status.installing', 'Installing')}
+ value={preparingMove ? undefined : getProgress(progress)}
+ label={
+ is.moving
+ ? t('status.moving-short', 'Moving')
+ : t('status.installing', 'Installing')
+ }
/>
)}
<p
diff --git a/src/frontend/screens/Game/GameSubMenu/SteamMoveModal.css b/src/frontend/screens/Game/GameSubMenu/SteamMoveModal.css
new file mode 100644
index 000000000..9a45bf2e0
--- /dev/null
+++ b/src/frontend/screens/Game/GameSubMenu/SteamMoveModal.css
@@ -0,0 +1,58 @@
+/* Sits right below the title. */
+.SteamMoveModal__warning {
+ margin-bottom: var(--space-md);
+}
+
+/* The picker keeps SelectField's default look: label above the dropdown. */
+.SteamMoveModal .selectFieldWrapper {
+ width: 100%;
+ margin-bottom: var(--space-md);
+}
+
+/* Read-only row matching the select's label and value text. */
+.SteamMoveModal__source {
+ display: grid;
+ margin-bottom: var(--space-md);
+}
+
+.SteamMoveModal__sourceLabel {
+ margin-bottom: var(--space-xs-fixed);
+ font-family: var(--primary-font-family);
+ font-size: var(--body-sm);
+ font-weight: var(--medium);
+ color: var(--field-label-color);
+}
+
+.SteamMoveModal__sourcePath {
+ font-family: var(--primary-font-family);
+ font-size: var(--body-md);
+ color: var(--text-default);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+/* Library paths can be long. */
+.SteamMoveModal .selectFieldWrapper .MuiSelect-select.MuiSelect-select {
+ display: block;
+ line-height: var(--field-height);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.SteamMoveModal__text {
+ margin: 0;
+ color: var(--text-secondary);
+ line-height: var(--leading-normal, 1.5);
+}
+
+.SteamMoveModal__closeSteam {
+ display: flex;
+ align-items: center;
+ gap: var(--space-xs-fixed);
+ font-family: var(--primary-font-family);
+ font-size: var(--body-md);
+ color: var(--text-default);
+ cursor: pointer;
+}
diff --git a/src/frontend/screens/Game/GameSubMenu/SteamMoveModal.tsx b/src/frontend/screens/Game/GameSubMenu/SteamMoveModal.tsx
new file mode 100644
index 000000000..eda0d167e
--- /dev/null
+++ b/src/frontend/screens/Game/GameSubMenu/SteamMoveModal.tsx
@@ -0,0 +1,148 @@
+import './SteamMoveModal.css'
+import { useEffect, useState } from 'react'
+import { useTranslation } from 'react-i18next'
+import {
+ Modal,
+ ModalContent,
+ ModalFooter,
+ ModalHeader
+} from 'frontend/components/UI/Modal'
+import Button from 'frontend/components/UI/Button'
+import Checkbox from 'frontend/components/UI/Checkbox'
+import { Alert, UpdateComponent } from 'frontend/components/UI'
+import SteamLibrarySelector from 'frontend/screens/Library/components/InstallModal/DownloadDialog/SteamLibrarySelector'
+import { SteamInstallLibrary } from 'common/types/steam'
+
+interface SteamMoveModalProps {
+ /** `<library>/steamapps/common/<dir>` of the installed game. */
+ installPath?: string
+ /** Starts the move; the modal closes itself. */
+ onMove: (destination: string) => void
+ onClose: () => void
+}
+
+const unifySeparators = (path: string) =>
+ path.replaceAll('\\', '/').replace(/\/+$/, '')
+
+/** Whether the game at `installPath` lives in `library`. */
+function isInLibrary(installPath: string, library: string): boolean {
+ return unifySeparators(installPath)
+ .toLowerCase()
+ .startsWith(`${unifySeparators(library).toLowerCase()}/steamapps/`)
+}
+
+/**
+ * Moves a Steam game to another Steam library folder. Steam only knows games
+ * inside its libraries, so the destination is picked from those instead of a
+ * free-form folder browser.
+ */
+export default function SteamMoveModal({
+ installPath,
+ onMove,
+ onClose
+}: SteamMoveModalProps) {
+ const { t } = useTranslation('gamepage')
+ const [libraries, setLibraries] = useState<SteamInstallLibrary[] | null>(null)
+ const [destination, setDestination] = useState('')
+ // Steam rewrites its library files on exit, so the user must agree to close it.
+ const [closeSteam, setCloseSteam] = useState(false)
+ // The library the game is in now; the install folder until that is known.
+ const [source, setSource] = useState(installPath ?? '')
+
+ useEffect(() => {
+ let cancelled = false
+ void window.api.getSteamInstallLibraries().then((all) => {
+ if (cancelled) return
+ const others = installPath
+ ? all.filter((lib) => !isInLibrary(installPath, lib.path))
+ : all
+ setLibraries(others)
+ const current = all.find(
+ (lib) => installPath && isInLibrary(installPath, lib.path)
+ )
+ if (current) setSource(current.path)
+ setDestination(others[0]?.path ?? '')
+ })
+ return () => {
+ cancelled = true
+ }
+ }, [installPath])
+
+ const confirm = () => {
+ if (!destination || !closeSteam) return
+ onMove(destination)
+ onClose()
+ }
+
+ return (
+ <Modal
+ onClose={onClose}
+ showCloseButton
+ size="md"
+ className="SteamMoveModal"
+ >
+ <ModalHeader>{t('box.move.title', 'Move Game Installation')}</ModalHeader>
+ <ModalContent>
+ {libraries === null ? (
+ <UpdateComponent inline />
+ ) : libraries.length === 0 ? (
+ <p className="SteamMoveModal__text">
+ {t(
+ 'box.move.steam-no-destination',
+ 'There is no other Steam library folder to move this game to. Add a drive in Steam first.'
+ )}
+ </p>
+ ) : (
+ <>
+ <Alert variant="warning" className="SteamMoveModal__warning">
+ {t(
+ 'box.move.steam-warning',
+ 'Be aware that this can take a long time. Steam must be closed during the move.'
+ )}
+ </Alert>
+ {source && (
+ <div className="SteamMoveModal__source">
+ <span className="SteamMoveModal__sourceLabel">
+ {t('box.move.steam-source', 'Current location')}
+ </span>
+ <span className="SteamMoveModal__sourcePath" title={source}>
+ {source}
+ </span>
+ </div>
+ )}
+ <SteamLibrarySelector
+ libraries={libraries}
+ selectedPath={destination}
+ onChange={setDestination}
+ label={t(
+ 'box.move.steam-destination',
+ 'Destination (Steam library)'
+ )}
+ />
+ <label className="SteamMoveModal__closeSteam">
+ <Checkbox
+ size="small"
+ checked={closeSteam}
+ onChange={(event) => setCloseSteam(event.target.checked)}
+ />
+ <span>
+ {t(
+ 'box.move.steam-close',
+ 'Close Steam if it is running. It only starts again if it was running.'
+ )}
+ </span>
+ </label>
+ </>
+ )}
+ </ModalContent>
+ <ModalFooter>
+ <Button variant="secondary" onClick={onClose}>
+ {t('box.cancel', { ns: 'translation', defaultValue: 'Cancel' })}
+ </Button>
+ <Button onClick={confirm} disabled={!destination || !closeSteam}>
+ {t('box.move.steam-confirm', 'Move')}
+ </Button>
+ </ModalFooter>
+ </Modal>
+ )
+}
diff --git a/src/frontend/screens/Game/GameSubMenu/index.css b/src/frontend/screens/Game/GameSubMenu/index.css
index bd680f82d..2ec6eaf34 100644
--- a/src/frontend/screens/Game/GameSubMenu/index.css
+++ b/src/frontend/screens/Game/GameSubMenu/index.css
@@ -54,3 +54,8 @@
width: var(--line-height) !important;
height: var(--line-height) !important;
}
+
+/* Keeps line breaks in move dialogs */
+.steamMoveMessage {
+ white-space: pre-line;
+}
diff --git a/src/frontend/screens/Game/GameSubMenu/index.tsx b/src/frontend/screens/Game/GameSubMenu/index.tsx
index 36e329c79..a1bebf6d9 100644
--- a/src/frontend/screens/Game/GameSubMenu/index.tsx
+++ b/src/frontend/screens/Game/GameSubMenu/index.tsx
@@ -2,7 +2,7 @@ import './index.css'
import { useCallback, useContext, useEffect, useState } from 'react'
-import { GameInfo, GameStatus, Runner } from 'common/types'
+import { GameInfo, GameStatus, MoveUnify, Runner } from 'common/types'
import { supportsCapability } from 'common/runnerCapabilities'
import { createNewWindow } from 'frontend/helpers'
@@ -13,6 +13,8 @@ import { NavLink } from 'react-router-dom'
import { CircularProgress, SvgIcon } from '@mui/material'
import UninstallModal from 'frontend/components/UI/UninstallModal'
+import SteamMoveModal from './SteamMoveModal'
+import { steamCompatdataPrefix } from 'frontend/helpers/steamPrefix'
import GameContext from '../GameContext'
import { openInstallGameModal } from 'frontend/state/InstallGameModal'
import useGlobalState from 'frontend/state/GlobalStateV2'
@@ -83,6 +85,7 @@ export default function GamesSubmenu({
const [eosOverlayRefresh, setEosOverlayRefresh] = useState<boolean>(false)
const eosOverlayAppName = '98bc04bc842e4906993fd6d6644ffb8d'
const [showUninstallModal, setShowUninstallModal] = useState(false)
+ const [showSteamMoveModal, setShowSteamMoveModal] = useState(false)
const [protonDBurl, setProtonDBurl] = useState(
`https://www.protondb.com/search?q=${title}`
)
@@ -93,12 +96,6 @@ export default function GamesSubmenu({
const canRepair = supportsCapability(runner, 'repair')
async function onMoveInstallYesClick() {
- // Steam manages the move (and destination drive selection) in its own
- // Storage Manager, so skip Heroic's directory picker and hand off to Steam.
- if (runner === 'steam') {
- await window.api.moveInstall({ appName, path: '', runner })
- return
- }
const { defaultInstallPath } = await window.api.requestAppSettings()
const path = await window.api.openDialog({
buttonLabel: t('box.choose'),
@@ -111,11 +108,69 @@ export default function GamesSubmenu({
}
}
+ // Progress and errors arrive through the game status, like other moves.
+ async function moveSteamGame(path: string, unify?: MoveUnify) {
+ const outcome = await window.api.moveInstall({
+ appName,
+ path,
+ runner,
+ // Required by the modal; only restarts a running Steam.
+ restartSteam: true,
+ unify
+ })
+ if (outcome?.warnings?.length) {
+ showDialogModal({
+ showDialog: true,
+ title: t('box.warning.title', 'Warning'),
+ message: (
+ <div className="steamMoveMessage">
+ {outcome.warnings.join('\n\n')}
+ </div>
+ ),
+ buttons: [{ text: t('box.ok', 'OK') }]
+ })
+ return
+ }
+ if (!outcome?.duplicate) return
+ // Installed in both libraries: offer to keep the destination's copy.
+ showDialogModal({
+ showDialog: true,
+ title: t('box.move.steam-duplicate.title', 'Game already installed'),
+ message: (
+ <div className="steamMoveMessage">
+ {t(
+ 'box.move.steam-duplicate.message',
+ '{{game}} is already installed in the destination library:\n{{destination}}\n\nWhich copy do you want to keep? The other one is deleted.',
+ { game: title, destination: path }
+ )}
+ </div>
+ ),
+ buttons: [
+ {
+ text: t(
+ 'box.move.steam-duplicate.keep-destination',
+ 'Keep destination copy'
+ ),
+ onClick: () => void moveSteamGame(path, 'destination')
+ },
+ {
+ text: t('box.move.steam-duplicate.keep-source', 'Keep current copy'),
+ onClick: () => void moveSteamGame(path, 'source')
+ },
+ { text: t('box.cancel', { ns: 'translation', defaultValue: 'Cancel' }) }
+ ]
+ })
+ }
+
function handleMoveInstall() {
+ // Steam games only move between Steam libraries, picked in their own modal.
+ if (runner === 'steam') {
+ setShowSteamMoveModal(true)
+ return
+ }
showDialogModal({
showDialog: true,
- message:
- runner === 'steam' ? t('box.move.steamMessage') : t('box.move.message'),
+ message: t('box.move.message'),
title: t('box.move.title'),
buttons: [
{ text: t('box.yes'), onClick: onMoveInstallYesClick },
@@ -289,12 +344,18 @@ export default function GamesSubmenu({
}, [gameInfo])
const onBrowsePrefix = useCallback(() => {
- const path = gameSettings?.winePrefix
+ // Steam games ignore Heroic's Wine prefix: they use the custom folder from
+ // their settings, else Steam's compatdata folder in the game's library.
+ const path =
+ runner === 'steam'
+ ? gameSettings?.steamPrefix ||
+ steamCompatdataPrefix(gameInfo.install.install_path, appName)
+ : gameSettings?.winePrefix
if (path) {
window.api.openFolder(path)
}
- }, [gameSettings])
+ }, [gameSettings, runner, gameInfo, appName])
return (
<>
@@ -307,6 +368,13 @@ export default function GamesSubmenu({
isDlc={false}
/>
)}
+ {showSteamMoveModal && (
+ <SteamMoveModal
+ installPath={gameInfo.install.install_path}
+ onMove={(destination) => void moveSteamGame(destination)}
+ onClose={() => setShowSteamMoveModal(false)}
+ />
+ )}
<div className={`submenu`}>
{isInstalled && (
<>
diff --git a/src/frontend/screens/Library/components/GameCard/constants.ts b/src/frontend/screens/Library/components/GameCard/constants.ts
index c1bebc223..70efdb1f1 100644
--- a/src/frontend/screens/Library/components/GameCard/constants.ts
+++ b/src/frontend/screens/Library/components/GameCard/constants.ts
@@ -45,6 +45,7 @@ export function getCardStatus(status: string | undefined) {
isInstallingRedist
return {
isInstalling,
+ isMoving,
notSupportedGame,
isUninstalling,
isQueued,
diff --git a/src/frontend/screens/Library/components/GameCard/index.tsx b/src/frontend/screens/Library/components/GameCard/index.tsx
index e053b198a..8a3fe38ea 100644
--- a/src/frontend/screens/Library/components/GameCard/index.tsx
+++ b/src/frontend/screens/Library/components/GameCard/index.tsx
@@ -277,6 +277,7 @@ const GameCard = ({
const {
isInstalling,
+ isMoving,
notSupportedGame,
isUninstalling,
isQueued,
@@ -286,9 +287,9 @@ const GameCard = ({
haveStatus
} = getCardStatus(status)
- const installingGrayscale = isInstalling
- ? `${125 - getProgress(progress)}%`
- : '100%'
+ // A move fills the cover in like an install does.
+ const installingGrayscale =
+ isInstalling || isMoving ? `${125 - getProgress(progress)}%` : '100%'
const handleRemoveFromQueue = () => {
window.api.removeFromDMQueue(appName)
diff --git a/src/frontend/screens/Library/components/InstallModal/DownloadDialog/SteamLibrarySelector.tsx b/src/frontend/screens/Library/components/InstallModal/DownloadDialog/SteamLibrarySelector.tsx
index 4bc8a721c..b05bb37e4 100644
--- a/src/frontend/screens/Library/components/InstallModal/DownloadDialog/SteamLibrarySelector.tsx
+++ b/src/frontend/screens/Library/components/InstallModal/DownloadDialog/SteamLibrarySelector.tsx
@@ -8,6 +8,8 @@ interface SteamLibrarySelectorProps {
libraries: SteamInstallLibrary[]
selectedPath: string
onChange: (path: string) => void
+ /** Overrides the default "Install Path" label. */
+ label?: string
}
/**
@@ -19,10 +21,12 @@ interface SteamLibrarySelectorProps {
export default function SteamLibrarySelector({
libraries,
selectedPath,
- onChange
+ onChange,
+ label: customLabel
}: SteamLibrarySelectorProps) {
const { t } = useTranslation('gamepage')
- const label = t('install.steam-path', 'Install Path (Steam library)')
+ const label =
+ customLabel ?? t('install.steam-path', 'Install Path (Steam library)')
if (!libraries.length) {
return (