|
| 1 | +<# |
| 2 | + OpenCoperLock — install the "Send to > OpenCoperLock" integration (Windows). |
| 3 | +
|
| 4 | + Per-user, NO administrator rights needed. It: |
| 5 | + 1. copies the uploader (send.ps1) and the brand icon into %LOCALAPPDATA%\OpenCoperLock, |
| 6 | + 2. asks for your WebDAV URL + API token and stores them there (the token is DPAPI-encrypted for |
| 7 | + your Windows user — unreadable by other users, and never leaves your machine), |
| 8 | + 3. pre-creates the "ComputerShared" space in your Drive, |
| 9 | + 4. adds an "OpenCoperLock" entry (with the logo) to Explorer's right-click "Send to" menu. |
| 10 | +
|
| 11 | + After this, right-click any file(s) -> Send to -> OpenCoperLock uploads them to ComputerShared. |
| 12 | +
|
| 13 | + Run: right-click install-windows.cmd, or |
| 14 | + powershell -ExecutionPolicy Bypass -File .\install-windows.ps1 |
| 15 | +#> |
| 16 | +[CmdletBinding()] |
| 17 | +param( |
| 18 | + [string]$Base, |
| 19 | + [string]$Token |
| 20 | +) |
| 21 | +$ErrorActionPreference = 'Stop' |
| 22 | + |
| 23 | +$srcDir = Split-Path -Parent $MyInvocation.MyCommand.Path # ...\send-to\windows |
| 24 | +$assets = Join-Path (Split-Path -Parent $srcDir) 'assets' # ...\send-to\assets |
| 25 | +$dstDir = Join-Path $env:LOCALAPPDATA 'OpenCoperLock' |
| 26 | +New-Item -ItemType Directory -Force -Path $dstDir | Out-Null |
| 27 | + |
| 28 | +# --- gather settings ----------------------------------------------------------------------------- |
| 29 | +$defaultBase = 'https://copper.forgenet.fr/api/dav' |
| 30 | +if (-not $Base) { |
| 31 | + $inp = Read-Host "WebDAV base URL [$defaultBase]" |
| 32 | + $Base = if ([string]::IsNullOrWhiteSpace($inp)) { $defaultBase } else { $inp.Trim() } |
| 33 | +} |
| 34 | +$Base = $Base.TrimEnd('/') |
| 35 | + |
| 36 | +if (-not $Token) { |
| 37 | + $sec = Read-Host "Paste your OpenCoperLock API token (ocl_...)" -AsSecureString |
| 38 | + $bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($sec) |
| 39 | + $Token = [Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr) |
| 40 | + [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr) |
| 41 | +} |
| 42 | +if ([string]::IsNullOrWhiteSpace($Token)) { throw "No token provided." } |
| 43 | + |
| 44 | +# --- install files ------------------------------------------------------------------------------- |
| 45 | +Copy-Item (Join-Path $srcDir 'send.ps1') (Join-Path $dstDir 'send.ps1') -Force |
| 46 | +Copy-Item (Join-Path $assets 'opencoperlock.ico') (Join-Path $dstDir 'opencoperlock.ico') -Force |
| 47 | + |
| 48 | +# DPAPI-encrypt the token (current-user scope) and write the config. |
| 49 | +$enc = ConvertTo-SecureString $Token -AsPlainText -Force | ConvertFrom-SecureString |
| 50 | +[pscustomobject]@{ base = $Base; token = $enc } | ConvertTo-Json | Set-Content (Join-Path $dstDir 'config.json') -Encoding UTF8 |
| 51 | + |
| 52 | +# --- pre-create the ComputerShared space --------------------------------------------------------- |
| 53 | +try { & curl.exe -s -u "me:$Token" -X MKCOL "$Base/ComputerShared/" | Out-Null } catch { } |
| 54 | +$Token = $null |
| 55 | + |
| 56 | +# --- Send To shortcut ---------------------------------------------------------------------------- |
| 57 | +$sendTo = [Environment]::GetFolderPath('SendTo') |
| 58 | +$lnkPath = Join-Path $sendTo 'OpenCoperLock.lnk' |
| 59 | +$ps = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe' |
| 60 | +$ws = New-Object -ComObject WScript.Shell |
| 61 | +$sc = $ws.CreateShortcut($lnkPath) |
| 62 | +$sc.TargetPath = $ps |
| 63 | +$sc.Arguments = '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "' + (Join-Path $dstDir 'send.ps1') + '"' |
| 64 | +$sc.IconLocation = (Join-Path $dstDir 'opencoperlock.ico') + ',0' |
| 65 | +$sc.Description = 'Send to OpenCoperLock (ComputerShared)' |
| 66 | +$sc.WorkingDirectory = $dstDir |
| 67 | +$sc.Save() |
| 68 | + |
| 69 | +Write-Host "" |
| 70 | +Write-Host "Installed. Right-click any file(s) -> Send to -> OpenCoperLock." -ForegroundColor Green |
| 71 | +Write-Host "Uploads land in the 'ComputerShared' space of your Drive." -ForegroundColor DarkGray |
| 72 | +Write-Host "To change the URL/token later, just run this installer again." -ForegroundColor DarkGray |
0 commit comments