From 138de65e8ea7e7bd3cbe84fa21676a1203de3e1a Mon Sep 17 00:00:00 2001
From: camoy <camo@m3l.net>
Date: Thu, 15 Aug 2024 15:57:18 -0700
Subject: [PATCH] Cleanup and code refactor into sweetcade.ps1

---
 scripts/ps/download.ps1  |  2 +-
 scripts/ps/gpudriver.ps1 |  4 +--
 scripts/ps/license.ps1   | 28 -------------------
 scripts/ps/makedirs.ps1  | 15 ----------
 scripts/ps/sweetcade.ps1 | 59 ++++++++++++++++++++++++++++++++++++++++
 scripts/unattend/EI.cfg  |  6 ----
 scripts/unattend/PID.txt |  2 --
 7 files changed, 62 insertions(+), 54 deletions(-)
 delete mode 100644 scripts/ps/license.ps1
 create mode 100644 scripts/ps/sweetcade.ps1
 delete mode 100644 scripts/unattend/EI.cfg
 delete mode 100644 scripts/unattend/PID.txt

diff --git a/scripts/ps/download.ps1 b/scripts/ps/download.ps1
index a836d3d..23529df 100644
--- a/scripts/ps/download.ps1
+++ b/scripts/ps/download.ps1
@@ -1,5 +1,5 @@
 Write-Host "---Download Wget---"
-Invoke-WebRequest "https://eternallybored.org/misc/wget/1.21.4/64/wget.exe" -OutFile "C:\sctools\wget\wget.exe"
+Invoke-WebRequest "https://eternallybored.org/misc/wget/1.21.4/64/wget.exe" -OutFile "C:\sc\tools\wget\wget.exe"
 Write-Host "---Download 7-Zip---"
 C:\sctools\wget\wget.exe -O "C:\sc\tools\7zip\7zr.exe" "https://7-zip.org/a/7zr.exe"
 Write-Host "---Download git---"
diff --git a/scripts/ps/gpudriver.ps1 b/scripts/ps/gpudriver.ps1
index 00f828e..02adb1f 100644
--- a/scripts/ps/gpudriver.ps1
+++ b/scripts/ps/gpudriver.ps1
@@ -2,8 +2,8 @@ Write-Host "---Detecting GPU Type---"
 #PSEUDO - Detect GPU vendor without drivers TODO
 # if nvidia
 # then
-#   C:\sctools\git\bin\git.exe clone https://github.com/lord-carlos/nvidia-update
-# nvidia.ps1 -clean -folder C:\sctools\nvidia
+#   C:\sc\tools\git\bin\git.exe clone https://github.com/lord-carlos/nvidia-update
+# nvidia.ps1 -clean -folder C:\sc\tools\nvidia
 
 # if amd
 # then
diff --git a/scripts/ps/license.ps1 b/scripts/ps/license.ps1
deleted file mode 100644
index 559050e..0000000
--- a/scripts/ps/license.ps1
+++ /dev/null
@@ -1,28 +0,0 @@
-Get-Content -Path ..\license.txt | Out-Host -Paging
-    if ($? -neq 0)
-    {
-        Write-Host "----------"
-        Write-Host "You must read and accept the terms of the software license to install Sweetcade."
-        Write-Host "This script will now exit after 60 seconds."
-        Start-Sleep -Seconds 60
-        Exit 1
-    }
-    
-    else
-    {   
-        Write-Host "----------"
-        Write-Host "You must accept the terms of the Mozilla Public License 2.0 in order to use Sweetcade."
-        Write-Host "If you [A]ccept, connect a keyboard and type A."
-        Write-Host "If you [R]eject, connect a keyboard and type R."
-            $vSCRejectTOS = Read-Host "A / R?"
-            if ($vSCNextHopUserResponse -contains "R")
-                {
-                    Write-Host "You have rejected the software license. The Sweetcade installer will now exit."
-                }
-
-            else
-                {
-                #PSEUDO - Go to next script (TODO)
-                }
-
-    }
\ No newline at end of file
diff --git a/scripts/ps/makedirs.ps1 b/scripts/ps/makedirs.ps1
index 2699b88..bc9553d 100644
--- a/scripts/ps/makedirs.ps1
+++ b/scripts/ps/makedirs.ps1
@@ -1,19 +1,4 @@
 Write-Host "---Create Directories---"
-New-Item -Path "C:\" -Name "sc" -ItemType "Directory"
-    if ( ?$ -neq True )
-        {
-            Write-Host "SC-DIR-ERR001: CANNOT CREATE NEEDED DIRECTORIES"
-            Write-Host "Creating the following directories has failed."
-            Write-Host "C:\sc"
-            Write-Host "Unable to continue. Please check that these locations are writable and that they do not already exist."
-            Start-Sleep -Seconds 60
-            Exit 1
-        }
-
-        else
-        {
-            #PSEUDO - Continue without writing function? TODO
-        }
 New-Item -Path "C:\sc" -Name "tools" -ItemType "Directory"
     if ( ?$ -neq True )
         {
diff --git a/scripts/ps/sweetcade.ps1 b/scripts/ps/sweetcade.ps1
new file mode 100644
index 0000000..b9f8d73
--- /dev/null
+++ b/scripts/ps/sweetcade.ps1
@@ -0,0 +1,59 @@
+# Script order:
+
+# sweetcade.ps1 (main launcher)
+# netcheck.ps1 (check for internet, dns resolution)
+# syscheck.ps1 (check system specs and OS state)
+# makerespt.ps1 (create restore point)
+# makedirs.ps1 (create directories)
+
+
+
+Write-Host "---------SWEETCADE INSTALL SCRIPT---------"
+Write-Host "---Retrieving Software License File---"
+Invoke-WebRequest "https://git.sdf.org/camoy/Sweetcade/raw/branch/main/license.txt" -OutFile .\license.txt
+Write-Host "---Displaying Software License File---"
+Get-Content -Path .\license.txt | Out-Host -Paging
+    if ($? -neq 0)
+    {
+        Write-Host "----------"
+        Write-Host "You must read and accept the terms of the software license to install Sweetcade."
+        Write-Host "This script will now exit after 60 seconds."
+        Start-Sleep -Seconds 60
+        Exit 1
+    }
+    
+    else
+    {   
+        Write-Host "----------"
+        Write-Host "You must accept the terms of the Mozilla Public License 2.0 in order to use Sweetcade."
+        Write-Host "If you [A]ccept, connect a keyboard and type A."
+        Write-Host "If you [R]eject, connect a keyboard and type R."
+            $vSCRejectTOS = Read-Host "A / R?"
+            if ($vSCNextHopUserResponse -contains "R")
+                {
+                    Write-Host "You have rejected the software license. The Sweetcade installer will now exit."
+                }
+
+            else
+                {
+                Write-Host "---Download Sweetcade---"
+                Invoke-WebRequest "https://git.sdf.org/camoy/Sweetcade/archive/main.zip" -OutFile .\main.zip
+                Write-Host "---Create Install Directory---"
+                New-Item -Path "C:\" -Name "sc" -ItemType "Directory"
+                Write-Host "---Extract Sweetcade---"
+                Expand-Archive -Path .\main.zip -Destination "C:\sc" -PassThru -Force   
+                Write-Host "---Start Network Check---" 
+                Invoke-Expression (start powershell ((Split-Path $MyInvocation.InvocationName) + "C:\sc\scripts\ps\netcheck.ps1"))
+                Write-Host "---Start System Check---"
+                Invoke-Expression (start powershell ((Split-Path $MyInvocation.InvocationName) + "C:\sc\scripts\ps\syscheck.ps1"))
+                Write-Host "---Create Restore Point---"
+                Invoke-Expression (start powershell ((Split-Path $MyInvocation.InvocationName) + "C:\sc\scripts\ps\makerespt.ps1"))
+                Write-Host "---Create Extra Directories---"
+                Invoke-Expression (start powershell ((Split-Path $MyInvocation.InvocationName) + "C:\sc\scripts\ps\makedirs.ps1"))
+                Write-Host "---Download Supporting Tools---"
+                Invoke-Expression (start powershell ((Split-Path $MyInvocation.InvocationName) + "C:\sc\scripts\ps\download.ps1"))
+                Write-Host "---Install GPU Graphics Driver---"
+                Invoke-Expression (start powershell ((Split-Path $MyInvocation.InvocationName) + "C:\sc\scripts\ps\gpudriver.ps1"))
+                }
+
+    }
\ No newline at end of file
diff --git a/scripts/unattend/EI.cfg b/scripts/unattend/EI.cfg
deleted file mode 100644
index d085137..0000000
--- a/scripts/unattend/EI.cfg
+++ /dev/null
@@ -1,6 +0,0 @@
-[EditionID]
-IoTEnterpriseS
-[Channel]
-Retail
-[VL]
-0
diff --git a/scripts/unattend/PID.txt b/scripts/unattend/PID.txt
deleted file mode 100644
index 0bd6f9c..0000000
--- a/scripts/unattend/PID.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-[PID]
-Value=00000-00000-00000-00000-00000
\ No newline at end of file