internal void HandleCompleteDownload(Packet pa) { AllDonePacket p = pa as AllDonePacket; currentDownload.ReadFile(downloaded); currentDownload.Save(); if (!Directory.Exists(Config.ModsPath + "/" + Path.GetDirectoryName(currentDownload.ModFile))) { Directory.CreateDirectory(Config.ModsPath + "/" + Path.GetFileName(currentDownload.ModFile)); } File.WriteAllBytes(Config.ModsPath + "/" + currentDownload.ModFile, downloaded); MinecraftModUpdater.Logger.Log(Logger.Level.Info, "Data transfer complete!"); }
private void HandleAllDone(Packet pa) { AllDonePacket p = pa as AllDonePacket; Mod m = mods.Find(new Predicate <Mod>(delegate(Mod mod) { return(mod.Identifier == p.Identifier); })); if (!Directory.Exists(Path.GetDirectoryName(InstancePath + m.File))) { Directory.CreateDirectory(Path.GetDirectoryName(InstancePath + m.File)); } File.WriteAllBytes(InstancePath + m.File, mods[currentDownload].Contents); updated++; if (updated == amountOfUpdates) { Thread.Sleep(3000); Invoke(new VoidInvoke(delegate { listBox1.Enabled = true; })); } }
void ph_AllDone(Packet pa) { AllDonePacket p = pa as AllDonePacket; int i = 0; while (progress[1] != progress[2]) { if (i > 10) { SplashScreen.UpdateStatusText("There was an error while downloading. Retrying..."); Thread.Sleep(5000); Packet.Send(new RequestModPacket { Type = RequestModPacket.RequestType.Download, Identifier = p.Identifier }, ph.Stream); return; } i++; Thread.Sleep(1000); } Mod m = Mods.Find(p.Identifier); string path = Path.GetDirectoryName(Properties.Settings.Default.MinecraftPath + "\\" + m.File); File.WriteAllBytes(path + "\\" + Path.GetFileName(m.File), CurrentDownload.Contents); MinecraftModUpdater.Logger.Log(Logger.Level.Info, "Downloaded " + path + "\\" + Path.GetFileName(m.File)); ProcessStartInfo pr = new ProcessStartInfo("cmd"); pr.CreateNoWindow = true; pr.UseShellExecute = false; pr.RedirectStandardOutput = true; pr.RedirectStandardInput = true; Process proc = new Process(); proc.StartInfo = pr; proc.Start(); foreach (string s in m.PostDownload) { try { proc.StandardInput.WriteLine(s); } catch (Exception e) { ExceptionHandler.HandleException(e, this); } } proc.Kill(); MinecraftModUpdater.Logger.Log(Logger.Level.Info, "[Post Download] " + proc.StandardOutput.ReadToEnd()); if (GetLastModToUpdate().File == m.File) { SplashScreen.UpdateStatusText("All files downloaded!"); Thread.Sleep(1000); warnDisconnect = false; Packet.Send(new LogPacket { LogMessages = MinecraftModUpdater.Logger.GetMessages() }, ph.Stream); Packet.Send(new DisconnectPacket(), ph.Stream); ph.RemovePacketHandler(PacketId.Metadata); ph.RemovePacketHandler(PacketId.ModInfo); ph.RemovePacketHandler(PacketId.ModList); ph.RemovePacketHandler(PacketId.NextDownload); ph.RemovePacketHandler(PacketId.FilePart); ph.RemovePacketHandler(PacketId.AllDone); TaskManager.AddAsyncTask(delegate { ph.Stop(); }, ThreadRole.Delayed, 5000); if (Properties.Settings.Default.LaunchAfterUpdate) { Program.RunOnUIThread(delegate { Program.StartMinecraft(); }); } else { SplashScreen.CloseSplashScreen(); } Program.RunOnUIThread(delegate { Close(); }); return; } progress[0]++; m = (Mod)lsModsToUpdate.Items[progress[0]]; Packet.Send(new RequestModPacket { Type = RequestModPacket.RequestType.Download, Identifier = m.Identifier }, ph.Stream); }