add sorting to firmwares list, optimize scanning a bit, change the recommended names of a few pce-cd and saturn firmware files to be short but descriptive, instead of insanely verbose and also full of spaces--this constitutes my final suggestions for the firmware names.

This commit is contained in:
zeromus 2013-08-03 19:34:51 +00:00
parent 31126d437b
commit eb04d7e35d
3 changed files with 333 additions and 193 deletions

View File

@ -28,173 +28,172 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FirmwaresConfig));
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.lvFirmwares = new System.Windows.Forms.ListView();
this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.panel1 = new System.Windows.Forms.Panel();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.tbbGroup = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.tbbScan = new System.Windows.Forms.ToolStripButton();
this.tbbOrganize = new System.Windows.Forms.ToolStripButton();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.panel1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// lvFirmwares
//
this.lvFirmwares.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FirmwaresConfig));
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.lvFirmwares = new System.Windows.Forms.ListView();
this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.panel1 = new System.Windows.Forms.Panel();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.tbbGroup = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.tbbScan = new System.Windows.Forms.ToolStripButton();
this.tbbOrganize = new System.Windows.Forms.ToolStripButton();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.panel1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// lvFirmwares
//
this.lvFirmwares.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader5,
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4});
this.lvFirmwares.Dock = System.Windows.Forms.DockStyle.Fill;
this.lvFirmwares.FullRowSelect = true;
this.lvFirmwares.GridLines = true;
this.lvFirmwares.Location = new System.Drawing.Point(0, 25);
this.lvFirmwares.MultiSelect = false;
this.lvFirmwares.Name = "lvFirmwares";
this.lvFirmwares.Size = new System.Drawing.Size(773, 447);
this.lvFirmwares.SmallImageList = this.imageList1;
this.lvFirmwares.TabIndex = 24;
this.lvFirmwares.UseCompatibleStateImageBehavior = false;
this.lvFirmwares.View = System.Windows.Forms.View.Details;
this.lvFirmwares.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lvFirmwares_ColumnClick);
this.lvFirmwares.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lvFirmwares_KeyDown);
//
// columnHeader5
//
this.columnHeader5.Text = "";
this.columnHeader5.Width = 31;
//
// columnHeader1
//
this.columnHeader1.Text = "System";
//
// columnHeader2
//
this.columnHeader2.Text = "Hash";
this.columnHeader2.Width = 475;
//
// columnHeader3
//
this.columnHeader3.Text = "Normal Filename";
this.columnHeader3.Width = 93;
//
// columnHeader4
//
this.columnHeader4.Text = "Description";
this.columnHeader4.Width = 220;
//
// panel1
//
this.tableLayoutPanel1.SetColumnSpan(this.panel1, 2);
this.panel1.Controls.Add(this.lvFirmwares);
this.panel1.Controls.Add(this.toolStrip1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(3, 3);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(773, 472);
this.panel1.TabIndex = 24;
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.lvFirmwares.Dock = System.Windows.Forms.DockStyle.Fill;
this.lvFirmwares.FullRowSelect = true;
this.lvFirmwares.GridLines = true;
this.lvFirmwares.Location = new System.Drawing.Point(0, 25);
this.lvFirmwares.Name = "lvFirmwares";
this.lvFirmwares.Size = new System.Drawing.Size(773, 447);
this.lvFirmwares.SmallImageList = this.imageList1;
this.lvFirmwares.TabIndex = 24;
this.lvFirmwares.UseCompatibleStateImageBehavior = false;
this.lvFirmwares.View = System.Windows.Forms.View.Details;
this.lvFirmwares.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lvFirmwares_ColumnClick);
this.lvFirmwares.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lvFirmwares_KeyDown);
//
// columnHeader5
//
this.columnHeader5.Text = "";
this.columnHeader5.Width = 31;
//
// columnHeader1
//
this.columnHeader1.Text = "System";
//
// columnHeader2
//
this.columnHeader2.Text = "Hash";
this.columnHeader2.Width = 475;
//
// columnHeader3
//
this.columnHeader3.Text = "Normal Filename";
this.columnHeader3.Width = 93;
//
// columnHeader4
//
this.columnHeader4.Text = "Description";
this.columnHeader4.Width = 220;
//
// panel1
//
this.tableLayoutPanel1.SetColumnSpan(this.panel1, 2);
this.panel1.Controls.Add(this.lvFirmwares);
this.panel1.Controls.Add(this.toolStrip1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(3, 3);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(773, 472);
this.panel1.TabIndex = 24;
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tbbGroup,
this.toolStripSeparator2,
this.tbbScan,
this.tbbOrganize});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(773, 25);
this.toolStrip1.TabIndex = 23;
this.toolStrip1.Text = "toolStrip1";
//
// tbbGroup
//
this.tbbGroup.Checked = true;
this.tbbGroup.CheckOnClick = true;
this.tbbGroup.CheckState = System.Windows.Forms.CheckState.Checked;
this.tbbGroup.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tbbGroup.Image = ((System.Drawing.Image)(resources.GetObject("tbbGroup.Image")));
this.tbbGroup.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbbGroup.Name = "tbbGroup";
this.tbbGroup.Size = new System.Drawing.Size(44, 22);
this.tbbGroup.Text = "Group";
this.tbbGroup.Click += new System.EventHandler(this.tbbGroup_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
//
// tbbScan
//
this.tbbScan.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tbbScan.Image = ((System.Drawing.Image)(resources.GetObject("tbbScan.Image")));
this.tbbScan.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbbScan.Name = "tbbScan";
this.tbbScan.Size = new System.Drawing.Size(36, 22);
this.tbbScan.Text = "Scan";
this.tbbScan.Click += new System.EventHandler(this.tbbScan_Click);
//
// tbbOrganize
//
this.tbbOrganize.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tbbOrganize.Image = ((System.Drawing.Image)(resources.GetObject("tbbOrganize.Image")));
this.tbbOrganize.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbbOrganize.Name = "tbbOrganize";
this.tbbOrganize.Size = new System.Drawing.Size(58, 22);
this.tbbOrganize.Text = "Organize";
this.tbbOrganize.Click += new System.EventHandler(this.tbbOrganize_Click);
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(779, 478);
this.tableLayoutPanel1.TabIndex = 25;
//
// FirmwaresConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(779, 478);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "FirmwaresConfig";
this.ShowIcon = false;
this.Text = "Firmwares";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FirmwaresConfig_FormClosed);
this.Load += new System.EventHandler(this.FirmwaresConfig_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(773, 25);
this.toolStrip1.TabIndex = 23;
this.toolStrip1.Text = "toolStrip1";
//
// tbbGroup
//
this.tbbGroup.Checked = true;
this.tbbGroup.CheckOnClick = true;
this.tbbGroup.CheckState = System.Windows.Forms.CheckState.Checked;
this.tbbGroup.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tbbGroup.Image = ((System.Drawing.Image)(resources.GetObject("tbbGroup.Image")));
this.tbbGroup.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbbGroup.Name = "tbbGroup";
this.tbbGroup.Size = new System.Drawing.Size(40, 22);
this.tbbGroup.Text = "Group";
this.tbbGroup.Click += new System.EventHandler(this.tbbGroup_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
//
// tbbScan
//
this.tbbScan.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tbbScan.Image = ((System.Drawing.Image)(resources.GetObject("tbbScan.Image")));
this.tbbScan.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbbScan.Name = "tbbScan";
this.tbbScan.Size = new System.Drawing.Size(34, 22);
this.tbbScan.Text = "Scan";
this.tbbScan.Click += new System.EventHandler(this.tbbScan_Click);
//
// tbbOrganize
//
this.tbbOrganize.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tbbOrganize.Image = ((System.Drawing.Image)(resources.GetObject("tbbOrganize.Image")));
this.tbbOrganize.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbbOrganize.Name = "tbbOrganize";
this.tbbOrganize.Size = new System.Drawing.Size(54, 22);
this.tbbOrganize.Text = "Organize";
this.tbbOrganize.Click += new System.EventHandler(this.tbbOrganize_Click);
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(779, 478);
this.tableLayoutPanel1.TabIndex = 25;
//
// FirmwaresConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(779, 478);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "FirmwaresConfig";
this.ShowIcon = false;
this.Text = "Firmwares";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FirmwaresConfig_FormClosed);
this.Load += new System.EventHandler(this.FirmwaresConfig_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -35,10 +36,10 @@ namespace BizHawk.MultiClient
new FDR("6472828403DE3589433A906E2C3F3D274C0FF008", "SNES", "st010.rom", "ST010 Rom"),
new FDR("FECBAE2CEC76C710422486BAA186FFA7CA1CF925", "SNES", "st011.rom", "ST011 Rom"),
new FDR("91383B92745CC7CC4F15409AC5BC2C2F699A43F1", "SNES", "st018.rom", "ST018 Rom"),
new FDR("79F5FF55DD10187C7FD7B8DAAB0B3FFBD1F56A2C", "PCECD", "[BIOS] Super CD-ROM System (Japan) (v3.0).pce", "Super CD-ROM System v3.0 (J)","FilenamePCEBios"),
new FDR("2B8CB4F87580683EB4D760E4ED210813D667F0A2", "SAT", "Sega Saturn BIOS v1.00 (US).bin", "Sega Saturn Bios v1.00 (NTSC)"),
new FDR("FAA8EA183A6D7BBE5D4E03BB1332519800D3FBC3", "SAT", "Sega Saturn BIOS (EUR).bin", "Sega Saturn Bios v1.00 (PAL)"),
new FDR("DF94C5B4D47EB3CC404D88B33A8FDA237EAF4720", "SAT", "Sega Saturn BIOS v1.01 (JAP).bin", "Sega Saturn Bios v1.01 (J)", "FilenameSaturnBios"),
new FDR("79F5FF55DD10187C7FD7B8DAAB0B3FFBD1F56A2C", "PCECD", "pcecd-3.0-J.pce", "Super CD-ROM System v3.0 (J)","FilenamePCEBios"),
new FDR("2B8CB4F87580683EB4D760E4ED210813D667F0A2", "SAT", "saturn-1.00-NTSC.bin", "Sega Saturn Bios v1.00 (NTSC)"),
new FDR("FAA8EA183A6D7BBE5D4E03BB1332519800D3FBC3", "SAT", "saturn-1.00-PAL.bin", "Sega Saturn Bios v1.00 (PAL)"),
new FDR("DF94C5B4D47EB3CC404D88B33A8FDA237EAF4720", "SAT", "saturn-1.01-J.bin", "Sega Saturn Bios v1.01 (J)", "FilenameSaturnBios"),
new FDR("D9D134BB6B36907C615A594CC7688F7BFCEF5B43", "A78", "7800NTSCBIOS.bin", "Atari 7800 NTSC Bios", "FilenameA78NTSCBios"),
new FDR("5A140136A16D1D83E4FF32A19409CA376A8DF874", "A78", "7800PALBIOS.bin", "Atari 7800 PAL Bios", "FilenameA78PALBios"),
new FDR("A3AF676991391A6DD716C79022D4947206B78164", "A78", "7800highscore.bin", "Atari 7800 Highscore Bios", "FilenameA78HSCBios"),
@ -94,12 +95,35 @@ namespace BizHawk.MultiClient
Font fixedFont;
class ListViewSorter : IComparer
{
public FirmwaresConfig dialog;
public int column;
public int sign;
public ListViewSorter(FirmwaresConfig dialog, int column)
{
this.dialog = dialog;
this.column = column;
}
public int Compare(object a, object b)
{
var lva = (ListViewItem)a;
var lvb = (ListViewItem)b;
return sign*string.Compare(lva.SubItems[column].Text, lvb.SubItems[column].Text);
}
}
ListViewSorter listviewSorter;
public FirmwaresConfig()
{
InitializeComponent();
//prep imagelist for listview with 3 item states for {idUnsure, idMissing, idOk}
imageList1.Images.AddRange(new[] { MultiClient.Properties.Resources.RetroQuestion, MultiClient.Properties.Resources.ExclamationRed, MultiClient.Properties.Resources.GreenCheck });
listviewSorter = new ListViewSorter(this, -1);
}
private void FirmwaresConfig_Load(object sender, EventArgs e)
@ -153,8 +177,15 @@ namespace BizHawk.MultiClient
private void lvFirmwares_ColumnClick(object sender, ColumnClickEventArgs e)
{
//TBD
//http://msdn.microsoft.com/en-us/library/ms996467.aspx#sorting_customfeatures
if (listviewSorter.column != e.Column)
{
listviewSorter.column = e.Column;
listviewSorter.sign = 1;
}
else listviewSorter.sign *= -1;
lvFirmwares.ListViewItemSorter = listviewSorter;
lvFirmwares.SetSortIcon(e.Column, listviewSorter.sign == 1 ? SortOrder.Descending : SortOrder.Ascending);
lvFirmwares.Sort();
}
private void tbbScan_Click(object sender, EventArgs e)
@ -179,12 +210,16 @@ namespace BizHawk.MultiClient
{
var di = todo.Dequeue();
foreach (var disub in di.GetDirectories()) todo.Enqueue(disub);
byte[] buffer = new byte[0];
foreach (var fi in di.GetFiles())
{
var rff = new RealFirmwareFile();
rff.fi = fi;
var bytes = File.ReadAllBytes(fi.FullName); //TODO - go faster by reusing buffers
rff.hash = Util.Hash_SHA1(bytes, 0, bytes.Length);
long len = fi.Length;
if (len > buffer.Length)
buffer = new byte[len];
using (var fs = fi.OpenRead()) fs.Read(buffer, 0, (int)len);
rff.hash = Util.Hash_SHA1(buffer, 0, (int)len);
files.Add(rff);
}
}
@ -204,11 +239,13 @@ namespace BizHawk.MultiClient
if (fdr.hash == f.hash)
{
foreach (ListViewItem lvi in lvFirmwares.Items)
{
if (lvi.Tag == fdr)
{
lvi.ImageIndex = idOk;
fdr.userPath = f.fi;
}
}
}
}
}
@ -252,41 +289,50 @@ namespace BizHawk.MultiClient
}
catch
{
//sometimes moves fail. especially in newer versions of windows with explorers more fragile than your great-grandma.
//I am embarassed that I know that.
}
}
//to be safe, better do this.
//to be safe, better do this. we want the db to track the state of the files after theyre moved.
DoScan();
}
private void lvFirmwares_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) //Copy
{
ListView.SelectedIndexCollection indexes = lvFirmwares.SelectedIndices;
if (indexes.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (int index in indexes)
{
foreach (ListViewItem.ListViewSubItem item in lvFirmwares.Items[index].SubItems)
{
if (!String.IsNullOrWhiteSpace(item.Text))
{
sb.Append(item.Text).Append('\t');
}
}
sb.Remove(sb.Length - 1, 1);
}
private void lvFirmwares_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift)
{
ListviewCopy();
}
}
if (sb.Length > 0)
{
Clipboard.SetDataObject(sb.ToString());
}
}
}
}
void ListviewCopy()
{
ListView.SelectedIndexCollection indexes = lvFirmwares.SelectedIndices;
if (indexes.Count <= 0)
return;
StringBuilder sb = new StringBuilder();
//walk over each selected item and subitem within it to generate a string from it
foreach (int index in indexes)
{
foreach (ListViewItem.ListViewSubItem item in lvFirmwares.Items[index].SubItems)
{
if (!String.IsNullOrWhiteSpace(item.Text))
sb.Append(item.Text).Append('\t');
}
//remove the last tab
sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n");
}
//remove last newline
sb.Length -= 2;
if (sb.Length > 0) Clipboard.SetDataObject(sb.ToString());
}
}
}

View File

@ -1,4 +1,6 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace BizHawk
@ -11,4 +13,97 @@ namespace BizHawk
control.Invoke((Delegate)action);
}
}
public static class ListViewExtensions
{
[StructLayout(LayoutKind.Sequential)]
public struct HDITEM
{
public Mask mask;
public int cxy;
[MarshalAs(UnmanagedType.LPTStr)]
public string pszText;
public IntPtr hbm;
public int cchTextMax;
public Format fmt;
public IntPtr lParam;
// _WIN32_IE >= 0x0300
public int iImage;
public int iOrder;
// _WIN32_IE >= 0x0500
public uint type;
public IntPtr pvFilter;
// _WIN32_WINNT >= 0x0600
public uint state;
[Flags]
public enum Mask
{
Format = 0x4, // HDI_FORMAT
};
[Flags]
public enum Format
{
SortDown = 0x200, // HDF_SORTDOWN
SortUp = 0x400, // HDF_SORTUP
};
};
public const int LVM_FIRST = 0x1000;
public const int LVM_GETHEADER = LVM_FIRST + 31;
public const int HDM_FIRST = 0x1200;
public const int HDM_GETITEM = HDM_FIRST + 11;
public const int HDM_SETITEM = HDM_FIRST + 12;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, ref HDITEM lParam);
public static void SetSortIcon(this ListView listViewControl, int columnIndex, SortOrder order)
{
IntPtr columnHeader = SendMessage(listViewControl.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);
for (int columnNumber = 0; columnNumber <= listViewControl.Columns.Count - 1; columnNumber++)
{
var columnPtr = new IntPtr(columnNumber);
var item = new HDITEM
{
mask = HDITEM.Mask.Format
};
if (SendMessage(columnHeader, HDM_GETITEM, columnPtr, ref item) == IntPtr.Zero)
{
throw new Win32Exception();
}
if (order != SortOrder.None && columnNumber == columnIndex)
{
switch (order)
{
case SortOrder.Ascending:
item.fmt &= ~HDITEM.Format.SortDown;
item.fmt |= HDITEM.Format.SortUp;
break;
case SortOrder.Descending:
item.fmt &= ~HDITEM.Format.SortUp;
item.fmt |= HDITEM.Format.SortDown;
break;
}
}
else
{
item.fmt &= ~HDITEM.Format.SortDown & ~HDITEM.Format.SortUp;
}
if (SendMessage(columnHeader, HDM_SETITEM, columnPtr, ref item) == IntPtr.Zero)
{
throw new Win32Exception();
}
}
}
}
}