diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2020-06-15 21:29:16 +0200 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2020-06-15 21:29:16 +0200 |
commit | 54df72dcc6b60693234880e7b1e4dde3a8f082f5 (patch) | |
tree | 008ad3b3a1293ef42c3000cb572a1577c65e3366 /modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs | |
parent | 17af0104785eac9c416bb89989d82e2968f8ab8f (diff) |
C#: Add VisualStudio support
Diffstat (limited to 'modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs')
-rw-r--r-- | modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs index d069651dd3..572c541412 100644 --- a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs +++ b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs @@ -19,9 +19,12 @@ namespace GodotTools.IdeMessaging private readonly string identity; private string MetaFilePath { get; } + private DateTime? metaFileModifiedTime; private GodotIdeMetadata godotIdeMetadata; private readonly FileSystemWatcher fsWatcher; + public string GodotEditorExecutablePath => godotIdeMetadata.EditorExecutablePath; + private readonly IMessageHandler messageHandler; private Peer peer; @@ -123,7 +126,7 @@ namespace GodotTools.IdeMessaging MetaFilePath = Path.Combine(projectMetadataDir, GodotIdeMetadata.DefaultFileName); // FileSystemWatcher requires an existing directory - if (!File.Exists(projectMetadataDir)) + if (!Directory.Exists(projectMetadataDir)) Directory.CreateDirectory(projectMetadataDir); fsWatcher = new FileSystemWatcher(projectMetadataDir, GodotIdeMetadata.DefaultFileName); @@ -142,6 +145,13 @@ namespace GodotTools.IdeMessaging if (!File.Exists(MetaFilePath)) return; + var lastWriteTime = File.GetLastWriteTime(MetaFilePath); + + if (lastWriteTime == metaFileModifiedTime) + return; + + metaFileModifiedTime = lastWriteTime; + var metadata = ReadMetadataFile(); if (metadata != null && metadata != godotIdeMetadata) @@ -173,6 +183,13 @@ namespace GodotTools.IdeMessaging if (IsConnected || !File.Exists(MetaFilePath)) return; + var lastWriteTime = File.GetLastWriteTime(MetaFilePath); + + if (lastWriteTime == metaFileModifiedTime) + return; + + metaFileModifiedTime = lastWriteTime; + var metadata = ReadMetadataFile(); if (metadata != null) @@ -185,7 +202,8 @@ namespace GodotTools.IdeMessaging private GodotIdeMetadata? ReadMetadataFile() { - using (var reader = File.OpenText(MetaFilePath)) + using (var fileStream = new FileStream(MetaFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + using (var reader = new StreamReader(fileStream)) { string portStr = reader.ReadLine(); @@ -272,6 +290,7 @@ namespace GodotTools.IdeMessaging // ReSharper disable once UnusedMember.Global public async void Start() { + fsWatcher.Created += OnMetaFileChanged; fsWatcher.Changed += OnMetaFileChanged; fsWatcher.Deleted += OnMetaFileDeleted; fsWatcher.EnableRaisingEvents = true; |