Skip to content

Commit 54c62fe

Browse files
author
Benoit Hudson
committed
Handle padding.
Turns out to be easy.
1 parent 6d85d31 commit 54c62fe

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ public static string IncrementFileName(string path, string filename)
218218
{
219219
string fileWithoutExt = Path.GetFileNameWithoutExtension (filename);
220220
string ext = Path.GetExtension (filename);
221+
// file, space, number, extension.
221222
string format = "{0} {1}{2}";
222223

223224
int index = 1;
@@ -226,10 +227,15 @@ public static string IncrementFileName(string path, string filename)
226227
var result = System.Text.RegularExpressions.Regex.Match(fileWithoutExt, @"\d+$");
227228
if (result != null) {
228229
var number = result.Value;
230+
231+
// Parse the number.
229232
int tempIndex;
230233
if (int.TryParse (number, out tempIndex)) {
231234
fileWithoutExt = fileWithoutExt.Remove (fileWithoutExt.LastIndexOf (number));
232-
format = "{0}{1}{2}"; // remove space from format
235+
// Change the format to remove the extra space we'd add
236+
// if there weren't already a number. Also, try to use the
237+
// same width (so Cube001 increments to Cube002, not Cube2).
238+
format = "{0}{1:D" + number.Length + "}{2}"; // file, number with padding, extension
233239
index = tempIndex+1;
234240
}
235241
}

Assets/FbxExporters/Editor/UnitTests/ConvertToModelTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ public void TestStaticHelpers()
3939
filename2 = Path.Combine(tempPath, basename + "2.fbx");
4040
Assert.AreEqual (filename2, ConvertToModel.IncrementFileName (tempPath, filename1));
4141

42-
// UNI-25513 spots this lovely behaviour.
43-
// Maybe we should detect zeroes and use them as padding?
42+
// UNI-25513: bug was that Cube01.fbx => Cube2.fbx
4443
filename1 = basename + "01.fbx";
45-
filename2 = Path.Combine(tempPath, basename + "2.fbx");
44+
filename2 = Path.Combine(tempPath, basename + "02.fbx");
4645
Assert.AreEqual (filename2, ConvertToModel.IncrementFileName (tempPath, filename1));
4746
}
4847

0 commit comments

Comments
 (0)