custom map name fixes (#11)

* attempt to fix linux file load

* fix download links and sort map names
This commit is contained in:
CommonLoon102 2020-01-29 23:33:32 +00:00 committed by GitHub
parent 7ff8ad8407
commit 2ca894266c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -29,10 +29,11 @@ namespace WebInterface.Services
"CPBB04.MAP",
};
private List<string> ListableCustomMaps => Directory.GetFiles(CommandLineUtils.BloodDir,
"*.map", SearchOption.TopDirectoryOnly)
private List<string> ListableCustomMaps => Directory.GetFiles(CommandLineUtils.BloodDir)
.Select(m => Path.GetFileName(m))
.Where(m => m.ToUpper().EndsWith(".MAP"))
.Where(m => !ContainsString(crypticMaps, m))
.OrderBy(m => m)
.ToList();
public IList<string> ListCustomMaps() => ListableCustomMaps;
@ -57,7 +58,7 @@ namespace WebInterface.Services
public string StoreTempCustomMap(IFormFile formFile)
{
string filename = Path.GetFileNameWithoutExtension(formFile.FileName);
string filename = Path.GetFileName(formFile.FileName);
ValidateFilename(filename);
string tempFolderName = Path.GetRandomFileName();
@ -65,7 +66,7 @@ namespace WebInterface.Services
if (!Directory.Exists(mapPath))
Directory.CreateDirectory(mapPath);
mapPath = Path.Combine(mapPath, filename + ".map");
mapPath = Path.Combine(mapPath, filename);
FileStream fs = new FileStream(mapPath, FileMode.CreateNew);
formFile.CopyTo(fs);
@ -75,9 +76,12 @@ namespace WebInterface.Services
private void ValidateFilename(string filename)
{
if (string.IsNullOrWhiteSpace(filename))
throw new WebInterfaceException("Invalid filename.");
throw new WebInterfaceException("Invalid file name.");
if (ContainsString(crypticMaps, filename + ".map"))
if (!filename.ToUpper().EndsWith(".MAP"))
throw new WebInterfaceException("Invalid extension.");
if (ContainsString(crypticMaps, filename))
throw new WebInterfaceException($"You cannot play this map ({filename}) as a custom map.");
foreach (var chr in Path.GetInvalidFileNameChars())

View File

@ -15,6 +15,6 @@
<ul>
@foreach (var map in Model)
{
<li><a href="@Url.Link("DownloadCustomMap", new { map = map })">@map</a></li>
<li><a href="@Url.Action("Index", "CustomMaps", new { map = map })">@map</a></li>
}
</ul>