-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
69 lines (59 loc) · 2.09 KB
/
install.ps1
File metadata and controls
69 lines (59 loc) · 2.09 KB
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
# Define paths
$localAppData = [Environment]::GetFolderPath("LocalApplicationData")
$folderPath = Join-Path $localAppData "OpenImageGallery"
$pythonPath = [Environment]::GetEnvironmentVariable('PYTHONPATH')
$requirementsFile = Join-Path $folderPath "requirements.txt"
# Create folder if it doesn't exist
if (-not (Test-Path $folderPath)) {
New-Item -Path $folderPath -ItemType Directory
}
# Copy other files to the folder
$filesToCopy = @("image_gallery.py", "icon.ico", "requirements.txt")
foreach ($file in $filesToCopy) {
Copy-Item ".\$file" -Destination $folderPath -ErrorAction Stop
}
# Check environment variables
$pythonPath = [Environment]::GetEnvironmentVariable('PYTHONPATH')
# Get the full path of pythonw.exe
try {
$pythonwPath = (Get-Command pythonw).Source
} catch {
Write-Host "pythonw.exe not found in PATH"
exit 1
}
# Check if Python is set
if ($pythonPath) {
# Install requirements if requirements.txt exists
if (Test-Path $requirementsFile) {
try {
python -m pip install --upgrade pip --user
python -m pip install -r $requirementsFile -v --user
} catch {
Write-Host "Error during pip installation: $_"
exit 1
}
} else {
Write-Host "requirements.txt not found in $folderPath"
exit 1
}
}
# Get the full path for image_gallery.py
$imageGalleryPath = Join-Path $folderPath "image_gallery.py"
# Generate registry script content
$regContent = @"
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\directory\shell\OpenImageGallery]
@="Open Image Gallery"
"Icon"="$($folderPath -replace '\\', '\\\\')\\icon.ico"
[HKEY_CLASSES_ROOT\directory\shell\OpenImageGallery\command]
@="`\"$($pythonwPath -replace '\\', '\\\\')`\" `\"$($imageGalleryPath -replace '\\', '\\\\')`\" `\"%1`\""
"@
# Write and execute the registry script
try {
$regFilePath = Join-Path $folderPath "Set-Context.reg"
Set-Content -Path $regFilePath -Value $regContent
Start-Process "regedit.exe" -ArgumentList "/s $regFilePath" -Wait
} catch {
Write-Host "Error executing Set-Context.reg: $_"
exit 1
}