Skip to content

Commit

Permalink
feat: Drop materials to install (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonjgardner authored Mar 5, 2024
1 parent e8603c7 commit 50f8c2b
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions v2/installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ if (-not (Test-Path $localizedDataPath)) {
}
}


Import-LocalizedData -BaseDirectory $localeDir -ErrorAction:SilentlyContinue -BindingVariable T -FileName $translationFilename
Clear-Host

$ioBit = Get-StartApps | Where-Object { $_.Name -eq "IObit Unlocker" }
$hasSideloaded = (Get-AppxPackage -Name "Microsoft.Minecraft*" | Where-Object { $_.InstallLocation -notlike "C:\Program Files\WindowsApps\*" }).Count -gt 0
Expand Down Expand Up @@ -419,7 +419,7 @@ function Expand-MinecraftPack() {
$StatusLabel.Visible = $false

# Check file type
if ($Pack -notlike "*.mcpack") {
if (($Pack -notlike "*.mcpack") -and ($Pack -notlike "*.rtpack")) {
$StatusLabel.Text = $T.error_invalid_file_type
$StatusLabel.ForeColor = 'Red'
$StatusLabel.Visible = $true
Expand All @@ -430,7 +430,7 @@ function Expand-MinecraftPack() {
$StatusLabel.ForeColor = 'Blue'
$StatusLabel.Visible = $true

$PackName = ($Pack -split "\\")[-1].Replace(".mcpack", "")
$PackName = ($Pack -split "\\")[-1].Replace(".mcpack", "").Replace(".rtpack", "")
$PackDirName = Join-Path -Path $BRTX_DIR -ChildPath "packs\$PackName"
$PackDir = New-Item -ItemType Directory -Path $PackDirName -Force
$Zip = Join-Path -Path $PackDir -ChildPath "$PackName.zip"
Expand Down Expand Up @@ -530,7 +530,6 @@ function DownloadPack() {
Write-Host "Failed to get API data for ID ${uuid}: $_"
}


foreach ($mc in $dataSrc) {
if ($ListBox.SelectedItems -notcontains $mc.FriendlyName) {
continue
Expand Down Expand Up @@ -600,7 +599,9 @@ $form.Add_DragEnter({
if (
$e.Data.GetDataPresent([Windows.Forms.DataFormats]::FileDrop) -and
$e.Data.GetData([Windows.Forms.DataFormats]::FileDrop).Count -eq 1 -and
$e.Data.GetData([Windows.Forms.DataFormats]::FileDrop)[0] -like "*.mcpack"
($e.Data.GetData([Windows.Forms.DataFormats]::FileDrop)[0] -like "*.mcpack" -or
$e.Data.GetData([Windows.Forms.DataFormats]::FileDrop)[0] -like "*.rtpack" -or
$e.Data.GetData([Windows.Forms.DataFormats]::FileDrop)[0] -like "*.material.bin")
) {
$e.Effect = [Windows.Forms.DragDropEffects]::Copy
}
Expand All @@ -611,8 +612,33 @@ $form.Add_DragEnter({
$form.Add_DragDrop({
param($sender, $e)

$StatusLabel.Visible = $false
$files = $e.Data.GetData([Windows.Forms.DataFormats]::FileDrop)
Expand-MinecraftPack -Pack $files[0]

if ($files.Count -eq 1 -and ($files[0] -like "*.mcpack" -or $files[0] -like "*.rtpack")) {
Expand-MinecraftPack -Pack $files[0]
}

if ($files.Count -ge 1 -and $files.Count -le 2 -and ($files[0] -like "*.material.bin")) {
foreach ($mc in $dataSrc) {
if ($ListBox.SelectedItems -notcontains $mc.FriendlyName) {
continue
}

$success = Copy-ShaderFiles -Location $mc.InstallLocation -Materials $files

if (-not $success) {
$StatusLabel.Text = $T.error_copy_failed
$StatusLabel.ForeColor = 'Red'
$StatusLabel.Visible = $true
return
}
}

$StatusLabel.Text = $T.success
$StatusLabel.ForeColor = 'Green'
$StatusLabel.Visible = $true
}
})

$flowPanel = New-Object System.Windows.Forms.FlowLayoutPanel
Expand Down Expand Up @@ -705,12 +731,12 @@ $InstallButton.Add_Click({
}
})

$flowPanel.Controls.Add($StatusLabel)
$flowPanel.Controls.Add($ListLabel)
$flowPanel.Controls.Add($ListBox)
$flowPanel.Controls.Add($PackListLabel)
$flowPanel.Controls.Add($PackSelectList)
$flowPanel.Controls.Add($InstallButton)
$flowPanel.Controls.Add($StatusLabel)
$form.Controls.Add($flowPanel)

# Add file menu to dialog
Expand Down

0 comments on commit 50f8c2b

Please sign in to comment.