From f83aef39b077ebad12e671c3d319c6a7752592ca Mon Sep 17 00:00:00 2001 From: fanoI Date: Sun, 1 Oct 2017 16:45:04 +0200 Subject: [PATCH] Removed from DirectoryImpl.cs all the method that did not need plug anymore: CosmosFileSystem methods are called directly from Net Core code, the only remaing plugs are the ones that need IEnumerable to work. --- Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs | 2 +- .../System.IO/DirectoryTest.cs | 8 ++ .../System/IO/CosmosFileSystem.cs | 19 +++- .../System/IO/DirectoryImpl.cs | 96 +------------------ 4 files changed, 26 insertions(+), 99 deletions(-) diff --git a/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs b/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs index 01d39f29c..d36b47522 100644 --- a/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs +++ b/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs @@ -38,7 +38,7 @@ namespace Cosmos.Kernel.Tests.Fat PathTest.Execute(mDebugger); DirectoryTest.Execute(mDebugger); FileTest.Execute(mDebugger); - FileStreamTest.Execute(mDebugger); + FileStreamTest.Execute(mDebugger); DirectoryInfoTest.Execute(mDebugger); //StreamWriterTest.Execute(mDebugger); diff --git a/Tests/Cosmos.Kernel.Tests.Fat/System.IO/DirectoryTest.cs b/Tests/Cosmos.Kernel.Tests.Fat/System.IO/DirectoryTest.cs index ea808ddae..c77b509b5 100644 --- a/Tests/Cosmos.Kernel.Tests.Fat/System.IO/DirectoryTest.cs +++ b/Tests/Cosmos.Kernel.Tests.Fat/System.IO/DirectoryTest.cs @@ -122,6 +122,14 @@ namespace Cosmos.Kernel.Tests.Fat.System.IO mDebugger.Send(""); + mDebugger.Send("START TEST: Set Current Directory:"); + var ExpectedCurrentDirectory = @"0:\TestDir1"; + Directory.SetCurrentDirectory(ExpectedCurrentDirectory); + var CurrentDirectory = Directory.GetCurrentDirectory(); + Assert.IsTrue(ExpectedCurrentDirectory == CurrentDirectory, "Current Directory is wrong!"); + mDebugger.Send("END TEST"); + + mDebugger.Send(""); } } } diff --git a/source/Cosmos.System2_Plugs/System/IO/CosmosFileSystem.cs b/source/Cosmos.System2_Plugs/System/IO/CosmosFileSystem.cs index 66210b4c6..f6c8872e2 100644 --- a/source/Cosmos.System2_Plugs/System/IO/CosmosFileSystem.cs +++ b/source/Cosmos.System2_Plugs/System/IO/CosmosFileSystem.cs @@ -1,4 +1,4 @@ -//#define COSMOSDEBUG +#define COSMOSDEBUG using System; using System.IO; using System.Collections.Generic; @@ -21,6 +21,12 @@ namespace Cosmos.System_Plugs.System.IO [Plug(TargetName = "System.IO.FileSystem, System.IO.FileSystem", Inheritable = true)] public static class CosmosFileSystem { + /* + * This "trick" will work until we have not multi threading / multi process then you must do in the correct + * way (an "attribute" of the running thread itself?) + */ + private static string mCurrentDirectory = string.Empty; + public static void CreateDirectory(object aThis, string fullPath) { // If 'fullPath' exists already we return already without dealing with VFSManager @@ -69,12 +75,17 @@ namespace Cosmos.System_Plugs.System.IO throw new NotImplementedException("MoveDirectory not implemented"); } -#if false public static string GetCurrentDirectory(object aThis) { - return ""; + Global.mFileSystemDebugger.SendInternal($"Directory.GetCurrentDirectory : mCurrentDirectory = {mCurrentDirectory}"); + return mCurrentDirectory; + } + + public static void SetCurrentDirectory(object aThis, string fullPath) + { + Global.mFileSystemDebugger.SendInternal($"Directory.SetCurrentDirectory : aPath = {fullPath}"); + mCurrentDirectory = fullPath; } -#endif public static object /* FileStreamBase */ Open(object aThis, string fullPath, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, FileStream parent) { diff --git a/source/Cosmos.System2_Plugs/System/IO/DirectoryImpl.cs b/source/Cosmos.System2_Plugs/System/IO/DirectoryImpl.cs index 4ae2615e6..7d15b2862 100644 --- a/source/Cosmos.System2_Plugs/System/IO/DirectoryImpl.cs +++ b/source/Cosmos.System2_Plugs/System/IO/DirectoryImpl.cs @@ -2,11 +2,8 @@ using System; using System.IO; using System.Collections.Generic; -using Cosmos.Debug.Kernel; -using Cosmos.IL2CPU.API; using Cosmos.IL2CPU.API.Attribs; using Cosmos.System; -using Cosmos.System.FileSystem; using Cosmos.System.FileSystem.Listing; using Cosmos.System.FileSystem.VFS; @@ -15,97 +12,7 @@ namespace Cosmos.System_Plugs.System.IO [Plug(Target = typeof(Directory))] public static class DirectoryImpl { - private static string mCurrentDirectory = string.Empty; - - public static string GetCurrentDirectory() - { - Global.mFileSystemDebugger.SendInternal($"Directory.GetCurrentDirectory : mCurrentDirectory = {mCurrentDirectory}"); - return mCurrentDirectory; - } - - public static void SetCurrentDirectory(string aPath) - { - Global.mFileSystemDebugger.SendInternal($"Directory.SetCurrentDirectory : aPath = {aPath}"); - mCurrentDirectory = aPath; - } - - public static bool Exists(string aPath) - { - if (aPath == null) - { - return false; - } - - Global.mFileSystemDebugger.SendInternal($"Directory.Exists : aPath = {aPath}"); - return VFSManager.DirectoryExists(aPath); - } - - public static DirectoryInfo CreateDirectory(string aPath) - { - if (aPath == null) - { - throw new ArgumentNullException("aPath"); - } - - if (aPath.Length == 0) - { - throw new ArgumentException("Path must not be empty.", "aPath"); - } - - Global.mFileSystemDebugger.SendInternal($"Directory.CreateDirectory : aPath = {aPath}"); - - var xEntry = VFSManager.CreateDirectory(aPath); - - if (xEntry == null) - { - return null; - } - - return new DirectoryInfo(aPath); - } - - public static void Delete(string aPath) - { - Delete(aPath, false); - } - - public static void Delete(string aPath, bool recursive) - { - String xFullPath = Path.GetFullPath(aPath); - - VFSManager.DeleteDirectory(xFullPath, recursive); - } - - public static DirectoryInfo GetParent(string aPath) - { - Global.mFileSystemDebugger.SendInternal("Directory.GetParent:"); - - if (aPath == null) - { - Global.mFileSystemDebugger.SendInternal("Directory.GetParent : aPath is null"); - throw new ArgumentNullException("aPath"); - } - - if (aPath.Length == 0) - { - Global.mFileSystemDebugger.SendInternal("Directory.GetParent : aPath is empty"); - throw new ArgumentException("Path must not be empty.", "aPath"); - } - - Global.mFileSystemDebugger.SendInternal("aPath ="); - Global.mFileSystemDebugger.SendInternal(aPath); - - string xFullPath = Path.GetFullPath(aPath); - string xParentDirectory = Path.GetDirectoryName(xFullPath); - if (xParentDirectory == null) - { - Global.mFileSystemDebugger.SendInternal("Directory.GetParent : xParentDirectory is null"); - return null; - } - - return new DirectoryInfo(xParentDirectory); - } - + /* The real implementation uses IEnumerable and do a conversion ToArray that crashes IL2CPU */ public static string[] GetDirectories(string aPath) { Global.mFileSystemDebugger.SendInternal("Directory.GetDirectories"); @@ -127,6 +34,7 @@ namespace Cosmos.System_Plugs.System.IO return xDirectories.ToArray(); } + /* The real implementation uses IEnumerable and do a conversion ToArray that crashes IL2CPU */ public static string[] GetFiles(string aPath) { Global.mFileSystemDebugger.SendInternal("Directory.GetFiles");