Improve handling of RA http requests, add some handling in case RA sound files are missing. Normally this shouldn't be needed as docs specify if the wav file fails to load it plays the default beep sound, except actually it just throws in practice???
The 2.9 rcs apparently have the "overlay" folder missing, so the sound files aren't present. I'm assuming there's some issue with build scripts there for releases...
This commit is contained in:
parent
f3ee3e7956
commit
767cc9059d
|
@ -1,28 +1,25 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public partial class RCheevos
|
||||
{
|
||||
private static readonly HttpClient _http = new();
|
||||
private static readonly HttpClient _http = new() { DefaultRequestHeaders = { ConnectionClose = true } };
|
||||
|
||||
private static async Task<byte[]> HttpGet(string url)
|
||||
{
|
||||
_http.DefaultRequestHeaders.ConnectionClose = false;
|
||||
var response = await _http.GetAsync(url).ConfigureAwait(false);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
|
||||
}
|
||||
return null;
|
||||
return new byte[1];
|
||||
}
|
||||
|
||||
private static async Task<byte[]> HttpPost(string url, string post)
|
||||
{
|
||||
_http.DefaultRequestHeaders.ConnectionClose = true;
|
||||
HttpResponseMessage response;
|
||||
try
|
||||
{
|
||||
|
@ -30,11 +27,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(e.ToString()); // bleh
|
||||
Console.WriteLine(e);
|
||||
return new byte[1];
|
||||
}
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return null;
|
||||
return new byte[1];
|
||||
}
|
||||
return await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
config.RAUsername = Username;
|
||||
config.RAToken = ApiToken;
|
||||
InitLoginDone.Set();
|
||||
if (EnableSoundEffects) _loginSound.Play();
|
||||
if (EnableSoundEffects) _loginSound.PlayNoExceptions();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (LoggedIn && EnableSoundEffects)
|
||||
{
|
||||
_loginSound.Play();
|
||||
_loginSound.PlayNoExceptions();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,4 +18,18 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private bool EnableSoundEffects { get; set; }
|
||||
}
|
||||
|
||||
public static class SoundPlayerExtensions
|
||||
{
|
||||
public static void PlayNoExceptions(this SoundPlayer sound)
|
||||
{
|
||||
try
|
||||
{
|
||||
sound.Play();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -436,7 +436,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var prefix = HardcoreMode ? "[HARDCORE] " : "";
|
||||
_mainForm.AddOnScreenMessage($"{prefix}Achievement Unlocked!");
|
||||
_mainForm.AddOnScreenMessage(cheevo.Description);
|
||||
if (EnableSoundEffects) _unlockSound.Play();
|
||||
if (EnableSoundEffects) _unlockSound.PlayNoExceptions();
|
||||
|
||||
if (cheevo.IsOfficial)
|
||||
{
|
||||
|
@ -457,7 +457,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var prefix = HardcoreMode ? "[HARDCORE] " : "";
|
||||
_mainForm.AddOnScreenMessage($"{prefix}Achievement Primed!");
|
||||
_mainForm.AddOnScreenMessage(cheevo.Description);
|
||||
if (EnableSoundEffects) _infoSound.Play();
|
||||
if (EnableSoundEffects) _infoSound.PlayNoExceptions();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -476,7 +476,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
CurrentLboard = lboard;
|
||||
_mainForm.AddOnScreenMessage($"Leaderboard Attempt Started!");
|
||||
_mainForm.AddOnScreenMessage(lboard.Description);
|
||||
if (EnableSoundEffects) _lboardStartSound.Play();
|
||||
if (EnableSoundEffects) _lboardStartSound.PlayNoExceptions();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -498,7 +498,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
_mainForm.AddOnScreenMessage($"Leaderboard Attempt Failed! ({lboard.Score})");
|
||||
_mainForm.AddOnScreenMessage(lboard.Description);
|
||||
if (EnableSoundEffects) _lboardFailedSound.Play();
|
||||
if (EnableSoundEffects) _lboardFailedSound.PlayNoExceptions();
|
||||
}
|
||||
|
||||
lboard.SetScore(0);
|
||||
|
@ -536,7 +536,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
_mainForm.AddOnScreenMessage($"Leaderboard Attempt Complete! ({lboard.Score})");
|
||||
_mainForm.AddOnScreenMessage(lboard.Description);
|
||||
if (EnableSoundEffects) _unlockSound.Play();
|
||||
if (EnableSoundEffects) _unlockSound.PlayNoExceptions();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -563,7 +563,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var prefix = HardcoreMode ? "[HARDCORE] " : "";
|
||||
_mainForm.AddOnScreenMessage($"{prefix}Achievement Unprimed!");
|
||||
_mainForm.AddOnScreenMessage(cheevo.Description);
|
||||
if (EnableSoundEffects) _infoSound.Play();
|
||||
if (EnableSoundEffects) _infoSound.PlayNoExceptions();
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue