Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$scriptDir = Split-Path -Parent $PSCommandPath
$minerPath = Join-Path $scriptDir "BTCpu.exe"
$form = New-Object System.Windows.Forms.Form
$form.MaximizeBox = $false
$form.TopMost = $true
$form.Text = "X-Launcher (Free Version) - BTCpu CPU 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\cpu.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 = 5000
    $tooltip.InitialDelay = 500
    $tooltip.ReshowDelay = 500
    $tooltip.ForeColor = [System.Drawing.Color]::Black
    $tooltip.BackColor = [System.Drawing.Color]::white
    $tooltip.SetToolTip($button, $tooltipText)
}
$lblAlgo = New-Object System.Windows.Forms.Label
$lblAlgo.Text = "Algorithm:"
$lblAlgo.Location = New-Object System.Drawing.Point(10,7)
$lblAlgo.Size = New-Object System.Drawing.Size(60,20)
$form.Controls.Add($lblAlgo)
$cmbAlgo = New-Object System.Windows.Forms.ComboBox
$cmbAlgo.Location = New-Object System.Drawing.Point(70,5)
$cmbAlgo.Size = New-Object System.Drawing.Size(70,20)
$cmbAlgo.Items.Add("sha256d")
$cmbAlgo.Items.Add("scrypt")
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(140,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(200,5)
$txtPassword.Size = New-Object System.Drawing.Size(50,20)
Set-ButtonTooltip $txtPassword "(Optional) Usualy x or just leave blank. Some sites require extra setting here."
$form.Controls.Add($txtPassword)
$lblThreads = New-Object System.Windows.Forms.Label
$lblThreads.Text = "Threads 1-64:"
$lblThreads.Location = New-Object System.Drawing.Point(255,7)
$lblThreads.Size = New-Object System.Drawing.Size(75,15)
$form.Controls.Add($lblThreads)
$txtThreads = New-Object System.Windows.Forms.TextBox
$txtThreads.Location = New-Object System.Drawing.Point(330,5)
$txtThreads.Size = New-Object System.Drawing.Size(30,20)
Set-ButtonTooltip $txtThreads "The number of CPU threads to mine on (wise to leave a few open for system stability."
$form.Controls.Add($txtThreads)
$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,15)
$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(60,15)
$form.Controls.Add($lblWallet)
$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,15)
$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: --quiet --benchmark)"
$lblCLI.Location = New-Object System.Drawing.Point(120,100)
$lblCLI.Size = New-Object System.Drawing.Size(280,15)
$form.Controls.Add($lblCLI)
$lblCLI2 = New-Object System.Windows.Forms.Label
$lblCLI2.Text = "Refer to BTCpu help.txt for more mining CLI command options."
$lblCLI2.Location = New-Object System.Drawing.Point(95,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({
    $algo = $cmbAlgo.SelectedItem
    $threads = $txtThreads.Text.Trim()
    $poolUrl = $txtPoolURL.Text.Trim()
    $wallet = $txtWallet.Text.Trim()
    $password = $txtPassword.Text.Trim()
    $Options = $txtOptions.Text.Trim()
    $Coin = $txtCoin.Text.Trim()
    $lblStatus.Text = "BTCpu.exe --algo $algo --threads $threads --url $poolUrl --user $wallet --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\cpu.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 BTCpu 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 BTCpu 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({
    $wallet = $txtWallet.Text.Trim()
    $algo = $cmbAlgo.SelectedItem
    $poolUrl = $txtPoolURL.Text.Trim()
    $password = $txtPassword.Text.Trim()
    $Options = $txtOptions.Text.Trim()
    $threads = $txtThreads.Text.Trim()
    $Coin = $txtCoin.Text.Trim()
    if ([string]::IsNullOrWhiteSpace($wallet)) {
        [System.Windows.Forms.MessageBox]::Show("Opps... Please enter a wallet Address.Worker","Error")
        return
    }
    if (-not ($threads -as [int])) {
        [System.Windows.Forms.MessageBox]::Show("Ummmm... Threads must be a number.","Error")
        return
    }
    if ([int]$threads -lt 1 -or [int]$threads -gt 64) {
        [System.Windows.Forms.MessageBox]::Show("To many... Threads must be between 1 and 64.","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 .\BTCpu.exe -ArgumentList "--algo $algo --threads $threads --url $poolUrl --user $wallet --pass $password $Options" -Verb RunAs
    $lblStatus.Text = "BTCpu.exe --algo $algo --threads $threads --url $poolUrl --user $wallet --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 BTCpu.exe to Install or Update:"
$label.ForeColor = "Maroon"
$label.Size = New-Object System.Drawing.Size(250,15)
$label.Location = New-Object System.Drawing.Point(140,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 BTCpu.exe miner location (ex. C:\Downloads\Miner\BTCpu.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 BTCpu 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.", "BTCpu Miner Exists", [System.Windows.Forms.MessageBoxButtons]::OK)
        } else {
             Copy-Item -Path $sourceFilePath -Destination $destinationFilePath
            [System.Windows.Forms.MessageBox]::Show("BTCpu Miner Installed successfully!", "Success", [System.Windows.Forms.MessageBoxButtons]::OK)
        }
    } else {
        [System.Windows.Forms.MessageBox]::Show("Please select a valid BTCpu.exe 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 BTCpu miner is released, you can update the X-Launchers installed BTCpu 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

