Skip to content

Commit 22c9c5f

Browse files
authored
Update Network_Configuration.ps1
Actually fixed the update function this time.
1 parent 5960c08 commit 22c9c5f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Network_Configuration.ps1

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,38 +45,38 @@ function Update-Script {
4545

4646
# Ensure the version file exists
4747
if (-not (Test-Path $versionFilePath)) {
48-
Write-Host "Version file not found. Creating a new one with version 1.0." -ForegroundColor Yellow
49-
Log-Message "Version file not found. Creating a new one with version 1.0."
50-
Set-Content -Path $versionFilePath -Value "1.0"
48+
Write-Host "Version file not found. Creating a new one with version 0.0." -ForegroundColor Yellow
49+
Log-Message "Version file not found. Creating a new one with version 0.0."
50+
Set-Content -Path $versionFilePath -Value "0.0"
5151
}
5252

5353
$currentVersion = (Get-Content $versionFilePath).Trim()
5454

5555
try {
5656
# Fetch the remote script content
5757
$RemoteScriptContent = Invoke-WebRequest -Uri $RemoteScriptURL -UseBasicParsing
58-
if (-not $RemoteScriptContent) {
58+
if (-not $RemoteScriptContent -or -not $RemoteScriptContent.Content) {
5959
Write-Host "Failed to fetch the remote script. Please check the URL." -ForegroundColor Red
6060
Log-Message "Failed to fetch the remote script. Please check the URL." "ERROR"
6161
return
6262
}
6363

6464
# Extract the version line from the remote script
65-
$VersionLine = ($RemoteScriptContent.Content -split "`n" | Select-Object -First 10 | Where-Object { $_ -match "# Version:" })
65+
$VersionLine = ($RemoteScriptContent.Content -split "`n" | Where-Object { $_ -match "# Version:" })[0]
6666

6767
if ($VersionLine) {
68-
# Strict regex to extract only the version number
68+
# Extract the version number using a strict regex
6969
$RemoteVersion = ($VersionLine -replace ".*# Version:\s*([0-9]+\.[0-9]+).*", '$1').Trim()
70-
} else {
71-
Write-Host "Could not find a valid version in the remote script." -ForegroundColor Red
72-
Log-Message "Could not find a valid version in the remote script." "ERROR"
73-
return
74-
}
7570

76-
# Ensure the version is valid
77-
if (-not $RemoteVersion -or $RemoteVersion -notmatch "^\d+\.\d+$") {
78-
Write-Host "Invalid version format in the remote script." -ForegroundColor Red
79-
Log-Message "Invalid version format in the remote script." "ERROR"
71+
# Validate the extracted version format
72+
if (-not $RemoteVersion -or $RemoteVersion -notmatch "^\d+\.\d+$") {
73+
Write-Host "Invalid version format in the remote script." -ForegroundColor Red
74+
Log-Message "Invalid version format in the remote script. Version Line: $VersionLine" "ERROR"
75+
return
76+
}
77+
} else {
78+
Write-Host "Could not find a valid version line in the remote script." -ForegroundColor Red
79+
Log-Message "Could not find a valid version line in the remote script." "ERROR"
8080
return
8181
}
8282

0 commit comments

Comments
 (0)