Apply R# clean-up for reliability (#877)

* Apply R# clean-up for reliability

- Migrate to NUnit4 Assert.That
- Update dependencise versions
- Fix LangVersion to 9.0 (until net core migration)
- Reformat code
- Apply 'var' style (easier for refactoring)
- Remove redundant parentheses
- Add braces on every condition blocks (1 line)
- Uses new null checking patterns
- Uses AutoProperties when possible
- Uses string scalar type instead of class
- Clean usings
- Add .orig files in git ignore
- Rename some properties to respect defined conventions and US format definition
	- ID -> Id
	- BPM -> Bpm
	- Finish -> End

* Update R# settings according to the clean-up made
This commit is contained in:
Quentin Bray authored and GitHub committed 2026-06-22 19:52:06 +02:00
1 parent b9b0f7c8df
commit 6ffa63b923
236 files changed
+14194 -7278

No files matched your search

+110 -60
View File
@@ -27,13 +27,13 @@ namespace VocaluxeLib.Songs
{
public class CSongPointer
{
public readonly int SongID;
public readonly int SongId;
public string SortString;
public bool IsSung;
public CSongPointer(int id, string sortString)
{
SongID = id;
SongId = id;
SortString = sortString;
}
}
@@ -46,7 +46,7 @@ namespace VocaluxeLib.Songs
MP3 = 4,
Instrumental = 5,
Vocals = 6,
BPM = 8,
Bpm = 8,
MedleyStartBeat = 16,
MedleyEndBeat = 32
}
@@ -93,17 +93,17 @@ namespace VocaluxeLib.Songs
public Encoding Encoding = new UTF8Encoding();
public bool ManualEncoding;
public string Folder = String.Empty;
public string FolderName = String.Empty;
public string FileName = String.Empty;
public string Folder = string.Empty;
public string FolderName = string.Empty;
public string FileName = string.Empty;
public bool Relative;
public string MP3FileName = String.Empty;
public string InstrumentalFileName = String.Empty;
public string VocalsFileName = String.Empty;
public string CoverFileName = String.Empty;
public string MP3FileName = string.Empty;
public string InstrumentalFileName = string.Empty;
public string VocalsFileName = string.Empty;
public string CoverFileName = string.Empty;
public readonly List<string> BackgroundFileNames = new List<string>();
public string VideoFileName = String.Empty;
public string VideoFileName = string.Empty;
public EAspect VideoAspect = EAspect.Automatic;
@@ -114,7 +114,10 @@ namespace VocaluxeLib.Songs
get
{
if (_CoverTextureSmall == null)
{
LoadSmallCover();
}
return _CoverTextureSmall;
}
@@ -127,11 +130,11 @@ namespace VocaluxeLib.Songs
set { _CoverTextureBig = value; }
}
public string Title = String.Empty;
public string Artist = String.Empty;
public string Title = string.Empty;
public string Artist = string.Empty;
public string TitleSorting = String.Empty;
public string ArtistSorting = String.Empty;
public string TitleSorting = string.Empty;
public string ArtistSorting = string.Empty;
public string Creator = "";
public string Version = "";
@@ -146,9 +149,9 @@ namespace VocaluxeLib.Songs
/// <summary>
/// End of the song in s (ms in txt)
/// </summary>
public float Finish;
public float End;
public float BPM = 1f;
public float Bpm = 1f;
/// <summary>
/// Gap of the mp3 in s (ms in txt)
/// </summary>
@@ -161,7 +164,7 @@ namespace VocaluxeLib.Songs
private string _Comment = "";
// Sorting
public int ID;
public int Id;
private readonly bool _Visible = true;
private readonly int _CatIndex = -1;
private readonly bool _Selected;
@@ -179,7 +182,7 @@ namespace VocaluxeLib.Songs
public readonly List<string> Languages = new List<string>();
public int DataBaseSongID = -1;
public int DataBaseSongId = -1;
public DateTime DateAdded = DateTime.Today;
public int NumPlayed;
public int NumPlayedSession;
@@ -191,11 +194,16 @@ namespace VocaluxeLib.Songs
{
get
{
var gms = new List<EGameMode> {IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL};
var gms = new List<EGameMode> { IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL };
if (Medley.Source != EDataSource.None)
{
gms.Add(EGameMode.TR_GAMEMODE_MEDLEY);
}
if (ShortEnd.Source != EDataSource.None)
{
gms.Add(EGameMode.TR_GAMEMODE_SHORTSONG);
}
return gms;
}
@@ -212,7 +220,7 @@ namespace VocaluxeLib.Songs
}
//No point creating a song without a text file --> Use factory method LoadSong
private CSong() {}
private CSong() { }
public CSong(CSong song)
{
@@ -255,15 +263,15 @@ namespace VocaluxeLib.Songs
UnknownTags = new List<string>(song.UnknownTags);
Start = song.Start;
Finish = song.Finish;
End = song.End;
BPM = song.BPM;
Bpm = song.Bpm;
Gap = song.Gap;
VideoGap = song.VideoGap;
_Comment = song._Comment;
ID = song.ID;
Id = song.Id;
_Visible = song._Visible;
_CatIndex = song._CatIndex;
_Selected = song._Selected;
@@ -276,7 +284,7 @@ namespace VocaluxeLib.Songs
Languages = new List<string>(song.Languages);
DataBaseSongID = song.DataBaseSongID;
DataBaseSongId = song.DataBaseSongId;
DateAdded = song.DateAdded;
NumPlayed = song.NumPlayed;
NumPlayedSession = song.NumPlayedSession;
@@ -300,9 +308,11 @@ namespace VocaluxeLib.Songs
public bool ReloadSong(bool reloadNotes)
{
var loader = new CSongLoader(this);
bool retValue = loader.ReadHeader();
var retValue = loader.ReadHeader();
if (!retValue)
{
return false;
}
retValue = loader.ReadNotes(reloadNotes);
return retValue;
@@ -352,12 +362,18 @@ namespace VocaluxeLib.Songs
public void LoadSmallCover()
{
if (_CoverTextureSmall != null)
{
return;
}
if (CoverFileName != "")
{
if (CBase.DataBase.GetCover(Path.Combine(Folder, CoverFileName), ref _CoverTextureSmall, CBase.Config.GetCoverSize()))
{
return;
}
}
_CoverTextureSmall = CBase.Cover.GenerateCover(Title, ECoverGeneratorType.Song, null);
}
@@ -365,33 +381,39 @@ namespace VocaluxeLib.Songs
{
if (CoverFileName == "")
{
IEnumerable<string> files = CHelper.ListImageFiles(Folder);
foreach (String file in files)
var files = CHelper.ListImageFiles(Folder);
foreach (var file in files)
{
if (file.ContainsIgnoreCase("[CO]") &&
(file.ContainsIgnoreCase(Title) || file.ContainsIgnoreCase(Artist)))
{
CoverFileName = file;
}
}
}
if (BackgroundFileNames.Count == 0)
{
IEnumerable<string> files = CHelper.ListImageFiles(Folder);
foreach (String file in files)
var files = CHelper.ListImageFiles(Folder);
foreach (var file in files)
{
if (file.ContainsIgnoreCase("[BG]") &&
(file.ContainsIgnoreCase(Title) || file.ContainsIgnoreCase(Artist)))
{
BackgroundFileNames.Add(file);
}
}
}
}
private void _CheckDuet()
{
for (int i = 0; i < Notes.VoiceCount; i++)
for (var i = 0; i < Notes.VoiceCount; i++)
{
if (!Notes.VoiceNames.IsSet(i))
{
CLog.Error("Warning: Can't find #P" + (i + 1) + "-tag for duets in \"" + Artist + " - " + Title + "\".");
}
}
}
@@ -404,42 +426,56 @@ namespace VocaluxeLib.Songs
private List<SSeries> _GetSeries()
{
CVoice voice = Notes.GetVoice(0);
var voice = Notes.GetVoice(0);
if (voice.NumLines == 0)
{
return null;
}
// build sentences list
List<string> sentences = voice.Lines.Select(line => line.Points != 0 ? line.Lyrics : String.Empty).ToList();
var sentences = voice.Lines.Select(line => line.Points != 0 ? line.Lyrics : string.Empty).ToList();
// find equal sentences series
var series = new List<SSeries>();
for (int i = 0; i < voice.NumLines - 1; i++)
for (var i = 0; i < voice.NumLines - 1; i++)
{
for (int j = i + 1; j < voice.NumLines; j++)
for (var j = i + 1; j < voice.NumLines; j++)
{
if (sentences[i] != sentences[j] || sentences[i] == "")
{
continue;
var tempSeries = new SSeries {Start = i, End = i};
}
var tempSeries = new SSeries { Start = i, End = i };
int max;
if (j + j - i > voice.NumLines)
{
max = voice.NumLines - 1 - j;
}
else
{
max = j - i - 1;
}
for (int k = 1; k <= max; k++)
for (var k = 1; k <= max; k++)
{
if (sentences[i + k] == sentences[j + k] && sentences[i + k] != "")
{
tempSeries.End = i + k;
}
else
{
break;
}
}
tempSeries.Length = tempSeries.End - tempSeries.Start + 1;
series.Add(tempSeries);
}
}
return series;
}
@@ -452,21 +488,27 @@ namespace VocaluxeLib.Songs
}
if (!_CalculateMedley || Medley.Source != EDataSource.None)
return;
List<SSeries> series = _GetSeries();
if (series == null)
return;
// search for longest series
int longest = 0;
for (int i = 0; i < series.Count; i++)
{
if (series[i].Length > series[longest].Length)
longest = i;
return;
}
CVoice voice = Notes.GetVoice(0);
var series = _GetSeries();
if (series == null)
{
return;
}
// search for longest series
var longest = 0;
for (var i = 0; i < series.Count; i++)
{
if (series[i].Length > series[longest].Length)
{
longest = i;
}
}
var voice = Notes.GetVoice(0);
// set medley vars
if (series.Count > 0 && series[longest].Length > CBase.Settings.GetMedleyMinSeriesLength())
@@ -474,15 +516,15 @@ namespace VocaluxeLib.Songs
Medley.StartBeat = voice.Lines[series[longest].Start].FirstNoteBeat;
Medley.EndBeat = voice.Lines[series[longest].End].LastNoteBeat;
bool foundEnd = CBase.Game.GetTimeFromBeats(Medley.EndBeat, BPM) - CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) < CBase.Settings.GetMedleyMinDuration();
var foundEnd = CBase.Game.GetTimeFromBeats(Medley.EndBeat, Bpm) - CBase.Game.GetTimeFromBeats(Medley.StartBeat, Bpm) < CBase.Settings.GetMedleyMinDuration();
// set end if duration < MedleyMinDuration
if (!foundEnd)
{
for (int i = series[longest].End + 1; i < voice.NumLines - 1; i++)
for (var i = series[longest].End + 1; i < voice.NumLines - 1; i++)
{
if (CBase.Game.GetTimeFromBeats(voice.Lines[i].LastNoteBeat, BPM) - CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) <
if (CBase.Game.GetTimeFromBeats(voice.Lines[i].LastNoteBeat, Bpm) - CBase.Game.GetTimeFromBeats(Medley.StartBeat, Bpm) <
CBase.Settings.GetMedleyMinDuration())
{
foundEnd = true;
@@ -504,10 +546,13 @@ namespace VocaluxeLib.Songs
private void _CheckPreview()
{
if (Preview.Source != EDataSource.None)
{
return;
}
if (Medley.Source != EDataSource.None)
{
Preview.StartTime = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM);
Preview.StartTime = CBase.Game.GetTimeFromBeats(Medley.StartBeat, Bpm);
Preview.Source = EDataSource.Calculated;
}
}
@@ -515,28 +560,33 @@ namespace VocaluxeLib.Songs
private void _FindShortEnd()
{
if (ShortEnd.Source != EDataSource.None)
{
return;
}
List<SSeries> series = _GetSeries();
var series = _GetSeries();
if (series == null)
{
return;
}
CVoice voice = Notes.GetVoice(0);
var voice = Notes.GetVoice(0);
//Calculate length of singing
int stop = (voice.Lines[voice.Lines.Length - 1].LastNoteBeat - voice.Lines[0].FirstNote.StartBeat) / 2 + voice.Lines[0].FirstNote.StartBeat;
var stop = (voice.Lines[voice.Lines.Length - 1].LastNoteBeat - voice.Lines[0].FirstNote.StartBeat) / 2 + voice.Lines[0].FirstNote.StartBeat;
//Check if stop is in series
for (int i = 0; i < series.Count; i++)
for (var i = 0; i < series.Count; i++)
{
if (voice.Lines[series[i].Start].FirstNoteBeat < stop && voice.Lines[series[i].End].LastNoteBeat > stop)
{
if (stop < (voice.Lines[series[i].Start].FirstNoteBeat + ((voice.Lines[series[i].End].LastNoteBeat - voice.Lines[series[i].Start].FirstNoteBeat) / 2)))
if (stop < voice.Lines[series[i].Start].FirstNoteBeat + (voice.Lines[series[i].End].LastNoteBeat - voice.Lines[series[i].Start].FirstNoteBeat) / 2)
{
ShortEnd.EndBeat = voice.Lines[series[i].Start - 1].LastNote.EndBeat;
ShortEnd.Source = EDataSource.Calculated;
return;
}
ShortEnd.EndBeat = voice.Lines[series[i].End].LastNote.EndBeat;
ShortEnd.Source = EDataSource.Calculated;
return;
@@ -544,7 +594,7 @@ namespace VocaluxeLib.Songs
}
//Check if stop is in line
foreach (CSongLine line in voice.Lines)
foreach (var line in voice.Lines)
{
if (line.FirstNoteBeat < stop && line.LastNoteBeat > stop)
{
@@ -558,4 +608,4 @@ namespace VocaluxeLib.Songs
ShortEnd.Source = EDataSource.Calculated;
}
}
}
}