mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-22 22:09:12 +00:00
Fixed path plugs
This commit is contained in:
parent
a52ea7a514
commit
043cbb2f19
6 changed files with 214 additions and 69 deletions
|
|
@ -134,7 +134,6 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Cosmos.snk" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -535,14 +535,14 @@ namespace Cosmos.IL2CPU.ILOpCodes {
|
|||
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*);
|
||||
|
|
@ -663,7 +663,7 @@ namespace Cosmos.IL2CPU.ILOpCodes {
|
|||
}
|
||||
if (StackPopTypes[0] == typeof(IntPtr) && StackPopTypes[1] == typeof(IntPtr))
|
||||
{
|
||||
StackPushTypes[0] = typeof(uint);
|
||||
StackPushTypes[0] = typeof(IntPtr);
|
||||
aSituationChanged = true;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ namespace Cosmos.IL2CPU.ILOpCodes
|
|||
}
|
||||
xArgIndexCorrection = -1;
|
||||
}
|
||||
string x = aMethod.Name;
|
||||
var xParams = aMethod.GetParameters();
|
||||
StackPushTypes[0] = xParams[Value + xArgIndexCorrection].ParameterType;
|
||||
if (StackPushTypes[0].IsEnum)
|
||||
|
|
@ -102,8 +103,6 @@ namespace Cosmos.IL2CPU.ILOpCodes
|
|||
StackPushTypes[0] = StackPushTypes[0].GetEnumUnderlyingType();
|
||||
}
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -423,20 +423,20 @@ namespace Cosmos.System.Plugs.System.IO
|
|||
// 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)
|
||||
//{
|
||||
|
|
@ -455,54 +455,54 @@ namespace Cosmos.System.Plugs.System.IO
|
|||
// return false;
|
||||
//}
|
||||
|
||||
//private static bool IsRelative(string aPath)
|
||||
//{
|
||||
// if (aPath == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("aPath");
|
||||
// }
|
||||
private static bool IsRelative(string aPath)
|
||||
{
|
||||
if (aPath == null)
|
||||
{
|
||||
throw new ArgumentNullException("aPath");
|
||||
}
|
||||
|
||||
// if (aPath.Length < 3)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
if (aPath.Length < 3)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// if (aPath[1] != Path.VolumeSeparatorChar)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
if (aPath[1] != Path.VolumeSeparatorChar)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// if (aPath[2] != Path.DirectorySeparatorChar)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
if (aPath[2] != Path.DirectorySeparatorChar)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// return false;
|
||||
//}
|
||||
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");
|
||||
// }
|
||||
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}");
|
||||
// }
|
||||
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);
|
||||
// }
|
||||
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;
|
||||
//}
|
||||
Global.mFileSystemDebugger.SendInternal($"Path.NormalizePath : aPath = {aPath}, returning {result}");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,13 +294,44 @@ namespace Cosmos.System.FileSystem.VFS
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -311,13 +342,34 @@ namespace Cosmos.System.FileSystem.VFS
|
|||
|
||||
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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue