-
-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Legendary config folder migration to migration system
- Loading branch information
Showing
3 changed files
with
38 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { app } from 'electron' | ||
import { type PathLike } from 'fs' | ||
import { access, cp, mkdir } from 'fs/promises' | ||
import { join } from 'path' | ||
|
||
import { isLinux, legendaryConfigPath, userHome } from 'backend/constants' | ||
|
||
import type { Migration } from '..' | ||
|
||
const exists = async (path: PathLike) => | ||
access(path).then( | ||
() => true, | ||
() => false | ||
) | ||
|
||
export class LegendaryGlobalConfigFolderMigration implements Migration { | ||
identifier = 'legendary-move-global-config-folder' | ||
async run(): Promise<boolean> { | ||
const hasHeroicSpecificConfig = await exists(legendaryConfigPath) | ||
// Don't overwrite existing configuration | ||
if (hasHeroicSpecificConfig) return true | ||
|
||
const globalLegendaryConfig = isLinux | ||
? join(app.getPath('appData'), 'legendary') | ||
: join(userHome, '.config', 'legendary') | ||
|
||
const hasGlobalConfig = await exists(globalLegendaryConfig) | ||
// Nothing to migrate | ||
if (!hasGlobalConfig) return true | ||
|
||
await mkdir(legendaryConfigPath, { recursive: true }) | ||
await cp(globalLegendaryConfig, legendaryConfigPath, { recursive: true }) | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters