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) {
file = null;
var fullPath = "";
name = name.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
var path = "";
if (Path.IsPathRooted(name)) {
// if the path is absolute, just use it directly
fullPath = name;
if (!File.Exists(fullPath)) {
path = name;
if (!File.Exists(path)) {
return sunImportResult.Missing;
}
}
else {
// check if the file exists relative to the current one;
// if it's not there, check the root directory
fullPath = Path.Combine(CurrentDirectory, name);
if (!File.Exists(fullPath)) {
fullPath = Path.Combine(mRootDirectory, name);
if (!File.Exists(fullPath)) {
path = Path.Combine(CurrentDirectory, name);
if (!File.Exists(path)) {
path = Path.Combine(mRootDirectory, name);
if (!File.Exists(path)) {
return sunImportResult.Missing;
}
}
}
// make sure the file has not been imported yet
if (mImports.Any(i => i.Name == fullPath)) {
if (mImports.Any(i => i.Name == path)) {
return sunImportResult.Skipped;
}
// open the file
try {
file = new sunScriptFile(name, File.OpenRead(fullPath));
file = new sunScriptFile(path, File.OpenRead(path));
}
catch {
return sunImportResult.FailedToLoad;