Created
April 26, 2015 01:35
-
-
Save robot56/185e37ff03f17bcfb2be to your computer and use it in GitHub Desktop.
Minecraft native launcher log reader
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
## Configuration | |
# The log path that Minecraft's native log uses. Update this if it changes. | |
$LogPath = "\Minecraft\nativelog.txt"; | |
$VERSION = "1.1"; | |
# Set the absolute log path based on OS arc | |
if ([System.IntPtr]::Size -eq 4) { | |
$AbsoluteLogPath = $env:ProgramFiles + $LogPath; | |
} else { | |
$AbsoluteLogPath = ${env:ProgramFiles(x86)} + $LogPath; | |
} | |
## Imports | |
Add-Type -AssemblyName System.Windows.Forms | |
Add-Type -AssemblyName System.Web | |
Add-Type -AssemblyName Microsoft.VisualBasic | |
## Start log search | |
# Do some IO checks and if the file is found, grab the content | |
try { | |
$content = [IO.File]::ReadAllText($AbsoluteLogPath); | |
} catch [System.IO.DirectoryNotFoundException] { | |
[System.Windows.Forms.MessageBox]::Show("The native Minecraft directory was not found in '{0}'. Please ensure that the Minecraft installer was able to run." -f $AbsoluteLogPath, "Directory not found", 0, "warning") | |
exit; | |
} catch [System.IO.FileNotFoundException] { | |
[System.Windows.Forms.MessageBox]::Show("The native Minecraft directory was found, but no log file exists. Please try running the native Minecraft launcher again.", "File not found", 0, "warning"); | |
exit; | |
} catch [System.UnauthorizedAccessException] { | |
[System.Windows.Forms.MessageBox]::Show("The native Minecraft directory was found in '{0}', but read access was denied. Please try running this program again with administrator privileges." -f $AbsoluteLogPath, "Access is denied", 0, "error"); | |
exit; | |
} catch [System.IO.IOException] { | |
[System.Windows.Forms.MessageBox]::Show("An unknown IO Exception occured while getting the contents of '{0}'. Please ensure that the Minecraft launcher is *not* running and try again.`nError: {1}" -f ($AbsoluteLogPath, $_), "Unknown IO Exception", 0, "error"); | |
exit; | |
} catch [System.Exception] { | |
[System.Windows.Forms.MessageBox]::Show("A system exception occured.`nError: {1}" -f ($AbsoluteLogPath, $_), "System Exception", 0, "error"); | |
exit; | |
} | |
# courtesy of http://www.revindex.com/Resources/KnowledgeBase/RevindexTaskScheduler/tabid/190/rvdwktid/web-post-powershell-245/Default.aspx | |
# This uses the legacy WebRequest to mantain compatability with pre-PowerShell 2.0 (pre-Windows 7 SP1) | |
Function PostWebRequest([String] $url, [String] $data, [int] $timeout) | |
{ | |
$buffer = [System.Text.Encoding]::UTF8.GetBytes($data) | |
[System.Net.HttpWebRequest] $webRequest = [System.Net.WebRequest]::Create($url) | |
$webRequest.Timeout = $timeout | |
$webRequest.Method = "POST" | |
$webRequest.ContentType = "application/x-www-form-urlencoded" | |
# add in user agent | |
$webRequest.UserAgent = "Mozilla/5.0 (Windows NT; "+(get-itemproperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName).ProductName+"; en-US) WindowsPowerShell/3.0 MinecraftNativeLogReader/"+$VERSION; | |
$webRequest.ContentLength = $buffer.Length; | |
$requestStream = $webRequest.GetRequestStream() | |
$requestStream.Write($buffer, 0, $buffer.Length) | |
$requestStream.Flush() | |
$requestStream.Close() | |
[System.Net.HttpWebResponse] $webResponse = $webRequest.GetResponse() | |
$streamReader = New-Object System.IO.StreamReader($webResponse.GetResponseStream()) | |
$result = $streamReader.ReadToEnd() | |
return $result | |
} | |
try { | |
$Payload = "sprunge=" + [System.Web.HttpUtility]::UrlEncode($content); | |
# grab the URL and copy it to the clipboard | |
$url = PostWebRequest "http://sprunge.us/" $Payload 4000; | |
$url | clip; | |
[Microsoft.VisualBasic.Interaction]::InputBox("The generated URL is listed below. It has been automatically copied to your clipboard.`nPlease give it to whom is helping you by using Ctrl+V (or right click -> Paste) to paste.", "Successfully submitted file", $url); | |
} catch [System.Exception] { | |
Write-Host "An exception occured: " + $_; | |
[System.Windows.Forms.MessageBox]::Show("The program could not automatically submit the contents to a paste service.`n`nA notepad window will instead be opened containing the native log.`nPlease copy everything in the notepad window that will open, and paste it to the text box at http://pastebin.com/ - afterwards press 'Submit' and give whom is helping you the URL to which it should redirect you.", "Manual action required", 0, "warning") | |
notepad ($AbsoluteLogPath); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment