Or use :
ps2exe ".\automatic_login.ps1" "XIVLauncher.exe" -noConsole -icon ".\dalamud.ico" -title "XIVLauncher" -STA -noOutput -noError
| # You shouldn't need to modify this unless you have a custom launcher install | |
| $LauncherPath = Join-Path $env:LOCALAPPDATA "XIVLauncher\XIVLauncher.exe" | |
| # change this to the key in 1password | |
| $VaultItemName = "FFXIV" | |
| function Get-OtpFrom1Password { | |
| param([Parameter(Mandatory)][string]$ItemName) | |
| $psi = [System.Diagnostics.ProcessStartInfo]::new() | |
| $psi.FileName = "op" | |
| $psi.Arguments = "item get `"$ItemName`" --otp" | |
| $psi.UseShellExecute = $false | |
| $psi.CreateNoWindow = $true | |
| $psi.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden | |
| $psi.RedirectStandardOutput = $true | |
| $psi.RedirectStandardError = $true | |
| $p = [System.Diagnostics.Process]::Start($psi) | |
| $out = $p.StandardOutput.ReadToEnd().Trim() | |
| $err = $p.StandardError.ReadToEnd().Trim() | |
| $p.WaitForExit() | |
| if ($p.ExitCode -ne 0 -or [string]::IsNullOrWhiteSpace($out)) { | |
| throw "op failed (exit $($p.ExitCode)): $err" | |
| } | |
| return $out | |
| } | |
| try { | |
| $OTP = Get-OtpFrom1Password -ItemName $VaultItemName | |
| } catch { | |
| # pas de Read-Host dans un exe GUI | |
| [System.Windows.Forms.MessageBox]::Show($_.Exception.Message, "XIVLauncher OTP", "OK", "Error") | Out-Null | |
| exit 1 | |
| } | |
| if ($OTP.Length -eq 6) { | |
| # Lance directement le launcher (PAS powershell.exe) | |
| Start-Process -FilePath $LauncherPath | |
| [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } | |
| Start-Sleep -Seconds 1 | |
| try { | |
| Invoke-WebRequest -Uri "http://127.0.0.1:4646/ffxivlauncher/$OTP" -UseBasicParsing | Out-Null | |
| } catch { } | |
| } else { | |
| [System.Windows.Forms.MessageBox]::Show("OTP invalide: '$OTP'", "XIVLauncher OTP", "OK", "Error") | Out-Null | |
| exit 1 | |
| } |