365 lines
11 KiB
C#
365 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using MyNes.Core;
|
|
using MyNes.Properties;
|
|
|
|
namespace MyNes;
|
|
|
|
public class GameInfoViewer : UserControl
|
|
{
|
|
private string currentID;
|
|
|
|
private MyNesDetectEntryInfo[] images;
|
|
|
|
private int fileIndex;
|
|
|
|
private IContainer components;
|
|
|
|
private ImagePanel imagePanel1;
|
|
|
|
private Panel panel1;
|
|
|
|
private Label label_path;
|
|
|
|
private Label label_size;
|
|
|
|
private Label label_name;
|
|
|
|
private Rating rating1;
|
|
|
|
private ToolTip toolTip1;
|
|
|
|
private Timer timer1;
|
|
|
|
private ListView listView1;
|
|
|
|
private ColumnHeader columnHeader1;
|
|
|
|
private ColumnHeader columnHeader2;
|
|
|
|
private ContextMenuStrip contextMenuStrip1;
|
|
|
|
private ToolStripMenuItem copyToolStripMenuItem;
|
|
|
|
private GroupBox groupBox1;
|
|
|
|
public event EventHandler RatingChanged;
|
|
|
|
public GameInfoViewer()
|
|
{
|
|
InitializeComponent();
|
|
Clear();
|
|
}
|
|
|
|
private void Clear()
|
|
{
|
|
Label label = label_name;
|
|
Label label2 = label_path;
|
|
string text = (label_size.Text = Resources.Status38);
|
|
string text3 = (label2.Text = text);
|
|
label.Text = text3;
|
|
rating1.rating = 0;
|
|
rating1.Enabled = false;
|
|
imagePanel1.ImageToView = null;
|
|
imagePanel1.Invalidate();
|
|
images = new MyNesDetectEntryInfo[0];
|
|
fileIndex = -1;
|
|
timer1.Stop();
|
|
listView1.Items.Clear();
|
|
}
|
|
|
|
private void ShowCurrentFile()
|
|
{
|
|
imagePanel1.ImageToView = null;
|
|
if (fileIndex >= 0 && fileIndex < images.Length)
|
|
{
|
|
try
|
|
{
|
|
string path = images[fileIndex].Path;
|
|
Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
|
byte[] buffer = new byte[stream.Length];
|
|
stream.Read(buffer, 0, (int)stream.Length);
|
|
stream.Dispose();
|
|
stream.Close();
|
|
imagePanel1.zoom = -1f;
|
|
imagePanel1.ImageToView = (Bitmap)Image.FromStream(new MemoryStream(buffer));
|
|
toolTip1.SetToolTip(imagePanel1, path);
|
|
imagePanel1.Text = "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
imagePanel1.ImageToView = null;
|
|
imagePanel1.ForeColor = Color.Red;
|
|
imagePanel1.Text = Resources.Status39 + "\n\n" + ex.Message;
|
|
}
|
|
}
|
|
imagePanel1.Invalidate();
|
|
}
|
|
|
|
public void RefreshForEntry(string id)
|
|
{
|
|
currentID = id;
|
|
Clear();
|
|
if (id == "")
|
|
{
|
|
return;
|
|
}
|
|
MyNesDBEntryInfo entry = MyNesDB.GetEntry(id);
|
|
label_name.Text = entry.Name;
|
|
toolTip1.SetToolTip(label_name, entry.Name);
|
|
label_size.Text = GetSize(entry.Size);
|
|
toolTip1.SetToolTip(label_size, label_size.Text);
|
|
label_path.Text = entry.Path;
|
|
toolTip1.SetToolTip(label_path, entry.Path);
|
|
rating1.rating = entry.Rating;
|
|
rating1.Enabled = true;
|
|
List<MyNesDetectEntryInfo> list = new List<MyNesDetectEntryInfo>();
|
|
list.AddRange(MyNesDB.GetDetects("SNAPS", id));
|
|
list.AddRange(MyNesDB.GetDetects("COVERS", id));
|
|
images = list.ToArray();
|
|
if (images.Length != 0)
|
|
{
|
|
fileIndex = 0;
|
|
}
|
|
if (Program.Settings.LauncherAutoCycleImagesInGameTab)
|
|
{
|
|
timer1.Start();
|
|
}
|
|
ShowCurrentFile();
|
|
DataSet entryDataSet = MyNesDB.GetEntryDataSet(currentID);
|
|
for (int i = 0; i < entryDataSet.Tables[0].Columns.Count; i++)
|
|
{
|
|
if (!(entryDataSet.Tables[0].Columns[i].ToString() != "Id") || !(entryDataSet.Tables[0].Columns[i].ToString() != "IsDB"))
|
|
{
|
|
continue;
|
|
}
|
|
string text = entryDataSet.Tables[0].Columns[i].ToString();
|
|
string text2 = entryDataSet.Tables[0].Rows[0][entryDataSet.Tables[0].Columns[i].ToString()].ToString().Replace("'", "'");
|
|
listView1.Items.Add(text);
|
|
switch (text)
|
|
{
|
|
case "Played":
|
|
text2 = ((!(text2 == "0")) ? ((!(text2 == "1")) ? (text2 + " " + Resources.Text2) : Resources.Text1) : Resources.Text0);
|
|
break;
|
|
case "Play Time":
|
|
{
|
|
if (text2 == "0")
|
|
{
|
|
text2 = Resources.Text0;
|
|
break;
|
|
}
|
|
int result = 0;
|
|
int.TryParse(text2, out result);
|
|
text2 = TimeSpan.FromSeconds(result).ToString();
|
|
break;
|
|
}
|
|
case "Size":
|
|
{
|
|
int result2 = 0;
|
|
int.TryParse(text2, out result2);
|
|
text2 = GetSize(result2);
|
|
break;
|
|
}
|
|
case "Last Played":
|
|
{
|
|
DateTime dateTime = (DateTime)entryDataSet.Tables[0].Rows[0][text];
|
|
text2 = ((!(dateTime != DateTime.MinValue)) ? Resources.Text0 : dateTime.ToLocalTime().ToString());
|
|
break;
|
|
}
|
|
}
|
|
listView1.Items[listView1.Items.Count - 1].SubItems.Add(text2);
|
|
}
|
|
}
|
|
|
|
private string GetSize(long size)
|
|
{
|
|
string text = " Byte";
|
|
double num = size;
|
|
if (size >= 1024)
|
|
{
|
|
num = (double)size / 1024.0;
|
|
text = " KB";
|
|
}
|
|
if (num >= 1024.0)
|
|
{
|
|
num /= 1024.0;
|
|
text = " MB";
|
|
}
|
|
if (num >= 1024.0)
|
|
{
|
|
num /= 1024.0;
|
|
text = " GB";
|
|
}
|
|
if (num < 0.0)
|
|
{
|
|
return "???";
|
|
}
|
|
return num.ToString("F2") + text;
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
if (!Program.Settings.LauncherAutoCycleImagesInGameTab)
|
|
{
|
|
timer1.Stop();
|
|
return;
|
|
}
|
|
if (NesEmu.ON)
|
|
{
|
|
timer1.Stop();
|
|
return;
|
|
}
|
|
if (images == null)
|
|
{
|
|
timer1.Stop();
|
|
return;
|
|
}
|
|
if (images.Length != 0)
|
|
{
|
|
fileIndex = (fileIndex + 1) % images.Length;
|
|
}
|
|
else
|
|
{
|
|
fileIndex = -1;
|
|
}
|
|
ShowCurrentFile();
|
|
}
|
|
|
|
private void rating1_RatingChanged(object sender, EventArgs e)
|
|
{
|
|
if (currentID == "")
|
|
{
|
|
rating1.rating = 0;
|
|
return;
|
|
}
|
|
if (MyNesDB.IsDatabaseLoaded)
|
|
{
|
|
MyNesDB.UpdateEntry(currentID, rating1.rating);
|
|
}
|
|
if (this.RatingChanged != null)
|
|
{
|
|
this.RatingChanged(rating1, new EventArgs());
|
|
}
|
|
}
|
|
|
|
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
RichTextBox richTextBox = new RichTextBox();
|
|
foreach (ListViewItem item in listView1.Items)
|
|
{
|
|
RichTextBox richTextBox2 = richTextBox;
|
|
richTextBox2.Text = richTextBox2.Text + item.Text + ": " + item.SubItems[1].Text + "\n";
|
|
}
|
|
richTextBox.SelectAll();
|
|
richTextBox.Copy();
|
|
MessageBox.Show(Resources.Message47);
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing && components != null)
|
|
{
|
|
components.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
this.components = new System.ComponentModel.Container();
|
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MyNes.GameInfoViewer));
|
|
this.panel1 = new System.Windows.Forms.Panel();
|
|
this.rating1 = new MyNes.Rating();
|
|
this.label_path = new System.Windows.Forms.Label();
|
|
this.label_size = new System.Windows.Forms.Label();
|
|
this.label_name = new System.Windows.Forms.Label();
|
|
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
|
this.imagePanel1 = new MyNes.ImagePanel();
|
|
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
|
|
this.listView1 = new System.Windows.Forms.ListView();
|
|
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
|
|
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
|
|
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
|
this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
|
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
|
this.panel1.SuspendLayout();
|
|
this.groupBox1.SuspendLayout();
|
|
this.contextMenuStrip1.SuspendLayout();
|
|
base.SuspendLayout();
|
|
resources.ApplyResources(this.panel1, "panel1");
|
|
this.panel1.Controls.Add(this.rating1);
|
|
this.panel1.Controls.Add(this.label_path);
|
|
this.panel1.Controls.Add(this.label_size);
|
|
this.panel1.Controls.Add(this.label_name);
|
|
this.panel1.Controls.Add(this.groupBox1);
|
|
this.panel1.Name = "panel1";
|
|
this.toolTip1.SetToolTip(this.panel1, resources.GetString("panel1.ToolTip"));
|
|
resources.ApplyResources(this.rating1, "rating1");
|
|
this.rating1.Name = "rating1";
|
|
this.rating1.rating = 0;
|
|
this.toolTip1.SetToolTip(this.rating1, resources.GetString("rating1.ToolTip"));
|
|
this.rating1.RatingChanged += new System.EventHandler(rating1_RatingChanged);
|
|
resources.ApplyResources(this.label_path, "label_path");
|
|
this.label_path.AutoEllipsis = true;
|
|
this.label_path.Name = "label_path";
|
|
this.toolTip1.SetToolTip(this.label_path, resources.GetString("label_path.ToolTip"));
|
|
resources.ApplyResources(this.label_size, "label_size");
|
|
this.label_size.AutoEllipsis = true;
|
|
this.label_size.Name = "label_size";
|
|
this.toolTip1.SetToolTip(this.label_size, resources.GetString("label_size.ToolTip"));
|
|
resources.ApplyResources(this.label_name, "label_name");
|
|
this.label_name.AutoEllipsis = true;
|
|
this.label_name.Name = "label_name";
|
|
this.toolTip1.SetToolTip(this.label_name, resources.GetString("label_name.ToolTip"));
|
|
resources.ApplyResources(this.groupBox1, "groupBox1");
|
|
this.groupBox1.Controls.Add(this.imagePanel1);
|
|
this.groupBox1.Name = "groupBox1";
|
|
this.groupBox1.TabStop = false;
|
|
this.toolTip1.SetToolTip(this.groupBox1, resources.GetString("groupBox1.ToolTip"));
|
|
resources.ApplyResources(this.imagePanel1, "imagePanel1");
|
|
this.imagePanel1.BackColor = System.Drawing.SystemColors.Control;
|
|
this.imagePanel1.DefaultImage = MyNes.Properties.Resources.MyNesImage;
|
|
this.imagePanel1.ImageToView = null;
|
|
this.imagePanel1.ImageViewMode = MyNes.ImageViewMode.StretchIfLarger;
|
|
this.imagePanel1.Name = "imagePanel1";
|
|
this.toolTip1.SetToolTip(this.imagePanel1, resources.GetString("imagePanel1.ToolTip"));
|
|
resources.ApplyResources(this.listView1, "listView1");
|
|
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[2] { this.columnHeader1, this.columnHeader2 });
|
|
this.listView1.ContextMenuStrip = this.contextMenuStrip1;
|
|
this.listView1.FullRowSelect = true;
|
|
this.listView1.GridLines = true;
|
|
this.listView1.MultiSelect = false;
|
|
this.listView1.Name = "listView1";
|
|
this.listView1.ShowItemToolTips = true;
|
|
this.toolTip1.SetToolTip(this.listView1, resources.GetString("listView1.ToolTip"));
|
|
this.listView1.UseCompatibleStateImageBehavior = false;
|
|
this.listView1.View = System.Windows.Forms.View.Details;
|
|
resources.ApplyResources(this.columnHeader1, "columnHeader1");
|
|
resources.ApplyResources(this.columnHeader2, "columnHeader2");
|
|
resources.ApplyResources(this.contextMenuStrip1, "contextMenuStrip1");
|
|
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[1] { this.copyToolStripMenuItem });
|
|
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
|
this.toolTip1.SetToolTip(this.contextMenuStrip1, resources.GetString("contextMenuStrip1.ToolTip"));
|
|
resources.ApplyResources(this.copyToolStripMenuItem, "copyToolStripMenuItem");
|
|
this.copyToolStripMenuItem.Name = "copyToolStripMenuItem";
|
|
this.copyToolStripMenuItem.Click += new System.EventHandler(copyToolStripMenuItem_Click);
|
|
this.timer1.Interval = 1500;
|
|
this.timer1.Tick += new System.EventHandler(timer1_Tick);
|
|
resources.ApplyResources(this, "$this");
|
|
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
base.Controls.Add(this.listView1);
|
|
base.Controls.Add(this.panel1);
|
|
base.Name = "GameInfoViewer";
|
|
this.toolTip1.SetToolTip(this, resources.GetString("$this.ToolTip"));
|
|
this.panel1.ResumeLayout(false);
|
|
this.groupBox1.ResumeLayout(false);
|
|
this.contextMenuStrip1.ResumeLayout(false);
|
|
base.ResumeLayout(false);
|
|
}
|
|
}
|