From 3837ff7cf9da7e21b9f887c528b3dea9043778f5 Mon Sep 17 00:00:00 2001 From: TiKevin83 <38826675+TiKevin83@users.noreply.github.com> Date: Thu, 4 Jun 2020 20:21:22 -0400 Subject: [PATCH] More cleanup to the new tasproj filename code (#2093) * Test class and basic unit test --- .../conversions/MovieConversionExtensions.cs | 34 +++---------------- .../Movie/MovieConversionExtensionTests.cs | 18 ++++++++++ 2 files changed, 23 insertions(+), 29 deletions(-) create mode 100644 src/BizHawk.Tests/Client.Common/Movie/MovieConversionExtensionTests.cs diff --git a/src/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs b/src/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs index 28629ae359..3c3115de84 100644 --- a/src/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs +++ b/src/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs @@ -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; } } } diff --git a/src/BizHawk.Tests/Client.Common/Movie/MovieConversionExtensionTests.cs b/src/BizHawk.Tests/Client.Common/Movie/MovieConversionExtensionTests.cs new file mode 100644 index 0000000000..7010ed6513 --- /dev/null +++ b/src/BizHawk.Tests/Client.Common/Movie/MovieConversionExtensionTests.cs @@ -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); + } + } +} \ No newline at end of file