private void listBox_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) { return; } e.DrawBackground(); if (((e.State & DrawItemState.Selected) != 0 || (e.State & DrawItemState.Focus) != 0)) { e.Graphics.FillRectangle(Brushes.Gainsboro, e.Bounds); } else { if (e.Index == 1 || e.Index % 2 != 0) { e.Graphics.FillRectangle(Brushes.WhiteSmoke, e.Bounds); } else { e.Graphics.FillRectangle(Brushes.White, e.Bounds); } } if (listBox.Items[e.Index] is PatchlistFile) { PatchlistFile p = (PatchlistFile)listBox.Items[e.Index]; e.Graphics.DrawString("Patch CRC: " + p.CRC.ToString("X4"), Font, Brushes.Black, new PointF(5, e.Bounds.Y + 6)); e.Graphics.DrawString("Patch Size: " + ((p.Size == 0) ? "Unknown" : p.Size.ToString("0,0")), Font, Brushes.Black, new PointF(150, e.Bounds.Y + 6)); e.Graphics.DrawString("Patch Url: " + p.Url, Font, Brushes.Black, new PointF(5, e.Bounds.Y + 24)); } }
// private void OnPercentChange( object sender, ProgressChangeEventArgs args) // { //Invoke((MethodInvoker)delegate { progressBar.Value = args.Percent; }); // } private bool DuplicateFileNames(PatchlistFile file) { for (int i = 0; i < listBox.Items.Count; i++) if (((PatchlistFile)listBox.Items[i]).FileName == file.FileName) return true; return false; }
// private void OnPercentChange( object sender, ProgressChangeEventArgs args) // { //Invoke((MethodInvoker)delegate { progressBar.Value = args.Percent; }); // } private bool DuplicateFileNames(PatchlistFile file) { for (int i = 0; i < listBox.Items.Count; i++) { if (((PatchlistFile)listBox.Items[i]).FileName == file.FileName) { return(true); } } return(false); }
private void importPatchToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog.Title = "Please select a compressed patch file"; openFileDialog.CheckFileExists = false; openFileDialog.Filter = "Zip File (*.zip)|*.zip|Rar File (*.rar)|*.rar"; if (openFileDialog.ShowDialog(this) == DialogResult.OK) { if (!File.Exists(openFileDialog.FileName)) { MessageBox.Show(this, "That file does not exist!"); return; } CRC32 crc32 = new CRC32(); crc32.PercentCompleteChange += new ProgressChangeHandler(OnPercentChange); FileStream stream = File.OpenRead(openFileDialog.FileName); uint crc = crc32.GetCrc32(stream); stream.Close(); string location = string.Empty; PathInputForm form = new PathInputForm(); form.PatchLocation = "http://"; if (form.ShowDialog(this) == DialogResult.Cancel) { return; } if (!form.PatchLocation.Contains(Path.GetFileName(openFileDialog.FileName))) { if (!form.PatchLocation.EndsWith("/")) { form.PatchLocation += "/"; } form.PatchLocation += Path.GetFileName(openFileDialog.FileName); } PatchlistFile file = new PatchlistFile(form.PatchLocation, crc, new FileInfo(openFileDialog.FileName).Length); if (!listBox.Items.Contains(file) && !DuplicateFileNames(file)) { _needsSaving = true; listBox.Items.Add(file); } } }
private void importPatchToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog.Title = "Please select a compressed patch file"; openFileDialog.CheckFileExists = false; openFileDialog.Filter = "Zip File (*.zip)|*.zip|Rar File (*.rar)|*.rar"; if( openFileDialog.ShowDialog(this) == DialogResult.OK ) { if( !File.Exists(openFileDialog.FileName) ) { MessageBox.Show(this, "That file does not exist!"); return; } CRC32 crc32 = new CRC32(); crc32.PercentCompleteChange += new ProgressChangeHandler(OnPercentChange); FileStream stream = File.OpenRead(openFileDialog.FileName); uint crc = crc32.GetCrc32(stream); stream.Close(); string location = string.Empty; PathInputForm form = new PathInputForm(); form.PatchLocation = "http://"; if( form.ShowDialog(this) == DialogResult.Cancel ) return; if (!form.PatchLocation.Contains(Path.GetFileName(openFileDialog.FileName))) { if (!form.PatchLocation.EndsWith("/")) form.PatchLocation += "/"; form.PatchLocation += Path.GetFileName(openFileDialog.FileName); } PatchlistFile file = new PatchlistFile(form.PatchLocation, crc, new FileInfo(openFileDialog.FileName).Length); if (!listBox.Items.Contains(file) && !DuplicateFileNames(file)) { _needsSaving = true; listBox.Items.Add(file); } } }