-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-sqlite.ps1
108 lines (93 loc) · 3.55 KB
/
setup-sqlite.ps1
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
$sqliteVersion = "3470100"
$amalgamationUrl = "https://www.sqlite.org/2024/sqlite-amalgamation-$sqliteVersion.zip"
$dllUrl = "https://www.sqlite.org/2024/sqlite-dll-win-x64-$sqliteVersion.zip"
$outputPath = "ConsoleApplication2\sqlite"
$dllOutputPath = "ConsoleApplication2"
$amalgamationZip = "sqlite-amalgamation.zip"
$dllZip = "sqlite-dll.zip"
# Create the sqlite directory if it doesn't exist
New-Item -ItemType Directory -Force -Path $outputPath
New-Item -ItemType Directory -Force -Path $dllOutputPath
Write-Host "Downloading files..." # Simply for end user convenience
# Download both zip files
#-Uri = URL | #-OutFile = Output
Invoke-WebRequest -Uri $amalgamationUrl -OutFile $amalgamationZip
Invoke-WebRequest -Uri $dllUrl -OutFile $dllZip
# Extract the contents
#Expand = Extract
Expand-Archive -Path $amalgamationZip -DestinationPath "temp_amalgamation" -Force
Expand-Archive -Path $dllZip -DestinationPath "temp_dll" -Force
# Copy only the header files from amalgamation
Copy-Item "temp_amalgamation\sqlite-amalgamation-$sqliteVersion\*.h" -Destination $outputPath
# Find and copy the DLL file (searching recursively)
$dllFile = Get-ChildItem -Path "temp_dll" -Filter "sqlite3.dll" -Recurse | Select-Object -First 1
if ($dllFile)
{
Copy-Item $dllFile.FullName -Destination $dllOutputPath
Write-Host "sqlite3.dll copied to $dllOutputPath"
}
# Find and copy the DEF file (searching recursively)
$defFile = Get-ChildItem -Path "temp_dll" -Filter "sqlite3.def" -Recurse | Select-Object -First 1
if ($defFile)
{
Copy-Item $defFile.FullName -Destination $outputPath
Write-Host "sqlite3.def copied to $outputPath"
}
# Clean up
#-Recurse = Recursively(Until no instance remains)
Remove-Item -Recurse -Force "temp_amalgamation"
Remove-Item -Recurse -Force "temp_dll"
Remove-Item $amalgamationZip
Remove-Item $dllZip
# Create .lib file using lib.bat - with improved error handling and debugging
Write-Host "Attempting to create .lib file..."
# Try to find Visual Studio installation
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vsWhere) #Set Test-Path to vsWhere
{
$vsPath = & $vsWhere -latest -property installationPath #Set vsPath to the latest installationPath found | -property = value (Sort of)
if ($vsPath)
{
Write-Host "Found Visual Studio at: $vsPath"
# Create a temporary batch file to run the commands
$tempBatch = "temp_lib_creation.bat" # @ must be at the beginning of the line for correct .ps1 syntax
@"
@echo off
call "$vsPath\Common7\Tools\VsDevCmd.bat"
cd /d "$outputPath"
lib /DEF:sqlite3.def /OUT:sqlite3.lib /MACHINE:X64
"@ | Out-File -FilePath $tempBatch -Encoding ASCII
Write-Host "Executing lib command..."
$result = cmd.exe /c $tempBatch 2>&1 #Run the .bat and capture output (Something like returning)
Write-Host $result
# Clean up | -ErrorAction = If an error is thrown do ?
Remove-Item $tempBatch -ErrorAction SilentlyContinue
}
else
{
Write-Host "Failed to get Visual Studio installation path"
}
}
else
{
Write-Host "Could not find Visual Studio installation using vswhere.exe"
}
Write-Host "`nFinal Status:"
Write-Host "=============="
Write-Host "Header files location: $outputPath"
if (Test-Path "$dllOutputPath\sqlite3.dll")
{
Write-Host "sqlite3.dll: FOUND at $dllOutputPath"
}
else
{
Write-Host "sqlite3.dll: MISSING"
}
if (Test-Path "$outputPath\sqlite3.lib")
{
Write-Host "sqlite3.lib: FOUND at $outputPath"
}
else
{
Write-Host "sqlite3.lib: MISSING"
}