private void MainForm_Load(object sender, EventArgs e) { ConnectionForm cf = new ConnectionForm(); if (cf.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { Close(); return; } listBox1.Items.AddRange(cf.Connection.Mods); mods.AddRange(cf.Connection.Mods); Connection = cf.Connection; Text = "MCModUpdater AdminCP (" + Connection.Server.Name + ")"; InstancePath = string.Format("{0}{1}Servers{1}{2}{1}WorkingCopy{1}", Environment.CurrentDirectory, Path.DirectorySeparatorChar, Connection.Server.Name); if (!Directory.Exists(InstancePath)) { Directory.CreateDirectory(InstancePath); } int count = 0; foreach (Mod m in mods) { bool exists = File.Exists(InstancePath + m.File); if (!exists) { m.NeedsUpdate = true; count++; downloadSize += m.Contents.Length; continue; } bool sameHash = Extras.GenerateHash(InstancePath + m.File) == m.Hash; if (!sameHash) { m.NeedsUpdate = true; count++; downloadSize += m.Contents.Length; continue; } } if (count > 0) { amountOfUpdates = count; button1.Enabled = false; listBox1.Enabled = false; panel1.Controls.Add(new ControlDownloadProgress()); MessageBox.Show(string.Format("{0} mods need to be synced.", count), Text + " - Alert"); Connection.PacketHandler.RegisterPacketHandler(PacketId.NextDownload, HandleDownloadInfo); Connection.PacketHandler.RegisterPacketHandler(PacketId.FilePart, HandleFilePart); Connection.PacketHandler.RegisterPacketHandler(PacketId.AllDone, HandleAllDone); foreach (Mod m in mods) { if (m.NeedsUpdate) { Packet.Send(new RequestModPacket { Identifier = m.Identifier, Type = RequestModPacket.RequestType.Download }, Connection.PacketHandler.Stream); } else { m.Contents = File.ReadAllBytes(InstancePath + m.File); } } TaskManager.AddAsyncTask(HandleSyncScreen); } }
private void MainForm_Load(object sender, EventArgs e) { ConnectionForm cf = new ConnectionForm(); if (cf.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { Close(); return; } listBox1.Items.AddRange(cf.Connection.Mods); mods.AddRange(cf.Connection.Mods); Connection = cf.Connection; Text = "MCModUpdater AdminCP (" + Connection.Server.Name + ")"; InstancePath = string.Format("{0}{1}Servers{1}{2}{1}WorkingCopy{1}", Environment.CurrentDirectory, Path.DirectorySeparatorChar, Connection.Server.Name); if (!Directory.Exists(InstancePath)) Directory.CreateDirectory(InstancePath); int count = 0; foreach (Mod m in mods) { bool exists = File.Exists(InstancePath + m.File); if (!exists) { m.NeedsUpdate = true; count++; downloadSize += m.Contents.Length; continue; } bool sameHash = Extras.GenerateHash(InstancePath + m.File) == m.Hash; if (!sameHash) { m.NeedsUpdate = true; count++; downloadSize += m.Contents.Length; continue; } } if (count > 0) { amountOfUpdates = count; button1.Enabled = false; listBox1.Enabled = false; panel1.Controls.Add(new ControlDownloadProgress()); MessageBox.Show(string.Format("{0} mods need to be synced.", count), Text + " - Alert"); Connection.PacketHandler.RegisterPacketHandler(PacketId.NextDownload, HandleDownloadInfo); Connection.PacketHandler.RegisterPacketHandler(PacketId.FilePart, HandleFilePart); Connection.PacketHandler.RegisterPacketHandler(PacketId.AllDone, HandleAllDone); foreach (Mod m in mods) { if (m.NeedsUpdate) { Packet.Send(new RequestModPacket { Identifier = m.Identifier, Type = RequestModPacket.RequestType.Download }, Connection.PacketHandler.Stream); } else { m.Contents = File.ReadAllBytes(InstancePath + m.File); } } TaskManager.AddAsyncTask(HandleSyncScreen); } }