You've already forked com.unity.ide.cursor
mirror of
https://github.com/boxqkrtm/com.unity.ide.cursor.git
synced 2026-05-21 10:30:08 +00:00
com.unity.ide.visualstudio@2.0.0
## [2.0.0] - 2019-11-06 - Improved Visual Studio and Visual Studio for Mac automatic discovery - Added support for the VSTU messaging system (start/stop features from Visual Studio) - Added support for solution roundtrip (preserves references to external projects and solution properties) - Added support for VSTU Analyzers (requires Visual Studio 2019 16.3, Visual Studio for Mac 8.3) - Added a warning when using legacy pdb symbol files. - Fixed issues while Opening Visual Studio on Windows - Fixed issues while Opening Visual Studio on Mac ## [1.1.1] - 2019-05-29 Fix Bridge assembly loading with non VS2017 editors ## [1.1.0] - 2019-05-27 Move internal extension handling to package.
This commit is contained in:
40
Editor/Messaging/Deserializer.cs
Normal file
40
Editor/Messaging/Deserializer.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor.Messaging
|
||||
{
|
||||
internal class Deserializer
|
||||
{
|
||||
private readonly BinaryReader _reader;
|
||||
|
||||
// Max UDP packet size is 65507
|
||||
private const int MaxStringLength = 65000;
|
||||
|
||||
public Deserializer(byte[] buffer)
|
||||
{
|
||||
_reader = new BinaryReader(new MemoryStream(buffer));
|
||||
}
|
||||
|
||||
public int ReadInt32()
|
||||
{
|
||||
return _reader.ReadInt32();
|
||||
}
|
||||
|
||||
public string ReadString()
|
||||
{
|
||||
var length = ReadInt32();
|
||||
return length > 0 && length <= MaxStringLength
|
||||
? Encoding.UTF8.GetString(_reader.ReadBytes(length))
|
||||
: "";
|
||||
}
|
||||
|
||||
public bool CanReadMore()
|
||||
{
|
||||
return _reader.BaseStream.Position < _reader.BaseStream.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Messaging/Deserializer.cs.meta
Normal file
11
Editor/Messaging/Deserializer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3eda7a83649158546826efb3ffe6c1e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Editor/Messaging/ExceptionEventArgs.cs
Normal file
18
Editor/Messaging/ExceptionEventArgs.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor.Messaging
|
||||
{
|
||||
internal class ExceptionEventArgs
|
||||
{
|
||||
public Exception Exception { get; }
|
||||
|
||||
public ExceptionEventArgs(Exception exception)
|
||||
{
|
||||
Exception = exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Messaging/ExceptionEventArgs.cs.meta
Normal file
11
Editor/Messaging/ExceptionEventArgs.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 917a51fff055ce547b4ad1215321f3da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Editor/Messaging/Message.cs
Normal file
23
Editor/Messaging/Message.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor.Messaging
|
||||
{
|
||||
internal class Message
|
||||
{
|
||||
public MessageType Type { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
|
||||
public IPEndPoint Origin { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "<Message type:{0} value:{1}>", Type, Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Messaging/Message.cs.meta
Normal file
11
Editor/Messaging/Message.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de1c9ea7b82c9904d9e5fba2ee70a998
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Editor/Messaging/MessageEventArgs.cs
Normal file
19
Editor/Messaging/MessageEventArgs.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
namespace Microsoft.Unity.VisualStudio.Editor.Messaging
|
||||
{
|
||||
internal class MessageEventArgs
|
||||
{
|
||||
public Message Message
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public MessageEventArgs(Message message)
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Messaging/MessageEventArgs.cs.meta
Normal file
11
Editor/Messaging/MessageEventArgs.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 275143c81d816ef4286fdc67aabc20c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
Editor/Messaging/MessageType.cs
Normal file
34
Editor/Messaging/MessageType.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
namespace Microsoft.Unity.VisualStudio.Editor.Messaging
|
||||
{
|
||||
internal enum MessageType
|
||||
{
|
||||
None = 0,
|
||||
|
||||
Ping,
|
||||
Pong,
|
||||
|
||||
Play,
|
||||
Stop,
|
||||
Pause,
|
||||
Unpause,
|
||||
|
||||
Build,
|
||||
Refresh,
|
||||
|
||||
Info,
|
||||
Error,
|
||||
Warning,
|
||||
|
||||
Open,
|
||||
Opened,
|
||||
|
||||
Version,
|
||||
UpdatePackage,
|
||||
|
||||
ProjectPath,
|
||||
}
|
||||
}
|
||||
11
Editor/Messaging/MessageType.cs.meta
Normal file
11
Editor/Messaging/MessageType.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3edbdc86577af648a23263aa75161e1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
176
Editor/Messaging/Messenger.cs
Normal file
176
Editor/Messaging/Messenger.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor.Messaging
|
||||
{
|
||||
internal class Messager : IDisposable
|
||||
{
|
||||
public event EventHandler<MessageEventArgs> ReceiveMessage;
|
||||
public event EventHandler<ExceptionEventArgs> MessagerException;
|
||||
|
||||
private readonly UdpSocket _socket;
|
||||
private readonly object _disposeLock = new object();
|
||||
private bool _disposed;
|
||||
|
||||
protected Messager(int port)
|
||||
{
|
||||
_socket = new UdpSocket();
|
||||
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, false);
|
||||
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||
_socket.Bind(IPAddress.Any, port);
|
||||
|
||||
BeginReceiveMessage();
|
||||
}
|
||||
|
||||
private void BeginReceiveMessage()
|
||||
{
|
||||
var buffer = new byte[UdpSocket.BufferSize];
|
||||
var any = UdpSocket.Any();
|
||||
|
||||
try
|
||||
{
|
||||
lock (_disposeLock)
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
|
||||
_socket.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref any, ReceiveMessageCallback, buffer);
|
||||
}
|
||||
}
|
||||
catch (SocketException se)
|
||||
{
|
||||
MessagerException?.Invoke(this, new ExceptionEventArgs(se));
|
||||
|
||||
BeginReceiveMessage();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void ReceiveMessageCallback(IAsyncResult result)
|
||||
{
|
||||
try
|
||||
{
|
||||
var endPoint = UdpSocket.Any();
|
||||
|
||||
lock (_disposeLock)
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
|
||||
_socket.EndReceiveFrom(result, ref endPoint);
|
||||
}
|
||||
|
||||
var message = DeserializeMessage(UdpSocket.BufferFor(result));
|
||||
if (message != null)
|
||||
{
|
||||
message.Origin = (IPEndPoint)endPoint;
|
||||
ReceiveMessage?.Invoke(this, new MessageEventArgs(message));
|
||||
}
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
RaiseMessagerException(e);
|
||||
}
|
||||
|
||||
BeginReceiveMessage();
|
||||
}
|
||||
|
||||
private void RaiseMessagerException(Exception e)
|
||||
{
|
||||
MessagerException?.Invoke(this, new ExceptionEventArgs(e));
|
||||
}
|
||||
|
||||
private static Message MessageFor(MessageType type, string value)
|
||||
{
|
||||
return new Message { Type = type, Value = value };
|
||||
}
|
||||
|
||||
public void SendMessage(IPEndPoint target, MessageType type, string value = "")
|
||||
{
|
||||
var message = MessageFor(type, value);
|
||||
var buffer = SerializeMessage(message);
|
||||
|
||||
try
|
||||
{
|
||||
lock (_disposeLock)
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
|
||||
_socket.BeginSendTo(buffer, 0, Math.Min(buffer.Length, UdpSocket.BufferSize), SocketFlags.None, target, SendMessageCallback, null);
|
||||
}
|
||||
}
|
||||
catch (SocketException se)
|
||||
{
|
||||
MessagerException?.Invoke(this, new ExceptionEventArgs(se));
|
||||
}
|
||||
}
|
||||
|
||||
private void SendMessageCallback(IAsyncResult result)
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (_disposeLock)
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
|
||||
_socket.EndSendTo(result);
|
||||
}
|
||||
}
|
||||
catch (SocketException se)
|
||||
{
|
||||
MessagerException?.Invoke(this, new ExceptionEventArgs(se));
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] SerializeMessage(Message message)
|
||||
{
|
||||
var serializer = new Serializer();
|
||||
serializer.WriteInt32((int)message.Type);
|
||||
serializer.WriteString(message.Value);
|
||||
|
||||
return serializer.Buffer();
|
||||
}
|
||||
|
||||
private static Message DeserializeMessage(byte[] buffer)
|
||||
{
|
||||
if (buffer.Length < 4)
|
||||
return null;
|
||||
|
||||
var deserializer = new Deserializer(buffer);
|
||||
var type = (MessageType)deserializer.ReadInt32();
|
||||
var value = deserializer.ReadString();
|
||||
|
||||
return new Message { Type = type, Value = value };
|
||||
}
|
||||
|
||||
public static Messager BindTo(int port)
|
||||
{
|
||||
return new Messager(port);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
lock (_disposeLock)
|
||||
{
|
||||
_disposed = true;
|
||||
_socket.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Messaging/Messenger.cs.meta
Normal file
11
Editor/Messaging/Messenger.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e249ae353801f043a6e4173410c6152
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Editor/Messaging/Serializer.cs
Normal file
43
Editor/Messaging/Serializer.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor.Messaging
|
||||
{
|
||||
internal class Serializer
|
||||
{
|
||||
private readonly MemoryStream _stream;
|
||||
private readonly BinaryWriter _writer;
|
||||
|
||||
public Serializer()
|
||||
{
|
||||
_stream = new MemoryStream();
|
||||
_writer = new BinaryWriter(_stream);
|
||||
}
|
||||
|
||||
public void WriteInt32(int i)
|
||||
{
|
||||
_writer.Write(i);
|
||||
}
|
||||
|
||||
public void WriteString(string s)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(s ?? "");
|
||||
if (bytes.Length > 0)
|
||||
{
|
||||
_writer.Write(bytes.Length);
|
||||
_writer.Write(bytes);
|
||||
}
|
||||
else
|
||||
_writer.Write(0);
|
||||
}
|
||||
|
||||
public byte[] Buffer()
|
||||
{
|
||||
return _stream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Messaging/Serializer.cs.meta
Normal file
11
Editor/Messaging/Serializer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 369c09afe05d2c346af49faef943c773
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Editor/Messaging/UdpSocket.cs
Normal file
53
Editor/Messaging/UdpSocket.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor.Messaging
|
||||
{
|
||||
internal class UdpSocket : Socket
|
||||
{
|
||||
public const int BufferSize = 1024 * 8;
|
||||
|
||||
internal UdpSocket()
|
||||
: base(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
|
||||
{
|
||||
SetIOControl();
|
||||
}
|
||||
|
||||
public void Bind(IPAddress address, int port = 0)
|
||||
{
|
||||
Bind(new IPEndPoint(address ?? IPAddress.Any, port));
|
||||
}
|
||||
|
||||
private void SetIOControl()
|
||||
{
|
||||
if (!VisualStudioEditor.IsWindows)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
const int SIO_UDP_CONNRESET = -1744830452;
|
||||
|
||||
IOControl(SIO_UDP_CONNRESET, new byte[] { 0 }, new byte[0]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// fallback
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] BufferFor(IAsyncResult result)
|
||||
{
|
||||
return (byte[])result.AsyncState;
|
||||
}
|
||||
|
||||
public static EndPoint Any()
|
||||
{
|
||||
return new IPEndPoint(IPAddress.Any, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Messaging/UdpSocket.cs.meta
Normal file
11
Editor/Messaging/UdpSocket.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38cb3a4a17d2cfd41926da95ce675934
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user