Created
January 30, 2014 05:05
-
-
Save anonymous/8702928 to your computer and use it in GitHub Desktop.
Dogecoin Update Script (Powershell)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Updates user's Dogecoin wallet | |
.DESCRIPTION | |
This script will prompt the user to select a Dogecoin wallet | |
from the Dogecoin GitHub page. Once selected, the wallet will | |
be downloaded and created in 'C:\Doge\CurrentWallet'. The | |
following folders will be created if they don't already exist: | |
C:\Doge\ | |
C:\Doge\CurrentWallet\ | |
C:\Doge\WalletDatBackups\ | |
C:\Doge\OtherWallets\WalletZips\ | |
C:\Doge\OtherWallets\OldWallets\ | |
This script will also backup the user's wallet.dat file, and | |
create a shortcut to the application on the user's desktop. | |
.NOTES | |
File Name : DogecoinUpdate.ps1 | |
Author : Eric Gross - doge@pop-pirate.biz | |
Requires : PowerShell V2 | |
.LINK | |
#> | |
function Create-VersionSelectBox { | |
param( | |
[array]$DropDownArray | |
) | |
Add-Type -AssemblyName System.Windows.Forms | |
Add-Type -AssemblyName System.Drawing | |
$Form = New-Object System.Windows.Forms.Form | |
$Form.width = 350 | |
$Form.height = 125 | |
$Form.Text = ”Dogecoin Wallet Update” | |
$Form.StartPosition = "CenterScreen" | |
$DropDownFrom = New-Object System.Windows.Forms.ComboBox | |
$DropDownFrom.Location = New-Object System.Drawing.Size(185,10) | |
$DropDownFrom.Size = New-Object System.Drawing.Size(130,30) | |
$DropDownArray | ForEach-Object { $DropDownFrom.Items.Add($_) | Out-Null } | |
$Form.Controls.Add($DropDownFrom) | |
$DropDownFromLabel = New-Object System.Windows.Forms.Label | |
$DropDownFromLabel.Location = New-Object System.Drawing.Size(10,10) | |
$DropDownFromLabel.Size = New-Object System.Drawing.Size(300,40) | |
$DropDownFromLabel.Text = "Select Dogecoin wallet version" | |
$Form.Controls.Add($DropDownFromLabel) | |
$OKButton = new-object System.Windows.Forms.Button | |
$OKButton.Location = new-object System.Drawing.Size(25,60) | |
$OKButton.Size = new-object System.Drawing.Size(100,20) | |
$OKButton.Text = "OK" | |
$OKButton.Add_Click({ | |
$Form.DialogResult = "OK" | |
$Form.close() | |
}) | |
$form.Controls.Add($OKButton) | |
$CancelButton = New-Object System.Windows.Forms.Button | |
$CancelButton.Location = New-Object System.Drawing.Size(200,60) | |
$CancelButton.Size = New-Object System.Drawing.Size(100,20) | |
$CancelButton.Text = "Cancel" | |
$CancelButton.Add_Click({ | |
$Form.DialogResult = "Cancel" | |
$Form.close() | |
}) | |
$Form.Controls.Add($CancelButton) | |
$Form.Add_Shown({$Form.Activate()}) | |
$result = $Form.ShowDialog() | |
if(($result -eq "OK") -and ($DropDownFrom.SelectedItem -ne $null)) { | |
return $DropDownFrom.SelectedItem.ToString() | |
} | |
} | |
function Get-DogeWalletArray { | |
#Scrape links from GitHub release page | |
$links = ($webclient.downloadstring('https://github.com/dogecoin/dogecoin/releases') -split "<a\s+") | ` | |
ForEach-Object {[void]($_ -match "^href=[`'`"]([^`'`">\s]*)"); if($matches.count -gt 0){ $matches[1] } } | ` | |
Where-Object { $_ -like "/dogecoin/dogecoin/releases/download/*/dogecoin-qt-*-Win.zip" } | |
$verdict = @{} | |
$links | ForEach-Object { | |
$verdict[($_ -split "/")[-1]] = $_ | |
} | |
return $verdict | |
} | |
$paths = @{ | |
"root" = "C:\Doge\" | |
"currentwallet" = "C:\Doge\CurrentWallet\" | |
"walletdatbkp" = "C:\Doge\WalletDatBackups\" | |
"walletzips" = "C:\Doge\OtherWallets\WalletZips\" | |
"oldwallets" = "C:\Doge\OtherWallets\OldWallets\" | |
} | |
$timestamp = Get-Date -Format "yyyyMMddHHmmss" | |
$webclient = New-Object -TypeName System.Net.WebClient | |
$walletarray = Get-DogeWalletArray | |
$choice = Create-VersionSelectBox -DropDownArray $walletarray.Keys | |
if($choice -ne $null) { | |
#Create Directory Structure | |
$paths.Keys | ForEach-Object { | |
if(!(Test-Path $paths[$_])){ | |
Write-Host -ForegroundColor Green "Creating $($paths[$_])..." | |
New-Item -ItemType directory -Path $paths[$_] | Out-Null | |
} | |
} | |
#Backup Existing Wallet.DAT file | |
Write-Host -ForegroundColor Green "Backing Up wallet.dat..." | |
Copy-Item "$env:APPDATA\DogeCoin\wallet.dat" "$($paths['walletdatbkp'])$($timestamp)_wallet.dat" -Force | |
#Move Existing Wallet | |
Write-Host -ForegroundColor Green "Moving Current Wallet..." | |
foreach($folder in (Get-ChildItem $paths['currentwallet'])){ | |
Move-Item -Path $folder.FullName -Destination "$($paths['oldwallets'])$($folder)_$timestamp" | |
} | |
#Define new wallet paths | |
$newwalletzip = "$($paths['walletzips'])$choice" | |
$newwalletfolder = "$($paths['currentwallet'])$($choice -replace '\.zip','\')" | |
#Download file | |
Write-Host -ForegroundColor Green "Downloading $choice..." | |
$webclient.DownloadFile("https://github.com$($walletarray[$choice])", $newwalletzip) | |
#Create a folder for the wallet | |
if(!(Test-Path $newwalletfolder)){ New-Item -ItemType directory -Path $newwalletfolder | Out-Null } | |
#Extract files from zip | |
$shell = new-object -com shell.application | |
$zip = $shell.NameSpace($newwalletzip) | |
foreach($item in $zip.items()){ $shell.Namespace($newwalletfolder).copyhere($item) } | |
#Create shortcut on desktop | |
Write-Host -ForegroundColor Green "Creating Desktop Shortcut..." | |
$wshshell = New-Object -ComObject WScript.Shell | |
$desktop = [System.Environment]::GetFolderPath('Desktop') | |
$lnk = $wshshell.CreateShortcut($desktop+"\DogeWallet.lnk") | |
$lnk.TargetPath = $newwalletfolder + "dogecoin-qt.exe" | |
$lnk.Save() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment