Skip to content
This repository was archived by the owner on Feb 19, 2021. It is now read-only.

Commit 32e7944

Browse files
author
Sammy Sammon
committed
More null checks everywhere
1 parent 7d31de0 commit 32e7944

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

MainForm.cs

+18-9
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ await Task.Run(() =>
225225

226226
picFavourite.SizeChanged += PicFavourite_SizeChanged;
227227

228-
bool favourite = songInfoStream?.currentInfo.song.favorite ?? false;
228+
bool favourite = songInfoStream?.currentInfo?.song.favorite ?? false;
229229
picFavourite.Image = favourite ? favSprite.Frames[favSprite.Frames.Length - 1] : favSprite.Frames[0];
230230

231231
ReloadScale();
@@ -558,7 +558,7 @@ private void ReloadSprites()
558558
picPlayPause.Image = Properties.Resources.play;
559559
}
560560

561-
if (songInfoStream?.currentInfo.song.favorite ?? false)
561+
if (songInfoStream?.currentInfo?.song.favorite ?? false)
562562
picFavourite.Image = favSprite?.Frames[favSprite.Frames.Length - 1];
563563
else
564564
picFavourite.Image = favSprite?.Frames[0];
@@ -667,7 +667,10 @@ private void SetPlayPauseSize(bool bigger)
667667
private void menuItemCopySongInfo_Click(object sender, EventArgs e)
668668
{
669669
SongInfoResponseData info = songInfoStream.currentInfo;
670-
Clipboard.SetText(info.song.title + " \n" + string.Join(", ", info.song.artists.Select(a => a.name)) + " \n" + info.song.source);
670+
if (info != null)
671+
{
672+
Clipboard.SetText(info.song.title + " \n" + string.Join(", ", info.song.artists.Select(a => a.name)) + " \n" + info.song.source);
673+
}
671674
}
672675

673676
private void picSettings_Click(object sender, EventArgs e)
@@ -753,33 +756,39 @@ private async void SetFavouriteSprite(bool favourited)
753756
}
754757

755758
isAnimating = false;
756-
songInfoStream.currentInfo.song.favorite = true;
759+
if (songInfoStream.currentInfo != null && songInfoStream.currentInfo.song != null)
760+
songInfoStream.currentInfo.song.favorite = true;
757761
}
758762
else
759763
{
760764
lock (animationLock)
761765
isAnimating = false;
762766
picFavourite.Image = favSprite.Frames[0];
763-
songInfoStream.currentInfo.song.favorite = false;
767+
if (songInfoStream.currentInfo != null && songInfoStream.currentInfo.song != null)
768+
songInfoStream.currentInfo.song.favorite = false;
764769
}
765770
}
766771

767772
private async void picFavourite_Click(object sender, EventArgs e)
768773
{
769-
bool currentStatus = songInfoStream?.currentInfo.song.favorite ?? false;
774+
bool currentStatus = songInfoStream?.currentInfo?.song.favorite ?? false;
770775
bool newStatus = !currentStatus;
771-
songInfoStream.currentInfo.song.favorite = newStatus;
776+
777+
if (songInfoStream.currentInfo != null && songInfoStream.currentInfo.song != null)
778+
songInfoStream.currentInfo.song.favorite = newStatus;
772779

773780
SetFavouriteSprite(newStatus);
774781

775782
(bool success, string result) = await WebHelper.Post("https://listen.moe/api/songs/favorite", Settings.Get<string>(Setting.Token), new Dictionary<string, string>() {
776-
["song"] = songInfoStream.currentInfo.song.id.ToString()
783+
["song"] = songInfoStream?.currentInfo?.song.id.ToString() ?? ""
777784
}, true);
778785

779786
var response = JsonConvert.DeserializeObject<FavouritesResponse>(result);
780787
picFavourite.Image = response.favorite ? favSprite.Frames[favSprite.Frames.Length - 1] :
781788
spriteColorInverted ? darkFavSprite.Frames[0] : favSprite.Frames[0];
782-
songInfoStream.currentInfo.song.favorite = response.favorite;
789+
790+
if (songInfoStream.currentInfo != null && songInfoStream.currentInfo.song != null)
791+
songInfoStream.currentInfo.song.favorite = response.favorite;
783792
}
784793

785794
private void menuItemResetLocation_Click(object sender, EventArgs e)

0 commit comments

Comments
 (0)