-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
6265 lines (5377 loc) · 251 KB
/
Copy pathProgram.cs
File metadata and controls
6265 lines (5377 loc) · 251 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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Adw;
using Gtk;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using Serilog;
using TheAirBlow.Syndical.Library;
using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
namespace Aesir
{
public static class ImageHelper
{
public static Gtk.Image LoadEmbeddedImage(string resourceName, int pixelSize = 128)
{
var image = Gtk.Image.New();
try
{
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
using var stream = assembly.GetManifestResourceStream($"Aesir.assets.{resourceName}");
if (stream != null)
{
// Create a temporary file to load the image
var tempPath = Path.GetTempFileName();
using (var fileStream = File.Create(tempPath))
{
stream.CopyTo(fileStream);
}
image.SetFromFile(tempPath);
image.SetPixelSize(pixelSize);
// Clean up temp file
File.Delete(tempPath);
}
else
{
throw new Exception($"Embedded resource not found: {resourceName}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load embedded image {resourceName}: {ex.Message}");
// Fallback to icon name
image.SetFromIconName("application-x-firmware");
image.SetIconSize(Gtk.IconSize.Large);
image.SetPixelSize(pixelSize);
}
return image;
}
public static string GetIconNameForEmbeddedImage(string resourceName, string desiredIconName)
{
try
{
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
using var stream = assembly.GetManifestResourceStream($"Aesir.assets.{resourceName}");
if (stream != null)
{
// Create a persistent temporary directory for icons
var iconDir = Path.Combine(Path.GetTempPath(), "aesir_icons");
Directory.CreateDirectory(iconDir);
var iconPath = Path.Combine(iconDir, desiredIconName + ".png");
if (!File.Exists(iconPath))
{
using (var fileStream = File.Create(iconPath))
{
stream.CopyTo(fileStream);
}
}
// Add the directory to the icon theme search path
var display = Gdk.Display.GetDefault();
if (display != null)
{
var iconTheme = Gtk.IconTheme.GetForDisplay(display);
iconTheme.AddSearchPath(iconDir);
}
return desiredIconName;
}
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load embedded icon {resourceName}: {ex.Message}");
}
return "application-x-executable";
}
}
public class AppSettings
{
public string Odin4Path { get; set; } = "";
public string HeimdallPath { get; set; } = "";
public string ThorPath { get; set; } = "";
public string DefaultFlashTool { get; set; } = "Odin4";
public string LastUsedDirectory { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
public bool AutoCheckForUpdates { get; set; } = true;
public bool CreateDesktopEntry { get; set; } = true;
public bool IsFirstRun { get; set; } = true;
public string CurrentVersion { get; set; } = "1.1.0";
private static readonly string SettingsPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"Aesir",
"settings.json"
);
public static AppSettings Load()
{
try
{
if (File.Exists(SettingsPath))
{
var json = File.ReadAllText(SettingsPath);
var settings = JsonConvert.DeserializeObject<AppSettings>(json);
return settings ?? new AppSettings();
}
}
catch (Exception ex)
{
Log.Warning($"Failed to load settings: {ex.Message}");
}
return new AppSettings();
}
public void Save()
{
try
{
var directory = Path.GetDirectoryName(SettingsPath);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory!);
}
var json = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(SettingsPath, json);
}
catch (Exception ex)
{
Log.Warning($"Failed to save settings: {ex.Message}");
}
}
public async Task<bool> CreateDesktopEntryAsync()
{
try
{
// Get the current executable path
var executablePath = Environment.ProcessPath;
if (string.IsNullOrEmpty(executablePath))
{
Log.Warning("Could not determine executable path for desktop entry");
return false;
}
// Create Aesir config directory if it doesn't exist
var configDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Aesir");
if (!Directory.Exists(configDir))
{
Directory.CreateDirectory(configDir);
}
// Download the icon using wget
var iconPath = Path.Combine(configDir, "A.png");
var iconUrl = "https://raw.githubusercontent.com/daglaroglou/Aesir/main/assets/A.png";
// Use wget to download the icon
var wgetProcess = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "wget",
Arguments = $"-O \"{iconPath}\" \"{iconUrl}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
wgetProcess.Start();
await wgetProcess.WaitForExitAsync();
if (wgetProcess.ExitCode != 0)
{
Log.Warning($"Failed to download icon with wget (exit code: {wgetProcess.ExitCode})");
// Continue anyway, desktop entry will work without icon
}
// Create desktop entry content
var desktopEntryContent = $@"[Desktop Entry]
Version=1.0
Type=Application
Name=Aesir
Comment=Samsung Firmware Flash Tool
Exec={executablePath}
Icon={iconPath}
Terminal=false
Categories=Development;System;
StartupNotify=true
";
// Get the desktop directory
var desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var desktopEntryPath = Path.Combine(desktopDir, "Aesir.desktop");
// Write the desktop entry
await File.WriteAllTextAsync(desktopEntryPath, desktopEntryContent);
// Make the desktop entry executable
var chmodProcess = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "chmod",
Arguments = $"+x \"{desktopEntryPath}\"",
UseShellExecute = false,
CreateNoWindow = true
}
};
chmodProcess.Start();
await chmodProcess.WaitForExitAsync();
Log.Information($"Desktop entry created successfully at: {desktopEntryPath}");
return true;
}
catch (Exception ex)
{
Log.Warning($"Failed to create desktop entry: {ex.Message}");
return false;
}
}
}
public class OdinMainWindow : Adw.ApplicationWindow
{
// Flash tool selection
public enum FlashTool
{
Odin4,
Heimdall,
Thor
}
private FlashTool selectedFlashTool = FlashTool.Odin4;
private Gtk.DropDown flashToolDropDown = null!;
private Gtk.Label flashToolSelectedLabel = null!;
// Odin tab controls
private Gtk.Entry blFileEntry = null!;
private Gtk.Entry apFileEntry = null!;
private Gtk.Entry cpFileEntry = null!;
private Gtk.Entry cscFileEntry = null!;
private Gtk.Entry userdataFileEntry = null!;
private Gtk.Button blButton = null!;
private Gtk.Button apButton = null!;
private Gtk.Button cpButton = null!;
private Gtk.Button cscButton = null!;
private Gtk.Button userdataButton = null!;
private Gtk.CheckButton blCheckButton = null!;
private Gtk.CheckButton apCheckButton = null!;
private Gtk.CheckButton cpCheckButton = null!;
private Gtk.CheckButton cscCheckButton = null!;
private Gtk.CheckButton userdataCheckButton = null!;
private Gtk.Label odinLogLabel = null!;
private Gtk.Button startButton = null!;
private Gtk.Button resetButton = null!;
private Gtk.Label deviceStatusLabel = null!;
private Gtk.Label comPortLabel = null!;
private Gtk.Label timeLabel = null!;
// Flash managers removed - only Odin4 supported
private Gtk.ProgressBar? progressBar = null!;
// Settings
private AppSettings settings = null!;
// Flash tools binary detection
private bool isOdin4Available = false;
private string odin4DevicePath = "";
private bool isHeimdallAvailable = false;
private string heimdallDevicePath = "";
private bool isThorAvailable = false;
private string thorDevicePath = "";
// Background services
private System.Threading.Timer? deviceCheckTimer = null;
private System.Threading.Timer? elapsedTimeTimer = null;
private DateTime flashStartTime = DateTime.Now;
private bool isFlashing = false;
// ADB tab controls
private Gtk.Label adbLogLabel = null!;
private Gtk.Entry shellCommandEntry = null!;
private Gtk.Entry packageNameEntry = null!;
private Gtk.Entry packagePathEntry = null!;
// ADB device detection widget
private Gtk.Label adbDeviceStatusLabel = null!;
private Gtk.Label adbDeviceModelLabel = null!;
private Gtk.Label adbDeviceSerialLabel = null!;
// ADB progress tracking
private Gtk.ProgressBar adbProgressBar = null!;
private Gtk.Label adbStepLabel = null!;
private Gtk.Label adbTimeLabel = null!;
// Tab tracking
private Gtk.Notebook mainNotebook = null!;
// Fastboot tab controls
private Gtk.Label fastbootLogLabel = null!;
private Gtk.Entry fastbootCommandEntry = null!;
private Gtk.Entry fastbootImagePathEntry = null!;
private Gtk.Entry fastbootPartitionEntry = null!;
// Fastboot device detection widgets
private Gtk.Label fastbootDeviceStatusLabel = null!;
private Gtk.Label fastbootDeviceModelLabel = null!;
private Gtk.Label fastbootDeviceSerialLabel = null!;
// Fastboot progress widgets
private Gtk.ProgressBar fastbootProgressBar = null!;
private Gtk.Label fastbootStepLabel = null!;
private Gtk.Label fastbootTimeLabel = null!;
// FUS tab controls
private Gtk.Label fusLogLabel = null!;
private Gtk.Entry fusModelEntry = null!;
private Gtk.Entry fusRegionEntry = null!;
private Gtk.Entry fusImeiEntry = null!;
private Gtk.Entry fusDownloadPathEntry = null!;
private Gtk.Button fusCheckButton = null!;
private Gtk.Button fusDownloadButton = null!;
private Gtk.Button fusPauseResumeButton = null!;
private Gtk.Button fusStopButton = null!;
private Gtk.Button fusDecryptButton = null!;
private Gtk.ProgressBar fusProgressBar = null!;
private CancellationTokenSource? fusDownloadCancellationSource = null;
private bool fusDownloadPaused = false;
private bool fusDownloadInProgress = false;
private Gtk.Label fusStepLabel = null!;
private Gtk.Label fusStatusLabel = null!;
private Gtk.Label fusFirmwareInfoLabel = null!;
private Gtk.Box fusFirmwareListBox = null!;
private Gtk.ScrolledWindow fusFirmwareScrollWindow = null!;
private List<Gtk.CheckButton> fusFirmwareCheckButtons = new List<Gtk.CheckButton>();
private TheAirBlow.Syndical.Library.DeviceFirmwaresXml? currentDeviceFirmwares = null;
private string? selectedFirmwareVersion = null;
// Log storage
private List<string> odinLogMessages = new List<string>();
private List<string> adbLogMessages = new List<string>();
private List<string> fastbootLogMessages = new List<string>();
private List<string> fusLogMessages = new List<string>();
private List<string> gappsLogMessages = new List<string>();
// GAPPS tab controls
private Gtk.Label gappsLogLabel = null!;
public OdinMainWindow(Adw.Application application) : base()
{
Application = application;
Title = "Aesir - Firmware Flash Tool";
SetDefaultSize(1050, 850);
SetSizeRequest(1050, 800); // Set minimum size to avoid GTK warning
// Load settings
settings = AppSettings.Load();
Resizable = true;
BuildUI();
ApplyGnomeStyles();
ConnectSignals();
_ = CheckToolsAvailability(); // Fire and forget async call
// Initialize Odin log
LogMessage("Aesir - Firmware Flash Tool");
LogMessage("");
LogMessage("<OSM> WARNING: This tool can modify your device firmware!");
LogMessage("<OSM> Use at your own risk and ensure you have proper backups.");
// Initialize ADB log
LogAdbMessage("ADB interface initialized");
LogAdbMessage("Ready for ADB commands...");
LogAdbMessage("Make sure ADB is installed and device has USB debugging enabled.");
// Initialize Fastboot log
LogFastbootMessage("Fastboot interface initialized");
LogFastbootMessage("Ready for Fastboot commands...");
LogFastbootMessage("Make sure Fastboot is installed and device is in bootloader mode.");
// Initialize FUS log
LogFusMessage("FUS (Firmware Update Service) initialized");
LogFusMessage("Samsung Firmware Downloader using Syndical library");
LogFusMessage("Ready to check and download firmware...");
// Initialize GAPPS log
LogGappsMessage("GAPPS Downloader initialized");
LogGappsMessage("Select your device architecture, Android version, and package variant");
LogGappsMessage("Click 'Download' to open the download page for your selection");
// Start background services
StartBackgroundServices();
// Connect destroy signal to cleanup background services
OnDestroy += OnWindowDestroy;
// Handle first run setup
HandleFirstRunSetup();
}
private void BuildUI()
{
// Create GNOME-style header bar
var headerBar = Gtk.HeaderBar.New();
headerBar.ShowTitleButtons = true;
// Create title widget with proper GNOME styling
var titleBox = Gtk.Box.New(Gtk.Orientation.Vertical, 0);
titleBox.SetValign(Gtk.Align.Center);
var titleLabel = Gtk.Label.New("Aesir");
titleLabel.AddCssClass("title");
titleBox.Append(titleLabel);
var subtitleLabel = Gtk.Label.New($"v{settings.CurrentVersion}");
subtitleLabel.AddCssClass("subtitle");
titleBox.Append(subtitleLabel);
headerBar.SetTitleWidget(titleBox);
// Create primary menu button (GNOME style)
var menuButton = Gtk.MenuButton.New();
menuButton.IconName = "open-menu-symbolic";
menuButton.SetTooltipText("Main Menu");
menuButton.AddCssClass("flat");
// Create primary menu model
var primaryMenu = Gio.Menu.New();
// Preferences section
var preferencesSection = Gio.Menu.New();
preferencesSection.Append("_Settings", "app.settings");
primaryMenu.AppendSection(null, preferencesSection);
// About section
var aboutSection = Gio.Menu.New();
aboutSection.Append("_About Aesir", "app.about");
primaryMenu.AppendSection(null, aboutSection);
menuButton.SetMenuModel(primaryMenu);
headerBar.PackEnd(menuButton);
// headerBar will be packed into the window content below
// Create main notebook for tabs
mainNotebook = Gtk.Notebook.New();
// Create Odin Tab
var odinTab = CreateOdinTab();
mainNotebook.AppendPage(odinTab, Gtk.Label.New("Odin"));
// Create ADB Tab
var adbTab = CreateAdbTab();
mainNotebook.AppendPage(adbTab, Gtk.Label.New("ADB"));
// Create Fastboot Tab
var fastbootTab = CreateFastbootTab();
mainNotebook.AppendPage(fastbootTab, Gtk.Label.New("Fastboot"));
// Create FUS Tab
var fusTab = CreateFusTab();
mainNotebook.AppendPage(fusTab, Gtk.Label.New("FUS"));
// Create GAPPS Tab
var gappsTab = CreateGappsTab();
mainNotebook.AppendPage(gappsTab, Gtk.Label.New("GAPPS"));
// Create Other Tab
var otherTab = CreateOtherTab();
mainNotebook.AppendPage(otherTab, Gtk.Label.New("Other"));
var windowContent = Gtk.Box.New(Gtk.Orientation.Vertical, 0);
windowContent.Append(headerBar);
// Allow the notebook to expand and fill the remaining space
mainNotebook.Vexpand = true;
windowContent.Append(mainNotebook);
Content = windowContent;
}
private void ApplyGnomeStyles()
{
var cssProvider = Gtk.CssProvider.New();
var css = @"
.title {
font-weight: bold;
font-size: 1.1em;
}
.subtitle {
font-size: 0.9em;
opacity: 0.6;
}
headerbar {
min-height: 46px;
}
headerbar button.flat {
border: none;
background: none;
box-shadow: none;
}
headerbar button.flat:hover {
background: alpha(currentColor, 0.08);
}
headerbar button.flat:active {
background: alpha(currentColor, 0.16);
}
";
cssProvider.LoadFromData(css, css.Length);
Gtk.StyleContext.AddProviderForDisplay(
Gdk.Display.GetDefault()!,
cssProvider,
600 // GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
);
}
private Gtk.Widget CreateOdinTab()
{
var mainVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 10);
mainVBox.SetMarginTop(10);
mainVBox.SetMarginBottom(10);
mainVBox.SetMarginStart(10);
mainVBox.SetMarginEnd(10);
// Top section - File selections
var topFrame = Gtk.Frame.New("Files");
var topGrid = Gtk.Grid.New();
topGrid.SetRowSpacing(8);
topGrid.SetColumnSpacing(10);
topGrid.SetMarginTop(10);
topGrid.SetMarginBottom(10);
topGrid.SetMarginStart(10);
topGrid.SetMarginEnd(10);
// Create file selection rows
CreateFileRow(topGrid, 0, "BL:", ref blFileEntry, ref blButton, ref blCheckButton);
CreateFileRow(topGrid, 1, "AP:", ref apFileEntry, ref apButton, ref apCheckButton);
CreateFileRow(topGrid, 2, "CP:", ref cpFileEntry, ref cpButton, ref cpCheckButton);
CreateFileRow(topGrid, 3, "CSC:", ref cscFileEntry, ref cscButton, ref cscCheckButton);
CreateFileRow(topGrid, 4, "USERDATA:", ref userdataFileEntry, ref userdataButton, ref userdataCheckButton);
topFrame.Child = topGrid;
mainVBox.Append(topFrame);
// Middle section - Options and controls
var middleHBox = Gtk.Box.New(Gtk.Orientation.Horizontal, 10);
// Left side - Options
// Middle - Progress and Status
var progressFrame = Gtk.Frame.New("Progress");
var progressBox = Gtk.Box.New(Gtk.Orientation.Vertical, 10);
progressBox.SetMarginTop(10);
progressBox.SetMarginBottom(10);
progressBox.SetMarginStart(10);
progressBox.SetMarginEnd(10);
progressBar = Gtk.ProgressBar.New();
progressBar.SetShowText(true);
progressBar.SetText("Ready");
progressBox.Append(progressBar);
var stepLabel = Gtk.Label.New("Step: Waiting for device...");
stepLabel.Xalign = 0;
progressBox.Append(stepLabel);
timeLabel = Gtk.Label.New("Elapsed: 00:00");
timeLabel.Xalign = 0;
progressBox.Append(timeLabel);
progressFrame.Child = progressBox;
middleHBox.Append(progressFrame);
// Right side - Status and control buttons
var controlFrame = Gtk.Frame.New("Control");
var controlVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 10);
controlVBox.SetMarginTop(10);
controlVBox.SetMarginBottom(10);
controlVBox.SetMarginStart(10);
controlVBox.SetMarginEnd(10);
// Device status
deviceStatusLabel = Gtk.Label.New("Device Status: Disconnected");
deviceStatusLabel.Xalign = 0;
controlVBox.Append(deviceStatusLabel);
comPortLabel = Gtk.Label.New("COM Port: N/A");
comPortLabel.Xalign = 0;
controlVBox.Append(comPortLabel);
// Control buttons
var buttonHBox = Gtk.Box.New(Gtk.Orientation.Horizontal, 10);
startButton = Gtk.Button.NewWithLabel("Start");
startButton.AddCssClass("suggested-action");
startButton.Sensitive = false;
buttonHBox.Append(startButton);
resetButton = Gtk.Button.NewWithLabel("Reset");
buttonHBox.Append(resetButton);
controlVBox.Append(buttonHBox);
controlFrame.Child = controlVBox;
middleHBox.Append(controlFrame);
// Flash Tool Selection Frame (next to Control)
var flashToolFrame = Gtk.Frame.New("Flash Tool");
var flashToolVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 10);
flashToolVBox.SetMarginTop(10);
flashToolVBox.SetMarginBottom(10);
flashToolVBox.SetMarginStart(10);
flashToolVBox.SetMarginEnd(10);
var flashToolModel = Gtk.StringList.New(new string[] { "Odin4", "Heimdall", "Thor" });
flashToolDropDown = Gtk.DropDown.New(flashToolModel, null);
selectedFlashTool = FlashTool.Odin4;
flashToolDropDown.SetSelected(0);
flashToolDropDown.OnNotify += (sender, e) => {
if (e.Pspec.GetName() == "selected")
{
var selectedIndex = flashToolDropDown.Selected;
if (selectedIndex == 0)
{
selectedFlashTool = FlashTool.Odin4;
settings.DefaultFlashTool = "Odin4";
}
else if (selectedIndex == 1)
{
selectedFlashTool = FlashTool.Heimdall;
settings.DefaultFlashTool = "Heimdall";
}
else if (selectedIndex == 2)
{
selectedFlashTool = FlashTool.Thor;
settings.DefaultFlashTool = "Thor";
}
settings.Save();
UpdateFlashToolLabel();
}
};
flashToolVBox.Append(flashToolDropDown);
flashToolSelectedLabel = Gtk.Label.New($"Selected: {selectedFlashTool}");
flashToolSelectedLabel.Xalign = 0;
flashToolSelectedLabel.AddCssClass("caption");
flashToolVBox.Append(flashToolSelectedLabel);
flashToolFrame.Child = flashToolVBox;
middleHBox.Append(flashToolFrame);
// Download Mode Guide Frame (next to Flash Tool)
var guideFrame = Gtk.Frame.New("Download Mode Guide");
var guideVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 5);
guideVBox.SetMarginTop(10);
guideVBox.SetMarginBottom(10);
guideVBox.SetMarginStart(10);
guideVBox.SetMarginEnd(10);
var step1 = Gtk.Label.New("1. Reboot device");
step1.Xalign = 0;
step1.AddCssClass("caption");
guideVBox.Append(step1);
var step2 = Gtk.Label.New("2. Hold Vol Down + Vol Up while booting *");
step2.Xalign = 0;
step2.AddCssClass("caption");
guideVBox.Append(step2);
var step3 = Gtk.Label.New("3. Press Vol Up at warning");
step3.Xalign = 0;
step3.AddCssClass("caption");
guideVBox.Append(step3);
var step4 = Gtk.Label.New("4. Connect USB cable");
step4.Xalign = 0;
step4.AddCssClass("caption");
guideVBox.Append(step4);
var warning = Gtk.Label.New("* May vary by device model");
warning.Xalign = 0;
warning.AddCssClass("caption");
guideVBox.Append(warning);
guideFrame.Child = guideVBox;
// Make the guide frame expand to fill remaining horizontal space
guideFrame.SetHexpand(true);
middleHBox.Append(guideFrame);
mainVBox.Append(middleHBox);
// Bottom section - Log output
var logFrame = Gtk.Frame.New("Log");
var logScrolled = Gtk.ScrolledWindow.New();
logScrolled.SetPolicy(Gtk.PolicyType.Automatic, Gtk.PolicyType.Automatic);
logScrolled.SetVexpand(true); // Allow vertical expansion
logScrolled.SetHexpand(true); // Allow horizontal expansion
odinLogLabel = Gtk.Label.New("");
odinLogLabel.Xalign = 0;
odinLogLabel.Yalign = 0;
odinLogLabel.AddCssClass("monospace");
odinLogLabel.SetSelectable(true);
odinLogLabel.SetWrapMode(Pango.WrapMode.Word);
logScrolled.Child = odinLogLabel;
logFrame.Child = logScrolled;
// Make the log frame expand to fill remaining space
logFrame.SetVexpand(true);
logFrame.SetHexpand(true);
mainVBox.Append(logFrame);
return mainVBox;
}
private void UpdateFlashToolLabel()
{
if (flashToolSelectedLabel != null)
{
flashToolSelectedLabel.SetText($"Selected: {selectedFlashTool}");
// Trigger device connection check when flash tool changes
CheckDeviceConnection();
}
}
private Gtk.Widget CreateAdbTab()
{
var mainVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 10);
mainVBox.SetMarginTop(10);
mainVBox.SetMarginBottom(10);
mainVBox.SetMarginStart(10);
mainVBox.SetMarginEnd(10);
// Top section - Package Management (similar to file selection in Odin)
var topFrame = Gtk.Frame.New("Package Management");
var topGrid = Gtk.Grid.New();
topGrid.SetRowSpacing(8);
topGrid.SetColumnSpacing(10);
topGrid.SetMarginTop(10);
topGrid.SetMarginBottom(10);
topGrid.SetMarginStart(10);
topGrid.SetMarginEnd(10);
// APK Install row
var apkLabel = Gtk.Label.New("APK File:");
apkLabel.Xalign = 0;
apkLabel.SetSizeRequest(80, -1);
topGrid.Attach(apkLabel, 0, 0, 1, 1);
packagePathEntry = Gtk.Entry.New();
packagePathEntry.PlaceholderText = "Package path or APK file";
packagePathEntry.SetHexpand(true);
topGrid.Attach(packagePathEntry, 1, 0, 1, 1);
var browseApkButton = Gtk.Button.NewWithLabel("...");
browseApkButton.SetSizeRequest(40, -1);
browseApkButton.OnClicked += (sender, e) => BrowseForFile(packagePathEntry, "Select APK File", "*.apk");
topGrid.Attach(browseApkButton, 2, 0, 1, 1);
var installButton = Gtk.Button.NewWithLabel("Install");
installButton.OnClicked += async (sender, e) => await InstallPackage(packagePathEntry.GetText());
topGrid.Attach(installButton, 3, 0, 1, 1);
// Package Uninstall row
var packageLabel = Gtk.Label.New("Package:");
packageLabel.Xalign = 0;
packageLabel.SetSizeRequest(80, -1);
topGrid.Attach(packageLabel, 0, 1, 1, 1);
packageNameEntry = Gtk.Entry.New();
packageNameEntry.PlaceholderText = "Package name";
packageNameEntry.SetHexpand(true);
topGrid.Attach(packageNameEntry, 1, 1, 1, 1);
var uninstallButton = Gtk.Button.NewWithLabel("Uninstall");
uninstallButton.OnClicked += async (sender, e) => await UninstallPackage(packageNameEntry.GetText());
topGrid.Attach(uninstallButton, 2, 1, 2, 1);
// Shell Command row
var shellLabel = Gtk.Label.New("Shell Cmd:");
shellLabel.Xalign = 0;
shellLabel.SetSizeRequest(80, -1);
topGrid.Attach(shellLabel, 0, 2, 1, 1);
shellCommandEntry = Gtk.Entry.New();
shellCommandEntry.PlaceholderText = "Enter shell command";
shellCommandEntry.SetHexpand(true);
topGrid.Attach(shellCommandEntry, 1, 2, 1, 1);
var executeButton = Gtk.Button.NewWithLabel("Execute");
executeButton.OnClicked += async (sender, e) => await ExecuteShellCommand(shellCommandEntry.GetText());
topGrid.Attach(executeButton, 2, 2, 2, 1);
topFrame.Child = topGrid;
mainVBox.Append(topFrame);
// Middle section - Four frames side by side (matching Odin structure)
var middleHBox = Gtk.Box.New(Gtk.Orientation.Horizontal, 10);
// Left side - Device Information
var deviceFrame = Gtk.Frame.New("Device Information");
var deviceVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 5);
deviceVBox.SetMarginTop(10);
deviceVBox.SetMarginBottom(10);
deviceVBox.SetMarginStart(10);
deviceVBox.SetMarginEnd(10);
var refreshDevicesButton = Gtk.Button.NewWithLabel("Refresh Connected Devices");
refreshDevicesButton.OnClicked += async (sender, e) => await RefreshAdbDevices();
deviceVBox.Append(refreshDevicesButton);
var getDeviceInfoButton = Gtk.Button.NewWithLabel("Get Device Info");
getDeviceInfoButton.OnClicked += async (sender, e) => await GetDeviceInfo();
deviceVBox.Append(getDeviceInfoButton);
var batteryInfoButton = Gtk.Button.NewWithLabel("Battery Info");
batteryInfoButton.OnClicked += async (sender, e) => await GetBatteryInfo();
deviceVBox.Append(batteryInfoButton);
var listPackagesButton = Gtk.Button.NewWithLabel("List Installed Packages");
listPackagesButton.OnClicked += async (sender, e) => await ListInstalledPackages();
deviceVBox.Append(listPackagesButton);
deviceFrame.Child = deviceVBox;
middleHBox.Append(deviceFrame);
// Middle - ADB Server Control
var serverFrame = Gtk.Frame.New("ADB Server");
var serverVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 5);
serverVBox.SetMarginTop(10);
serverVBox.SetMarginBottom(10);
serverVBox.SetMarginStart(10);
serverVBox.SetMarginEnd(10);
var startServerButton = Gtk.Button.NewWithLabel("Start ADB Server");
startServerButton.OnClicked += async (sender, e) => await StartAdbServer();
serverVBox.Append(startServerButton);
var killServerButton = Gtk.Button.NewWithLabel("Kill ADB Server");
killServerButton.OnClicked += async (sender, e) => await KillAdbServer();
serverVBox.Append(killServerButton);
var listDevicesButton = Gtk.Button.NewWithLabel("List Devices");
listDevicesButton.OnClicked += async (sender, e) => await ListAdbDevices();
serverVBox.Append(listDevicesButton);
serverFrame.Child = serverVBox;
middleHBox.Append(serverFrame);
// Right side - System Actions
var systemFrame = Gtk.Frame.New("System Actions");
var systemVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 5);
systemVBox.SetMarginTop(10);
systemVBox.SetMarginBottom(10);
systemVBox.SetMarginStart(10);
systemVBox.SetMarginEnd(10);
var rebootButton = Gtk.Button.NewWithLabel("Reboot Device");
rebootButton.OnClicked += async (sender, e) => await RebootDevice();
systemVBox.Append(rebootButton);
var rebootBootloaderButton = Gtk.Button.NewWithLabel("Reboot to Bootloader");
rebootBootloaderButton.OnClicked += async (sender, e) => await RebootToBootloader();
systemVBox.Append(rebootBootloaderButton);
var rebootRecoveryButton = Gtk.Button.NewWithLabel("Reboot to Recovery");
rebootRecoveryButton.OnClicked += async (sender, e) => await RebootToRecovery();
systemVBox.Append(rebootRecoveryButton);
var rebootDownloadButton = Gtk.Button.NewWithLabel("Reboot to Download");
rebootDownloadButton.OnClicked += async (sender, e) => await RebootToDownload();
systemVBox.Append(rebootDownloadButton);
var startLogcatButton = Gtk.Button.NewWithLabel("Start Logcat");
startLogcatButton.OnClicked += async (sender, e) => await StartLogcat();
systemVBox.Append(startLogcatButton);
systemFrame.Child = systemVBox;
middleHBox.Append(systemFrame);
// Fourth column - Device Detection and Progress (2 separate frames stacked vertically)
var deviceProgressColumnVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 10);
// Top frame - Device Detection
var deviceDetectionFrame = Gtk.Frame.New("Device Detection");
var deviceInfoVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 5);
deviceInfoVBox.SetMarginTop(10);
deviceInfoVBox.SetMarginBottom(10);
deviceInfoVBox.SetMarginStart(10);
deviceInfoVBox.SetMarginEnd(10);
// Status row
var statusHBox = Gtk.Box.New(Gtk.Orientation.Horizontal, 5);
var statusLabel = Gtk.Label.New("Status:");
statusLabel.Xalign = 0;
statusLabel.SetSizeRequest(60, -1);
statusHBox.Append(statusLabel);
adbDeviceStatusLabel = Gtk.Label.New("No device detected");
adbDeviceStatusLabel.Xalign = 0;
adbDeviceStatusLabel.SetHexpand(true);
adbDeviceStatusLabel.AddCssClass("dim-label");
statusHBox.Append(adbDeviceStatusLabel);
deviceInfoVBox.Append(statusHBox);
// Model row
var modelHBox = Gtk.Box.New(Gtk.Orientation.Horizontal, 5);
var modelLabel = Gtk.Label.New("Model:");
modelLabel.Xalign = 0;
modelLabel.SetSizeRequest(60, -1);
modelHBox.Append(modelLabel);
adbDeviceModelLabel = Gtk.Label.New("Unknown");
adbDeviceModelLabel.Xalign = 0;
adbDeviceModelLabel.SetHexpand(true);
adbDeviceModelLabel.AddCssClass("dim-label");
modelHBox.Append(adbDeviceModelLabel);
deviceInfoVBox.Append(modelHBox);
// Serial row
var serialHBox = Gtk.Box.New(Gtk.Orientation.Horizontal, 5);
var serialLabel = Gtk.Label.New("Serial:");
serialLabel.Xalign = 0;
serialLabel.SetSizeRequest(60, -1);
serialHBox.Append(serialLabel);
adbDeviceSerialLabel = Gtk.Label.New("Unknown");
adbDeviceSerialLabel.Xalign = 0;
adbDeviceSerialLabel.SetHexpand(true);
adbDeviceSerialLabel.AddCssClass("dim-label");
serialHBox.Append(adbDeviceSerialLabel);
deviceInfoVBox.Append(serialHBox);
deviceDetectionFrame.Child = deviceInfoVBox;
deviceProgressColumnVBox.Append(deviceDetectionFrame);
// Bottom frame - Progress Tracker
var progressFrame = Gtk.Frame.New("Progress");
var progressVBox = Gtk.Box.New(Gtk.Orientation.Vertical, 10);
progressVBox.SetMarginTop(10);
progressVBox.SetMarginBottom(10);
progressVBox.SetMarginStart(10);
progressVBox.SetMarginEnd(10);
adbProgressBar = Gtk.ProgressBar.New();
adbProgressBar.SetShowText(true);
adbProgressBar.SetText("Ready");
progressVBox.Append(adbProgressBar);
adbStepLabel = Gtk.Label.New("Step: Waiting for operation...");
adbStepLabel.Xalign = 0;
progressVBox.Append(adbStepLabel);
adbTimeLabel = Gtk.Label.New("Elapsed: 00:00");