Skip to content

Commit

Permalink
Fix crash when renaming a state to be uppercase or lowercase on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DrSmugleaf committed Jan 9, 2024
1 parent 5d64a9b commit 3d4db84
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
11 changes: 11 additions & 0 deletions SpaceWizards.RsiLib/Extensions/FileExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace SpaceWizards.RsiLib.Extensions;

public static class FileExtensions
{
public static bool IsCaseInsensitive()
{
return OperatingSystem.IsWindows() || OperatingSystem.IsMacOS();
}
}
28 changes: 27 additions & 1 deletion SpaceWizards.RsiLib/RSI/Rsi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.Json;
using JetBrains.Annotations;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SpaceWizards.RsiLib.Directions;
using SpaceWizards.RsiLib.Extensions;
using static System.StringComparison;

namespace SpaceWizards.RsiLib.RSI;

Expand Down Expand Up @@ -121,12 +124,35 @@ public void SaveImagesToFolder(string rsiFolder)
}
else if (state.ImagePath != path)
{
File.Copy(state.ImagePath, path, true);
if (FileExtensions.IsCaseInsensitive() && state.ImagePath.Equals(path, OrdinalIgnoreCase))
{
File.Move(state.ImagePath, path, true);
}
else
{
File.Copy(state.ImagePath, path, true);
}
}
}

foreach (var name in OriginalStateNames)
{
if (FileExtensions.IsCaseInsensitive())
{
var found = false;
foreach (var state in States)
{
if (state.Name.Equals(name, OrdinalIgnoreCase))
{
found = true;
break;
}
}

if (found)
continue;
}

var path = Path.Combine(rsiFolder, $"{name}.png");
File.Delete(path);
}
Expand Down

0 comments on commit 3d4db84

Please sign in to comment.