-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExport-VortexModList.ps1
More file actions
139 lines (118 loc) · 5.02 KB
/
Export-VortexModList.ps1
File metadata and controls
139 lines (118 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<#
.SYNOPSIS
This script reads the list of mods from the Vortex backup.json and provides them as a object array.
.DESCRIPTION
This script reads the mods from the latest Vortex backup.json and provides them as a object array.
The result can then easily be processed by other powershell command to filter, format or convert it. The
core result is not very useful by itself. It's meant to be further processed by other PowerShell commands.
Note: Mods with a status of "Uninstalled" in Vortex are not included in the list.
Note: The script reads the data from the newer file in ($($env:APPDATA)\Vortex\temp\state_backups_full\*.json).
Neither of these files is updated real-time by Vortex. So, if you change something in the mod settings, it's
best to restart Vortex if you want to see the change in this script.
The available properties returned by the script can be listed by calling:
Export-VortexModList | Get-Member
.LINK
https://github.com/detlefs/Export-VertexModList
.EXAMPLE
Export-VortexModList
Reads all data from the Vortex backup file and returns an object array of type ModData.
.EXAMPLE
Export-VortexModList | Where-Object gameName -eq baldursgate3
Reads all data from the Vortex backup and the result is piped to the Where-Object command that is
filtering the mod list for the name of the game.
The result is a mod list only containing the mods used by Baldur's Gate III
.EXAMPLE
Export-VortexModList | Select-Object gameName -Unique
Reads all data from the Vortex backup and the result is piped to Select-Object.
The result is a list of the games.
#>
[CmdletBinding()]
# Parameters: Currently there are none.
Param(
)
# Class for games. Holds data read about the games in the backup.
class GameData {
[string]$name
[string]$id
GameData([string]$name, [string]$id) {
$this.name = $name
$this.id = $id
}
}
# Class for mod data. Holds data about the mods and games
class ModData
{
[string]$gameName
[string]$gameId
[string]$id
[string]$author
[string]$description
[string]$homepage
[string]$modName
[string]$modVersion
[string]$name
[string]$newestVersion
[string]$pictureUrl
[string]$shortDescription
[string]$source
[string]$state
[long]$loadOrderNumber
[string]$enabled
ModData([string]$gameName, [string]$gameId, [string]$id, [string]$description, [string]$author, [string]$homepage, [string]$modName, [string]$modVersion, [string]$name, [string]$newestVersion, [string]$pictureUrl, [string]$shortDescription, [string]$source, [string]$state, [long]$loadOrderNumber, [string]$enabled)
{
$this.gameName = $gameName
$this.gameId = $gameId
$this.id = $id
$this.author = $author
$this.description = $description
$this.homepage = $homepage
$this.modName = $modName
$this.modVersion = $modVersion
$this.name = $name
$this.newestVersion = $newestVersion
$this.pictureUrl = $pictureUrl
$this.shortDescription = $shortDescription
$this.source = $source
$this.state = $state
$this.loadOrderNumber = $loadOrderNumber
$this.enabled = $enabled
}
}
# Globval variables
$vortexBackupJsonPath = "$($env:APPDATA)\Vortex\temp\state_backups_full\*.json"
$game = @()
$mod = @()
# Read the latest backup JSON from the default location of the Vortex backup files.
try {
$latest = Get-ChildItem -Path $vortexBackupJsonPath | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$vortexBackupJson = Get-Content -Path $latest | ConvertFrom-Json
}
catch {
"Could not read the vortex backup file: $_"
return
}
# Get the last active games from the backup and add it to the $game array.
$lastActiveProfile = $vortexBackupJson.settings.profiles.lastActiveProfile
foreach ($key in $lastActiveProfile.PSObject.Properties.Name) {
$game += [GameData]::new($key, $($lastActiveProfile.$key))
}
if ($game.count -lt 1) {
Write-Host "No games found!" -ForegroundColor Yellow
return
}
# Get the mods for each game from the backup and add details to the $mod array
foreach ($g in $game) {
$modList = $vortexBackupJson.persistent.mods.$($g.name)
foreach ($modKey in $modList.PSObject.Properties.Name) {
$m = $vortexBackupJson.persistent.mods.$($g.name).$($modKey)
$enabledState = $vortexBackupJson.persistent.profiles.$($g.id).modState.$modKey.enabled
$sortOrder = $vortexBackupJson.persistent.loadOrder.$($g.id)
$matchingItem = $sortOrder | Where-Object { $_.modId -eq $($m.id) }
if ($matchingItem) {
$index = $sortOrder.IndexOf($matchingItem)
}
$mod += [ModData]::new($g.name, $g.id, $m.id, $m.attributes.description, $m.attributes.author, $m.attributes.homepage, $m.attributes.modName, $m.attributes.modVersion, $m.attributes.name, $m.attributes.newestVersion, $m.attributes.pictureUrl, $m.attributes.shortDescription, $m.attributes.source, $m.state, $index, $enabledState)
}
}
# Return the $mod array
$mod