Skip to content

Commit

Permalink
Fix more path name issues
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin committed Jan 24, 2023
1 parent 69dfd39 commit a0ce238
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/PathSanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
static class PathSanitizer
{
static readonly Regex invalidCharsRegex = new(@"\W");
public static string Sanitize(string path)
public static string Sanitize(string path, string parent)
{
var partStr = invalidCharsRegex.Replace(path, "_");
if (char.IsDigit(partStr[0]))
if (char.IsDigit(partStr[0]) || partStr == parent)
partStr = "_" + partStr;
return partStr;
}
Expand Down
11 changes: 9 additions & 2 deletions src/ThisAssembly.Resources/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ public static Area Load(string basePath, List<Resource> resources, string rootAr
var parts = basePath.Split(new[] { "\\", "/" }, StringSplitOptions.RemoveEmptyEntries);
var end = resources.Count == 1 ? ^1 : ^0;

var parent = "Resources";
foreach (var part in parts.AsSpan()[..end])
{
var partStr = PathSanitizer.Sanitize(part);
var partStr = PathSanitizer.Sanitize(part, parent);
parent = partStr;

area.NestedArea = new Area(partStr);
area = area.NestedArea;
}

area.Resources = resources;
area.Resources = resources
.Select(r => r with
{
Name = PathSanitizer.Sanitize(r.Name, parent),
});
return root;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ThisAssembly.Resources/ResourcesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void GenerateSource(
? Path.GetFileNameWithoutExtension(f.resourceName)
: Path.GetExtension(f.resourceName)[1..];
return new Resource(
Name: PathSanitizer.Sanitize(name),
Name: name,
Comment: f.comment,
IsText: isText,
Path: f.resourceName);
Expand Down

0 comments on commit a0ce238

Please sign in to comment.