Skip to content

Commit

Permalink
More fixes and updates
Browse files Browse the repository at this point in the history
• Commenting functions better and general code cleanup
• New logging improvements
• Checking for Git better and adding it to PATH if not present
  • Loading branch information
Mozoloa committed Dec 30, 2022
1 parent e0de82c commit 9b95232
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 144 deletions.
11 changes: 8 additions & 3 deletions Advanced Installer/A1111's Web UI Autoinstaller.aip
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<ROW Property="MSIFASTINSTALL" MultiBuildValue="DefaultBuild:3"/>
<ROW Property="Manufacturer" Value="Empire Media Science"/>
<ROW Property="MsiLogging" MultiBuildValue="DefaultBuild:vp"/>
<ROW Property="ProductCode" Value="2057:{426DD183-A2B8-46F2-9C7E-8DB350019B50} " Type="16"/>
<ROW Property="ProductCode" Value="2057:{085D014D-5267-4011-8375-490FEBDECB7F} " Type="16"/>
<ROW Property="ProductLanguage" Value="2057"/>
<ROW Property="ProductName" Value="A1111 Web UI Autoinstaller"/>
<ROW Property="ProductVersion" Value="1.5.2"/>
<ROW Property="ProductVersion" Value="1.5.3"/>
<ROW Property="REBOOT" MultiBuildValue="DefaultBuild:ReallySuppress"/>
<ROW Property="SecureCustomProperties" Value="OLDPRODUCTS;AI_NEWERPRODUCTFOUND;AI_SETUPEXEPATH;SETUPEXEDIR"/>
<ROW Property="UpgradeCode" Value="{ED3F2830-A9E0-46B4-9D7E-C242564349CB}"/>
Expand All @@ -51,16 +51,18 @@
<ROW Directory="Launcher_Dir" Directory_Parent="APPDIR" DefaultDir="Launcher"/>
<ROW Directory="TARGETDIR" DefaultDir="SourceDir"/>
<ROW Directory="regid.199509.com.example_Dir" Directory_Parent="CommonAppDataFolder" DefaultDir="REGID1~1.EXA|regid.1995-09.com.example"/>
<ROW Directory="tmp_Dir" Directory_Parent="Launcher_Dir" DefaultDir="tmp"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.MsiCompsComponent">
<ROW Component="AI_CustomARPName" ComponentId="{3C62274F-F0B5-4917-8FDA-14762431506E}" Directory_="APPDIR" Attributes="260" KeyPath="DisplayName" Options="1"/>
<ROW Component="AI_CustomARPName" ComponentId="{46E6E478-9501-4B15-8230-D925D83CEF4E}" Directory_="APPDIR" Attributes="260" KeyPath="DisplayName" Options="1"/>
<ROW Component="AI_DisableModify" ComponentId="{F2050EAB-4FE0-4037-BD04-5CC3D395CCD6}" Directory_="APPDIR" Attributes="260" KeyPath="NoModify" Options="1"/>
<ROW Component="AI_ExePath" ComponentId="{B811E420-F0BA-4852-9CFC-442518C5004C}" Directory_="APPDIR" Attributes="260" KeyPath="AI_ExePath"/>
<ROW Component="APPDIR" ComponentId="{8CF866A2-A911-49F3-990F-8C58E2C86E81}" Directory_="APPDIR" Attributes="0"/>
<ROW Component="InstallDlg" ComponentId="{43D6052F-DBBE-4963-A5D7-1DA28EDA7216}" Directory_="InstallDlg" Attributes="0"/>
<ROW Component="ProductInformation" ComponentId="{89B7657B-A9AC-47E0-934E-DFD5C27F709B}" Directory_="APPDIR" Attributes="260" KeyPath="Version"/>
<ROW Component="definitions.json" ComponentId="{6A0F435C-A63A-448F-9ED7-320D31F7F1E2}" Directory_="Launcher_Dir" Attributes="0" KeyPath="definitions.json" Type="0"/>
<ROW Component="regid.199509.com.example" ComponentId="{CED1F5AE-CD32-43C2-B701-4C359940B9A3}" Directory_="regid.199509.com.example_Dir" Attributes="0"/>
<ROW Component="stderr.txt" ComponentId="{62F03C49-8685-40A4-8D49-DD9F1CD5034D}" Directory_="tmp_Dir" Attributes="0" KeyPath="stderr.txt" Type="0"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.MsiFeatsComponent">
<ROW Feature="MainFeature" Title="MainFeature" Description="Description" Display="1" Level="1" Directory_="APPDIR" Attributes="0"/>
Expand All @@ -72,6 +74,8 @@
<ROW File="LauncherUI.ps1" Component_="definitions.json" FileName="LAUNCH~1.PS1|LauncherUI.ps1" Attributes="0" SourcePath="Launcher\LauncherUI.ps1" SelfReg="false"/>
<ROW File="logger.psm1" Component_="definitions.json" FileName="LOGGER~1.PSM|logger.psm1" Attributes="0" SourcePath="Launcher\logger.psm1" SelfReg="false"/>
<ROW File="shared.ps1" Component_="definitions.json" FileName="shared.ps1" Attributes="0" SourcePath="Launcher\shared.ps1" SelfReg="false"/>
<ROW File="stderr.txt" Component_="stderr.txt" FileName="stderr.txt" Attributes="0" SourcePath="Launcher\tmp\stderr.txt" SelfReg="false"/>
<ROW File="stdout.txt" Component_="stderr.txt" FileName="stdout.txt" Attributes="0" SourcePath="Launcher\tmp\stdout.txt" SelfReg="false"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.custcomp.AiComponentAliasComponent">
<ROW AliasRowId="InstallDlg" AliasRowOperation="1"/>
Expand Down Expand Up @@ -356,6 +360,7 @@
<ROW Feature_="MainFeature" Component_="InstallDlg"/>
<ROW Feature_="MainFeature" Component_="definitions.json"/>
<ROW Feature_="MainFeature" Component_="AI_ExePath"/>
<ROW Feature_="MainFeature" Component_="stderr.txt"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.MsiIconsComponent">
<ROW Name="logoAlpha.exe" SourcePath="Advanced Installer\Looks\Exports\logoAlpha.ico" Index="0"/>
Expand Down
177 changes: 40 additions & 137 deletions Launcher/Functions.psm1
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
. "$PSScriptRoot\shared.ps1"
Import-Module "$PSScriptRoot\logger.psm1" -Force -Global -Prefix "logger."

# General Utilities
#-----------------------------
#Startup fonctions
#-----------------------------
function Search-RegForPyPath {
$pyCore = Get-ItemProperty -path "hkcu:\Software\Python\PythonCore\3.10\InstallPath" -ErrorAction SilentlyContinue
if ($pyCore) {
Expand All @@ -28,26 +30,37 @@ function Install-py {
Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.10.6/python-3.10.6-amd64.exe" -OutFile "$tempFolder\python.exe"
logger.action "Download successful, installing"
."$tempFolder\python.exe" /quiet InstallAllUsers=0 PrependPath=1
logger.info "Done"
logger.success
return
}
}
function Install-git {
if (!(Test-Path "$env:ProgramFiles\Git")) {
if (!(Test-Path "$gitPath\bin\git.exe")) {
logger.action "Git not found, downloading, please be patient"
Invoke-WebRequest -Uri "https://github.com/git-for-windows/git/releases/download/v2.38.1.windows.1/Git-2.38.1-64-bit.exe" -OutFile "$tempFolder\git.exe"
logger.action "Download successful, installing"
."$tempFolder\git.exe" /VERYSILENT /NORESTART
logger.info "Done"
logger.success
}
else {
logger.info "Git found at $("$env:ProgramFiles\Git")"
}
if (!(Get-Command git -ErrorAction SilentlyContinue)) {
logger.action "Git not found in PATH, adding it"
$env:Path += ";$gitPath\bin"
logger.success
return
}
logger.info "Git found at $("$env:ProgramFiles\Git")"
else {
logger.info "Git is in PATH"
}

}
function Install-WebUI {
if (!(Test-Path $webuiPath)) {
logger.action "Automatic1111 SD WebUI was not found, cloning git"
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui $webuiPath
logger.info "Done"
logger.success
return
}
logger.info "Automatic1111 SD WebUI found at $webuiPath"
Expand All @@ -60,7 +73,7 @@ function Import-BaseModel {
logger.action "Downloading Base Model, this can take a while"
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile("https://anga.tv/ems/model.ckpt", "$modelsPath\SD15NewVAEpruned.ckpt")
logger.info "Done"
logger.success
}
}
}
Expand Down Expand Up @@ -106,6 +119,9 @@ function Get-WebUICommitHash {
$hash = Get-Content $hashPath
if ($hash) { return $hash }
}
#-----------------------------
#Settings related functions
#-----------------------------
function Write-Settings($settings) {
logger.action "Updating Settings File"
$settings | ConvertTo-Json -Depth 100 | Out-File $settingsPath
Expand Down Expand Up @@ -204,7 +220,6 @@ function Convert-SettingsToArguments ($settings) {
}
return $string
}

function Convert-BatToGitOptions ($batFile) {
$GitOptions = @(
@{
Expand All @@ -230,26 +245,16 @@ function Convert-BatToGitOptions ($batFile) {
return $GitOptions
}

function Format-Config($config) {
$config2 = @()
foreach ($param in $config) {
$object = @{
arg = $param.arg
value = $param.value
}
$config2 += $object
}
return $config2
}

#-----------------------------
#UI related functions
#-----------------------------
function Select-Folder ([string]$InitialDirectory) {
$app = New-Object -ComObject Shell.Application
$folder = $app.BrowseForFolder(0, "Please select a folder", 0, "")

if ($folder) { return $folder.Self.Path } else { return '' }
}

function Select-File([string]$InitialDirectory) {
function Select-File([string]$InitialDirectory) {
$dialog = New-Object System.Windows.Forms.OpenFileDialog
$dialog.InitialDirectory = $webuiPath
$dialog.Title = "Please Select a File"
Expand All @@ -259,28 +264,17 @@ function Select-File([string]$InitialDirectory) {
return $dialog.FileName
}

function Clear-Outputs {
$Exprompt = [system.windows.messagebox]::Show("All previously generated images will be deleted, are you sure ?`n`nClick 'No' to not delete any image this time`n`nUncheck 'Clear Generated Images' in the launcher to disable it", 'Warning', 'YesNo', 'Warning')
if ($Exprompt -eq "Yes") {
logger.action "Clearing all outputs in default output directories"
if ($outputsPath) {
Get-ChildItem $outputsPath -Force -Recurse -File -Filter *.png | Remove-Item -Force
Get-ChildItem $outputsPath -Force -Recurse -File -Filter *.jpg | Remove-Item -Force
}
logger.info "Done"
}
}

#Updates
#-----------------------------
#General Settings functions
#-----------------------------
function Update-WebUI ($enabled) {
if ($enabled) {
logger.action "Updating Webui"
Set-Location $webuiPath
git pull origin
logger.info "Done"
logger.success
}
}

function Update-Extensions ($enabled) {
if ($enabled) {
Set-Location $extPath
Expand All @@ -291,111 +285,20 @@ function Update-Extensions ($enabled) {
Set-Location $ext.Fullname
git pull origin
}
logger.info "Done"
logger.success
return
}
logger.info "No extension found in the extensions folder"
}
}

#Clean JSon function
function Format-Json {
<#
.SYNOPSIS
Prettifies JSON output.
.DESCRIPTION
Reformats a JSON string so the output looks better than what ConvertTo-Json outputs.
.PARAMETER Json
Required: [string] The JSON text to prettify.
.PARAMETER Minify
Optional: Returns the json string compressed.
.PARAMETER Indentation
Optional: The number of spaces (1..1024) to use for indentation. Defaults to 4.
.PARAMETER AsArray
Optional: If set, the output will be in the form of a string array, otherwise a single string is output.
.EXAMPLE
$json | ConvertTo-Json | Format-Json -Indentation 2
#>
[CmdletBinding(DefaultParameterSetName = 'Prettify')]
Param(
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
[string]$Json,

[Parameter(ParameterSetName = 'Minify')]
[switch]$Minify,

[Parameter(ParameterSetName = 'Prettify')]
[ValidateRange(1, 1024)]
[int]$Indentation = 4,

[Parameter(ParameterSetName = 'Prettify')]
[switch]$AsArray
)

if ($PSCmdlet.ParameterSetName -eq 'Minify') {
return ($Json | ConvertFrom-Json) | ConvertTo-Json -Depth 100 -Compress
}

# If the input JSON text has been created with ConvertTo-Json -Compress
# then we first need to reconvert it without compression
if ($Json -notmatch '\r?\n') {
$Json = ($Json | ConvertFrom-Json) | ConvertTo-Json -Depth 100
}

$indent = 0
$regexUnlessQuoted = '(?=([^"]*"[^"]*")*[^"]*$)'

$result = $Json -split '\r?\n' |
ForEach-Object {
# If the line contains a ] or } character,
# we need to decrement the indentation level unless it is inside quotes.
if ($_ -match "[}\]]$regexUnlessQuoted") {
$indent = [Math]::Max($indent - $Indentation, 0)
}

# Replace all colon-space combinations by ": " unless it is inside quotes.
$line = (' ' * $indent) + ($_.TrimStart() -replace ":\s+$regexUnlessQuoted", ': ')

# If the line contains a [ or { character,
# we need to increment the indentation level unless it is inside quotes.
if ($_ -match "[\{\[]$regexUnlessQuoted") {
$indent += $Indentation
}

$line
}

if ($AsArray) { return $result }
return $result -Join [Environment]::NewLine
}
#Converts Object to hashtable
function Convert-PSObjectToHashtable {
param (
[Parameter(ValueFromPipeline)]
$InputObject
)

process {
if ($null -eq $InputObject) { return $null }

if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string]) {
$collection = @(
foreach ($object in $InputObject) { Convert-PSObjectToHashtable $object }
)

Write-Output -NoEnumerate $collection
}
elseif ($InputObject -is [psobject]) {
$hash = @{}

foreach ($property in $InputObject.PSObject.Properties) {
$hash[$property.Name] = Convert-PSObjectToHashtable $property.Value
}

$hash
}
else {
$InputObject
function Clear-Outputs {
$Exprompt = [system.windows.messagebox]::Show("All previously generated images will be deleted, are you sure ?`n`nClick 'No' to not delete any image this time`n`nUncheck 'Clear Generated Images' in the launcher to disable it", 'Warning', 'YesNo', 'Warning')
if ($Exprompt -eq "Yes") {
logger.action "Clearing all outputs in default output directories"
if ($outputsPath) {
Get-ChildItem $outputsPath -Force -Recurse -File -Filter *.png | Remove-Item -Force
Get-ChildItem $outputsPath -Force -Recurse -File -Filter *.jpg | Remove-Item -Force
}
logger.success
}
}
9 changes: 6 additions & 3 deletions Launcher/LauncherUI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function Invoke-WebUI {
# Parsing args from settings
$arguments = Convert-SettingsToArguments $settings

logger.pop "WEBUI LAUNCHING VIA EMS LAUNCHER, EXIT THIS WINDOW TO STOP THE WEBUI"
logger.warn "If you see the line 'commit hash : XXXX' or 'Installing Torch...' bellow, any error happening afterwards is not related to the launcher, but the WebUI itself which EMS is not affiliated with, we won't be able to help you fix those, you'll have to ask them on Automatic1111's github, not ours."
logger.space

Set-Location $webuiPath

$env:PYTHON = "`"$pyPath`""
Expand All @@ -67,9 +71,6 @@ function Invoke-WebUI {
Start-Process "$webuiPath/webui.bat" -NoNewWindow
Set-Location $PSScriptRoot
$form.Close()
logger.pop "WEBUI LAUNCHING VIA EMS LAUNCHER, EXIT THIS WINDOW TO STOP THE WEBUI"
logger.warn "If you see the line 'commit hash : XXXX' or 'Installing Torch...' bellow, any error happening afterwards is not related to the launcher, but the WebUI itself which EMS is not affiliated with, we won't be able to help you fix those, you'll have to ask them on Automatic1111's github, not ours."
logger.space
}

Function Reset-Path($param) {
Expand Down Expand Up @@ -390,5 +391,7 @@ function Makeform {

$Form.ShowDialog()
}
logger.space
logger.action "Opening A1111 WebUI Launcher"
logger.space
MakeForm
10 changes: 9 additions & 1 deletion Launcher/logger.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@ function pop ($object) {
space
}
function space {
Write-Host "------------------------------`n------------------------------`n------------------------------" -ForegroundColor "Cyan"
for ($i = 1; $i -le 60; $i++) {
# Print the character "X"
Write-Host -NoNewline ([char]126) -ForegroundColor "DarkGray"
}
Write-Host ""
}
function success {
Write-Host "[Success]" -ForegroundColor "Cyan"
space
}

0 comments on commit 9b95232

Please sign in to comment.