Skip to content

Commit

Permalink
Fixed path plugs
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbetros committed Feb 25, 2016
1 parent a52ea7a commit 043cbb2
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 76 deletions.
1 change: 0 additions & 1 deletion source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
</ItemGroup>
<ItemGroup>
<None Include="Cosmos.snk" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
107 changes: 101 additions & 6 deletions source/Cosmos.Core.Plugs/System/IO/PathHelperImpl.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,121 @@
using Cosmos.IL2CPU.Plugs;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;

using Cosmos.IL2CPU.Plugs;

namespace Cosmos.Core.Plugs.System.IO
{
[Plug(TargetName = "System.IO.PathHelper")]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static class PathHelperImpl
{
public static unsafe void Ctor(ref object aThis, char* aCharArrayPtr, int aLength,
[FieldAccess(Name = "System.Boolean System.IO.PathHelper.doNotTryExpandShortFileName")] ref bool mDoNotTryExpandShortFileName,
[FieldAccess(Name = "System.Char* System.IO.PathHelper.m_arrayPtr")] ref char* mArrayPtr,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_capacity")] ref int mCapacity,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_length")] ref int mLength,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_maxPath")] ref int mMaxPath,
[FieldAccess(Name = "System.Boolean System.IO.PathHelper.useStackAlloc")] ref bool mUseStackAlloc
)
{
mLength = 0;
mCapacity = aLength;
mArrayPtr = aCharArrayPtr;
mUseStackAlloc = true;
}

public static unsafe void Ctor(ref object aThis, int aCapacity, int aMaxPath,
[FieldAccess(Name = "System.Boolean System.IO.PathHelper.doNotTryExpandShortFileName")] ref bool mDoNotTryExpandShortFileName,
[FieldAccess(Name = "System.Char* System.IO.PathHelper.m_arrayPtr")] ref char* mArrayPtr,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_capacity")] ref int mCapacity,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_length")] ref int mLength,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_maxPath")] ref int mMaxPath,
[FieldAccess(Name = "System.Boolean System.IO.PathHelper.useStackAlloc")] ref bool mUseStackAlloc)
{
mLength = 0;
mCapacity = aCapacity;
mUseStackAlloc = true;

}

public static int get_Capacity(ref object aThis,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_capacity")] ref int mCapacity)
{
return mCapacity;
}

public static unsafe char get_Item(ref object aThis, int aIndex,
[FieldAccess(Name = "System.Char* System.IO.PathHelper.m_arrayPtr")] ref char* mArrayPtr)
{
return mArrayPtr[aIndex];
}

public static unsafe void set_Item(ref object aThis, int aIndex, char aValue,
[FieldAccess(Name = "System.Char* System.IO.PathHelper.m_arrayPtr")] ref char* mArrayPtr)
{
mArrayPtr[aIndex] = aValue;
}

public static int get_Length(ref object aThis,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_length")] ref int mLength)
{
return mLength;
}

public static void set_Length(ref object aThis, int aValue,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_length")] ref int mLength)
{
mLength = aValue;
}

public static unsafe void Append(ref object aThis, char aValue,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_capacity")] ref int mCapacity,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_length")] ref int mLength,
[FieldAccess(Name = "System.Char* System.IO.PathHelper.m_arrayPtr")] ref char* mArrayPtr)
{
if (mLength + 1 > mCapacity)
{
throw new PathTooLongException();
}

mArrayPtr[mLength] = aValue;
mLength++;
}

public static unsafe int GetFullPathName(ref object aThis,
[FieldAccess(Name = "System.Char* System.IO.PathHelper.m_arrayPtr")] ref char* aArrayPtr)
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_length")] ref int mLength,
[FieldAccess(Name = "System.Char* System.IO.PathHelper.m_arrayPtr")] ref char* mArrayPtr)
{
int xLength = 0;
while (*aArrayPtr != '\0')
while (*mArrayPtr != '\0')
{
xLength++;
aArrayPtr++;
mArrayPtr++;
}
mLength = xLength;
return xLength;
}

public static bool TryExpandShortFileName(ref object aThis)
public static unsafe string ToString(ref object aThis,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_length")] ref int mLength,
[FieldAccess(Name = "System.Char* System.IO.PathHelper.m_arrayPtr")] ref char* mArrayPtr)
{
return new string(mArrayPtr, 0, mLength);
}

public static unsafe bool TryExpandShortFileName(ref object aThis,
[FieldAccess(Name = "System.Int32 System.IO.PathHelper.m_length")] ref int mLength,
[FieldAccess(Name = "System.Char* System.IO.PathHelper.m_arrayPtr")] ref char* mArrayPtr)
{
int xLength = 0;
while (*mArrayPtr != '\0')
{
xLength++;
mArrayPtr++;
}
mLength = xLength;
return true;
}
}

}
6 changes: 3 additions & 3 deletions source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,14 @@ protected override void DoInterpretStackTypes(ref bool aSituationChanged)
return;
}

if ((StackPopTypes[0] == typeof (IntPtr) && StackPopTypes[1] == typeof (UInt32*))
if ((StackPopTypes[0] == typeof (IntPtr) && StackPopTypes[1] == typeof (uint*))
|| (StackPopTypes[0] == typeof (uint*) && StackPopTypes[1] == typeof (IntPtr)))
{
StackPushTypes[0] = typeof (uint*);
aSituationChanged = true;
return;
}
if ((StackPopTypes[0] == typeof(UIntPtr) && StackPopTypes[1] == typeof(UInt32*))
if ((StackPopTypes[0] == typeof(UIntPtr) && StackPopTypes[1] == typeof(uint*))
|| (StackPopTypes[0] == typeof(uint*) && StackPopTypes[1] == typeof(UIntPtr)))
{
StackPushTypes[0] = typeof(uint*);
Expand Down Expand Up @@ -663,7 +663,7 @@ protected override void DoInterpretStackTypes(ref bool aSituationChanged)
}
if (StackPopTypes[0] == typeof(IntPtr) && StackPopTypes[1] == typeof(IntPtr))
{
StackPushTypes[0] = typeof(uint);
StackPushTypes[0] = typeof(IntPtr);
aSituationChanged = true;
return;
}
Expand Down
3 changes: 1 addition & 2 deletions source/Cosmos.IL2CPU/ILOpCodes/OpVar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ protected override void DoInitStackAnalysis(MethodBase aMethod)
}
xArgIndexCorrection = -1;
}
string x = aMethod.Name;
var xParams = aMethod.GetParameters();
StackPushTypes[0] = xParams[Value + xArgIndexCorrection].ParameterType;
if (StackPushTypes[0].IsEnum)
{
StackPushTypes[0] = StackPushTypes[0].GetEnumUnderlyingType();
}
return;
default:
break;
}
}
}
Expand Down
120 changes: 60 additions & 60 deletions source/Cosmos.System.Plugs/System/IO/PathImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,20 +423,20 @@ public static string RemoveLongPathPrefix(string aPath)
// return false;
//}

//public static bool IsDirectorySeparator(char aC)
//{
// if (aC.ToString() == Path.DirectorySeparatorChar.ToString())
// {
// return true;
// }
public static bool IsDirectorySeparator(char aC)
{
if (aC.ToString() == Path.DirectorySeparatorChar.ToString())
{
return true;
}

// if (aC.ToString() == Path.AltDirectorySeparatorChar.ToString())
// {
// return true;
// }
if (aC.ToString() == Path.AltDirectorySeparatorChar.ToString())
{
return true;
}

// return false;
//}
return false;
}

//public static bool IsPathRooted(string aPath)
//{
Expand All @@ -455,54 +455,54 @@ public static string RemoveLongPathPrefix(string aPath)
// return false;
//}

//private static bool IsRelative(string aPath)
//{
// if (aPath == null)
// {
// throw new ArgumentNullException("aPath");
// }

// if (aPath.Length < 3)
// {
// return true;
// }

// if (aPath[1] != Path.VolumeSeparatorChar)
// {
// return true;
// }

// if (aPath[2] != Path.DirectorySeparatorChar)
// {
// return true;
// }

// return false;
//}

//public static string NormalizePath(string aPath, bool aFullCheck)
//{
// if (aPath == null)
// {
// Global.mFileSystemDebugger.SendInternal($"Path.NormalizePath : aPath is null");
// throw new ArgumentNullException("aPath");
// }

// string result = aPath;
// if (IsRelative(result))
// {
// result = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + result;
// Global.mFileSystemDebugger.SendInternal($"Path.NormalizePath : aPath is relative, aPath = {aPath}, result = {result}");
// }

// if (IsDirectorySeparator(result[result.Length - 1]))
// {
// Global.mFileSystemDebugger.SendInternal($"Path.NormalizePath : Found directory seprator");
// result = result.Remove(result.Length - 1);
// }
private static bool IsRelative(string aPath)
{
if (aPath == null)
{
throw new ArgumentNullException("aPath");
}

if (aPath.Length < 3)
{
return true;
}

if (aPath[1] != Path.VolumeSeparatorChar)
{
return true;
}

if (aPath[2] != Path.DirectorySeparatorChar)
{
return true;
}

return false;
}

// Global.mFileSystemDebugger.SendInternal($"Path.NormalizePath : aPath = {aPath}, returning {result}");
// return result;
//}
public static string NormalizePath(string aPath, bool aFullCheck)
{
if (aPath == null)
{
Global.mFileSystemDebugger.SendInternal($"Path.NormalizePath : aPath is null");
throw new ArgumentNullException("aPath");
}

string result = aPath;
if (IsRelative(result))
{
result = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + result;
Global.mFileSystemDebugger.SendInternal($"Path.NormalizePath : aPath is relative, aPath = {aPath}, result = {result}");
}

if (IsDirectorySeparator(result[result.Length - 1]))
{
Global.mFileSystemDebugger.SendInternal($"Path.NormalizePath : Found directory seprator");
result = result.Remove(result.Length - 1);
}

Global.mFileSystemDebugger.SendInternal($"Path.NormalizePath : aPath = {aPath}, returning {result}");
return result;
}
}
}
60 changes: 56 additions & 4 deletions source/Cosmos.System/FileSystem/VFS/VFSManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,44 @@ public static char GetDirectorySeparatorChar()

public static char[] GetInvalidFileNameChars()
{
char[] xReturn = { '"', '<', '>', '|', '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r', ':', '*', '?', '\\', '/' };
char[] xReturn = new char[17];
xReturn[0] = '"';
xReturn[1] = '<';
xReturn[2] = '>';
xReturn[3] = '|';
xReturn[4] = '\0';
xReturn[5] = '\a';
xReturn[6] = '\b';
xReturn[7] = '\t';
xReturn[8] = '\n';
xReturn[9] = '\v';
xReturn[10] = '\f';
xReturn[11] = '\r';
xReturn[12] = ':';
xReturn[13] = '*';
xReturn[14] = '?';
xReturn[15] = '\\';
xReturn[16] = '/';
return xReturn;
}

public static char[] GetInvalidPathCharsWithAdditionalChecks()
{
char[] xReturn = { '"', '<', '>', '|', '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r', '*', '?' };
char[] xReturn = new char[14];
xReturn[0] = '"';
xReturn[1] = '<';
xReturn[2] = '>';
xReturn[3] = '|';
xReturn[4] = '\0';
xReturn[5] = '\a';
xReturn[6] = '\b';
xReturn[7] = '\t';
xReturn[8] = '\n';
xReturn[9] = '\v';
xReturn[10] = '\f';
xReturn[11] = '\r';
xReturn[12] = '*';
xReturn[13] = '?';
return xReturn;
}

Expand All @@ -311,13 +342,34 @@ public static char GetPathSeparator()

public static char[] GetRealInvalidPathChars()
{
char[] xReturn = { '"', '<', '>', '|', '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r' };
char[] xReturn = new char[12];
xReturn[0] = '"';
xReturn[1] = '<';
xReturn[2] = '>';
xReturn[3] = '|';
xReturn[4] = '\0';
xReturn[5] = '\a';
xReturn[6] = '\b';
xReturn[7] = '\t';
xReturn[8] = '\n';
xReturn[9] = '\v';
xReturn[10] = '\f';
xReturn[11] = '\r';
return xReturn;
}

public static char[] GetTrimEndChars()
{
return new[] { (char)0x9, (char)0xA, (char)0xB, (char)0xC, (char)0xD, (char)0x20, (char)0x85, (char)0xA0 };
char[] xReturn = new char[8];
xReturn[0] = (char)0x9;
xReturn[1] = (char)0xA;
xReturn[2] = (char)0xB;
xReturn[3] = (char)0xC;
xReturn[4] = (char)0xD;
xReturn[5] = (char)0x20;
xReturn[6] = (char)0x85;
xReturn[7] = (char)0xA0;
return xReturn;
}

public static char GetVolumeSeparatorChar()
Expand Down

0 comments on commit 043cbb2

Please sign in to comment.