Attempt to improve Unix filesystem support

Add some new methods to PK3StructuredReader and DirectoryReader, which get the filename with the correct case, and get a file at a particular path.
Replace backslashes in modeldef model paths with forward slashes, instead of doing the opposite, which was preventing some models from loading.

I don't know whether or not this is a good solution or not, since I don't know the UDB codebase very well.
This commit is contained in:
Kevin Caccamo 2020-07-29 03:57:42 -04:00
parent c047b98ba4
commit 42be899204
No known key found for this signature in database
GPG key ID: 483F90E1F56A8723
3 changed files with 38 additions and 38 deletions

View file

@ -467,12 +467,12 @@ namespace CodeImp.DoomBuilder.Data
internal override MemoryStream LoadFile(string filename)
{
MemoryStream s = null;
string casecorrectfilename = GetCorrectCaseForFile(filename);
try
{
lock(this)
{
s = new MemoryStream(File.ReadAllBytes(Path.Combine(location.location, filename)));
s = new MemoryStream(File.ReadAllBytes(Path.Combine(location.location, casecorrectfilename)));
}
}
catch(Exception e)
@ -514,6 +514,11 @@ namespace CodeImp.DoomBuilder.Data
return tempfile;
}
protected override string GetCorrectCaseForFile(string filepathname)
{
return files.GetFileInfo(filepathname).filepathname;
}
#endregion
#region ================== Compiling (mxd)

View file

@ -501,17 +501,7 @@ namespace CodeImp.DoomBuilder.Data
if(filename.IndexOf('.') > -1)
{
string fullname = Path.Combine(pathname, filename);
if(FileExists(fullname))
{
allfilenames = new string[1];
allfilenames[0] = Path.Combine(pathname, filename);
}
else
{
allfilenames = new string[0];
General.ErrorLogger.Add(ErrorType.Warning, "Unable to load DECORATE file \"" + fullname + "\"");
}
allfilenames = GetFileAtPath(filename, pathname, "DECORATE");
}
else
allfilenames = GetAllFilesWithTitle(pathname, filename, false);
@ -545,17 +535,7 @@ namespace CodeImp.DoomBuilder.Data
if (filename.IndexOf('.') > -1)
{
string fullname = Path.Combine(pathname, filename);
if (FileExists(fullname))
{
allfilenames = new string[1];
allfilenames[0] = Path.Combine(pathname, filename);
}
else
{
allfilenames = new string[0];
General.ErrorLogger.Add(ErrorType.Warning, "Unable to load ZSCRIPT file \"" + fullname + "\"");
}
allfilenames = GetFileAtPath(filename, pathname, "ZSCRIPT");
}
else
allfilenames = GetAllFilesWithTitle(pathname, filename, false);
@ -589,17 +569,7 @@ namespace CodeImp.DoomBuilder.Data
if (filename.IndexOf('.') > -1)
{
string fullname = Path.Combine(pathname, filename);
if (FileExists(fullname))
{
allfilenames = new string[1];
allfilenames[0] = Path.Combine(pathname, filename);
}
else
{
allfilenames = new string[0];
General.ErrorLogger.Add(ErrorType.Warning, "Unable to load MODELDEF file \"" + fullname + "\"");
}
allfilenames = GetFileAtPath(filename, pathname, "MODELDEF");
}
else
allfilenames = GetAllFilesWithTitle(pathname, filename, false);
@ -771,6 +741,25 @@ namespace CodeImp.DoomBuilder.Data
return images;
}
protected string[] GetFileAtPath(string filename, string pathname, string type)
{
string[] allfilenames;
string fullname = Path.Combine(pathname, filename);
if (FileExists(fullname))
{
allfilenames = new string[1];
allfilenames[0] = Path.Combine(pathname, filename);
allfilenames[0] = GetCorrectCaseForFile(allfilenames[0]);
}
else
{
allfilenames = new string[0];
General.ErrorLogger.Add(ErrorType.Warning, "Unable to load " + type + " file \"" + fullname + "\"");
}
return allfilenames;
}
// This copies images from a collection unless they already exist in the list
private static void AddImagesToList(Dictionary<long, ImageData> targetlist, IEnumerable<ImageData> sourcelist)
{
@ -834,6 +823,12 @@ namespace CodeImp.DoomBuilder.Data
}
}
// Unix-like systems have case-sensitive filesystems. Use this to correct the case of a filename with the given path.
protected virtual string GetCorrectCaseForFile(string filepathname)
{
return filepathname;
}
//mxd. Archives and Folders don't have lump indices
internal override MemoryStream LoadFile(string name, int unused)
{

View file

@ -102,7 +102,7 @@ namespace CodeImp.DoomBuilder.ZDoom
{
case "path":
parser.SkipWhitespace(true);
path = parser.StripTokenQuotes(parser.ReadToken(false)).Replace("/", "\\"); // Don't skip newline
path = parser.StripTokenQuotes(parser.ReadToken(false)).Replace("\\", "/"); // Don't skip newline
if(string.IsNullOrEmpty(path))
{
parser.ReportError("Expected model path");