Skip to content

Commit

Permalink
Fixed Path
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbetros committed Feb 25, 2016
2 parents 1f104d8 + 043cbb2 commit 5b35e17
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
<Bochs_StartCosmosGDB>false</Bochs_StartCosmosGDB>
<TraceAssemblies>All</TraceAssemblies>
<Bochs_TraceAssemblies>All</Bochs_TraceAssemblies>
<StackCorruptionDetectionEnabled>False</StackCorruptionDetectionEnabled>
<Bochs_StackCorruptionDetectionEnabled>False</Bochs_StackCorruptionDetectionEnabled>
<StackCorruptionDetectionEnabled>True</StackCorruptionDetectionEnabled>
<Bochs_StackCorruptionDetectionEnabled>True</Bochs_StackCorruptionDetectionEnabled>
<VMware_StackCorruptionDetectionEnabled>False</VMware_StackCorruptionDetectionEnabled>
<VMware_TraceAssemblies>All</VMware_TraceAssemblies>
<ISO_StackCorruptionDetectionEnabled>False</ISO_StackCorruptionDetectionEnabled>
Expand All @@ -67,9 +67,9 @@
<ISO_TraceAssemblies>All</ISO_TraceAssemblies>
<ISO_EnableGDB>False</ISO_EnableGDB>
<ISO_StartCosmosGDB>false</ISO_StartCosmosGDB>
<EnableBochsDebug>False</EnableBochsDebug>
<EnableBochsDebug>True</EnableBochsDebug>
<StartBochsDebugGui>False</StartBochsDebugGui>
<Bochs_EnableBochsDebug>False</Bochs_EnableBochsDebug>
<Bochs_EnableBochsDebug>True</Bochs_EnableBochsDebug>
<Bochs_StartBochsDebugGui>False</Bochs_StartBochsDebugGui>
<ISO_EnableBochsDebug>False</ISO_EnableBochsDebug>
<ISO_StartBochsDebugGui>False</ISO_StartBochsDebugGui>
Expand Down
40 changes: 40 additions & 0 deletions source/Cosmos.Common/StringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ public static class StringHelper
{
internal static Debugger mDebugger = new Debugger("Common", "String Helpers");

internal enum StringComparisonResultEnum
{
Less = -1,

Equal = 0,

Greater = 1
}

public static string GetCharArrayString(char[] aArray)
{
if (aArray == null)
Expand Down Expand Up @@ -131,5 +140,36 @@ public static int GetStringToNumber(string aString)

return xNumber;
}

public static int Compare(
string aString1,
int aIndex1,
string aString2,
int aIndex2,
int aLength1,
int aLength2)
{
if (aString1.Length < aString2.Length)
{
return (int)StringComparisonResultEnum.Less;
}
if (aString1.Length > aString2.Length)
{
return (int)StringComparisonResultEnum.Greater;
}

for (int i = aString1.Length; i < aString1.Length; i++)
{
if (aString1[i] < aString2[i])
{
return (int)StringComparisonResultEnum.Equal;
}
if (aString1[i] > aString2[i])
{
return (int)StringComparisonResultEnum.Greater;
}
}
return (int)StringComparisonResultEnum.Equal;
}
}
}
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;
}
}
}
Loading

0 comments on commit 5b35e17

Please sign in to comment.