From 49c9e3398cef0ac26d5558015775b5bbf4bd2086 Mon Sep 17 00:00:00 2001 From: Yoooi Date: Fri, 25 Dec 2020 19:08:35 +0100 Subject: [PATCH 1/6] Update project file list --- ToySerialController.csproj | 5 ++--- meta.json | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ToySerialController.csproj b/ToySerialController.csproj index da8c1c9..51ae188 100644 --- a/ToySerialController.csproj +++ b/ToySerialController.csproj @@ -104,8 +104,8 @@ - - + + @@ -118,7 +118,6 @@ - diff --git a/meta.json b/meta.json index 28ef68d..ba6e254 100644 --- a/meta.json +++ b/meta.json @@ -25,10 +25,9 @@ "Custom\\Scripts\\Yoooi\\ToySerialController\\lib\\vam-debug-utils\\LineDrawer.cs", "Custom\\Scripts\\Yoooi\\ToySerialController\\src\\Config\\ConfigManager.cs", "Custom\\Scripts\\Yoooi\\ToySerialController\\src\\Config\\IConfigProvider.cs", - "Custom\\Scripts\\Yoooi\\ToySerialController\\src\\Device\\AbstractGenericDevice.cs", - "Custom\\Scripts\\Yoooi\\ToySerialController\\src\\Device\\AbstractGenericDevice.UI.cs", "Custom\\Scripts\\Yoooi\\ToySerialController\\src\\Device\\IDevice.cs", "Custom\\Scripts\\Yoooi\\ToySerialController\\src\\Device\\TCodeDevice.cs", + "Custom\\Scripts\\Yoooi\\ToySerialController\\src\\Device\\TCodeDevice.UI.cs", "Custom\\Scripts\\Yoooi\\ToySerialController\\src\\MotionSource\\AbstractFemaleMotionSource.cs", "Custom\\Scripts\\Yoooi\\ToySerialController\\src\\MotionSource\\AbstractRefreshableMotionSource.cs", "Custom\\Scripts\\Yoooi\\ToySerialController\\src\\MotionSource\\AnimationMotionSource.cs", From 120e6103af94d98e29da15396464b5fec254ad12 Mon Sep 17 00:00:00 2001 From: Yoooi Date: Wed, 6 Jan 2021 14:13:10 +0100 Subject: [PATCH 2/6] Fix incorrect axis labels --- src/Device/TCodeDevice.UI.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Device/TCodeDevice.UI.cs b/src/Device/TCodeDevice.UI.cs index 2c9c5d6..bc5daac 100644 --- a/src/Device/TCodeDevice.UI.cs +++ b/src/Device/TCodeDevice.UI.cs @@ -203,7 +203,7 @@ private void CreateR1AxisUI(IUIBuilder builder) { var group = new UIGroup(builder); var visible = false; - R1AxisTitle = builder.CreateButton("Pitch | R1", () => group.SetVisible(visible = !visible), Color.magenta * 0.8f, Color.white, true); + R1AxisTitle = builder.CreateButton("Roll | R1", () => group.SetVisible(visible = !visible), Color.magenta * 0.8f, Color.white, true); RangeMaxR1Slider = group.CreateSlider("Device:RangeMaxR1", "Range Max (+/- \u00b0)", 30, 1, 89, true, true, true, "F0"); OutputMaxR1Slider = group.CreateSlider("Device:OutputMaxR1", "Output Max (+/- %)", 0.5f, 0f, 0.5f, true, true, true, "P0"); OffsetR1Slider = group.CreateSlider("Device:OffsetR1", "Offset (%)", 0f, -0.25f, 0.25f, true, true, true, "P0"); @@ -218,7 +218,7 @@ private void CreateR2AxisUI(IUIBuilder builder) { var group = new UIGroup(builder); var visible = false; - R2AxisTitle = builder.CreateButton("Roll | R2", () => group.SetVisible(visible = !visible), Color.yellow * 0.8f, Color.white, true); + R2AxisTitle = builder.CreateButton("Pitch | R2", () => group.SetVisible(visible = !visible), Color.yellow * 0.8f, Color.white, true); RangeMaxR2Slider = group.CreateSlider("Device:RangeMaxR2", "Range Max (+/- \u00b0)", 30, 1, 89, true, true, true, "F0"); OutputMaxR2Slider = group.CreateSlider("Device:OutputMaxR2", "Output Max (+/- %)", 0.5f, 0.01f, 0.5f, true, true, true, "P0"); OffsetR2Slider = group.CreateSlider("Device:OffsetR2", "Offset (%)", 0f, -0.25f, 0.25f, true, true, true, "P0"); From c7f9bc7e7ffc1121cb5642f75e2e6013d9dce921 Mon Sep 17 00:00:00 2001 From: Yoooi Date: Wed, 6 Jan 2021 14:13:24 +0100 Subject: [PATCH 3/6] Fix inverted R1 axis --- src/Device/TCodeDevice.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Device/TCodeDevice.cs b/src/Device/TCodeDevice.cs index 4840553..381a91a 100644 --- a/src/Device/TCodeDevice.cs +++ b/src/Device/TCodeDevice.cs @@ -120,7 +120,7 @@ public bool Update(IMotionSource motionSource) correctedRight -= 2 * Vector3.Project(correctedRight, motionSource.ReferenceRight); RTarget[0] = Vector3.SignedAngle(motionSource.ReferenceRight, correctedRight, motionSource.ReferenceUp) / 180; - RTarget[1] = Vector3.SignedAngle(motionSource.ReferenceUp, Vector3.ProjectOnPlane(motionSource.TargetUp, motionSource.ReferenceForward), motionSource.ReferenceForward) / 90; + RTarget[1] = -Vector3.SignedAngle(motionSource.ReferenceUp, Vector3.ProjectOnPlane(motionSource.TargetUp, motionSource.ReferenceForward), motionSource.ReferenceForward) / 90; RTarget[2] = Vector3.SignedAngle(motionSource.ReferenceUp, Vector3.ProjectOnPlane(motionSource.TargetUp, motionSource.ReferenceRight), motionSource.ReferenceRight) / 90; ETarget[0] = OutputV0CurveEditorSettings.Evaluate(XTarget, RTarget); From 93d4a0f733c035a49612c1aee5bfc43a463b5bf5 Mon Sep 17 00:00:00 2001 From: Yoooi Date: Wed, 6 Jan 2021 14:20:00 +0100 Subject: [PATCH 4/6] Cleanup smooting --- src/Device/TCodeDevice.cs | 97 ++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/src/Device/TCodeDevice.cs b/src/Device/TCodeDevice.cs index 381a91a..a944b18 100644 --- a/src/Device/TCodeDevice.cs +++ b/src/Device/TCodeDevice.cs @@ -12,9 +12,9 @@ public partial class TCodeDevice : IDevice protected readonly float[] XTarget, RTarget, ETarget; protected readonly float[] XCmd, RCmd, ECmd; - private float? _lastCollisionTime; - private bool _lastCollisionSmoothingEnabled; - private float _lastCollisionSmoothingStartTime, _lastCollisionSmoothingDuration; + private float? _lastNoCollisionTime; + private bool _lastNoCollisionSmoothingEnabled; + private float _lastNoCollisionSmoothingStartTime, _lastNoCollisionSmoothingDuration; protected string DeviceReport { get; set; } public string GetDeviceReport() => DeviceReport; @@ -28,6 +28,8 @@ public TCodeDevice() XCmd = new float[] { 0.5f, 0.5f, 0.5f }; RCmd = new float[] { 0.5f, 0.5f, 0.5f }; ECmd = new float[9]; + + _lastNoCollisionTime = Time.time; } public void Write(SerialPort serial) @@ -85,47 +87,57 @@ public bool Update(IMotionSource motionSource) for (var i = 0; i < 5; i++) DebugDraw.DrawCircle(Vector3.Lerp(motionSource.ReferencePosition, referenceEnding, i / 4.0f), motionSource.ReferenceUp, Color.grey, radius); - if (diffPosition.magnitude > 0.00001f) - { - var t = Mathf.Clamp(Vector3.Dot(motionSource.TargetPosition - motionSource.ReferencePosition, motionSource.ReferenceUp), 0f, length); - var closestPoint = motionSource.ReferencePosition + motionSource.ReferenceUp * t; + var t = Mathf.Clamp(Vector3.Dot(motionSource.TargetPosition - motionSource.ReferencePosition, motionSource.ReferenceUp), 0f, length); + var closestPoint = motionSource.ReferencePosition + motionSource.ReferenceUp * t; - if (Vector3.Magnitude(closestPoint - motionSource.TargetPosition) > radius) + if (Vector3.Magnitude(closestPoint - motionSource.TargetPosition) <= radius) + { + if (diffPosition.magnitude > 0.0001f) + { + XTarget[0] = 1 - Mathf.Clamp01((closestPoint - motionSource.ReferencePosition).magnitude / length); + if (aboveTarget) + XTarget[0] = XTarget[0] > 0 ? 1 : 0; + + var diffOnPlane = Vector3.ProjectOnPlane(diffPosition, motionSource.ReferencePlaneNormal); + var yOffset = Vector3.Project(diffOnPlane, motionSource.ReferenceRight); + var zOffset = Vector3.Project(diffOnPlane, motionSource.ReferenceForward); + XTarget[1] = yOffset.magnitude * Mathf.Sign(Vector3.Dot(yOffset, motionSource.ReferenceRight)); + XTarget[2] = zOffset.magnitude * Mathf.Sign(Vector3.Dot(zOffset, motionSource.ReferenceForward)); + } + else { - if (_lastCollisionTime == null) - _lastCollisionTime = Time.time; - return false; + XTarget[0] = 1; + XTarget[1] = 0; + XTarget[2] = 0; } - XTarget[0] = 1 - Mathf.Clamp01((closestPoint - motionSource.ReferencePosition).magnitude / length); - if (aboveTarget) - XTarget[0] = XTarget[0] > 0 ? 1 : 0; + var correctedRight = Vector3.ProjectOnPlane(motionSource.TargetRight, motionSource.ReferenceUp); + if (Vector3.Dot(correctedRight, motionSource.ReferenceRight) < 0) + correctedRight -= 2 * Vector3.Project(correctedRight, motionSource.ReferenceRight); + + RTarget[0] = Vector3.SignedAngle(motionSource.ReferenceRight, correctedRight, motionSource.ReferenceUp) / 180; + RTarget[1] = -Vector3.SignedAngle(motionSource.ReferenceUp, Vector3.ProjectOnPlane(motionSource.TargetUp, motionSource.ReferenceForward), motionSource.ReferenceForward) / 90; + RTarget[2] = Vector3.SignedAngle(motionSource.ReferenceUp, Vector3.ProjectOnPlane(motionSource.TargetUp, motionSource.ReferenceRight), motionSource.ReferenceRight) / 90; - var diffOnPlane = Vector3.ProjectOnPlane(diffPosition, motionSource.ReferencePlaneNormal); - var yOffset = Vector3.Project(diffOnPlane, motionSource.ReferenceRight); - var zOffset = Vector3.Project(diffOnPlane, motionSource.ReferenceForward); - XTarget[1] = yOffset.magnitude * Mathf.Sign(Vector3.Dot(yOffset, motionSource.ReferenceRight)); - XTarget[2] = zOffset.magnitude * Mathf.Sign(Vector3.Dot(zOffset, motionSource.ReferenceForward)); + ETarget[0] = OutputV0CurveEditorSettings.Evaluate(XTarget, RTarget); + ETarget[1] = OutputV1CurveEditorSettings.Evaluate(XTarget, RTarget); + ETarget[2] = OutputL3CurveEditorSettings.Evaluate(XTarget, RTarget); + + if (_lastNoCollisionTime != null) + { + _lastNoCollisionSmoothingEnabled = true; + _lastNoCollisionSmoothingStartTime = Time.time; + _lastNoCollisionSmoothingDuration = Mathf.Clamp(Time.time - _lastNoCollisionTime.Value, 0.5f, 2); + _lastNoCollisionTime = null; + } } else { - SuperController.singleton.Message("diff"); - XTarget[0] = 1; - XTarget[1] = 0; - XTarget[2] = 0; - } - - var correctedRight = Vector3.ProjectOnPlane(motionSource.TargetRight, motionSource.ReferenceUp); - if (Vector3.Dot(correctedRight, motionSource.ReferenceRight) < 0) - correctedRight -= 2 * Vector3.Project(correctedRight, motionSource.ReferenceRight); - - RTarget[0] = Vector3.SignedAngle(motionSource.ReferenceRight, correctedRight, motionSource.ReferenceUp) / 180; - RTarget[1] = -Vector3.SignedAngle(motionSource.ReferenceUp, Vector3.ProjectOnPlane(motionSource.TargetUp, motionSource.ReferenceForward), motionSource.ReferenceForward) / 90; - RTarget[2] = Vector3.SignedAngle(motionSource.ReferenceUp, Vector3.ProjectOnPlane(motionSource.TargetUp, motionSource.ReferenceRight), motionSource.ReferenceRight) / 90; + if (_lastNoCollisionTime == null) + _lastNoCollisionTime = Time.time; - ETarget[0] = OutputV0CurveEditorSettings.Evaluate(XTarget, RTarget); - ETarget[1] = OutputV1CurveEditorSettings.Evaluate(XTarget, RTarget); - ETarget[2] = OutputL3CurveEditorSettings.Evaluate(XTarget, RTarget); + return false; + } var l0t = (XTarget[0] - RangeMinL0Slider.val) / (RangeMaxL0Slider.val - RangeMinL0Slider.val); var l1t = (XTarget[1] + RangeMaxL1Slider.val) / (2 * RangeMaxL1Slider.val); @@ -184,21 +196,12 @@ public bool Update(IMotionSource motionSource) if (EnableOverrideV1Toggle.val) v1CmdRaw = OverrideV1Slider.val; if (EnableOverrideL3Toggle.val) l3CmdRaw = OverrideL3Slider.val; - if (_lastCollisionTime != null) - { - var noCollisionDuration = Time.time - _lastCollisionTime.Value; - _lastCollisionSmoothingDuration = Mathf.Clamp(noCollisionDuration, 0.5f, 2); - _lastCollisionSmoothingStartTime = Time.time; - _lastCollisionSmoothingEnabled = true; - _lastCollisionTime = null; - } - - if (_lastCollisionSmoothingEnabled) + if (_lastNoCollisionSmoothingEnabled) { - var lastCollisionSmoothingT = Mathf.Pow(2, 10 * ((Time.time - _lastCollisionSmoothingStartTime) / _lastCollisionSmoothingDuration - 1)); + var lastCollisionSmoothingT = Mathf.Pow(2, 10 * ((Time.time - _lastNoCollisionSmoothingStartTime) / _lastNoCollisionSmoothingDuration - 1)); if (lastCollisionSmoothingT >= 1.0f) { - _lastCollisionSmoothingEnabled = false; + _lastNoCollisionSmoothingEnabled = false; } else { From cc7de274ffa3d2bf7fee6d3a0238f8ea2725dd33 Mon Sep 17 00:00:00 2001 From: Yoooi Date: Wed, 6 Jan 2021 14:21:50 +0100 Subject: [PATCH 5/6] Cleanup --- src/Device/TCodeDevice.UI.cs | 1 - src/Device/TCodeDevice.cs | 17 ++++++++--------- src/MotionSource/AssetFemaleMotionSource.cs | 1 - src/MotionSource/DildoFemaleMotionSource.cs | 1 - src/MotionSource/RangeTestMotionSource.cs | 1 - src/Plugin.cs | 3 --- src/Utils/PInvoke.cs | 1 - 7 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/Device/TCodeDevice.UI.cs b/src/Device/TCodeDevice.UI.cs index bc5daac..161d3a4 100644 --- a/src/Device/TCodeDevice.UI.cs +++ b/src/Device/TCodeDevice.UI.cs @@ -1,7 +1,6 @@ using CurveEditor; using CurveEditor.UI; using SimpleJSON; -using System; using System.Collections.Generic; using ToySerialController.Config; using ToySerialController.UI; diff --git a/src/Device/TCodeDevice.cs b/src/Device/TCodeDevice.cs index a944b18..27bc4c0 100644 --- a/src/Device/TCodeDevice.cs +++ b/src/Device/TCodeDevice.cs @@ -1,5 +1,4 @@ using DebugUtils; -using System; using System.IO.Ports; using System.Text; using ToySerialController.MotionSource; @@ -53,14 +52,14 @@ public void Write(SerialPort serial) var sb = new StringBuilder(); sb.Append(" Target Cmd Serial\n"); - sb.Append("L0\t").AppendFormat("{0,5:0.00}", XTarget[0]).Append(",\t").AppendFormat("{0,5:0.00}", XCmd[0]).Append(",\t").Append(l0).AppendLine(); - sb.Append("L1\t").AppendFormat("{0,5:0.00}", XTarget[1]).Append(",\t").AppendFormat("{0,5:0.00}", XCmd[1]).Append(",\t").Append(l1).AppendLine(); - sb.Append("L2\t").AppendFormat("{0,5:0.00}", XTarget[2]).Append(",\t").AppendFormat("{0,5:0.00}", XCmd[2]).Append(",\t").Append(l2).AppendLine(); - sb.Append("R0\t").AppendFormat("{0,5:0.00}", RTarget[0]).Append(",\t").AppendFormat("{0,5:0.00}", RCmd[0]).Append(",\t").Append(r0).AppendLine(); - sb.Append("R1\t").AppendFormat("{0,5:0.00}", RTarget[1]).Append(",\t").AppendFormat("{0,5:0.00}", RCmd[1]).Append(",\t").Append(r1).AppendLine(); - sb.Append("R2\t").AppendFormat("{0,5:0.00}", RTarget[2]).Append(",\t").AppendFormat("{0,5:0.00}", RCmd[2]).Append(",\t").Append(r2).AppendLine(); - sb.Append("V0\t").AppendFormat("{0,5:0.00}", ETarget[0]).Append(",\t").AppendFormat("{0,5:0.00}", ECmd[0]).Append(",\t").Append(v0).AppendLine(); - sb.Append("V1\t").AppendFormat("{0,5:0.00}", ETarget[1]).Append(",\t").AppendFormat("{0,5:0.00}", ECmd[1]).Append(",\t").Append(v1).AppendLine(); + sb.Append("L0\t").AppendFormat("{0,5:0.00}", XTarget[0]).Append(",\t").AppendFormat("{0,5:0.00}", XCmd[0]).Append(",\t").AppendLine(l0); + sb.Append("L1\t").AppendFormat("{0,5:0.00}", XTarget[1]).Append(",\t").AppendFormat("{0,5:0.00}", XCmd[1]).Append(",\t").AppendLine(l1); + sb.Append("L2\t").AppendFormat("{0,5:0.00}", XTarget[2]).Append(",\t").AppendFormat("{0,5:0.00}", XCmd[2]).Append(",\t").AppendLine(l2); + sb.Append("R0\t").AppendFormat("{0,5:0.00}", RTarget[0]).Append(",\t").AppendFormat("{0,5:0.00}", RCmd[0]).Append(",\t").AppendLine(r0); + sb.Append("R1\t").AppendFormat("{0,5:0.00}", RTarget[1]).Append(",\t").AppendFormat("{0,5:0.00}", RCmd[1]).Append(",\t").AppendLine(r1); + sb.Append("R2\t").AppendFormat("{0,5:0.00}", RTarget[2]).Append(",\t").AppendFormat("{0,5:0.00}", RCmd[2]).Append(",\t").AppendLine(r2); + sb.Append("V0\t").AppendFormat("{0,5:0.00}", ETarget[0]).Append(",\t").AppendFormat("{0,5:0.00}", ECmd[0]).Append(",\t").AppendLine(v0); + sb.Append("V1\t").AppendFormat("{0,5:0.00}", ETarget[1]).Append(",\t").AppendFormat("{0,5:0.00}", ECmd[1]).Append(",\t").AppendLine(v1); sb.Append("L3\t").AppendFormat("{0,5:0.00}", ETarget[2]).Append(",\t").AppendFormat("{0,5:0.00}", ECmd[2]).Append(",\t").Append(l3); DeviceReport = sb.ToString(); } diff --git a/src/MotionSource/AssetFemaleMotionSource.cs b/src/MotionSource/AssetFemaleMotionSource.cs index 1ae9289..f70779d 100644 --- a/src/MotionSource/AssetFemaleMotionSource.cs +++ b/src/MotionSource/AssetFemaleMotionSource.cs @@ -5,7 +5,6 @@ using ToySerialController.Utils; using UnityEngine; using DebugUtils; -using Leap.Unity; namespace ToySerialController.MotionSource { diff --git a/src/MotionSource/DildoFemaleMotionSource.cs b/src/MotionSource/DildoFemaleMotionSource.cs index 06519d1..1ff5d78 100644 --- a/src/MotionSource/DildoFemaleMotionSource.cs +++ b/src/MotionSource/DildoFemaleMotionSource.cs @@ -1,5 +1,4 @@ using SimpleJSON; -using System.Collections.Generic; using System.Linq; using ToySerialController.UI; using ToySerialController.Utils; diff --git a/src/MotionSource/RangeTestMotionSource.cs b/src/MotionSource/RangeTestMotionSource.cs index fa4f030..31d4793 100644 --- a/src/MotionSource/RangeTestMotionSource.cs +++ b/src/MotionSource/RangeTestMotionSource.cs @@ -1,6 +1,5 @@ using DebugUtils; using SimpleJSON; -using System; using System.Collections.Generic; using ToySerialController.UI; using UnityEngine; diff --git a/src/Plugin.cs b/src/Plugin.cs index d45e282..225a536 100644 --- a/src/Plugin.cs +++ b/src/Plugin.cs @@ -5,9 +5,6 @@ using ToySerialController.MotionSource; using DebugUtils; using ToySerialController.Utils; -using MVR.FileManagementSecure; -using Microsoft.Win32.SafeHandles; -using UnityEngine; namespace ToySerialController { diff --git a/src/Utils/PInvoke.cs b/src/Utils/PInvoke.cs index 826897a..3ca7c60 100644 --- a/src/Utils/PInvoke.cs +++ b/src/Utils/PInvoke.cs @@ -1,7 +1,6 @@ using Microsoft.Win32.SafeHandles; using System; using System.Runtime.InteropServices; -using System.Threading; namespace ToySerialController.Utils { From 5c02bf1018e3f37a34c8c84ce845b05d014d0f39 Mon Sep 17 00:00:00 2001 From: Yoooi Date: Mon, 1 Feb 2021 21:35:25 +0100 Subject: [PATCH 6/6] Fix for vam 1.22.77.3 --- ADD_ME.cslist | 1 - ToySerialController.csproj | 1 - src/Config/ConfigManager.cs | 15 +++++++++++---- src/Utils/PInvoke.cs | 21 --------------------- 4 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 src/Utils/PInvoke.cs diff --git a/ADD_ME.cslist b/ADD_ME.cslist index b175989..ab8fd89 100644 --- a/ADD_ME.cslist +++ b/ADD_ME.cslist @@ -35,4 +35,3 @@ src\UI\UIGroup.cs src\Utils\ComponentCache.cs src\Utils\Extensions.cs src\Utils\MathUtils.cs -src\Utils\PInvoke.cs diff --git a/ToySerialController.csproj b/ToySerialController.csproj index 51ae188..b1dc32d 100644 --- a/ToySerialController.csproj +++ b/ToySerialController.csproj @@ -125,7 +125,6 @@ - diff --git a/src/Config/ConfigManager.cs b/src/Config/ConfigManager.cs index 4a92338..05a00b7 100644 --- a/src/Config/ConfigManager.cs +++ b/src/Config/ConfigManager.cs @@ -31,11 +31,14 @@ public static void SaveConfig(string path, IConfigProvider provider) if (!CheckPath(ref path)) return; + var directory = FileManagerSecure.GetDirectoryName(path); + if (!FileManagerSecure.DirectoryExists(directory)) + FileManagerSecure.CreateDirectory(directory); + var config = new JSONClass(); provider.StoreConfig(config); - Controller.SaveJSON(config, path); + Controller.SaveJSON(config, path, () => SuperController.LogMessage($"Saved config! \"{path}\""), null, null); - SuperController.LogMessage($"Saved config! \"{path}\""); } public static void LoadConfig(string path, IConfigProvider provider) @@ -43,6 +46,10 @@ public static void LoadConfig(string path, IConfigProvider provider) if (!CheckPath(ref path)) return; + var directory = FileManagerSecure.GetDirectoryName(path); + if (!FileManagerSecure.DirectoryExists(directory)) + return; + var config = Controller.LoadJSON(path); provider.RestoreConfig(config); @@ -51,8 +58,8 @@ public static void LoadConfig(string path, IConfigProvider provider) private static void OpenDialog(string defaultPath, string filter, bool textEntry, uFileBrowser.FileBrowserCallback callback) { - if(!FileManagerSecure.DirectoryExists(defaultPath)) - PInvoke.MakeSureDirectoryPathExists(defaultPath); + if (!FileManagerSecure.DirectoryExists(defaultPath)) + FileManagerSecure.CreateDirectory(defaultPath); Controller.mediaFileBrowserUI.fileRemovePrefix = null; Controller.mediaFileBrowserUI.hideExtension = false; diff --git a/src/Utils/PInvoke.cs b/src/Utils/PInvoke.cs deleted file mode 100644 index 3ca7c60..0000000 --- a/src/Utils/PInvoke.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.Win32.SafeHandles; -using System; -using System.Runtime.InteropServices; - -namespace ToySerialController.Utils -{ - public static class PInvoke - { - [DllImport("dbgHelp", SetLastError = true)] - public static extern bool MakeSureDirectoryPathExists(string dirPath); - - [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern SafeFileHandle CreateFile(string fileName, uint fileAccess, uint fileShare, - IntPtr securityAttributes, uint creationDisposition, uint flags, IntPtr template); - - [DllImport("kernel32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool WriteFile(IntPtr hFile, byte[] lpBuffer,uint nNumberOfBytesToWrite, - out uint lpNumberOfBytesWritten, IntPtr lpOverlapped); - } -}