File.Exists works for files in subdirectories as well.

This commit is contained in:
Matthijs ter Woord 2015-07-05 11:14:16 +02:00
parent 667861ebe3
commit 65fdc07bad
4 changed files with 73 additions and 54 deletions

View file

@ -41,7 +41,7 @@ namespace SentinelKernel
}
Console.WriteLine("Subfolder exists as well!");
xTest = File.Exists(@"0:\Kudzu.txt");
xTest = File.Exists(@"0:\KudzU.txt");
if (!xTest)
{
Console.WriteLine(@"\Kudzu.txt not found!");
@ -50,6 +50,15 @@ namespace SentinelKernel
Console.WriteLine("Kudzu.txt found!");
xTest = File.Exists(@"0:\Test\DirInTest\Readme.txt");
if (!xTest)
{
Console.WriteLine(@"\Test\DirInTest\Readme.txt not found!");
return;
}
Console.WriteLine(@"Test\DirInTest\Readme.txt found!");
}
catch (Exception e)
{

View file

@ -241,17 +241,20 @@ namespace SentinelKernel.System.FileSystem.FAT
{
var xResult = new List<Base>();
//TODO: Change xLongName to StringBuilder
string xLongName = "";
string xName = "";
for (UInt32 i = 0; i < xData.Length; i = i + 32)
{
FatHelpers.Debug("-------------------------------------------------");
string xLongName = "";
byte xAttrib = xData[i + 11];
FatHelpers.Debug("Attrib = " + xAttrib.ToString());
byte xStatus = xData[i];
FatHelpers.Debug("Attrib = " + xAttrib.ToString() + ", Status = " + xStatus);
if (xAttrib == DirectoryEntryAttributeConsts.LongName)
{
byte xType = xData[i + 12];
byte xOrd = xData[i];
FatHelpers.Debug("Reading LFN with Seqnr " + xOrd.ToString());
FatHelpers.Debug("Reading LFN with Seqnr " + xOrd.ToString() + ", Type = " + xType);
if (xOrd == 0xE5)
{
FatHelpers.Debug("Skipping deleted entry");
@ -280,65 +283,74 @@ namespace SentinelKernel.System.FileSystem.FAT
}
}
xLongName = xLongPart + xLongName;
xLongPart = null;
//TODO: LDIR_Chksum
}
}
string xName = xLongName;
byte xStatus = xData[i];
if (xStatus == 0x00)
else
{
// Empty slot, and no more entries after this
break;
}
else if (xStatus == 0x05)
{
// Japanese characters - We dont handle these
}
else if (xStatus == 0xE5)
{
// Empty slot, skip it
}
else if (xStatus >= 0x20)
{
if (xLongName.Length > 0)
xName = xLongName;
if (xStatus == 0x00)
{
// Leading and trailing spaces are to be ignored according to spec.
// Many programs (including Windows) pad trailing spaces although it
// it is not required for long names.
// As per spec, ignore trailing periods
xName = xLongName.Trim();
//If there are trailing periods
int nameIndex = xName.Length - 1;
if (xName[nameIndex] == '.')
{
//Search backwards till we find the first non-period character
for (; nameIndex > 0; nameIndex--)
{
if (xName[nameIndex] != '.')
{
break;
}
}
//Substring to remove the periods
xName = xName.Substring(0, nameIndex + 1);
}
// Empty slot, and no more entries after this
break;
}
else
else if (xStatus == 0x05)
{
string xEntry = xData.GetAsciiString(i, 11);
xName = xEntry.Substring(0, 8).TrimEnd();
string xExt = xEntry.Substring(8, 3).TrimEnd();
if (xExt.Length > 0)
// Japanese characters - We dont handle these
}
else if (xStatus == 0xE5)
{
// Empty slot, skip it
}
else if (xStatus >= 0x20)
{
if (xLongName.Length > 0)
{
xName = xName + "." + xExt;
// Leading and trailing spaces are to be ignored according to spec.
// Many programs (including Windows) pad trailing spaces although it
// it is not required for long names.
// As per spec, ignore trailing periods
xName = xLongName.Trim();
//If there are trailing periods
int nameIndex = xName.Length - 1;
if (xName[nameIndex] == '.')
{
//Search backwards till we find the first non-period character
for (; nameIndex > 0; nameIndex--)
{
if (xName[nameIndex] != '.')
{
break;
}
}
//Substring to remove the periods
xName = xName.Substring(0, nameIndex + 1);
}
xLongName = "";
}
else
{
string xEntry = xData.GetAsciiString(i, 11);
xName = xEntry.Substring(0, 8).TrimEnd();
string xExt = xEntry.Substring(8, 3).TrimEnd();
if (xExt.Length > 0)
{
xName = xName + "." + xExt;
}
}
}
}
UInt32 xFirstCluster = (UInt32)(xData.ToUInt16(i + 20) << 16 | xData.ToUInt16(i + 26));
var xTest = xAttrib & (DirectoryEntryAttributeConsts.Directory | DirectoryEntryAttributeConsts.VolumeID);
if (xTest == 0)
if (xAttrib == DirectoryEntryAttributeConsts.LongName)
{
// skip adding, as it's a LongFileName entry, meaning the next normal entry is the item with the name.
FatHelpers.Debug("Entry was an Long FileName entry. Current LongName = '" + xLongName + "'");
}
else if (xTest == 0)
{
UInt32 xSize = xData.ToUInt32(i + 28);
if (xSize == 0 && xName.Length == 0)
@ -348,11 +360,11 @@ namespace SentinelKernel.System.FileSystem.FAT
xResult.Add(new FatFile(this, xName, xSize, xFirstCluster));
FatHelpers.Debug("Returning file '" + xName + "'");
}
else if (xTest == DirectoryEntryAttributeConsts.Directory || xAttrib == DirectoryEntryAttributeConsts.LongName)
else if (xTest == DirectoryEntryAttributeConsts.Directory)
{
UInt32 xSize = xData.ToUInt32(i + 28);
var xFatDirectory = new FatDirectory(this, xName, xFirstCluster);
FatHelpers.Debug("Returning directory '" + xFatDirectory.Name + "'");
FatHelpers.Debug("Returning directory '" + xFatDirectory.Name + "', FirstCluster = " + xFirstCluster);
xResult.Add(xFatDirectory);
}
else if (xTest == DirectoryEntryAttributeConsts.VolumeID)
@ -364,7 +376,6 @@ namespace SentinelKernel.System.FileSystem.FAT
{
FatHelpers.Debug("Not sure what to do!");
}
xLongName = "";
}
return xResult;

View file

@ -8,7 +8,7 @@ namespace SentinelKernel.System.FileSystem
private static Debugger mDebugger = new Debugger("FAT", "Debug");
public static void Debug(string message)
{
mDebugger.Send("FAT Debug: " + message);
//mDebugger.Send("FAT Debug: " + message);
}
}
}

View file

@ -149,7 +149,6 @@ namespace SentinelKernel.System.FileSystem.VFS
xDirectory = xDirectory + Path.DirectorySeparatorChar;
}
var xList = GetDirectoryListing(xDirectory);
for (int i = 0; i < xList.Count; i++)
{