4
4
5
5
. EXAMPLE
6
6
iwr app.sophia.team -useb | iex
7
+
8
+ . NOTES
9
+ Current user
7
10
#>
8
11
9
12
[Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
29
32
}
30
33
31
34
$Parameters = @ {
32
- Uri = " https://raw.githubusercontent .com/Sophia-Community/SophiApp/master/sophiapp_versions.json "
33
- UseBasicParsing = $true
35
+ Uri = " https://api.github .com/repos/ Sophia-Community/SophiApp/releases/latest "
36
+ UseBasicParsing = $true
34
37
}
35
- $LatestRelease = (Invoke-RestMethod @Parameters ).SophiApp_release
38
+ $LatestRelease = (Invoke-RestMethod @Parameters ).assets.browser_download_url
36
39
$Parameters = @ {
37
- Uri = " https://github.com/Sophia-Community/SophiApp/releases/download/ $LatestRelease /SophiApp.zip "
40
+ Uri = $LatestRelease
38
41
OutFile = " $DownloadsFolder \SophiApp.zip"
39
42
UseBasicParsing = $true
40
43
Verbose = $true
@@ -52,28 +55,35 @@ Remove-Item -Path "$DownloadsFolder\SophiApp.zip" -Force
52
55
Start-Sleep - Second 1
53
56
Invoke-Item - Path " $DownloadsFolder \SophiApp"
54
57
55
- $SetForegroundWindow = @ {
56
- Namespace = " WinAPI"
57
- Name = " ForegroundWindow"
58
- Language = " CSharp"
59
- MemberDefinition = @"
58
+ # https://github.com/PowerShell/PowerShell/issues/21070
59
+ $CompilerParameters = [System.CodeDom.Compiler.CompilerParameters ]::new(" System.dll" )
60
+ $CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection ]::new($env: TEMP , $false )
61
+ $CompilerParameters.GenerateInMemory = $true
62
+ $Signature = @ {
63
+ Namespace = " WinAPI"
64
+ Name = " ForegroundWindow"
65
+ Language = " CSharp"
66
+ CompilerParameters = $CompilerParameters
67
+ MemberDefinition = @"
60
68
[DllImport("user32.dll")]
61
69
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
62
70
[DllImport("user32.dll")]
63
71
[return: MarshalAs(UnmanagedType.Bool)]
64
72
public static extern bool SetForegroundWindow(IntPtr hWnd);
65
73
"@
74
+ }
75
+
76
+ # PowerShell 7 has CompilerOptions argument instead of CompilerParameters as PowerShell 5 has
77
+ # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/add-type#-compileroptions
78
+ if ($Host.Version.Major -eq 7 )
79
+ {
80
+ $Signature.Remove (" CompilerParameters" )
81
+ $Signature.Add (" CompilerOptions" , $CompilerParameters )
66
82
}
83
+
67
84
if (-not (" WinAPI.ForegroundWindow" -as [type ]))
68
85
{
69
- try
70
- {
71
- Add-Type @SetForegroundWindow
72
- }
73
- catch [System.ComponentModel.Win32Exception ]
74
- {
75
- Write-Warning - Message " PowerShell 5.1 does not compile code if the username contains non-Latin characters (including emoji) and is written in lowercase. Ignore this error message. Open background folder manually."
76
- }
86
+ Add-Type @Signature
77
87
}
78
88
79
89
Start-Sleep - Seconds 1
0 commit comments