private void PacFiles_DragDrop(object sender, DragEventArgs e) { List <string> paths = ((string[])e.Data.GetData(DataFormats.FileDrop)).ToList(); Console.WriteLine(Path.GetExtension(paths[0])); if (paths.Count == 1 && Path.GetExtension(paths[0] ?? "").Equals(".pac", StringComparison.InvariantCultureIgnoreCase)) { pac?.Dispose(); PacFiles.Items.Clear(); pac = new Pac(); pac.LoadFile(paths[0]); PacFiles.Items.AddRange(pac.Files.Select(entry => new ListViewItem(entry.Path.ZeroTerminatedString) { Tag = entry }).ToArray()); } else { List <string> directories = new List <string>(); List <string> files = new List <string>(); paths.ForEach(path => { if (Directory.Exists(path)) { directories.Add(path); files.AddRange(Directory.GetFiles(path, "*", SearchOption.AllDirectories)); } }); directories.ForEach(directory => paths.Remove(directory)); paths.AddRange(files); if (pac == null) { MessageBox.Show("Please load a .pac first !", "Warning !", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { foreach (var file in paths) { string correspondingPath = (from ListViewItem pacFile in PacFiles.Items select pacFile.Text).ToList().Find(path => file.Contains(path)); if (correspondingPath == null) { MessageBox.Show($"{file} isn't present in the currently opened .pac !", "Not found !", MessageBoxButtons.OK, MessageBoxIcon.Warning); continue; } ListViewItem item = PacFiles.Items.Cast <ListViewItem>().FirstOrDefault(fileItem => fileItem.Text == correspondingPath); item.ForeColor = Color.Red; var entry = (PacEntry)item.Tag; var fileStream = File.OpenRead(file); entry.SetFile(false, (int)fileStream.Length, fileStream, 0, (int)fileStream.Length, false, false); } } } }