-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into jsdbg_gdb_support
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//-------------------------------------------------------------- | ||
// | ||
// 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 FileCache { | ||
internal FileCache() { | ||
this.cachedFiles = new Dictionary<string, string>(); | ||
this.lastFlushDate = DateTime.Now; | ||
} | ||
|
||
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. | ||
if ((DateTime.Now - this.lastFlushDate).TotalSeconds > 3600) { | ||
this.lastFlushDate = DateTime.Now; | ||
this.cachedFiles = new Dictionary<string, string>(); | ||
} | ||
|
||
if (FileCache.PathIsNetworkPath(path)) { | ||
if (!cachedFiles.ContainsKey(path)) { | ||
cachedFiles[path] = File.ReadAllText(path); | ||
} | ||
|
||
MemoryStream stream = new MemoryStream(); | ||
StreamWriter writer = new StreamWriter(stream); | ||
writer.Write(cachedFiles[path]); | ||
writer.Flush(); | ||
stream.Position = 0; | ||
return stream; | ||
} else { | ||
return File.OpenRead(path); | ||
} | ||
} | ||
|
||
private DateTime lastFlushDate; | ||
private Dictionary<string, string> cachedFiles; | ||
} | ||
} |