From f1773d5efbc67a7d2a7f803b138bcdfaa0791c74 Mon Sep 17 00:00:00 2001 From: Christian Biesinger Date: Thu, 2 May 2019 13:13:38 -0500 Subject: [PATCH] Make FileCache work on non-Windows platforms (#79) --- server/JsDbg.Core/DllImports.cs | 19 +++++++++++++++++++ server/JsDbg.Core/FileCache.cs | 9 +++++++-- server/JsDbg.Core/JsDbg.Core.csproj | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 server/JsDbg.Core/DllImports.cs diff --git a/server/JsDbg.Core/DllImports.cs b/server/JsDbg.Core/DllImports.cs new file mode 100644 index 00000000..220015a0 --- /dev/null +++ b/server/JsDbg.Core/DllImports.cs @@ -0,0 +1,19 @@ +//-------------------------------------------------------------- +// +// MIT License +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +//-------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; + +namespace JsDbg.Core { + internal class DllImports { + [DllImport("shlwapi.dll")] + internal static extern bool PathIsNetworkPath(string path); + } +} diff --git a/server/JsDbg.Core/FileCache.cs b/server/JsDbg.Core/FileCache.cs index 4196a4ac..23de013a 100644 --- a/server/JsDbg.Core/FileCache.cs +++ b/server/JsDbg.Core/FileCache.cs @@ -18,8 +18,13 @@ internal FileCache() { this.lastFlushDate = DateTime.Now; } - [DllImport("shlwapi.dll")] - internal static extern bool PathIsNetworkPath(string path); + internal static bool PathIsNetworkPath(string path) { + try { + return DllImports.PathIsNetworkPath(path); + } catch (DllNotFoundException) { + return false; + } + } internal Stream ReadFile(string path) { // Flush the cache every hour for the scenario where JsDbg is left open overnight etc. diff --git a/server/JsDbg.Core/JsDbg.Core.csproj b/server/JsDbg.Core/JsDbg.Core.csproj index 9e74c927..7fad9db4 100644 --- a/server/JsDbg.Core/JsDbg.Core.csproj +++ b/server/JsDbg.Core/JsDbg.Core.csproj @@ -79,6 +79,7 @@ +