mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-22 20:02:48 +00:00
Added parsing of relative includes in ZScript (PR#787 by JaedenDuhreis)
This commit is contained in:
parent
aee47aacb0
commit
82f1ee09bc
1 changed files with 27 additions and 7 deletions
|
@ -284,14 +284,34 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
return false;
|
||||
}
|
||||
|
||||
//mxd. Relative paths are not supported
|
||||
// [JD] Relative paths are supported by GZDoom since 4.8.0
|
||||
if (filename.StartsWith(RELATIVE_PATH_MARKER) || filename.StartsWith(CURRENT_FOLDER_PATH_MARKER) ||
|
||||
filename.StartsWith(ALT_RELATIVE_PATH_MARKER) || filename.StartsWith(ALT_CURRENT_FOLDER_PATH_MARKER))
|
||||
{
|
||||
ReportError("Relative include paths are not supported by ZDoom");
|
||||
List<string> pathTokens = localsourcename.Split('\\', '/').ToList(); // take full path of current source file, split to individual folders
|
||||
pathTokens.RemoveAt(pathTokens.Count - 1); // remove filename itself
|
||||
pathTokens.AddRange(filename.Split('\\', '/')); // add relative path
|
||||
pathTokens.RemoveAll(token => token.Equals(".", StringComparison.InvariantCulture)); // remove all "." folders from the path
|
||||
|
||||
for (int i = 0; i < pathTokens.Count; i++)
|
||||
{
|
||||
if (pathTokens[i].Equals("..", StringComparison.InvariantCulture)) // for each "..": remove them and previous folder from the path
|
||||
{
|
||||
if (i == 0) // cannot have ".." at start of full path
|
||||
{
|
||||
ReportError("Relative path escaping archive");
|
||||
return false;
|
||||
}
|
||||
|
||||
pathTokens.RemoveAt(i);
|
||||
pathTokens.RemoveAt(i - 1);
|
||||
i -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
filename = string.Join("/", pathTokens); // combine the included file path
|
||||
}
|
||||
|
||||
//mxd. Backward slashes are not supported
|
||||
if (filename.Contains("\\"))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue