Created
October 6, 2012 07:22
-
-
Save renevo/3844304 to your computer and use it in GitHub Desktop.
Minecraft Launch
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
private static void AutoLaunchApplication(IEnumerable<string> commandLineOptions) | |
{ | |
const string java6Location = @"C:\Program Files\Java\jre6\bin\javaw.exe"; | |
const string java7Location = @"C:\Program Files\Java\jre7\bin\javaw.exe"; | |
var javaLocation = File.Exists(java7Location) ? java7Location : java6Location; | |
// check for java - eww | |
if (!File.Exists(javaLocation)) // default java location for both 32/64 bit | |
{ | |
MessageBox.Show(@"Java not found, exiting", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
return; | |
} | |
// get latest version | |
if (!File.Exists("./minecraft.jar")) | |
new WebClient().DownloadFile("https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft.jar", "./minecraft.jar"); | |
var memory = 1024; | |
if (commandLineOptions.Any(x => x.StartsWith("-memory:"))) | |
{ | |
var memoryCommandLineOption = commandLineOptions.FirstOrDefault(x => x.StartsWith("-memory:")); | |
if (!String.IsNullOrWhiteSpace(memoryCommandLineOption)) | |
{ | |
// TODO: Validate this to 512/1024/2048/4096? | |
var memoryValue = memoryCommandLineOption.Split(':').Last(); | |
int.TryParse(memoryValue, out memory); | |
} | |
} | |
// So I can do javaw Xms# Xmx# -cp -jar launcher/launcher.jar username xxx pass xxx fullscreen w h | |
// javaw -cp Minecraft.jar net.minecraft.LauncherFrame <username> <password> <server ip:port> -- doesn't seem to work :/ | |
var processStartInfo = new ProcessStartInfo { Arguments = "-Xmx" + memory + "M -Xms" + memory + "M -jar \"" + Path.GetFullPath("./minecraft.jar") + "\"", FileName = javaLocation, WorkingDirectory = Environment.CurrentDirectory, UseShellExecute = false }; | |
// set to local environment for this | |
if (commandLineOptions.Contains("-local")) | |
processStartInfo.EnvironmentVariables["APPDATA"] = Environment.CurrentDirectory; | |
// set the custom environment for this | |
else if (commandLineOptions.Contains("-custom")) | |
processStartInfo.EnvironmentVariables["APPDATA"] = commandLineOptions.Last(); | |
var process = Process.Start(processStartInfo); | |
while (process.MainWindowHandle == IntPtr.Zero) | |
{ | |
process.WaitForExit(10); | |
if (process.HasExited) | |
return; | |
} | |
NativeMethods.SetWindowFullScreenWindowed(process.MainWindowHandle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment