Skip to content

Commit fe286f0

Browse files
committed
Removed Checkboxes and Automatically select all available updates
1 parent a58a726 commit fe286f0

File tree

2 files changed

+129
-155
lines changed

2 files changed

+129
-155
lines changed

Update.ps1

Lines changed: 0 additions & 155 deletions
This file was deleted.

Updates.ps1

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Load Windows Forms
2+
Add-Type -AssemblyName System.Windows.Forms
3+
Add-Type -AssemblyName System.Drawing
4+
5+
# Function to get the current version from the registry
6+
function Get-CurrentVersion {
7+
$modelKey = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation'
8+
$orgKey = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
9+
10+
$modelVersion = (Get-ItemProperty -Path $modelKey).Model
11+
$orgVersion = (Get-ItemProperty -Path $orgKey).RegisteredOrganization
12+
13+
return $modelVersion, $orgVersion
14+
}
15+
16+
# Function to update the UI
17+
function Update-UI {
18+
param (
19+
[string]$version,
20+
[array]$availableUpdates,
21+
[hashtable]$changeLogs
22+
)
23+
24+
# Create the form
25+
$form = New-Object System.Windows.Forms.Form
26+
$form.Text = "Update Manager"
27+
$form.Size = New-Object System.Drawing.Size(400, 500)
28+
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
29+
$form.BackColor = [System.Drawing.Color]::FromArgb(240, 240, 240)
30+
31+
# Label for current version and update range
32+
$label = New-Object System.Windows.Forms.Label
33+
$label.Text = "Current Version: $version`nAvailable Update: $($availableUpdates[0]) to $($availableUpdates[-1])"
34+
$label.AutoSize = $true
35+
$label.Location = New-Object System.Drawing.Point(10, 10)
36+
$label.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold)
37+
$form.Controls.Add($label)
38+
39+
# RichTextBox for showing all changelogs
40+
$richTextBox = New-Object System.Windows.Forms.RichTextBox
41+
$richTextBox.Location = New-Object System.Drawing.Point(10, 50)
42+
$richTextBox.Size = New-Object System.Drawing.Size(360, 350)
43+
$richTextBox.ReadOnly = $true
44+
$richTextBox.ScrollBars = [System.Windows.Forms.RichTextBoxScrollBars]::Vertical
45+
$richTextBox.Font = New-Object System.Drawing.Font("Segoe UI", 9)
46+
$richTextBox.BackColor = [System.Drawing.Color]::FromArgb(255, 255, 255)
47+
$richTextBox.BorderStyle = [System.Windows.Forms.BorderStyle]::Fixed3D
48+
$form.Controls.Add($richTextBox)
49+
50+
# Display all changelogs in the RichTextBox by default
51+
foreach ($update in $availableUpdates) {
52+
$richTextBox.SelectionFont = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold)
53+
$richTextBox.AppendText("Changelogs for ${update}:`n")
54+
$richTextBox.SelectionFont = New-Object System.Drawing.Font("Segoe UI", 9)
55+
$changeLogEntries = $changeLogs[$update] -split "`n"
56+
for ($i = 0; $i -lt $changeLogEntries.Count; $i++) {
57+
$richTextBox.AppendText("$($i + 1). $($changeLogEntries[$i])`n")
58+
}
59+
$richTextBox.AppendText("`n")
60+
}
61+
62+
# Update button
63+
$updateButton = New-Object System.Windows.Forms.Button
64+
$updateButton.Text = "Apply Updates"
65+
$updateButton.Location = New-Object System.Drawing.Point(10, 410)
66+
$updateButton.Size = New-Object System.Drawing.Size(360, 30)
67+
$updateButton.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold)
68+
$updateButton.BackColor = [System.Drawing.Color]::FromArgb(0, 120, 215)
69+
$updateButton.ForeColor = [System.Drawing.Color]::White
70+
$updateButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
71+
$updateButton.Add_Click({
72+
foreach ($selectedUpdate in $availableUpdates) {
73+
Apply-Update $selectedUpdate
74+
}
75+
[System.Windows.Forms.MessageBox]::Show("All updates have been applied.", "Updates Applied")
76+
$form.Close()
77+
})
78+
$form.Controls.Add($updateButton)
79+
80+
# Show the form
81+
$form.ShowDialog() | Out-Null
82+
}
83+
84+
# Function to apply the update
85+
function Apply-Update {
86+
param (
87+
[string]$updateVersion
88+
)
89+
90+
# Placeholder for update commands based on the version
91+
switch ($updateVersion) {
92+
"4.1" {
93+
Write-Host "Applying update 4.1..."
94+
}
95+
"4.5" {
96+
Write-Host "Applying update 4.5..."
97+
}
98+
default {
99+
Write-Host "No actions defined for version: $updateVersion"
100+
}
101+
}
102+
103+
# Update the registry with the new version
104+
$newVersion = "ShivaayOS - V$updateVersion"
105+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation' -Name "Model" -Value $newVersion
106+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name "RegisteredOrganization" -Value $newVersion
107+
Write-Host "System version updated to $newVersion."
108+
}
109+
110+
# Main execution
111+
$currentVersion, $orgVersion = Get-CurrentVersion
112+
113+
# Parse numeric part of current version (e.g., "4.1" from "ShivaayOS - V4.1")
114+
$currentVersionNumeric = ($currentVersion -split "V")[-1].Trim()
115+
116+
# Filter available updates to exclude the current version
117+
$availableUpdates = @("4.1", "4.5") | Where-Object { $_ -gt $currentVersionNumeric }
118+
119+
# Change logs for each update
120+
$changeLogs = @{
121+
"4.1" = "Added Feature A.`nImproved Performance."
122+
"4.5" = "Fixed bugs.`nEnhanced UI.`nAdded Feature B."
123+
}
124+
125+
if ($availableUpdates.Count -gt 0) {
126+
Update-UI -version $currentVersion -availableUpdates $availableUpdates -changeLogs $changeLogs
127+
} else {
128+
[System.Windows.Forms.MessageBox]::Show("No available updates for your version.", "No Updates")
129+
}

0 commit comments

Comments
 (0)