Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 0eb8055

Browse files
committed
fix files not opening when the editor is opened
revert PipeInterop commenting back to the solution
1 parent 468082f commit 0eb8055

File tree

3 files changed

+97
-97
lines changed

3 files changed

+97
-97
lines changed

Interop/PipeInteropClient.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
//using System;
2-
//using System.IO;
3-
//using System.IO.Pipes;
4-
//using System.Text;
1+
using System;
2+
using System.IO;
3+
using System.IO.Pipes;
4+
using System.Text;
55

6-
//namespace SPCode.Interop
7-
//{
8-
// public static class PipeInteropClient
9-
// {
10-
// public static void ConnectToMasterPipeAndSendData(string data)
11-
// {
12-
// var stringData = Encoding.UTF8.GetBytes(data);
13-
// var stringLength = stringData.Length;
14-
// var array = new byte[sizeof(int) + stringLength];
15-
// using (var stream = new MemoryStream(array))
16-
// {
17-
// var stringLengthData = BitConverter.GetBytes(stringLength);
18-
// stream.Write(stringLengthData, 0, stringLengthData.Length);
19-
// stream.Write(stringData, 0, stringData.Length);
20-
// }
21-
// using var pipeClient = new NamedPipeClientStream(".", "SPCodeNamedPipeServer", PipeDirection.Out, PipeOptions.Asynchronous);
22-
// pipeClient.Connect(5000);
23-
// pipeClient.Write(array, 0, array.Length);
24-
// pipeClient.Flush();
25-
// }
26-
// }
27-
//}
6+
namespace SPCode.Interop
7+
{
8+
public static class PipeInteropClient
9+
{
10+
public static void ConnectToMasterPipeAndSendData(string data)
11+
{
12+
var stringData = Encoding.UTF8.GetBytes(data);
13+
var stringLength = stringData.Length;
14+
var array = new byte[sizeof(int) + stringLength];
15+
using (var stream = new MemoryStream(array))
16+
{
17+
var stringLengthData = BitConverter.GetBytes(stringLength);
18+
stream.Write(stringLengthData, 0, stringLengthData.Length);
19+
stream.Write(stringData, 0, stringData.Length);
20+
}
21+
using var pipeClient = new NamedPipeClientStream(".", "SPCodeNamedPipeServer", PipeDirection.Out, PipeOptions.Asynchronous);
22+
pipeClient.Connect(5000);
23+
pipeClient.Write(array, 0, array.Length);
24+
pipeClient.Flush();
25+
}
26+
}
27+
}

Interop/PipeInteropServer.cs

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
1-
//using System;
2-
//using System.IO.Pipes;
3-
//using System.Text;
4-
//using SPCode.UI;
1+
using System;
2+
using System.IO.Pipes;
3+
using System.Text;
4+
using SPCode.UI;
55

6-
//namespace SPCode.Interop
7-
//{
8-
// public class PipeInteropServer : IDisposable
9-
// {
10-
// private NamedPipeServerStream pipeServer;
11-
// private readonly MainWindow _window;
6+
namespace SPCode.Interop
7+
{
8+
public class PipeInteropServer : IDisposable
9+
{
10+
private NamedPipeServerStream pipeServer;
11+
private readonly MainWindow _window;
1212

13-
// public PipeInteropServer(MainWindow window)
14-
// {
15-
// _window = window;
16-
// }
13+
public PipeInteropServer(MainWindow window)
14+
{
15+
_window = window;
16+
}
1717

18-
// public void Start()
19-
// {
20-
// StartInteropServer();
21-
// }
18+
public void Start()
19+
{
20+
StartInteropServer();
21+
}
2222

23-
// public void Close()
24-
// {
25-
// pipeServer.Close();
26-
// }
23+
public void Close()
24+
{
25+
pipeServer.Close();
26+
}
2727

28-
// public void Dispose()
29-
// {
30-
// pipeServer.Close();
31-
// }
28+
public void Dispose()
29+
{
30+
pipeServer.Close();
31+
}
3232

33-
// private void StartInteropServer()
34-
// {
35-
// if (pipeServer != null)
36-
// {
37-
// pipeServer.Close();
38-
// pipeServer = null;
39-
// }
40-
// pipeServer = new NamedPipeServerStream("SPCodeNamedPipeServer", PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
41-
// pipeServer.BeginWaitForConnection(new AsyncCallback(PipeConnection_MessageIn), null);
42-
// }
33+
private void StartInteropServer()
34+
{
35+
if (pipeServer != null)
36+
{
37+
pipeServer.Close();
38+
pipeServer = null;
39+
}
40+
pipeServer = new NamedPipeServerStream("SPCodeNamedPipeServer", PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
41+
pipeServer.BeginWaitForConnection(new AsyncCallback(PipeConnection_MessageIn), null);
42+
}
4343

44-
// private void PipeConnection_MessageIn(IAsyncResult iar)
45-
// {
46-
// pipeServer.EndWaitForConnection(iar);
47-
// var byteBuffer = new byte[4];
48-
// pipeServer.Read(byteBuffer, 0, sizeof(int));
49-
// var length = BitConverter.ToInt32(byteBuffer, 0);
50-
// byteBuffer = new byte[length];
51-
// pipeServer.Read(byteBuffer, 0, length);
52-
// var data = Encoding.UTF8.GetString(byteBuffer);
53-
// var files = data.Split('|');
54-
// var SelectIt = true;
55-
// for (var i = 0; i < files.Length; ++i)
56-
// {
57-
// _window.Dispatcher.Invoke(() =>
58-
// {
59-
// if (_window.IsLoaded)
60-
// {
61-
// if (_window.TryLoadSourceFile(files[i], out _, SelectIt) && _window.WindowState == System.Windows.WindowState.Minimized)
62-
// {
63-
// _window.WindowState = System.Windows.WindowState.Normal;
64-
// SelectIt = false;
65-
// }
66-
// }
67-
// });
68-
// }
69-
// StartInteropServer();
70-
// }
71-
// }
72-
//}
44+
private void PipeConnection_MessageIn(IAsyncResult iar)
45+
{
46+
pipeServer.EndWaitForConnection(iar);
47+
var byteBuffer = new byte[4];
48+
pipeServer.Read(byteBuffer, 0, sizeof(int));
49+
var length = BitConverter.ToInt32(byteBuffer, 0);
50+
byteBuffer = new byte[length];
51+
pipeServer.Read(byteBuffer, 0, length);
52+
var data = Encoding.UTF8.GetString(byteBuffer);
53+
var files = data.Split('|');
54+
var SelectIt = true;
55+
for (var i = 0; i < files.Length; ++i)
56+
{
57+
_window.Dispatcher.Invoke(() =>
58+
{
59+
if (_window.IsLoaded)
60+
{
61+
if (_window.TryLoadSourceFile(files[i], out _, SelectIt) && _window.WindowState == System.Windows.WindowState.Minimized)
62+
{
63+
_window.WindowState = System.Windows.WindowState.Normal;
64+
SelectIt = false;
65+
}
66+
}
67+
});
68+
}
69+
StartInteropServer();
70+
}
71+
}
72+
}

Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ public static void Main(string[] args)
157157
}
158158
#endif
159159
MainWindow = new MainWindow(splashScreen);
160-
//var pipeServer = new PipeInteropServer(MainWindow);
161-
//pipeServer.Start();
160+
var pipeServer = new PipeInteropServer(MainWindow);
161+
pipeServer.Start();
162162
#if !DEBUG
163163
}
164164
catch (Exception e)
@@ -229,10 +229,10 @@ public static void Main(string[] args)
229229
}
230230
}
231231

232-
//if (addedFiles)
233-
//{
234-
// PipeInteropClient.ConnectToMasterPipeAndSendData(sBuilder.ToString());
235-
//}
232+
if (addedFiles)
233+
{
234+
PipeInteropClient.ConnectToMasterPipeAndSendData(sBuilder.ToString());
235+
}
236236
}
237237
catch (Exception)
238238
{

0 commit comments

Comments
 (0)