Repository navigation
Expand file tree
/
Copy pathMainWindow.axaml.cs
More file actions
197 lines (172 loc) · 7.31 KB
/
Copy pathMainWindow.axaml.cs
File metadata and controls
197 lines (172 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using Avalonia.Controls;
using Avalonia.Markup.Xaml.Templates;
using Avalonia.VisualTree;
using MsBox.Avalonia;
using MsBox.Avalonia.Enums;
using RemoteHub.Classe;
using RemoteHub.Popup;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace RemoteHub
{
public partial class MainWindow : Window
{
internal ObservableCollection<RDAEntry> RDAEntries { get; } = new();
internal RDAManager rdaManager = new RDAManager();
public MainWindow()
{
InitializeComponent();
ListRDA.LayoutUpdated += (_, _) => ListRDA_Loaded();
UpdateRDAList();
}
private void UpdateRDAList()
{
ListRDA.Items.Clear();
if (rdaManager.FileExists()) {
foreach (var entry in rdaManager.GetAllRDA())
{
ListRDA.Items.Add(entry);
}
}
}
private void ListRDA_Loaded()
{
for (int i = 0; i < ListRDA.ItemCount; i++)
{
var container = ListRDA.ItemContainerGenerator.ContainerFromIndex(i);
if (container is ListBoxItem listBoxItem)
{
var buttons = listBoxItem.GetVisualDescendants().OfType<Button>().ToList();
if (buttons.Count == 1)
{
buttons[0].Click -= OpenRDA_Click; // Open button
buttons[0].Click += OpenRDA_Click; // Open button
}
}
}
}
private void AddRDA_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
try
{
var popup = new AddRDAPopup();
popup.Closed += (_, _) => UpdateRDAList();
popup.Show();
}
catch (Exception ex)
{
Debug.WriteLine($"Error showing AddSitePopup: {ex.Message}");
Debug.WriteLine(ex.StackTrace);
}
}
private void Popup_Closed(object? sender, EventArgs e)
{
throw new NotImplementedException();
}
#region Interactions RDA
private void ModifyRDA_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
if (sender is MenuItem menu && menu.Tag is RDAEntry rdaEntry)
{
var popup = new ModifyRDAPopup(rdaEntry);
popup.Closed += (_, _) => UpdateRDAList();
popup.Show();
}
}
private void OpenRDA_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
if (sender is Button button && button.DataContext is RDAEntry rdaEntry)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
string tempPath = Path.Combine(Path.GetTempPath(), $"{rdaEntry.Name}.rdp");
var sb = new StringBuilder();
sb.AppendLine($"full address:s:{rdaEntry.Address}");
sb.AppendLine($"username:s:{rdaEntry.Username}");
sb.AppendLine("desktopscalefactor:i:100");
sb.AppendLine("compression:i:1");
sb.AppendLine("keyboardhook:i:2");
sb.AppendLine("connection type:i:7");
sb.AppendLine("networkautodetect:i:1");
sb.AppendLine("server port:i:3389");
sb.AppendLine("authentication level:i:2");
sb.AppendLine("promptcredentialonce:i:0");
sb.AppendLine("prompt for credentials:i:0");
sb.AppendLine("negotiate security layer:i:1");
sb.AppendLine("enablecredsspsupport:i:1");
sb.AppendLine("clipboard flags:i:51");
sb.AppendLine("enablerdsaadauth:i:0");
sb.AppendLine("drivestoredirect:s:C:\\;");
// Ajout conditionnel des features
// RemoteApp
if (!string.IsNullOrWhiteSpace(rdaEntry.Software))
{
sb.AppendLine("remoteapplicationmode:i:1");
sb.AppendLine($"remoteapplicationprogram:s:{rdaEntry.Software}");
}
// Audio
if (rdaEntry.Features.Contains("Son"))
{
sb.AppendLine("audiocapturemode:i:1");
sb.AppendLine("audiomode:i:0");
sb.AppendLine("audioqualitymode:i:2");
}
File.WriteAllText(tempPath, sb.ToString());
string target = $"TERMSRV/{rdaEntry.Address}";
CredentialManager.SaveCredential(target, rdaEntry.Username, rdaEntry.Password);
var Proc = Process.Start(new ProcessStartInfo
{
FileName = "mstsc.exe",
Arguments = $"\"{tempPath}\"",
UseShellExecute = true
});
Proc?.WaitForExit();
CredentialManager.DeleteCredential(target);
File.Delete(tempPath);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var parts = rdaEntry.Username.Split('\\');
string domain = parts[0];
string user = parts[1];
string args = "";
args = $"/u:{user} /p:\"{rdaEntry.Password}\" /v:{rdaEntry.Address} /dynamic-resolution /cert:ignore";
if (rdaEntry.Features.Contains("Son")) { args += " /sound:sys:pulse /microphone:sys:pulse"; }
if (rdaEntry.Software != "") { args += $" /app:\"{rdaEntry.Software}\""; }
var Proc = Process.Start(new ProcessStartInfo
{
FileName = "xfreerdp",
Arguments = args,
UseShellExecute = false
});
Console.WriteLine(Proc.ToString());
//Proc.WaitForExit(); ;
//File.Delete(tempPath);
}
}
}
private async void About_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var infoVersion = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
string version = infoVersion?.Split('+')[0];
var box = MessageBoxManager.GetMessageBoxStandard("Version", "Version: " + version, ButtonEnum.Ok);
await box.ShowAsync();
}
private void DeleteRDA_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
if (sender is MenuItem menu && menu.Tag is RDAEntry rdaEntry)
{
rdaManager.DeleteRDA(rdaEntry);
UpdateRDAList();
}
UpdateRDAList();
}
#endregion
}
}