Skip to content
Permalink
Browse files

[UWP] Simplified some code (can now use Thread and other newer API)

  • Loading branch information
xen2 committed Dec 18, 2018
1 parent 1b076ca commit 48dddcf52dbc0734a588868c3fe66eb4d1e3bd86
Showing with 135 additions and 1,116 deletions.
  1. +1 −1 sources/core/Xenko.Core.Design/Xenko.Core.Design.csproj
  2. +0 −4 sources/core/Xenko.Core.IO/DirectoryWatcher.cs
  3. +0 −46 sources/core/Xenko.Core.IO/FileSystemProvider.UWP.cs
  4. +1 −1 sources/core/Xenko.Core.IO/FileSystemProvider.Windows.cs
  5. +9 −13 sources/core/Xenko.Core.IO/FileSystemProvider.cs
  6. +96 −0 sources/core/Xenko.Core.IO/NativeLockFile.cs
  7. +0 −4 sources/core/Xenko.Core.Mathematics/AngleSingle.cs
  8. +0 −4 sources/core/Xenko.Core.MicroThreading/Scheduler.cs
  9. +0 −23 sources/core/Xenko.Core.Serialization/IO/NativeLockFile.cs
  10. +12 −94 sources/core/Xenko.Core.Serialization/IO/Store.cs
  11. +1 −1 sources/core/Xenko.Core.Serialization/Storage/BundleOdbBackend.cs
  12. +0 −16 sources/core/Xenko.Core/BrowsableAttribute.cs
  13. +0 −20 sources/core/Xenko.Core/CategoryAttribute.cs
  14. +0 −4 sources/core/Xenko.Core/Diagnostics/SafeAction.cs
  15. +0 −111 sources/core/Xenko.Core/IO/NativeFile.UWP.cs
  16. +0 −50 sources/core/Xenko.Core/IO/NativeFile.cs
  17. +0 −11 sources/core/Xenko.Core/Native/SuppressUnmanagedCodeSecurityAttribute.cs
  18. +0 −27 sources/core/Xenko.Core/Platform.cs
  19. +2 −8 sources/core/Xenko.Core/PlatformFolders.cs
  20. +0 −7 sources/core/Xenko.Core/Reflection/ModuleRuntimeHelpers.cs
  21. +0 −18 sources/core/Xenko.Core/ThreadHelper.UWP.cs
  22. +11 −11 sources/engine/Xenko.Engine/Engine/Network/RouterClient.cs
  23. +0 −31 sources/engine/Xenko.Engine/Engine/Network/SocketSerializer.cs
  24. +0 −2 sources/engine/Xenko.Engine/Engine/Network/Sockets.Implementation.NET/CommsInterface.cs
  25. +0 −2 sources/engine/Xenko.Engine/Engine/Network/Sockets.Implementation.NET/CommsInterfaceNative.cs
  26. +0 −2 sources/engine/Xenko.Engine/Engine/Network/Sockets.Implementation.NET/NetworkExtensions.cs
  27. +0 −2 sources/engine/Xenko.Engine/Engine/Network/Sockets.Implementation.NET/TcpSocketClient.cs
  28. +2 −8 sources/engine/Xenko.Engine/Engine/Network/Sockets.Implementation.NET/TcpSocketListener.cs
  29. +0 −141 sources/engine/Xenko.Engine/Engine/Network/Sockets.Implementation.WinRT/CommsInterface.cs
  30. +0 −21 sources/engine/Xenko.Engine/Engine/Network/Sockets.Implementation.WinRT/LICENSE.md
  31. +0 −109 sources/engine/Xenko.Engine/Engine/Network/Sockets.Implementation.WinRT/NetworkExtensions.cs
  32. +0 −139 sources/engine/Xenko.Engine/Engine/Network/Sockets.Implementation.WinRT/TcpSocketClient.cs
  33. +0 −134 sources/engine/Xenko.Engine/Engine/Network/Sockets.Implementation.WinRT/TcpSocketListener.cs
  34. +0 −8 sources/engine/Xenko.Graphics/Font/FontManager.cs
  35. +0 −1 sources/engine/Xenko.Input/Windows/MouseWinforms.cs
  36. +0 −5 sources/engine/Xenko.Physics/Data/ConvexHullColliderShapeDesc.cs
  37. +0 −7 sources/engine/Xenko.Shaders.Compiler/OpenGL/ShaderCompiler.cs
  38. +0 −2 sources/engine/Xenko.Shaders.Parser/Mixins/ShaderSourceManager.cs
  39. +0 −18 sources/engine/Xenko.Shaders/Compiler/EffectPriorityScheduler.cs
  40. +0 −4 sources/engine/Xenko/Effects/ParameterKey.cs
  41. +0 −2 sources/shaders/Irony/Parsing/Grammar/Grammar.cs
  42. +0 −2 sources/shared/Xenko.Core.ShellHelper/ProcessOutputs.cs
  43. +0 −2 sources/shared/Xenko.Core.ShellHelper/ShellHelper.cs
@@ -21,7 +21,7 @@
<Compile Include="..\..\shared\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\Xenko.Core.Serialization\IO\NativeLockFile.cs">
<Compile Include="..\Xenko.Core.IO\NativeLockFile.cs">
<Link>Windows\NativeLockFile.cs</Link>
</Compile>
</ItemGroup>
@@ -12,9 +12,7 @@ namespace Xenko.Core.IO
public partial class DirectoryWatcher : IDisposable
{
private const int SleepBetweenWatcherCheck = 200;
#if !XENKO_PLATFORM_UWP
private Thread watcherCheckThread;
#endif
private bool exitThread;

/// <summary>
@@ -44,13 +42,11 @@ public DirectoryWatcher(string fileFilter = null)
public virtual void Dispose()
{
exitThread = true;
#if !XENKO_PLATFORM_UWP
if (watcherCheckThread != null)
{
watcherCheckThread.Join();
watcherCheckThread = null;
}
#endif
DisposeInternal();
}

This file was deleted.

@@ -1,6 +1,6 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
#if XENKO_PLATFORM_WINDOWS_DESKTOP || XENKO_PLATFORM_UNIX
#if XENKO_PLATFORM_WINDOWS_DESKTOP || XENKO_PLATFORM_UNIX || XENKO_PLATFORM_UWP
using System;
using System.IO;
using System.Linq;
@@ -11,13 +11,8 @@ namespace Xenko.Core.IO
/// </summary>
public partial class FileSystemProvider : VirtualFileProviderBase
{
#if XENKO_PLATFORM_UWP
public static readonly char VolumeSeparatorChar = ':';
public static readonly char DirectorySeparatorChar = '\\';
#else
public static readonly char VolumeSeparatorChar = Path.VolumeSeparatorChar;
public static readonly char DirectorySeparatorChar = Path.DirectorySeparatorChar;
#endif
public static readonly char AltDirectorySeparatorChar = AltDirectorySeparatorChar == '/' ? '\\' : '/';

/// <summary>
@@ -68,7 +63,7 @@ protected virtual string ConvertFullPathToUrl(string path)
public override bool DirectoryExists(string url)
{
var path = ConvertUrlToFullPath(url);
return NativeFile.DirectoryExists(path);
return Directory.Exists(path);
}

/// <inheritdoc/>
@@ -77,7 +72,7 @@ public override void CreateDirectory(string url)
var path = ConvertUrlToFullPath(url);
try
{
NativeFile.DirectoryCreate(path);
Directory.CreateDirectory(path);
}
catch (Exception ex)
{
@@ -88,24 +83,25 @@ public override void CreateDirectory(string url)
/// <inheritdoc/>
public override bool FileExists(string url)
{
return NativeFile.FileExists(ConvertUrlToFullPath(url));
return File.Exists(ConvertUrlToFullPath(url));
}

public override long FileSize(string url)
{
return NativeFile.FileSize(ConvertUrlToFullPath(url));
var fileInfo = new FileInfo(ConvertUrlToFullPath(url));
return fileInfo.Length;
}

/// <inheritdoc/>
public override void FileDelete(string url)
{
NativeFile.FileDelete(ConvertUrlToFullPath(url));
File.Delete(ConvertUrlToFullPath(url));
}

/// <inheritdoc/>
public override void FileMove(string sourceUrl, string destinationUrl)
{
NativeFile.FileMove(ConvertUrlToFullPath(sourceUrl), ConvertUrlToFullPath(destinationUrl));
File.Move(ConvertUrlToFullPath(sourceUrl), ConvertUrlToFullPath(destinationUrl));
}

/// <inheritdoc/>
@@ -115,7 +111,7 @@ public override void FileMove(string sourceUrl, IVirtualFileProvider destination
if (fsProvider != null)
{
destinationProvider.CreateDirectory(destinationUrl.Substring(0, destinationUrl.LastIndexOf(VirtualFileSystem.DirectorySeparatorChar)));
NativeFile.FileMove(ConvertUrlToFullPath(sourceUrl), fsProvider.ConvertUrlToFullPath(destinationUrl));
File.Move(ConvertUrlToFullPath(sourceUrl), fsProvider.ConvertUrlToFullPath(destinationUrl));
}
else
{
@@ -124,7 +120,7 @@ public override void FileMove(string sourceUrl, IVirtualFileProvider destination
{
sourceStream.CopyTo(destinationStream);
}
NativeFile.FileDelete(sourceUrl);
File.Delete(sourceUrl);
}
}
}
@@ -0,0 +1,96 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
#pragma warning disable SA1310 // Field names must not contain underscore
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;

namespace Xenko.Core.IO
{
public static class NativeLockFile
{
#if XENKO_PLATFORM_WINDOWS_DESKTOP || XENKO_PLATFORM_UWP
[DllImport("Kernel32.dll", SetLastError = true)]
internal static extern bool LockFileEx(Microsoft.Win32.SafeHandles.SafeFileHandle handle, uint flags, uint reserved, uint countLow, uint countHigh, ref System.Threading.NativeOverlapped overlapped);

[DllImport("Kernel32.dll", SetLastError = true)]
internal static extern bool UnlockFileEx(Microsoft.Win32.SafeHandles.SafeFileHandle handle, uint reserved, uint countLow, uint countHigh, ref System.Threading.NativeOverlapped overlapped);

internal const uint LOCKFILE_FAIL_IMMEDIATELY = 0x00000001;
internal const uint LOCKFILE_EXCLUSIVE_LOCK = 0x00000002;
#endif

public static void LockFile(FileStream fileStream, long offset, long count, bool exclusive)
{
#if XENKO_PLATFORM_ANDROID
// Android does not support large file and thus is limited to files
// whose sizes are less than 2GB.
// We substract the offset to not go beyond the 2GB limit.
count = (count + offset > int.MaxValue) ? int.MaxValue - offset: count;
#endif

#if XENKO_PLATFORM_WINDOWS_DESKTOP || XENKO_PLATFORM_UWP
var countLow = (uint)count;
var countHigh = (uint)(count >> 32);

var overlapped = new NativeOverlapped()
{
InternalLow = IntPtr.Zero,
InternalHigh = IntPtr.Zero,
OffsetLow = (int)(offset & 0x00000000FFFFFFFF),
OffsetHigh = (int)(offset >> 32),
EventHandle = IntPtr.Zero,
};

if (!LockFileEx(fileStream.SafeFileHandle, exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, countLow, countHigh, ref overlapped))
{
throw new IOException("Couldn't lock file.");
}
#else
bool tryAgain;
do
{
tryAgain = false;
try
{
fileStream.Lock(offset, count);
}
catch (IOException)
{
tryAgain = true;
}
} while (tryAgain);
#endif
}

public static void UnlockFile(FileStream fileStream, long offset, long count)
{
#if XENKO_PLATFORM_ANDROID
// See comment on `LockFile`.
count = (count + offset > int.MaxValue) ? int.MaxValue - offset: count;
#endif

#if XENKO_PLATFORM_WINDOWS_DESKTOP || XENKO_PLATFORM_UWP
var countLow = (uint)count;
var countHigh = (uint)(count >> 32);

var overlapped = new NativeOverlapped()
{
InternalLow = IntPtr.Zero,
InternalHigh = IntPtr.Zero,
OffsetLow = (int)(offset & 0x00000000FFFFFFFF),
OffsetHigh = (int)(offset >> 32),
EventHandle = IntPtr.Zero,
};

if (!UnlockFileEx(fileStream.SafeFileHandle, 0, countLow, countHigh, ref overlapped))
{
throw new IOException("Couldn't unlock file.");
}
#else
fileStream.Unlock(offset, count);
#endif
}
}
}
@@ -465,9 +465,6 @@ public static AngleSingle ZeroAngle
get { return new AngleSingle(0.0f, AngleType.Radian); }
}

// Currently those 3 routines RightAngle, StraightAngle and FullRotationAngle are causing the .NET native
// compiler to crash when targeting Windows 10 Universal apps.
#if !XENKO_PLATFORM_UWP || WIN_X64_AOT_BUG_FIXED
/// <summary>
/// Gets a new Xenko.Core.Mathematics.AngleSingle instance that represents the right angle (i.e. 90° or π/2).
/// </summary>
@@ -491,7 +488,6 @@ public static AngleSingle FullRotationAngle
{
get { return new AngleSingle(MathUtil.TwoPi, AngleType.Radian); }
}
#endif

/// <summary>
/// Returns a System.Boolean that indicates whether the values of two Xenko.Core.Mathematics.Angle
@@ -111,11 +111,7 @@ public ChannelMicroThreadAwaiter<int> NextFrame()
/// </summary>
public void Run()
{
#if XENKO_PLATFORM_UWP
int managedThreadId = 0;
#else
int managedThreadId = Thread.CurrentThread.ManagedThreadId;
#endif

MicroThreadCallbackList callbacks = default(MicroThreadCallbackList);

This file was deleted.

0 comments on commit 48dddcf

Please sign in to comment.
You can’t perform that action at this time.