UI: Fixed load performance issues with game selection screen
This commit is contained in:
parent
bf6a8a2de2
commit
d137dec59f
2 changed files with 16 additions and 27 deletions
|
@ -43,8 +43,8 @@ namespace Mesen.GUI.Controls
|
|||
|
||||
_recentGame = value;
|
||||
|
||||
lblGameName.Text = Path.GetFileNameWithoutExtension(_recentGame.RomName);
|
||||
lblSaveDate.Text = _recentGame.Timestamp.ToString();
|
||||
lblGameName.Text = Path.GetFileNameWithoutExtension(_recentGame.FileName);
|
||||
lblSaveDate.Text = new FileInfo(_recentGame.FileName).LastWriteTime.ToString();
|
||||
|
||||
lblGameName.Visible = true;
|
||||
lblSaveDate.Visible = true;
|
||||
|
@ -53,13 +53,17 @@ namespace Mesen.GUI.Controls
|
|||
Task.Run(() => {
|
||||
Image img = null;
|
||||
try {
|
||||
ZipArchive zip = new ZipArchive(new MemoryStream(File.ReadAllBytes(_recentGame.FileName)));
|
||||
ZipArchive zip = new ZipArchive(new MemoryStream(File.ReadAllBytes(value.FileName)));
|
||||
ZipArchiveEntry entry = zip.GetEntry("Screenshot.png");
|
||||
if(entry != null) {
|
||||
using(Stream stream = entry.Open()) {
|
||||
img = Image.FromStream(stream);
|
||||
}
|
||||
}
|
||||
using(StreamReader sr = new StreamReader(zip.GetEntry("RomInfo.txt").Open())) {
|
||||
string romName = sr.ReadLine();
|
||||
value.RomPath = sr.ReadLine();
|
||||
}
|
||||
} catch { }
|
||||
|
||||
this.BeginInvoke((Action)(() => {
|
||||
|
|
|
@ -100,6 +100,9 @@ namespace Mesen.GUI.Controls
|
|||
}
|
||||
tlpGrid.ResumeLayout();
|
||||
UpdateGameInfo();
|
||||
|
||||
picPrevGame.Visible = _recentGames.Count > _elementsPerPage;
|
||||
picNextGame.Visible = _recentGames.Count > _elementsPerPage;
|
||||
}
|
||||
|
||||
public new bool Visible
|
||||
|
@ -134,31 +137,15 @@ namespace Mesen.GUI.Controls
|
|||
_recentGames = new List<RecentGameInfo>();
|
||||
_currentIndex = 0;
|
||||
|
||||
foreach(string file in Directory.GetFiles(ConfigManager.RecentGamesFolder, "*.rgd")) {
|
||||
List<string> files = Directory.GetFiles(ConfigManager.RecentGamesFolder, "*.rgd").OrderByDescending((file) => new FileInfo(file).LastWriteTime).ToList();
|
||||
for(int i = 0; i < files.Count && _recentGames.Count < 36; i++) {
|
||||
try {
|
||||
RecentGameInfo info = new RecentGameInfo();
|
||||
ZipArchive zip = new ZipArchive(new MemoryStream(File.ReadAllBytes(file)));
|
||||
|
||||
using(StreamReader sr = new StreamReader(zip.GetEntry("RomInfo.txt").Open())) {
|
||||
info.RomName = sr.ReadLine();
|
||||
info.RomPath = sr.ReadLine();
|
||||
}
|
||||
|
||||
info.Timestamp = new FileInfo(file).LastWriteTime;
|
||||
info.FileName = file;
|
||||
|
||||
if(info.RomPath.Exists) {
|
||||
_recentGames.Add(info);
|
||||
}
|
||||
info.FileName = files[i];
|
||||
_recentGames.Add(info);
|
||||
} catch { }
|
||||
}
|
||||
|
||||
_recentGames = _recentGames.OrderBy((info) => info.Timestamp).Reverse().ToList();
|
||||
|
||||
if(_recentGames.Count > 36) {
|
||||
_recentGames.RemoveRange(36, _recentGames.Count - 36);
|
||||
}
|
||||
|
||||
InitGrid();
|
||||
|
||||
if(_recentGames.Count == 0) {
|
||||
|
@ -169,8 +156,8 @@ namespace Mesen.GUI.Controls
|
|||
tmrInput.Enabled = true;
|
||||
}
|
||||
|
||||
picPrevGame.Visible = true;
|
||||
picNextGame.Visible = true;
|
||||
picPrevGame.Visible = _recentGames.Count > _elementsPerPage;
|
||||
picNextGame.Visible = _recentGames.Count > _elementsPerPage;
|
||||
}
|
||||
|
||||
public void UpdateGameInfo()
|
||||
|
@ -356,8 +343,6 @@ namespace Mesen.GUI.Controls
|
|||
public class RecentGameInfo
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string RomName { get; set; }
|
||||
public ResourcePath RomPath { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue