-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathForm1.cs
More file actions
126 lines (109 loc) · 4.13 KB
/
Form1.cs
File metadata and controls
126 lines (109 loc) · 4.13 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
using ConsoleServiceTool.Console.Sony.PlayStation5.Views;
using ConsoleServiceTool.Utils;
using ConsoleServiceTool.Views;
using System.Diagnostics;
using System.Reflection;
using Velopack;
#if RELEASE
using Velopack.Sources;
#endif
namespace ConsoleServiceTool
{
internal partial class Form1 : Form
{
private readonly UserControlFactory controlFactory = UserControlFactory.Instance;
internal Form1()
{
InitializeComponent();
DoubleBuffered = true;
InitializeControlFactory();
ShowControl<HomeView>();
InitializeMenuItems();
}
private void InitializeControlFactory()
{
controlFactory.Register<HomeView>();
controlFactory.Register<PlayStation5MainView>();
controlFactory.Register<PS5NorView>();
controlFactory.Register<PS5UartView>();
}
private void InitializeMenuItems()
{
homeToolStripMenuItem.Click += MenuItem_Click<HomeView>;
playStation5ToolStripMenuItem.Click += MenuItem_Click<PlayStation5MainView>;
}
internal static List<int> DecodeErrorToBanks(string id)
{
// Remove the prefix to isolate the bank numbers part
string bankNumbersPart = id[6..];
// Parse the bank numbers part as hexadecimal
int bankNumbers = Convert.ToInt32(bankNumbersPart, 16);
// Initialize a list to store the extracted bank numbers
List<int> extractedBankNumbers = [];
// Iterate through each bit position and check if it's set (1)
for (int i = 0; i < 8; i++)
{
// Check if the least significant bit is set
if ((bankNumbers & 1) == 1)
{
// Add the corresponding bank number to the list
extractedBankNumbers.Add(i + 1); // Add 1 to match bank numbering (1-indexed)
}
// Right shift the bank numbers to move to the next bit
bankNumbers >>= 1;
}
return extractedBankNumbers;
}
private async void Form1_Load(object sender, EventArgs e)
{
Text = $"{Text} - {Assembly.GetExecutingAssembly().GetName().Version}";
try
{
await CheckForUpdatesAsync();
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
private static async Task CheckForUpdatesAsync()
{
if (!IsSquirrelInstall()) return;
#if DEBUG
var mgr = new UpdateManager(@"bin\Releases");
#else
var source = new GithubSource(@"https://github.com/amoamare/Console-Service-Tool", accessToken: default, prerelease: false);
var mgr = new UpdateManager(source);
#endif
var newVersion = await mgr.CheckForUpdatesAsync();
if (newVersion == null)
return;
await mgr.DownloadUpdatesAsync(newVersion);
mgr.ApplyUpdatesAndRestart(newVersion);
}
private static bool IsSquirrelInstall()
{
var assembly = Assembly.GetEntryAssembly();
if (assembly == default || assembly.Location == default) return false;
var assemblyLocation = Path.GetDirectoryName(assembly.Location);
if (assemblyLocation == default) return false;
var updateDotExe = Path.Combine(assemblyLocation, "..", "Update.exe");
return File.Exists(updateDotExe);
}
private void ShowControl<T>() where T : UserControl
{
MainPanel.SuspendLayout();
var control = controlFactory.Get<T>();
MainPanel.Controls.Clear();
MainPanel.Controls.Add(control);
if (control is IUserControl inter)
label1.Text = inter.FriendlyName;
control.Dock = DockStyle.Fill;
MainPanel.ResumeLayout();
}
private void MenuItem_Click<T>(object? sender, EventArgs e) where T : UserControl
{
ShowControl<T>();
}
}
}