Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$scriptDir = Split-Path -Parent $PSCommandPath
$minerPath = Join-Path $scriptDir "t-rex.exe"
$form = New-Object System.Windows.Forms.Form
$form.MaximizeBox = $false
$form.TopMost = $true
$form.Text = "X-Launcher (Free Version) - T-Rex GPU Miner"
$form.Size = New-Object System.Drawing.Size(495,560)
$form.StartPosition = "CenterScreen"
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.BackColor = [System.Drawing.Color]::white
$imagePath = "$PSScriptRoot\rex.png" 
$image = [System.Drawing.Image]::FromFile($imagePath)
$form.BackgroundImage = $image
$form.BackgroundImageLayout = "Center"
$color_text = [System.Drawing.Color]::Black
$form.ForeColor = $color_text
function Set-ButtonTooltip($button, $tooltipText) {
    $tooltip = New-Object System.Windows.Forms.ToolTip
    $tooltip.AutoPopDelay = 2500
    $tooltip.InitialDelay = 500
    $tooltip.ReshowDelay = 500
    $tooltip.ForeColor = [System.Drawing.Color]::Black
    $tooltip.BackColor = [System.Drawing.Color]::white
    $tooltip.SetToolTip($button, $tooltipText)
}
$lblWorker = New-Object System.Windows.Forms.Label
$lblWorker.Text = "Worker:"
$lblWorker.Location = New-Object System.Drawing.Point(10,7)
$lblWorker.Size = New-Object System.Drawing.Size(60,15)
$form.Controls.Add($lblWorker)
$txtWorker = New-Object System.Windows.Forms.TextBox
$txtWorker.Location = New-Object System.Drawing.Point(70,5)
$txtWorker.Size = New-Object System.Drawing.Size(50,20)
$form.Controls.Add($txtWorker)
$lblAlgo = New-Object System.Windows.Forms.Label
$lblAlgo.Text = "Algo:"
$lblAlgo.Location = New-Object System.Drawing.Point(125,7)
$lblAlgo.Size = New-Object System.Drawing.Size(30,20)
$form.Controls.Add($lblAlgo)
$cmbAlgo = New-Object System.Windows.Forms.ComboBox
$cmbAlgo.Location = New-Object System.Drawing.Point(155,5)
$cmbAlgo.Size = New-Object System.Drawing.Size(75,20)
$cmbAlgo.Items.Add("autolykos2")
$cmbAlgo.Items.Add("blake3")
$cmbAlgo.Items.Add("etchash")
$cmbAlgo.Items.Add("ethash")
$cmbAlgo.Items.Add("firopow")
$cmbAlgo.Items.Add("kawpow")
$cmbAlgo.Items.Add("mtp")
$cmbAlgo.Items.Add("mtp-tcr")
$cmbAlgo.Items.Add("multi")
$cmbAlgo.Items.Add("octopus")
$cmbAlgo.Items.Add("progpow")
$cmbAlgo.Items.Add("progpow")
$cmbAlgo.Items.Add("veil")
$cmbAlgo.Items.Add("progpowz")
$cmbAlgo.Items.Add("tensority")
Set-ButtonTooltip $cmbAlgo "Select an Algorithm to mine."
$form.Controls.Add($cmbAlgo)
$lblPassword = New-Object System.Windows.Forms.Label
$lblPassword.Text = "Password:"
$lblPassword.Location = New-Object System.Drawing.Point(235,7)
$lblPassword.Size = New-Object System.Drawing.Size(60,20)
$form.Controls.Add($lblPassword)
$txtPassword = New-Object System.Windows.Forms.TextBox
$txtPassword.UseSystemPasswordChar = $false
$txtPassword.Location = New-Object System.Drawing.Point(295,5)
$txtPassword.Size = New-Object System.Drawing.Size(65,20)
Set-ButtonTooltip $txtPassword "(Optional) Usualy x or just leave blank. Some sites require extra setting here."
$form.Controls.Add($txtPassword)
$lblCn = New-Object System.Windows.Forms.Label
$lblCn.Text = "Coin:"
$lblCn.Location = New-Object System.Drawing.Point(365,7)
$lblCn.Size = New-Object System.Drawing.Size(35,20)
$form.Controls.Add($lblCn)
$txtCoin = New-Object System.Windows.Forms.TextBox
$txtCoin.Location = New-Object System.Drawing.Point(400,5)
$txtCoin.Size = New-Object System.Drawing.Size(70,20)
Set-ButtonTooltip $txtCoin "Here you can enter the coin you are mining. Used for reference when reviewing CLI Database."
$form.Controls.Add($txtCoin)
$lblWallet = New-Object System.Windows.Forms.Label
$lblWallet.Text = "Address:"
$lblWallet.Location = New-Object System.Drawing.Point(10,32)
$lblWallet.Size = New-Object System.Drawing.Size(50,15)
$form.Controls.Add($lblWallet)
Set-ButtonTooltip $lblWallet "This is you wallet address."
$txtWallet = New-Object System.Windows.Forms.TextBox
$txtWallet.Location = New-Object System.Drawing.Point(70,30)
$txtWallet.Size = New-Object System.Drawing.Size(400,20)
Set-ButtonTooltip $txtWallet "This is you wallet address."
$form.Controls.Add($txtWallet)
$lblPoolURL = New-Object System.Windows.Forms.Label
$lblPoolURL.Text = "Pool URL:"
$lblPoolURL.Location = New-Object System.Drawing.Point(10,57)
$lblPoolURL.Size = New-Object System.Drawing.Size(60,20)
$form.Controls.Add($lblPoolURL)
$txtPoolURL = New-Object System.Windows.Forms.TextBox
$txtPoolURL.Location = New-Object System.Drawing.Point(70,55)
$txtPoolURL.Size = New-Object System.Drawing.Size(400,20)
Set-ButtonTooltip $txtPoolURL "This is where you would enter your mining pool address."
$form.Controls.Add($txtPoolURL)
$lblOptions = New-Object System.Windows.Forms.Label
$lblOptions.Text = "Options:"
$lblOptions.Location = New-Object System.Drawing.Point(10,82)
$lblOptions.Size = New-Object System.Drawing.Size(55,15)
$form.Controls.Add($lblOptions)
$txtOptions = New-Object System.Windows.Forms.TextBox
$txtOptions.UseSystemPasswordChar = $false
$txtOptions.Location = New-Object System.Drawing.Point(70,80)
$txtOptions.Size = New-Object System.Drawing.Size(400,20)
Set-ButtonTooltip $txtOptions "Enter as many CLI options as you wish for fine tuning your rig."
$form.Controls.Add($txtOptions)
$lblCLI = New-Object System.Windows.Forms.Label
$lblCLI.Text = "(Optional CLI commands eg: --coin etc --fan 10,20 --devices 0,1,2)"
$lblCLI.Location = New-Object System.Drawing.Point(100,100)
$lblCLI.Size = New-Object System.Drawing.Size(350,15)
$form.Controls.Add($lblCLI)
$lblCLI2 = New-Object System.Windows.Forms.Label
$lblCLI2.Text = "Refer to T-Rex help.txt for more mining CLI command options."
$lblCLI2.Location = New-Object System.Drawing.Point(120,115)
$lblCLI2.Size = New-Object System.Drawing.Size(320,15)
$form.Controls.Add($lblCLI2)
$lblCLI3 = New-Object System.Windows.Forms.Label
$lblCLI3.Text = "-------------------------------------------------------------------------------------------------------------------------"
$lblCLI3.Location = New-Object System.Drawing.Point(10,125)
$lblCLI3.Size = New-Object System.Drawing.Size(460,10)
$form.Controls.Add($lblCLI3)
$btndisbut = New-Object System.Windows.Forms.Button
$btndisbut.Text = "Display"
$btndisbut.Location = New-Object System.Drawing.Point(140,150)
$btndisbut.Size = New-Object System.Drawing.Size(60,25)
$btndisbut.BackColor = [System.Drawing.Color]::Silver
$btndisbut.ForeColor = [System.Drawing.Color]::black
$btndisbut.Font = New-Object System.Drawing.Font("Arial", 9, [System.Drawing.FontStyle]::Bold)
$form.Controls.Add($btndisbut)
$btndisbut.Add_Click({
    $wallet = $txtWallet.Text.Trim()
    $algo = $cmbAlgo.SelectedItem
    $poolUrl = $txtPoolURL.Text.Trim()
    $worker = $txtWorker.Text.Trim()
    $password = $txtPassword.Text.Trim()
    $Options = $txtOptions.Text.Trim()
    $Coin = $txtCoin.Text.Trim()
    $lblStatus.Text = "t-rex.exe --algo $algo --url $poolUrl --user $wallet --worker $worker --pass $password $Options"
})
$pictureBox = New-Object System.Windows.Forms.PictureBox
$pictureBox.Location = New-Object System.Drawing.Point(210, 135)
$pictureBox.Size = New-Object System.Drawing.Size(60, 50)
$pictureBox.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::StretchImage
$pictureBox.ImageLocation = "$PSScriptRoot\rex.gif"
$form.Controls.Add($pictureBox)
$btnLaunch = New-Object System.Windows.Forms.Button
$btnLaunch.Text = "Launch"
$btnLaunch.Location = New-Object System.Drawing.Point(280,150)
$btnLaunch.Size = New-Object System.Drawing.Size(60,25)
$btnLaunch.BackColor = [System.Drawing.Color]::Silver
$btnLaunch.ForeColor = [System.Drawing.Color]::Maroon
$btnLaunch.Font = New-Object System.Drawing.Font("Arial", 9, [System.Drawing.FontStyle]::Bold)
$form.Controls.Add($btnLaunch)
$lblCLICOM = New-Object System.Windows.Forms.Label
$lblCLICOM.Text = "Loaded T-Rex CLI command"
$lblCLICOM.Location = New-Object System.Drawing.Point(160,190)
$lblCLICOM.Size = New-Object System.Drawing.Size(160,15)
$form.Controls.Add($lblCLICOM)
$lblStatus = New-Object System.Windows.Forms.Label
$lblStatus.Text = ""
$lblStatus.Location = New-Object System.Drawing.Point(5,205)
$lblStatus.Size = New-Object System.Drawing.Size(470,90)
$lblStatus.Font = New-Object System.Drawing.Font("Arial", 10, [System.Drawing.FontStyle]::Bold)
$lblStatus.TextAlign = "MiddleCenter"
$lblStatus.ForeColor = [System.Drawing.Color]::Black
Set-ButtonTooltip $lblStatus "Here is where the CLI output is displayed when the BTCpu miner is launched."
$form.Controls.Add($lblStatus)
$lblCLIline2 = New-Object System.Windows.Forms.Label
$lblCLIline2.Text = "-----------------------------------------------------------------------------------------------------------------------------"
$lblCLIline2.Location = New-Object System.Drawing.Point(5,290)
$lblCLIline2.Size = New-Object System.Drawing.Size(470,10)
$form.Controls.Add($lblCLIline2)
$rtb = New-Object System.Windows.Forms.RichTextBox
$rtb.Location = New-Object System.Drawing.Point(10,325)
$rtb.Size = New-Object System.Drawing.Size(460,130)
$rtb.ReadOnly = $true
$rtb.WordWrap = $false
$form.Controls.Add($rtb)
    $text = Get-Content -Path '.\Tutorial.txt' -Raw 
    $rtb.Text = $text
$button = New-Object System.Windows.Forms.Button
$button.Text = "Save .bat"
$button.BackColor = [System.Drawing.Color]::Silver
$button.ForeColor = [System.Drawing.Color]::Gray
$button.Location = New-Object System.Drawing.Point(10,300)
$button.Size = New-Object System.Drawing.Size(65,20)
Set-ButtonTooltip $button "Save the loaded CLI output to a .bat file. (Available in the Paid Version)"
$form.Controls.Add($button)
$tuthelp = New-Object System.Windows.Forms.Button
$tuthelp.Text = "Tutorial"
$tuthelp.BackColor = [System.Drawing.Color]::Silver
$tuthelp.Location = New-Object System.Drawing.Point(80,300)
$tuthelp.Size = New-Object System.Drawing.Size(65,20)
Set-ButtonTooltip $tuthelp "This is information on how to setup and run the X-Launcher."
$tuthelp.Add_Click({ { $rtb.Visible = $true } })
function Load-ButtonTextFile($fileName) {
    $text = Get-Content -Path $fileName -Raw
    $rtb.Text = $text
}
$tuthelp.Add_Click({ Load-ButtonTextFile ".\Tutorial.txt" })
$form.Controls.Add($tuthelp)
$clihelp = New-Object System.Windows.Forms.Button
$clihelp.Text = "CLI Help"
$clihelp.BackColor = [System.Drawing.Color]::Silver
$clihelp.Location = New-Object System.Drawing.Point(150,300)
$clihelp.Size = New-Object System.Drawing.Size(65,20)
Set-ButtonTooltip $clihelp "This is all the CLI options for the T-Rex miner."
$clihelp.Add_Click({ { $rtb.Visible = $true } })
function Load-ButtonTextFile($fileName) {
    $text = Get-Content -Path $fileName -Raw
    $rtb.Text = $text
}
$clihelp.Add_Click({ Load-ButtonTextFile ".\Help.txt" })
$form.Controls.Add($clihelp)
$lblVersion = New-Object System.Windows.Forms.Label
$lblVersion.Text = "v1.10"
$lblVersion.Location = New-Object System.Drawing.Point(220,300)
$lblVersion.Size = New-Object System.Drawing.Size(40,20)
$lblVersion.Font = New-Object System.Drawing.Font("Georgia", 10)
$lblVersion.ForeColor = "Maroon"
$form.Controls.Add($lblVersion)
$btnCLIdb = New-Object System.Windows.Forms.Button
$btnCLIdb.Text = "CLI DB"
$btnCLIdb.BackColor = [System.Drawing.Color]::Silver
$btnCLIdb.ForeColor = [System.Drawing.Color]::Gray
$btnCLIdb.Location = New-Object System.Drawing.Point(260,300)
$btnCLIdb.Size = New-Object System.Drawing.Size(65,20)
Set-ButtonTooltip $btnCLIdb "This is a database of all saved CLI command lines. (Available in the Paid Version)"
$form.Controls.Add($btnCLIdb)
$btnSaveCLI = New-Object System.Windows.Forms.Button
$btnSaveCLI.Text = "Save CLI"
$btnSaveCLI.BackColor = [System.Drawing.Color]::Silver
$btnSaveCLI.ForeColor = [System.Drawing.Color]::Gray
$btnSaveCLI.Location = New-Object System.Drawing.Point(330,300)
$btnSaveCLI.Size = New-Object System.Drawing.Size(65,20)
Set-ButtonTooltip $btnSaveCLI "You can save your generated CLI to a database. (Available in the Paid Version)"
$form.Controls.Add($btnSaveCLI)
$btnWarning = New-Object System.Windows.Forms.Button
$btnWarning.Text = "WARNING"
$btnWarning.BackColor = [System.Drawing.Color]::Silver
$btnWarning.ForeColor = [System.Drawing.Color]::Maroon
$btnWarning.Location = New-Object System.Drawing.Point(400,300)
$btnWarning.Size = New-Object System.Drawing.Size(70,20)
Set-ButtonTooltip $btnWarning "This is a Warning from the creator of this interface."
$btnWarning.Add_Click({
    if ($lblStatus.Text -ne "") {
        $message = ""
        $lblStatus.Text = $message 
    } else {
        $message = "If this software is from someone other than Digital-X-Mines        CRYPTO IS NOT SECURE"
        $lblStatus.Text = $message
    }
})
$form.Controls.Add($btnWarning)
$btnLaunch.Add_Click({
    $algo = $cmbAlgo.SelectedItem
    $poolUrl = $txtPoolURL.Text.Trim()
    $wallet = $txtWallet.Text.Trim()
    $worker = $txtWorker.Text.Trim()
    $password = $txtPassword.Text.Trim()
    $Options = $txtOptions.Text.Trim()
    $Coin = $txtCoin.Text.Trim()    
    if ([string]::IsNullOrWhiteSpace($wallet)) {
        [System.Windows.Forms.MessageBox]::Show("Opps... Please enter a wallet Address","Error")
        return
    }
    if ($algo -eq "") {
        [System.Windows.Forms.MessageBox]::Show("Opps... Please select an algorithm.","Error")
        return
    }
    if ([string]::IsNullOrWhiteSpace($poolUrl)) {
        [System.Windows.Forms.MessageBox]::Show("Opps... Please enter a pool URL.","Error")
        return
    }
    Start-Process -FilePath .\t-rex.exe -ArgumentList "--algo $algo --url $poolUrl --user $wallet --worker $worker --pass $password $Options" -Verb RunAs
    $lblStatus.Text = "t-rex.exe --algo $algo --url $poolUrl --user $wallet --worker $worker --pass $password $Options"
})
$btnwebaddress1 = New-Object System.Windows.Forms.Button
$btnwebaddress1.Text = "D.X.M"
$btnwebaddress1.BackColor = [System.Drawing.Color]::Silver
$btnwebaddress1.Location = New-Object System.Drawing.Point(10,500)
$btnwebaddress1.Size = New-Object System.Drawing.Size(55,15)
$btnwebaddress1.Font = New-Object System.Drawing.Font("Arial", 6)
Set-ButtonTooltip $btnwebaddress1 "Digital-X-Mines Homepage."
$form.Controls.Add($btnwebaddress1)
$btnwebaddress1.Add_Click({
    Start-Process "https://www.digitalxmines.com"
})
$btnwebaddress2 = New-Object System.Windows.Forms.Button
$btnwebaddress2.Text = "YouTube"
$btnwebaddress2.BackColor = [System.Drawing.Color]::Silver
$btnwebaddress2.Location = New-Object System.Drawing.Point(70,500)
$btnwebaddress2.Size = New-Object System.Drawing.Size(55,15)
$btnwebaddress2.Font = New-Object System.Drawing.Font("Arial", 6)
Set-ButtonTooltip $btnwebaddress2 "Digital-X-Mines on YouTube."
$form.Controls.Add($btnwebaddress2)
$btnwebaddress2.Add_Click({
    Start-Process "https://www.youtube.com/@digitalxmines3109"
})
$label = New-Object System.Windows.Forms.Label
$label.Text = "Browse t-rex.exe to Install or Update:"
$label.ForeColor = "Maroon"
$label.Size = New-Object System.Drawing.Size(250,15)
$label.Location = New-Object System.Drawing.Point(145,460)
$form.Controls.Add($label)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(135,475)
$textBox.Size = New-Object System.Drawing.Size(210, 15)
$form.Controls.Add($textBox)
$buttonBrowse = New-Object System.Windows.Forms.Button
$buttonBrowse.Text = "Browse"
$buttonBrowse.BackColor = [System.Drawing.Color]::Silver
$buttonBrowse.Size = New-Object System.Drawing.Size(65,20)
$buttonBrowse.Location = New-Object System.Drawing.Point(137,495)
Set-ButtonTooltip $buttonBrowse "Browse to T-Rex.exe location (ex. C:\Downloads\T-Rex\t-rex.exe) you wish to install or update."
$form.Controls.Add($buttonBrowse)
$buttonCopy = New-Object System.Windows.Forms.Button
$buttonCopy.Text = "Install"
$buttonCopy.BackColor = [System.Drawing.Color]::Silver
$buttonCopy.Size = New-Object System.Drawing.Size(65,20)
$buttonCopy.Location = New-Object System.Drawing.Point(207,495)
Set-ButtonTooltip $buttonCopy "Installs the selected T-Rex miner to the X-Launcher interface (only needs to be installed once)."
$form.Controls.Add($buttonCopy)
$destinationDirectory = ".\"
$buttonBrowse.Add_Click({
    $openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $openFileDialog.Filter = "All Files (*.*)|*.*"
    if ($openFileDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
        $textBox.Text = $openFileDialog.FileName
    }
})
$buttonCopy.Add_Click({
    $sourceFilePath = $textBox.Text
    if (-Not [string]::IsNullOrWhiteSpace($sourceFilePath) -and (Test-Path $sourceFilePath)) {
        $destinationFilePath = Join-Path -Path $destinationDirectory -ChildPath (Split-Path -Leaf $sourceFilePath)
        if (Test-Path $destinationFilePath) {
            [System.Windows.Forms.MessageBox]::Show("The file already exists in the destination.", "File Exists", [System.Windows.Forms.MessageBoxButtons]::OK)
        } else {
            Copy-Item -Path $sourceFilePath -Destination $destinationFilePath
            [System.Windows.Forms.MessageBox]::Show("File copied successfully!", "Success", [System.Windows.Forms.MessageBoxButtons]::OK)
        }
    } else {
        [System.Windows.Forms.MessageBox]::Show("Please select a valid source file.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK)
    }
})
$buttonUpdate = New-Object System.Windows.Forms.Button
$buttonUpdate.Text = "Update"
$buttonUpdate.BackColor = [System.Drawing.Color]::Silver
$buttonUpdate.ForeColor = [System.Drawing.Color]::Gray
$buttonUpdate.Size = New-Object System.Drawing.Size(65,20)
$buttonUpdate.Location = New-Object System.Drawing.Point(277, 495)
Set-ButtonTooltip $buttonUpdate "If a newer version of the T-Rex miner is released, you can update the X-Launchers installed T-Rex miner. (Available in the Paid Version)"
$form.Controls.Add($buttonUpdate)
$btnwebaddress3 = New-Object System.Windows.Forms.Button
$btnwebaddress3.Text = "M.P.S"
$btnwebaddress3.BackColor = [System.Drawing.Color]::Silver
$btnwebaddress3.Location = New-Object System.Drawing.Point(355,500)
$btnwebaddress3.Size = New-Object System.Drawing.Size(55,15)
$btnwebaddress3.Font = New-Object System.Drawing.Font("Arial", 6)
Set-ButtonTooltip $btnwebaddress3 "www.miningpoolstats.com"
$form.Controls.Add($btnwebaddress3)
$btnwebaddress3.Add_Click({
    Start-Process "https://miningpoolstats.stream"
})
$btnwebaddress4 = New-Object System.Windows.Forms.Button
$btnwebaddress4.Text = "W.T.M"
$btnwebaddress4.BackColor = [System.Drawing.Color]::Silver
$btnwebaddress4.Location = New-Object System.Drawing.Point(415,500)
$btnwebaddress4.Size = New-Object System.Drawing.Size(55,15)
$btnwebaddress4.Font = New-Object System.Drawing.Font("Arial", 6)
Set-ButtonTooltip $btnwebaddress4 "www.whattomine.com."
$form.Controls.Add($btnwebaddress4)
$btnwebaddress4.Add_Click({
    Start-Process "https://whattomine.com"
})
$controls = $form.Controls
foreach ($control in $controls) {
 if ($control -is [System.Windows.Forms.Label]) {
         $control.BackColor = [System.Drawing.Color]::Transparent
   }
}
$form.ShowDialog() | Out-Null

