Skip to content

Commit

Permalink
Fix more bugs, add Internet connection test prompt and other makeovers
Browse files Browse the repository at this point in the history
  • Loading branch information
CatmanFan committed Jan 22, 2025
1 parent 9cf56ea commit 51836c7
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 70 deletions.
1 change: 0 additions & 1 deletion FriishProduce/FriishProduce.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@
<ItemGroup>
<Content Include="icon.ico" />
<None Include="Resources\vc\saveicon_placeholder_c.png" />
<None Include="Resources\Icon_C64.png" />
<None Include="Resources\apps\tg16inject1.exe" />
<None Include="Resources\apps\bincuesplit1.exe" />
<None Include="Resources\apps\tg16inject.exe" />
Expand Down
76 changes: 70 additions & 6 deletions FriishProduce/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial class MainForm : Form
{
private readonly string[] files = null;
private readonly SettingsForm settings = new();
private Wait wait = new(false);

#region //////////////////// Platforms ////////////////////
public readonly IDictionary<Platform, Bitmap> Icons = new Dictionary<Platform, Bitmap>
Expand All @@ -26,9 +27,7 @@ public partial class MainForm : Form
{ Platform.PCE, new Icon(Properties.Resources.nec_turbografx_16, 16, 16).ToBitmap() },
{ Platform.PCECD, new Icon(Properties.Resources.nec_turbografx_16, 16, 16).ToBitmap() },
{ Platform.NEO, new Icon(Properties.Resources.snk_neo_geo_aes, 16, 16).ToBitmap() },
#if DEBUG
{ Platform.C64, Properties.Resources.c64 },
#endif
{ Platform.MSX, Properties.Resources.msx },
{ Platform.PSX, new Icon(Properties.Resources.sony_playstation, 16, 16).ToBitmap() },
{ Platform.Flash, Properties.Resources.flash },
Expand All @@ -49,10 +48,8 @@ public partial class MainForm : Form
null,
Platform.NEO.ToString(),
null,
#if DEBUG
Platform.C64.ToString(),
null,
#endif
Platform.MSX.ToString(),
null,
Platform.Flash.ToString(),
Expand Down Expand Up @@ -235,6 +232,70 @@ private void MainForm_Closing(object sender, FormClosingEventArgs e)
}
}

/// <summary>
/// Displays wait dialog.
/// </summary>
/// <param name="reset">Resets the dialog.</param>
/// <param name="show">Shows or hides the dialog.</param>
/// <param name="msg">The message to display.</param>
/// <param name="progress">Progress value</param>
/// <param name="showProgress">Whether to display the progress bar.</param>
public void Wait(bool show, bool reset, bool showProgress, int progress = 0, int msg = 0)
{
if (InvokeRequired)
{
Invoke(new MethodInvoker(delegate
{
Enabled = !show;

if (show)
{
if (reset || wait == null)
{
if (wait != null) wait.Visible = false;
wait = new(showProgress, msg) { Visible = false };
}

if (!wait.Visible)
wait.Show(this);
}

else
{
if (wait != null) wait.Visible = false;
Select();
}

wait.progress.Value = progress;
}));
}

else
{
Enabled = !show;

if (show)
{
if (reset || wait == null)
{
if (wait != null) wait.Visible = false;
wait = new(showProgress, msg) { Visible = false };
}

if (!wait.Visible)
wait.Show(this);
}

else
{
if (wait != null) wait.Visible = false;
Select();
}

wait.progress.Value = progress;
}
}

private void Settings_Click(object sender, EventArgs e) => settings.ShowDialog(this);

public void TabChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -451,7 +512,7 @@ private void OpenRecent(object sender, EventArgs e)
var control = sender as MenuItem;
var list = open_recent.MenuItems.OfType<MenuItem>().Where(x => x.Text == control?.Text).ToArray();

if (list.Length > 1)
if (list?.Length > 0)
{
for (int i = 0; i < 10; i++)
{
Expand All @@ -469,7 +530,10 @@ private void OpenRecent(object sender, EventArgs e)
0 or _ => Program.Config.paths.recent_00
};

if (Path.GetFileName(file)?.Replace("&", "&&") == list[0].Text)
string title1 = Path.GetFileName(file)?.Replace("&", "&&");
string title2 = list[0].Text;

if (title1 == title2)
{
OpenProject(new string[] { file });
return;
Expand Down
119 changes: 73 additions & 46 deletions FriishProduce/ProjectForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public partial class ProjectForm : Form
protected Platform targetPlatform { get; set; }
private readonly BannerOptions banner_form;
private readonly Savedata savedata;
private Wait wait = new(false);
private HTMLForm htmlForm;

protected string TIDCode;
Expand Down Expand Up @@ -107,24 +106,6 @@ public bool IsEmpty
}
}

public void Wait(bool show, int msg = 0, bool showProgress = false)
{
Invoke(new MethodInvoker(delegate
{
if (!show) ParentForm.Select();

if (show)
{
wait = new(showProgress, msg);
wait.Show(this);
}
else
wait.Hide();

(ParentForm as MainForm).Enabled = Enabled = !show;
}));
}

public bool IsExportable
{
get
Expand Down Expand Up @@ -354,23 +335,66 @@ private libWiiSharp.Region _bannerRegion

// -----------------------------------

private void SetRecentProjects(string path)
private void SetRecentProjects(string project)
{
if (path != Program.Config.paths.recent_00)
int max = 10;
bool modified = false;

// Add project to #1 slot
// ********
if (project != Program.Config.paths.recent_00)
{
Program.Config.paths.recent_09 = Program.Config.paths.recent_08;
Program.Config.paths.recent_08 = Program.Config.paths.recent_07;
Program.Config.paths.recent_07 = Program.Config.paths.recent_06;
Program.Config.paths.recent_06 = Program.Config.paths.recent_05;
Program.Config.paths.recent_05 = Program.Config.paths.recent_04;
Program.Config.paths.recent_04 = Program.Config.paths.recent_03;
Program.Config.paths.recent_03 = Program.Config.paths.recent_02;
Program.Config.paths.recent_02 = Program.Config.paths.recent_01;
Program.Config.paths.recent_01 = Program.Config.paths.recent_00;
Program.Config.paths.recent_00 = path;
for (int i = 0; i < max - 1; i++)
{
var prop1 = Program.Config.paths.GetType().GetProperty($"recent_{i:D2}");
var prop2 = Program.Config.paths.GetType().GetProperty($"recent_{i + 1:D2}");
prop2.SetValue(Program.Config.paths, prop1.GetValue(Program.Config.paths, null));
}

Program.Config.Save();
Program.Config.paths.recent_00 = project;
modified = true;
}

// Clean duplicate projects if there are any
// ********
for (int x = 0; x < max; x++)
{
var prop1 = Program.Config.paths.GetType().GetProperty($"recent_{x:D2}");
var path1 = prop1.GetValue(Program.Config.paths, null)?.ToString();

for (int y = x; y < max; y++)
{
var prop2 = Program.Config.paths.GetType().GetProperty($"recent_{y:D2}");
var path2 = prop2.GetValue(Program.Config.paths, null)?.ToString();

if (path1 == path2 && path2 != null && x != y)
{
prop2.SetValue(Program.Config.paths, null);
modified = true;
}
}
}

// Resort slots in case of empty ones
// ********
for (int i = 0; i < max - 1; i++)
{
var prop1 = Program.Config.paths.GetType().GetProperty($"recent_{i:D2}");

if (prop1.GetValue(Program.Config.paths, null)?.ToString() == null)
{
var prop2 = Program.Config.paths.GetType().GetProperty($"recent_{i + 1:D2}");

prop1.SetValue(Program.Config.paths, prop2.GetValue(Program.Config.paths, null));
prop2.SetValue(Program.Config.paths, null);

modified = true;
}
}

if (modified)
{
Program.Config.Save();
Program.MainForm.RefreshRecent();
}
}
Expand Down Expand Up @@ -1266,12 +1290,9 @@ public bool LoadWAD(string path)

Failed:
SystemSounds.Beep.Play();
try
{
MessageBox.Show(string.Format(Program.Lang.Msg(5), Reader.UpperTitleID));
Reader.Dispose();
}
catch { Reader = null; }
MessageBox.Show(string.Format(Program.Lang.Msg(5), Reader.UpperTitleID == "\0\0\0\0" || Reader.UpperTitleID.Length != 4 ? Program.Lang.String("none") : Reader.UpperTitleID));

try { Reader.Dispose(); } catch { Reader = null; }
inWadFile = null;
return false;
}
Expand Down Expand Up @@ -1533,6 +1554,7 @@ public void LoadROM(string ROMpath, bool AutoScan = true, bool filter = false)
/// Gets any game metadata that is available for the file based on its CRC32 reading hash, including the software title, year, players, and title image URL.
/// </summary>
/// <param name="platform"></param>
/// <param name="path">The ROM/ISO path.</param>
/// <returns></returns>
protected (string Name, string Serial, string Year, string Players, string Image, bool IsComplete) GetGameData(Platform platform, string path)
{
Expand All @@ -1548,6 +1570,10 @@ public void LoadROM(string ROMpath, bool AutoScan = true, bool filter = false)
return (null, null, null, null, null, false);
}

if (Databases.LibRetro.IsWeb(platform))
Web.InternetTest();
Program.MainForm.Wait(true, true, false);

var result = Databases.LibRetro.Read(path, platform);

if (!string.IsNullOrEmpty(result.Name))
Expand All @@ -1563,8 +1589,6 @@ public async void GameScan(bool imageOnly)
{
if (rom == null || rom.FilePath == null) return;

Wait(true);

try
{
(string Name, string Serial, string Year, string Players, string Image, bool IsComplete) gameData = (null, null, null, null, null, false);
Expand Down Expand Up @@ -1596,13 +1620,13 @@ public async void GameScan(bool imageOnly)
// Set image
if (!string.IsNullOrEmpty(gameData.Image))
{
LoadImage(gameData.Image);
await Task.Run(() => { LoadImage(gameData.Image); });
}

resetImages(true);
}

Wait(false);
Program.MainForm.Wait(false, false, false);

// Show message if partially failed to retrieve data
if (retrieved && !gameData.IsComplete && !imageOnly)
Expand All @@ -1612,17 +1636,16 @@ public async void GameScan(bool imageOnly)

catch (Exception ex)
{
Wait(false);
Program.MainForm.Wait(false, false, false);
MessageBox.Error(ex.Message);
}
}

public void SaveToWAD(string targetFile = null) => backgroundWorker.RunWorkerAsync(targetFile);
private void saveToWAD_UpdateProgress(object sender, System.ComponentModel.ProgressChangedEventArgs e) => wait.progress.Value = e.ProgressPercentage;
private void saveToWAD_UpdateProgress(object sender, System.ComponentModel.ProgressChangedEventArgs e) => Program.MainForm.Wait(true, false, true, e.ProgressPercentage);
private void saveToWAD(object sender, System.ComponentModel.DoWorkEventArgs e)
{
Exception error = null;
Wait(true, 1, true);

string targetFile = e.Argument.ToString();
if (targetFile == null) targetFile = Paths.WorkingFolder + "out.wad";
Expand Down Expand Up @@ -1675,6 +1698,10 @@ private void saveToWAD(object sender, System.ComponentModel.DoWorkEventArgs e)
Start:
// Get WAD data
// *******
if (inWadFile == null)
Web.InternetTest();
Program.MainForm.Wait(true, true, true, 0, 1);

if (inWadFile != null) m.GetWAD(inWadFile, baseID.Text);
else
{
Expand Down Expand Up @@ -1747,7 +1774,7 @@ private void saveToWAD(object sender, System.ComponentModel.DoWorkEventArgs e)

finally
{
Wait(false);
Program.MainForm.Wait(false, false, false);
Program.CleanTemp();

Invoke(new MethodInvoker(delegate
Expand Down
1 change: 1 addition & 0 deletions FriishProduce/Strings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"do_not_show": "Do not show this again",
"busy0": "Please wait...",
"busy1": "Exportation in progress...",
"busy2": "Testing Internet connection...",

"by_default": "Default",
"disabled": "Disabled",
Expand Down
1 change: 1 addition & 0 deletions FriishProduce/Strings/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"do_not_show": "No volver a mostrar este mensaje",
"busy0": "Cargando...",
"busy1": "Exportación en curso...",
"busy2": "Probando la conexión de Internet...",

"by_default": "Por defecto",
"disabled": "Deshabilitado(a)",
Expand Down
1 change: 1 addition & 0 deletions FriishProduce/Strings/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"do_not_show": "Ne plus afficher ce message",
"busy0": "Veuillez patienter ...",
"busy1": "Exportation en cours ...",
"busy2": "Test de connexion en cours ...",

"by_default": "Par défaut",
"disabled": "Désactivé(e)",
Expand Down
Binary file modified FriishProduce/Strings/ja.json
Binary file not shown.
1 change: 1 addition & 0 deletions FriishProduce/Strings/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"do_not_show": "다시 표시하지 않음",
"busy0": "잠시만 기다리세요...",
"busy1": "내보내기 진행 중...",
"busy2": "Testing Internet connection...",

"by_default": "기본값",
"disabled": "비활성화",
Expand Down
3 changes: 2 additions & 1 deletion FriishProduce/Subforms/Wait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public Wait(bool showProgress, int msg = 0)
fader.Tick += Fade;
fader.Start();

label1.Font = Program.MainForm.Font;
if (Program.MainForm != null)
label1.Font = Program.MainForm.Font;
label1.Text = Program.Lang.String($"busy{msg}");

progress.Visible = showProgress;
Expand Down
Loading

0 comments on commit 51836c7

Please sign in to comment.