public static async Task BeginDownloadMinecraft(this MainWindow window)
{
window.LoadingBox.Visibility = Visibility.Visible;
window.LoadingText.Content = "Updating Minecraft...";
window.LoadingProgress.IsIndeterminate = true;
if (!Directory.Exists(Globals.LauncherDataPath + @"\Minecraft")) Directory.CreateDirectory(Globals.LauncherDataPath + @"\Minecraft");
if (!Directory.Exists(Globals.LauncherDataPath + @"\Minecraft\bin")) Directory.CreateDirectory(Globals.LauncherDataPath + @"\Minecraft\bin");
if (!Directory.Exists(Globals.LauncherDataPath + @"\Minecraft\bin\natives")) Directory.CreateDirectory(Globals.LauncherDataPath + @"\Minecraft\bin\natives");
WebClient c = new WebClient();
try
{
if ((long)Settings.Default["CachedLWJGLTimestamp"] == null || LauncherInformation.Current.LWJGLTimestamp > (long)Settings.Default["CachedLWJGLTimestamp"])
{
window.LoadingText.Content = "Downloading updated LWJGL...";
byte[] d = await c.DownloadDataTaskAsync(LauncherInformation.Current.LWJGLLocation);
ZipFile f = ZipFile.Read(new MemoryStream(d));
f.ExtractAll(Globals.LauncherDataPath + @"\Minecraft\bin", ExtractExistingFileAction.OverwriteSilently);
Settings.Default["CachedLWJGLTimestamp"] = LauncherInformation.Current.LWJGLTimestamp;
Settings.Default.Save();
}
if((long)Settings.Default["CachedMinecraftTimestamp"] == null || LauncherInformation.Current.MinecraftTimestamp > (long)Settings.Default["CachedMinecraftTimestamp"])
{
MessageBoxResult r = MessageBox.Show("Do you want to update Minecraft? (Latest version: " + LauncherInformation.Current.MinecraftVersion + ")", "MCLauncher", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (r == MessageBoxResult.Yes)
{
window.LoadingText.Content = "Downloading Minecraft " + LauncherInformation.Current.MinecraftVersion + "...";
byte[] mc = await c.DownloadDataTaskAsync(LauncherInformation.Current.MinecraftLocation);
File.WriteAllBytes(Globals.LauncherDataPath + @"\Minecraft\bin\minecraft.jar", mc);
Settings.Default["CachedMinecraftTimestamp"] = LauncherInformation.Current.MinecraftTimestamp;
Settings.Default.Save();
}
}
}
catch (WebException ex)
{
MessageBox.Show("Failed to update Minecraft. Is your internet down? Exception information: " + ex.ToString(), "An error has occured.", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
c.Dispose();
}
}