File.Exists works (at least for root files)

This commit is contained in:
Matthijs ter Woord 2015-07-04 18:43:32 +02:00
parent 36fcf8fa01
commit c5198ccb80
7 changed files with 107 additions and 66 deletions

View file

@ -26,32 +26,41 @@ namespace SentinelKernel
var xRoot = Path.GetPathRoot(@"0:\test");
bool xTest = Directory.Exists("0:\\test");
Console.WriteLine("After test");
if (xTest)
{
Console.WriteLine("Folder exists!");
xTest = Directory.Exists("0:\\test\\DirInTest");
if (xTest)
{
Console.WriteLine("Subfolder exists as well!");
}
else
{
Console.WriteLine("Subfolder doesn't exist!");
}
}
else
if (!xTest)
{
Console.WriteLine("Folder does not exist!");
return;
}
Console.WriteLine("Folder exists!");
xTest = Directory.Exists("0:\\test\\DirInTest");
if (!xTest)
{
Console.WriteLine("Subfolder doesn't exist!");
return;
}
Console.WriteLine("Subfolder exists as well!");
xTest = File.Exists(@"0:\Kudzu.txt");
if (!xTest)
{
Console.WriteLine(@"\Kudzu.txt not found!");
return;
}
Console.WriteLine("Kudzu.txt found!");
}
catch (Exception e)
{
Console.WriteLine("Exception occurred:");
Console.WriteLine(e.Message);
}
Stop();
finally
{
while (true)
;
}
}
}
}

View file

@ -394,5 +394,10 @@ namespace SentinelKernel.System.FileSystem.FAT
return GetDirectoryContents((FatDirectory)baseDirectory);
}
}
public override Directory GetRootDirectory(string name)
{
return new FatDirectory(this, name, RootCluster);
}
}
}

View file

@ -41,5 +41,7 @@ namespace SentinelKernel.System.FileSystem
}
public abstract List<Listing.Base> GetDirectoryListing(Directory baseDirectory);
public abstract Directory GetRootDirectory(string name);
}
}

View file

@ -141,29 +141,34 @@ namespace SentinelKernel.System.FileSystem.VFS
throw new ArgumentNullException("aPath");
}
return null;
/*
string xFileName = Path.GetFileName(aPath);
string xDirectory = Path.GetDirectoryName(aPath) + Path.DirectorySeparatorChar;
foreach (var xEntry in GetDirectoryListing(xDirectory))
string xDirectory = Path.GetDirectoryName(aPath);
var xLastChar = xDirectory[xDirectory.Length - 1];
if (xLastChar != Path.DirectorySeparatorChar)
{
if ((xEntry is FileSystem.Listing.File) && (xEntry.Name == xFileName))
xDirectory = xDirectory + Path.DirectorySeparatorChar;
}
var xList = GetDirectoryListing(xDirectory);
for (int i = 0; i < xList.Count; i++)
{
var xEntry = xList[i];
var xFile = xEntry as Listing.File;
if (xFile != null && String.Equals(xEntry.Name, xFileName, StringComparison.OrdinalIgnoreCase))
{
return (xEntry as FileSystem.Listing.File);
return xFile;
}
}
return null;
*/
}
public static List<Listing.File> GetFiles(string aPath)
{
if (string.IsNullOrEmpty(aPath))
{
throw new ArgumentNullException("sPath");
throw new ArgumentNullException("aPath");
}
return null;
@ -274,8 +279,10 @@ namespace SentinelKernel.System.FileSystem.VFS
{
return (VFSManager.GetFile(aPath) != null);
}
catch (Exception)
catch (Exception E)
{
Console.Write("Exception occurred: ");
Console.WriteLine(E.Message);
return false;
}
}

View file

@ -59,7 +59,6 @@
<Compile Include="System\IO\DriveInfoImpl.cs" />
<Compile Include="System\IO\FileImpl.cs" />
<Compile Include="System\IO\FileInfoImpl.cs" />
<Compile Include="System\IO\FileStreamImpl.cs" />
<Compile Include="System\IO\FileSystemInfoImpl.cs" />
<Compile Include="System\IO\PathImpl.cs" />
<Compile Include="System\IO\StreamReaderImpl.cs" />

View file

@ -8,6 +8,7 @@ using System.IO;
using SentinelKernel.System.FileSystem.FAT;
using SentinelKernel.System.FileSystem.Listing;
using Console = global::System.Console;
using Directory = SentinelKernel.System.FileSystem.Listing.Directory;
namespace SentinelKernel.System.FileSystem.VFS
{
@ -199,12 +200,12 @@ namespace SentinelKernel.System.FileSystem.VFS
for (int i = 0; i < mFileSystems.Count; i++)
{
string xTest = mFileSystems[i].Key;
if (xTest == xPath)
if (String.Equals(xTest, xPath))
{
return mFileSystems[i].Value;
}
}
return null;
throw new Exception("Unable to determine filesystem for path: " + aPath);
}
public override void Initialize()
@ -221,55 +222,63 @@ namespace SentinelKernel.System.FileSystem.VFS
public override Listing.Directory GetDirectory(string aPath)
{
string[] xPathParts = VFSManager.SplitPath(aPath);
var xFS = GetFileSystemFromPath(aPath);
if (xFS != null)
return DoGetDirectory(aPath, xFS);
}
private Directory DoGetDirectory(string aPath, FileSystem aFS)
{
if (aFS == null)
{
if (xPathParts.Length == 1)
throw new ArgumentNullException("aFS");
}
string[] xPathParts = VFSManager.SplitPath(aPath);
if (xPathParts.Length == 1)
{
return GetVolume(aFS, aPath);
}
Listing.Directory xBaseDirectory = null;
// start at index 1, because 0 is the volume
for (int i = 1; i < xPathParts.Length; i++)
{
var xPathPart = xPathParts[i];
var xPartFound = false;
var xListing = aFS.GetDirectoryListing(xBaseDirectory);
for (int j = 0; j < xListing.Count; j++)
{
return GetVolume(xPathParts[0]);
}
Listing.Directory xBaseDirectory = null;
// start at index 1, because 0 is the volume
for (int i = 1; i < xPathParts.Length; i++)
{
var xPathPart = xPathParts[i];
var xPartFound = false;
var xListing = xFS.GetDirectoryListing(xBaseDirectory);
for (int j = 0; j < xListing.Count; j++)
var xListingItem = xListing[j];
if (String.Equals(xListingItem.Name, xPathPart, StringComparison.OrdinalIgnoreCase))
{
var xListingItem = xListing[j];
if (String.Equals(xListingItem.Name, xPathPart, StringComparison.OrdinalIgnoreCase))
if (xListingItem is Listing.Directory)
{
if (xListingItem is Listing.Directory)
{
xBaseDirectory = (Listing.Directory)xListingItem;
xPartFound = true;
}
else
{
throw new Exception("Path part '" + xPathPart + "' found, but not a directory!");
}
xBaseDirectory = (Listing.Directory)xListingItem;
xPartFound = true;
}
else
{
throw new Exception("Path part '" + xPathPart + "' found, but not a directory!");
}
}
if (!xPartFound)
{
throw new Exception("Path part '" + xPathPart + "' not found!");
}
}
return xBaseDirectory;
if (!xPartFound)
{
throw new Exception("Path part '" + xPathPart + "' not found!");
}
}
return null;
return xBaseDirectory;
}
public override List<Listing.Base> GetDirectoryListing(string aPath)
{
throw new NotImplementedException();
var xFS = GetFileSystemFromPath(aPath);
var xDirectory = DoGetDirectory(aPath, xFS);
return xFS.GetDirectoryListing(xDirectory);
}
public override List<Listing.Base> GetDirectoryListing(Listing.Directory aParentDirectory)
@ -287,6 +296,11 @@ namespace SentinelKernel.System.FileSystem.VFS
throw new NotImplementedException();
}
public Listing.Directory GetVolume(FileSystem filesystem, string name)
{
return filesystem.GetRootDirectory(name);
}
/*
public override SentinelKernel.System.FileSystem.Listing.Directory GetVolume(string aVolume)
{

View file

@ -245,7 +245,12 @@ namespace SentinelKernel.System.Plugs.System.IO
return null;
}
aPath = NormalizePath(aPath, false);
return aPath.Substring(0, GetRootLength(aPath));
var xResult = aPath.Substring(0, GetRootLength(aPath));
if (xResult[xResult.Length - 1] != Path.DirectorySeparatorChar)
{
xResult = xResult + Path.DirectorySeparatorChar;
}
return xResult;
}
public static string GetRandomFileName()