Fixed: construct file instance with absolute path

Before it was set to the local name (from the import statement), and
then would fail because the code compares them to the full path later.
This commit is contained in:
arookas 2016-02-01 06:23:31 -05:00
parent 03fb7c20b4
commit f00b7c4296

View file

@ -43,33 +43,28 @@ namespace arookas {
} }
public override sunImportResult ResolveImport(string name, out sunScriptFile file) { public override sunImportResult ResolveImport(string name, out sunScriptFile file) {
file = null; file = null;
var fullPath = "";
name = name.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); name = name.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
var path = "";
if (Path.IsPathRooted(name)) { if (Path.IsPathRooted(name)) {
// if the path is absolute, just use it directly path = name;
fullPath = name; if (!File.Exists(path)) {
if (!File.Exists(fullPath)) {
return sunImportResult.Missing; return sunImportResult.Missing;
} }
} }
else { else {
// check if the file exists relative to the current one; path = Path.Combine(CurrentDirectory, name);
// if it's not there, check the root directory if (!File.Exists(path)) {
fullPath = Path.Combine(CurrentDirectory, name); path = Path.Combine(mRootDirectory, name);
if (!File.Exists(fullPath)) { if (!File.Exists(path)) {
fullPath = Path.Combine(mRootDirectory, name);
if (!File.Exists(fullPath)) {
return sunImportResult.Missing; return sunImportResult.Missing;
} }
} }
} }
// make sure the file has not been imported yet if (mImports.Any(i => i.Name == path)) {
if (mImports.Any(i => i.Name == fullPath)) {
return sunImportResult.Skipped; return sunImportResult.Skipped;
} }
// open the file
try { try {
file = new sunScriptFile(name, File.OpenRead(fullPath)); file = new sunScriptFile(path, File.OpenRead(path));
} }
catch { catch {
return sunImportResult.FailedToLoad; return sunImportResult.FailedToLoad;