diff --git a/source/Cosmos/Cosmos.System/VFSManager.cs b/source/Cosmos/Cosmos.System/VFSManager.cs
index f9fa7693e..a1293548d 100644
--- a/source/Cosmos/Cosmos.System/VFSManager.cs
+++ b/source/Cosmos/Cosmos.System/VFSManager.cs
@@ -97,13 +97,13 @@ namespace Cosmos.Sys {
// return false;
//}
+
///
/// Get a single directory from the given path.
///
- ///
+ /// Absolute path
///
public static FilesystemEntry GetDirectoryEntry(string aPath) {
- Cosmos.Hardware.DebugUtil.SendMessage("GetDirectoryEntry", "Searching for " + aPath);
//if (String.IsNullOrEmpty(aPath)) {
// throw new ArgumentNullException("aPath");
//}
@@ -115,9 +115,12 @@ namespace Cosmos.Sys {
return null;
} else {
string[] xPathParts = SplitPath(aPath);
+
+
// first get the correct FS
Cosmos.Hardware.DebugUtil.SendMessage("GetDirectoryEntry", "Searching for filesystem");
var xFS = GetFileSystemFromPath(xPathParts[0], 0);
+
//var xFS = mFilesystems[ParseStringToInt(xPathParts[0], 0)];
var xCurrentFSEntryId = xFS.RootId;
Cosmos.Hardware.DebugUtil.SendMessage("GetDirectoryEntry", "Found filesystem " + xCurrentFSEntryId);
@@ -156,7 +159,7 @@ namespace Cosmos.Sys {
/// Directory to search in. Can be absolute and relative.
/// All Directories and Files in the given path.
public static FilesystemEntry[] GetDirectoryListing(string aPath) {
-
+
if (String.IsNullOrEmpty(aPath)) {
throw new ArgumentNullException("aPath is null in GetDirectoryListing");
}
@@ -197,6 +200,24 @@ namespace Cosmos.Sys {
}
+
+ ///
+ /// Get a single volume
+ ///
+ public static FilesystemEntry GetVolumeEntry(int volumeId)
+ {
+ var xFS = GetFileSystemFromPath(volumeId.ToString(), 0);
+
+ return new FilesystemEntry()
+ {
+ Name = volumeId.ToString(),
+ Filesystem = xFS,
+ IsDirectory = true,
+ IsReadonly = true,
+ Id = (ulong)volumeId
+ };
+ }
+
private static FilesystemEntry[] GetVolumes()
{
//if (aFilesystems == null)
@@ -206,13 +227,7 @@ namespace Cosmos.Sys {
var xResult = new FilesystemEntry[mFilesystems.Count];
for (int i = 0; i < mFilesystems.Count; i++)
{
- xResult[i] = new FilesystemEntry()
- {
- Id = (ulong)i,
- IsDirectory = true,
- IsReadonly = true,
- Name = i.ToString() //Volume number
- };
+ xResult[i] = GetVolumeEntry(i);
}
return xResult;
}
@@ -426,7 +441,11 @@ namespace Cosmos.Sys {
List xDirectories = new List();
Cosmos.Hardware.DebugUtil.SendMessage("GetDirectories", "About to GetDirectoryListing");
- var xEntries = VFSManager.GetDirectoryListing(Path.GetDirectoryName(aDir));
+
+ var xDir = VFSManager.GetDirectoryEntry(Path.GetDirectoryName(aDir));
+ Cosmos.Hardware.DebugUtil.SendMessage("GetDirectories", xDir.Name + " with ID " + xDir.Id.ToString());
+ var xEntries = VFSManager.GetDirectoryListing(xDir);
+ //var xEntries = VFSManager.GetDirectoryListing(Path.GetDirectoryName(aDir));
foreach (FilesystemEntry entry in xEntries)
if (entry.IsDirectory)
@@ -508,7 +527,7 @@ namespace Cosmos.Sys {
// throw new DirectoryNotFoundException("Unable to find directory " + aDir);
List xFiles = new List();
- var xEntries = GetDirectoryListing(Path.GetDirectoryName(aDir));
+ var xEntries = VFSManager.GetDirectoryListing(Path.GetDirectoryName(aDir));
foreach (FilesystemEntry entry in xEntries)
if (!entry.IsDirectory)
diff --git a/source/FrodeTest/Application/cd.cs b/source/FrodeTest/Application/cd.cs
index 52f2f87ee..d46f28d7f 100644
--- a/source/FrodeTest/Application/cd.cs
+++ b/source/FrodeTest/Application/cd.cs
@@ -30,7 +30,7 @@ namespace FrodeTest.Application
//TODO: Use DirectoryInfo.GetParent
string xCurDir = Directory.GetCurrentDirectory();
xCurDir = xCurDir.TrimEnd(Path.DirectorySeparatorChar);
- //EnvironmentVariables.GetCurrent().CurrentDirectory = xCurDir.Substring(0, xCurDir.LastIndexOf(Path.DirectorySeparatorChar));
+
Directory.SetCurrentDirectory(
Directory.GetCurrentDirectory().Substring(
0,
@@ -41,16 +41,14 @@ namespace FrodeTest.Application
return 0;
}
- string xNewPath = Directory.GetCurrentDirectory() + args[0] + "/"; //EnvironmentVariables.GetCurrent().CurrentDirectory + args[0] + "/";
+ string xNewPath = Directory.GetCurrentDirectory() + args[0] + "/";
DebugUtil.SendMessage("cd.cs", "Checking path " + xNewPath);
if (Directory.Exists(xNewPath))
{
- //EnvironmentVariables.GetCurrent().CurrentDirectory = xNewPath;
Directory.SetCurrentDirectory(xNewPath);
}
else if (Directory.Exists(args[0] + "/"))
{
- //EnvironmentVariables.GetCurrent().CurrentDirectory += args[0] + "/";
Directory.SetCurrentDirectory(Directory.GetCurrentDirectory() + args[0] + "/");
}
else
diff --git a/source/FrodeTest/Application/dir.cs b/source/FrodeTest/Application/dir.cs
index 5b14d70ee..3ba5bc82d 100644
--- a/source/FrodeTest/Application/dir.cs
+++ b/source/FrodeTest/Application/dir.cs
@@ -16,25 +16,32 @@ namespace FrodeTest.Application
{
try
{
- //Get current directory
+ //Get directory
string xDir = string.Empty;
if (args[0] != null)
xDir = args[0];
else
xDir = Directory.GetCurrentDirectory();
- //xDir= EnvironmentVariables.GetCurrent().CurrentDirectory; //HACK
- Console.WriteLine(" Directory of " + xDir);
+ if (!Directory.Exists(xDir))
+ {
+ Console.WriteLine("No such directory: " + xDir);
+ return -1;
+ }
+ else
+ {
+ Console.WriteLine(" Directory of " + xDir);
- foreach (string xDirectory in Directory.GetDirectories(xDir))
- Console.WriteLine("\t" + xDirectory);
+ foreach (string xDirectory in Directory.GetDirectories(xDir))
+ Console.WriteLine("\t" + xDirectory);
- foreach (string xFile in Directory.GetFiles(xDir))
- Console.WriteLine("\t\t" + xFile);
+ foreach (string xFile in Directory.GetFiles(xDir))
+ Console.WriteLine("\t\t" + xFile);
+ }
}
catch (Exception e)
{
- Console.WriteLine("ERROR: " + e.Message);
+ Console.WriteLine("ERROR in dir command: " + e.Message);
}
return 0;
}
diff --git a/source/FrodeTest/FrodeTest.csproj b/source/FrodeTest/FrodeTest.csproj
index b4a197480..5d98fa001 100644
--- a/source/FrodeTest/FrodeTest.csproj
+++ b/source/FrodeTest/FrodeTest.csproj
@@ -70,6 +70,7 @@
+
diff --git a/source/FrodeTest/Program.cs b/source/FrodeTest/Program.cs
index 4a587e885..2c70def9a 100644
--- a/source/FrodeTest/Program.cs
+++ b/source/FrodeTest/Program.cs
@@ -66,7 +66,8 @@ namespace FrodeTest
//Test.ExceptionTest.RunTest();
//Test.FilesystemEntryTest.RunTest();
//Test.VirtualFileSystemTest.RunTest();
- Test.DirectoryInfoTest.RunTest();
+ Test.DirectoryTest.RunTest();
+ //Test.DirectoryInfoTest.RunTest();
//Test.FileInfoTest.RunTest();
//Tests ready for Matthijs to fix ;)
diff --git a/source/FrodeTest/Test/DirectoryTest.cs b/source/FrodeTest/Test/DirectoryTest.cs
new file mode 100644
index 000000000..1ab3ccee2
--- /dev/null
+++ b/source/FrodeTest/Test/DirectoryTest.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+
+namespace FrodeTest.Test
+{
+ public class DirectoryTest
+ {
+ public static void RunTest()
+ {
+ Check.Text = "Exists";
+ Check.Validate(Directory.Exists("/0/"));
+ Check.Validate(Directory.Exists("/0/Alfa/"));
+ Check.Validate(Directory.Exists("/0/Alfa/Bravo/"));
+ Check.Validate(!Directory.Exists("/0/InvalidDir/"));
+
+ Check.Text = "GetDirectories";
+ Check.Validate(Directory.GetDirectories("/0/").Length == 3);
+ Check.Validate(Directory.GetDirectories("/0/Alfa/").Length == 1);
+
+ Check.Text = "GetFiles";
+ Check.Validate(Directory.GetFiles("/0/Alfa/").Length == 0);
+ Check.Validate(Directory.GetFiles("/0/Alfa/Bravo/").Length == 1);
+
+ Check.Text = "GetLogicalDrives";
+ Check.Validate(Directory.GetLogicalDrives().Length == 2);
+
+ Check.Text = "GetParent";
+ Check.Validate(Directory.GetParent("/0/Alfa/Bravo/") == "/0/Alfa/");
+ }
+ }
+}