| skipped 26 lines |
27 | 27 | | protected IRepository _repository; |
28 | 28 | | protected Logger _logger; |
29 | 29 | | protected StreamWriter? _pipe { private set; get; } |
30 | | - | NamedPipeClientStream? _pipeClient; |
31 | 30 | | CancellationTokenSource cancelUpdateToken = new(); |
32 | 31 | | |
33 | 32 | | public Logger Logger => _logger; |
| skipped 18 lines |
52 | 51 | | if (Path.GetExtension(cmd) == ".dll") |
53 | 52 | | { |
54 | 53 | | RunProcessElevated(cmd, version.Uri.ToString()); |
55 | | - | //RunProcessElevated("dotnet", $"{cmd} {version.Uri}"); |
56 | 54 | | } |
57 | 55 | | else |
58 | 56 | | { |
| skipped 3 lines |
62 | 60 | | |
63 | 61 | | public abstract bool IsCurrentProcessElevated(); |
64 | 62 | | |
65 | | - | protected void superviseInstallation_old() |
66 | | - | { |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | NamedPipeServerStream pipeServer = new NamedPipeServerStream("duvinstallation2", PipeDirection.InOut, 1); |
71 | | - | pipeServer.WaitForConnection(); |
72 | | - | if (pipeServer.IsConnected) |
73 | | - | { |
74 | | - | _logger.WriteLine("Recieved connection from subprocess"); |
75 | | - | |
76 | | - | } |
77 | | - | else |
78 | | - | { |
79 | | - | _logger.WriteLine("Failed receving connection"); |
80 | | - | } |
81 | | - | |
82 | | - | bool isComplete = false; |
83 | | - | float progress = 0f; |
84 | | - | string description = ""; |
85 | | - | try |
86 | | - | { |
87 | | - | using (StreamReader sr = new StreamReader(pipeServer)) |
88 | | - | { |
89 | | - | string? greeting = sr.ReadLine(); |
90 | | - | if (greeting == null) |
91 | | - | { |
92 | | - | _logger.WriteLine("Unable to read from client"); |
93 | | - | } |
94 | | - | else |
95 | | - | { |
96 | | - | _logger.WriteLine($"Received greeting: {greeting} from client"); |
97 | | - | } |
98 | | - | while (pipeServer.IsConnected && !isComplete && !cancelUpdateToken.IsCancellationRequested) |
99 | | - | { |
100 | | - | string? update = sr.ReadLine(); |
101 | | - | _logger.WriteLine("Received update: " + update); |
102 | | - | |
103 | | - | if (string.IsNullOrEmpty(update) || update == "ping") |
104 | | - | { |
105 | | - | continue; |
106 | | - | } |
107 | | - | var cols = update.Split(";"); |
108 | | - | float.TryParse(cols[0], out progress); |
109 | | - | if (cols.Length > 1) |
110 | | - | bool.TryParse(cols[1], out isComplete); |
111 | | - | if (cols.Length > 2) |
112 | | - | description = cols[2]; |
113 | | - | else |
114 | | - | _logger.WriteLine($"Need 2 semi colons from installer process. Got {update}"); |
115 | | - | if (!cancelUpdateToken.IsCancellationRequested) |
116 | | - | { |
117 | | - | OnInstallationUpdate?.Invoke(this, new((int)Math.Round(progress), description, isComplete)); |
118 | | - | } |
119 | | - | } |
120 | | - | _logger.WriteLine("No longer connected to sub process"); |
121 | | - | pipeServer.Dispose(); |
122 | | - | } |
123 | | - | } |
124 | | - | catch (ObjectDisposedException e) |
125 | | - | { |
126 | | - | _logger.WriteLine("Unable to connect to elevated installer: " + e); |
127 | | - | } |
128 | | - | catch (Exception e) |
129 | | - | { |
130 | | - | _logger.WriteLine("Lost connection to installer: " + e); |
131 | | - | |
132 | | - | } |
133 | | - | } |
134 | 63 | | protected async void superviseInstallation() |
135 | 64 | | { |
136 | 65 | | bool isComplete = false; |
137 | 66 | | float progress = 0f; |
138 | 67 | | string description = ""; |
139 | 68 | | NamedPipeServerStream pipeServer = new NamedPipeServerStream(PIPENAME, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); |
140 | | - | await pipeServer.WaitForConnectionAsync(); |
141 | 69 | | StreamReader sr = new StreamReader(pipeServer); |
142 | 70 | | while (!isComplete && !cancelUpdateToken.IsCancellationRequested) |
143 | 71 | | { |
144 | 72 | | try |
145 | 73 | | { |
146 | | - | if (pipeServer.IsConnected == false) |
| 74 | + | if (!pipeServer.IsConnected) |
147 | 75 | | { |
148 | 76 | | pipeServer = new NamedPipeServerStream(PIPENAME, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); |
149 | 77 | | await pipeServer.WaitForConnectionAsync(); |
| skipped 7 lines |
157 | 85 | | { |
158 | 86 | | continue; |
159 | 87 | | } |
160 | | - | _logger.WriteLine("Received update: " + update); |
161 | 88 | | |
162 | 89 | | var cols = update.Split(";"); |
163 | 90 | | float.TryParse(cols[0], out progress); |
| skipped 141 lines |
305 | 232 | | _logger.WriteLine($"The path {args[0]} is not a version"); |
306 | 233 | | } |
307 | 234 | | } |
308 | | - | |
309 | | - | //_pipeClient = new NamedPipeClientStream(".", "duvinstallation", PipeDirection.Out, PipeOptions.None, System.Security.Principal.TokenImpersonationLevel.Impersonation); |
310 | | - | //_logger.WriteLine("Client created. Start stream writer"); |
311 | | - | |
312 | | - | //_logger.WriteLine("Done"); |
313 | 235 | | } |
314 | 236 | | else |
315 | 237 | | { |
| skipped 63 lines |