More cleanup to the new tasproj filename code (#2093)
* Test class and basic unit test
This commit is contained in:
parent
e11509421d
commit
3837ff7cf9
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue