Skip to content

Commit c0258b3

Browse files
authored
Small optimizations
Small optimizations
1 parent 78e8d02 commit c0258b3

3 files changed

Lines changed: 35 additions & 34 deletions

File tree

README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Update 11/01/2021:
3939
- Improved Fallout default game installation path checking in the main script(s)
4040
- Fixed a few typo's in comments
4141

42+
Update 04/10/2021:
43+
- Small optimization in code.
44+
4245
-----
4346

4447
>> In high level overview, these are the steps we do:

fo76_ba2_archive_extract_sounds.ps1

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Pieter De Ridder
44
# Extract Fallout 76 (Or Fallout 4) Sound files from BA2 archive files
55
# Created : 15/03/2020
6-
# Updated : 11/01/2021
6+
# Updated : 04/10/2021
77
#
88
# Note : Because I use Powershell and use objects, but not really use OO architecture,
99
# i work in each Function with Open en Close file statements. Just to be safe.
@@ -52,10 +52,10 @@ Function Get-BA2FileList {
5252
)
5353

5454
# create empty array
55-
$BA2FilesList = @()
55+
[System.Collections.ArrayList]$BA2FilesList = @()
5656

5757
# hunt BA2 Archive files from given folder
58-
If (Test-Path $GameInstallationPath) {
58+
If (Test-Path -Path $GameInstallationPath) {
5959
$BA2FilesList = @((Get-ChildItem -Path $GameInstallationPath -File -Filter "*.ba2").FullName)
6060

6161
# we got some files?
@@ -86,7 +86,7 @@ Function Dump-BA2HeaderRaw {
8686
[string]$BA2Filename
8787
)
8888

89-
If (Test-Path $BA2Filename) {
89+
If (Test-Path -Path $BA2Filename) {
9090
# dump first 24 bytes (BA2 Header) as a string
9191
$bytes = [System.IO.File]::ReadAllBytes($BA2Filename)
9292
$BA2Dump = [System.Text.Encoding]::ASCII.GetString($bytes, 0, $global:BA2HeaderSize)
@@ -110,7 +110,7 @@ Function Read-BA2Header {
110110
# init empty var
111111
$BA2Header = $null
112112

113-
If (Test-Path $BA2Filename) {
113+
If (Test-Path -Path $BA2Filename) {
114114
# Create a custom PWSH object for the BA2 Header
115115
$BA2Header = New-Object PSObject
116116

@@ -175,7 +175,7 @@ Function Read-BA2NameTable {
175175
$BA2NameTable = [System.Collections.ArrayList]@()
176176

177177
If ($BA2Header -ne $null) {
178-
If (Test-Path $BA2Header.ArchiveFilePath) {
178+
If (Test-Path -Path $BA2Header.ArchiveFilePath) {
179179
# open the BA2 Archive
180180
$BA2File = [System.IO.File]::OpenRead($BA2Header.ArchiveFilePath)
181181
$BA2Reader = New-Object System.IO.BinaryReader($BA2File, [System.Text.Encoding]::ASCII)
@@ -225,7 +225,7 @@ Function Read-BA2FileTable {
225225
$BA2FileTable = [System.Collections.ArrayList]@()
226226

227227
If ($BA2Header -ne $null) {
228-
If (Test-Path $BA2Header.ArchiveFilePath) {
228+
If (Test-Path -Path $BA2Header.ArchiveFilePath) {
229229
# open the BA2 Archive
230230
$BA2File = [System.IO.File]::OpenRead($BA2Header.ArchiveFilePath)
231231
$BA2Reader = New-Object System.IO.BinaryReader($BA2File, [System.Text.Encoding]::ASCII)
@@ -389,7 +389,7 @@ Function DecompressWrite-BA2Lump {
389389

390390
#
391391
# Function : Extract-BA2Data
392-
# Open archive and extract data lumps
392+
# Open archive and extract BA2 archive data lumps as files
393393
#
394394
Function Extract-BA2Data {
395395
Param(
@@ -401,7 +401,7 @@ Function Extract-BA2Data {
401401
If (Test-Path $ExtractDestinationPath) {
402402

403403
If ($BA2Header -ne $null) {
404-
If (Test-Path $BA2Header.ArchiveFilePath) {
404+
If (Test-Path -Path $BA2Header.ArchiveFilePath) {
405405
Write-Host ""
406406
Write-Host "Archive File : $($BA2Header.ArchiveFilePath)"
407407

@@ -427,10 +427,10 @@ Function Extract-BA2Data {
427427
Write-Host "Archive Type : BA2 General archive"
428428
Write-Host ""
429429

430-
If ($BA2FileTable.Length -gt 0) {
430+
If ($BA2FileTable.Length -gt 0) {
431431
ForEach($BA2FileSig in $BA2FileTable) {
432-
$packedFilename = Split-Path -Path $BA2FileSig.FileName -Leaf
433-
#$packedFolder = Split-Path -Path $BA2FileSig.FileName -Parent
432+
[string]$packedFilename = Split-Path -Path $BA2FileSig.FileName -Leaf
433+
#[string]$packedFolder = Split-Path -Path $BA2FileSig.FileName -Parent
434434

435435
# extract only sound files
436436
If ($packedFilename.EndsWith(".xwm") -or $packedFilename.EndsWith(".fuz")) {
@@ -541,7 +541,7 @@ Function Main {
541541
)
542542

543543
[string]$FalloutGame = "Fallout 76" # change this to Fallout 4, Fallout 76, Fallout 76 PTS
544-
[string]$FalloutInstallPath = "" # internal var for installation path
544+
[string]$FalloutInstallPath = [string]::Empty # internal var for installation path
545545
[string]$MyExtractionFolder = "$($PSScriptRoot)\extracted_sfx" # extraction folder
546546

547547
# logic for cmdline arguments
@@ -550,8 +550,8 @@ Function Main {
550550
#Write-Host "DEBUG : Arg $($i.ToString()) is $($Arguments[$i])"
551551

552552
# default, a PWSH Switch statement on a String is always case insensitive
553-
Switch ($Arguments[$i]) {
554-
"-InstallPath" {
553+
Switch ($Arguments[$i]) {
554+
"-InstallPath" {
555555
# manually override Fallout Installation Path
556556
If (($i +1) -le $Arguments.Length) {
557557
$FalloutInstallPath = $Arguments[$i +1]
@@ -574,7 +574,7 @@ Function Main {
574574
"Fallout4" { $FalloutGame = "Fallout 4" }
575575
"Fallout76" { $FalloutGame = "Fallout 76" }
576576
"Fallout76PTS" { $FalloutGame = "Fallout 76 PTS" }
577-
}
577+
}
578578
}
579579

580580
"-ExtractDir" {
@@ -628,15 +628,13 @@ Function Main {
628628
# verify custom path with Data folder
629629
If (Test-Path -Path "$($FalloutInstallPath)\Data") {
630630
# add <game>\Data folder if needed our selves
631-
$FalloutInstallPath += "\Data"
631+
$FalloutInstallPath = $FalloutInstallPath + "\Data"
632632
}
633633
}
634634

635-
636-
# Override path to my local path (for debugging)
635+
# Override path to my personal local path (for debugging)
637636
#$FalloutInstallPath = "E:\Bethesda\$($FalloutGame.Substring(" ", ''))\Data"
638637

639-
640638
Write-Host ""
641639
Write-Host " --- EXTRACT FALLOUT SOUNDS FILES ---"
642640
Write-Host " Fallout game : $($FalloutGame)"

fo76_ba2_archive_extracter_early_test.ps1

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Pieter De Ridder
44
# Extract Fallout 76 (Or Fallout 4) BA2 archive files
55
# Created : 15/03/2020
6-
# Updated : 11/01/2021
6+
# Updated : 04/10/2021
77
#
88
# Currently, the script can only extract BA2 'GNRL' (= General) Archive files.
99
# BA2 'DX10' (=DirectX Textures) and 'GNMF' (=PS4) files types are not supported.
@@ -55,10 +55,10 @@ Function Get-BA2FileList {
5555
)
5656

5757
# create empty array
58-
$BA2FilesList = @()
58+
[System.Collections.ArrayList]$BA2FilesList = @()
5959

6060
# hunt BA2 Archive files from given folder
61-
If (Test-Path $GameInstallationPath) {
61+
If (Test-Path -Path $GameInstallationPath) {
6262
$BA2FilesList = @((Get-ChildItem -Path $GameInstallationPath -File -Filter "*.ba2").FullName)
6363

6464
# we got some files?
@@ -89,7 +89,7 @@ Function Dump-BA2HeaderRaw {
8989
[string]$BA2Filename
9090
)
9191

92-
If (Test-Path $BA2Filename) {
92+
If (Test-Path -Path $BA2Filename) {
9393
# dump first 24 bytes (BA2 Header) as a string
9494
$bytes = [System.IO.File]::ReadAllBytes($BA2Filename)
9595
$BA2Dump = [System.Text.Encoding]::ASCII.GetString($bytes, 0, $global:BA2HeaderSize)
@@ -113,7 +113,7 @@ Function Read-BA2Header {
113113
# init empty var
114114
$BA2Header = $null
115115

116-
If (Test-Path $BA2Filename) {
116+
If (Test-Path -Path $BA2Filename) {
117117
# Create a custom PWSH object for the BA2 Header
118118
$BA2Header = New-Object PSObject
119119

@@ -178,7 +178,7 @@ Function Read-BA2NameTable {
178178
$BA2NameTable = [System.Collections.ArrayList]@()
179179

180180
If ($BA2Header -ne $null) {
181-
If (Test-Path $BA2Header.ArchiveFilePath) {
181+
If (Test-Path -Path $BA2Header.ArchiveFilePath) {
182182
# open the BA2 Archive
183183
$BA2File = [System.IO.File]::OpenRead($BA2Header.ArchiveFilePath)
184184
$BA2Reader = New-Object System.IO.BinaryReader($BA2File, [System.Text.Encoding]::ASCII)
@@ -228,7 +228,7 @@ Function Read-BA2FileTable {
228228
$BA2FileTable = [System.Collections.ArrayList]@()
229229

230230
If ($BA2Header -ne $null) {
231-
If (Test-Path $BA2Header.ArchiveFilePath) {
231+
If (Test-Path -Path $BA2Header.ArchiveFilePath) {
232232
# open the BA2 Archive
233233
$BA2File = [System.IO.File]::OpenRead($BA2Header.ArchiveFilePath)
234234
$BA2Reader = New-Object System.IO.BinaryReader($BA2File, [System.Text.Encoding]::ASCII)
@@ -390,7 +390,7 @@ Function DecompressWrite-BA2Lump {
390390

391391
#
392392
# Function : Extract-BA2Data
393-
# Open archive and extract data lumps
393+
# Open archive and extract BA2 archive data lumps as files
394394
#
395395
Function Extract-BA2Data {
396396
Param(
@@ -402,7 +402,7 @@ Function Extract-BA2Data {
402402
If (Test-Path $ExtractDestinationPath) {
403403

404404
If ($BA2Header -ne $null) {
405-
If (Test-Path $BA2Header.ArchiveFilePath) {
405+
If (Test-Path -Path $BA2Header.ArchiveFilePath) {
406406
Write-Host ""
407407
Write-Host "Archive File : $($BA2Header.ArchiveFilePath)"
408408

@@ -428,10 +428,10 @@ Function Extract-BA2Data {
428428
Write-Host "Archive Type : BA2 General archive"
429429
Write-Host ""
430430

431-
If ($BA2FileTable.Length -gt 0) {
431+
If ($BA2FileTable.Length -gt 0) {
432432
ForEach($BA2FileSig in $BA2FileTable) {
433-
$packedFilename = Split-Path -Path $BA2FileSig.FileName -Leaf
434-
#$packedFolder = Split-Path -Path $BA2FileSig.FileName -Parent
433+
[string]$packedFilename = Split-Path -Path $BA2FileSig.FileName -Leaf
434+
#[string]$packedFolder = Split-Path -Path $BA2FileSig.FileName -Parent
435435

436436
# create subfolders if needed
437437
[string[]]$packedSubFolders = (Split-Path -Path $BA2FileSig.FileName -Parent).ToString().Split('\')
@@ -543,7 +543,7 @@ Function Main {
543543
)
544544

545545
[string]$FalloutGame = "Fallout76" # change this to Fallout4 or Fallout76
546-
[string]$FalloutInstallPath = "" # internal var for installation path
546+
[string]$FalloutInstallPath = [string]::Empty # internal var for installation path
547547
[string]$MyExtractionFolder = "$($PSScriptRoot)\extracted_sfx" # extraction folder
548548

549549
# logic for cmdline arguments
@@ -635,7 +635,7 @@ Function Main {
635635
}
636636

637637

638-
# Override path to my local path (for debugging)
638+
# Override path to my personal local path (for debugging)
639639
#$FalloutInstallPath = "E:\Bethesda\$($FalloutGame.Substring(" ", ''))\Data"
640640

641641

0 commit comments

Comments
 (0)