More cleanup to the new tasproj filename code (#2093)

* Test class and basic unit test
This commit is contained in:
TiKevin83 2020-06-04 20:21:22 -04:00 committed by GitHub
parent e11509421d
commit 3837ff7cf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 29 deletions

View File

@ -311,38 +311,14 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
public static string GetNewFileName(string oldFileName)
{
string newFilename = oldFileName;
string oldExtension = Path.GetExtension(oldFileName);
if (oldExtension == $".{TasMovie.Extension}" || oldExtension == $".{Bk2Movie.Extension}")
string newFileName = Path.ChangeExtension(oldFileName, $".{TasMovie.Extension}");
int fileSuffix = 0;
while (File.Exists(newFileName))
{
newFilename = Path.ChangeExtension(newFilename, null);
newFilename = $"{newFilename}.{TasMovie.Extension}";
}
else
{
newFilename = $"{oldFileName}.{TasMovie.Extension}";
newFileName = $"{Path.GetDirectoryName(oldFileName)}{Path.GetFileNameWithoutExtension(oldFileName)} {++fileSuffix}.{TasMovie.Extension}";
}
if (File.Exists(newFilename))
{
int fileNum = 1;
bool fileConflict = true;
while (fileConflict)
{
if (File.Exists(newFilename))
{
newFilename = $"{oldFileName} ({fileNum}).{TasMovie.Extension}";
fileNum++;
}
else
{
fileConflict = false;
}
}
}
return newFilename;
return newFileName;
}
}
}

View File

@ -0,0 +1,18 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BizHawk.Client.Common.MovieConversionExtensions;
namespace BizHawk.Common.Tests.Client.Common.Movie
{
[TestClass]
public class MovieConversionExtensionTests
{
private string oldBk2FileName = "C:\\Temp\\TestMovie.bk2";
[TestMethod]
public void GetNewFileNameFromBk2()
{
var actual = MovieConversionExtensions.GetNewFileName(oldBk2FileName);
Assert.AreEqual("C:\\Temp\\TestMovie.tasproj", actual);
}
}
}