Skip to content

Commit 985cd3e

Browse files
committed
✨ Implement version checker in system info app
1 parent fea9064 commit 985cd3e

File tree

4 files changed

+183
-50
lines changed

4 files changed

+183
-50
lines changed

SRC/Aura_OS/Properties/VersionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ namespace Aura_OS
22
{
33
public class VersionInfo
44
{
5-
public static string revision = "110320241632";
5+
public static string revision = "110320241725";
66
}
77
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* PROJECT: Aura Operating System Development
3+
* CONTENT: Version utils class
4+
* PROGRAMMER(S): Valentin Charbonnier <[email protected]>
5+
*/
6+
7+
using System;
8+
using JZero;
9+
using System.Linq;
10+
11+
namespace Aura_OS.System.Network
12+
{
13+
public static class Version
14+
{
15+
public static (string, string, string) GetLastVersionInfo()
16+
{
17+
string json = Http.DownloadFile("http://aura.valentin.bzh/os.json");
18+
19+
JsonReader rdr = new(json);
20+
rdr.ReadObjectStart();
21+
22+
string latestVersion = null;
23+
string latestRevision = null;
24+
string latestReleaseUrl = null;
25+
26+
while (rdr.NextProperty())
27+
{
28+
var charSegment = rdr.ReadPropertyName();
29+
string propertyName = new string(charSegment.Array, charSegment.Offset, charSegment.Count);
30+
31+
if (propertyName.Equals("last-version"))
32+
{
33+
var latestVersionCharSegment = rdr.ReadString();
34+
latestVersion = new string(latestVersionCharSegment.Array, latestVersionCharSegment.Offset, latestVersionCharSegment.Count);
35+
}
36+
else if (propertyName.Equals("last-revision"))
37+
{
38+
var latestRevisionCharSegment = rdr.ReadString();
39+
latestRevision = new string(latestRevisionCharSegment.Array, latestRevisionCharSegment.Offset, latestRevisionCharSegment.Count);
40+
}
41+
else if (propertyName.Equals("last-release-url"))
42+
{
43+
var latestReleaseUrlCharSegment = rdr.ReadString();
44+
latestReleaseUrl = new string(latestReleaseUrlCharSegment.Array, latestReleaseUrlCharSegment.Offset, latestReleaseUrlCharSegment.Count);
45+
}
46+
}
47+
48+
rdr.ReadEof();
49+
50+
return (latestVersion, latestRevision, latestReleaseUrl);
51+
}
52+
53+
public static int CompareVersions(string version1, string version2)
54+
{
55+
var version1Parts = version1.Split('.').Select(v => int.TryParse(v, out int val) ? val : 0).ToArray();
56+
var version2Parts = version2.Split('.').Select(v => int.TryParse(v, out int val) ? val : 0).ToArray();
57+
58+
for (int i = 0; i < Math.Min(version1Parts.Length, version2Parts.Length); i++)
59+
{
60+
if (version1Parts[i] > version2Parts[i])
61+
return 1;
62+
if (version1Parts[i] < version2Parts[i])
63+
return -1;
64+
}
65+
66+
return version1Parts.Length.CompareTo(version2Parts.Length);
67+
}
68+
69+
public static int CompareRevisions(string rev1, string rev2)
70+
{
71+
bool successRev1 = long.TryParse(rev1, out long revision1);
72+
bool successRev2 = long.TryParse(rev2, out long revision2);
73+
74+
if (!successRev1 || !successRev2)
75+
{
76+
return 0;
77+
}
78+
79+
return revision1.CompareTo(revision2);
80+
}
81+
}
82+
}

SRC/Aura_OS/System/Processing/Applications/SystemInfoApp.cs

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
* PROGRAMMERS: Valentin Charbonnier <[email protected]>
55
*/
66

7+
using System;
78
using System.Drawing;
89
using Aura_OS.System.Graphics.UI.GUI;
10+
using Aura_OS.System.Graphics.UI.GUI.Components;
11+
using Cosmos.System.Network;
912

1013
namespace Aura_OS.System.Processing.Applications
1114
{
@@ -14,15 +17,78 @@ public class SystemInfoApp : Application
1417
public static string ApplicationName = "SystemInfo";
1518

1619
public Color _greenPen = Color.Green;
20+
public Color _redPen = Color.Red;
1721

1822
const string _title = "Aura Operating System";
1923
const string _credit = "Created by Alexy DA CRUZ and Valentin CHARBONNIER.";
2024
const string _website = "Project: github.com/aura-systems/Aura-Operating-System";
2125
const string _website2 = "Kernel: github.com/CosmosOS/Cosmos";
26+
private string _version = "";
27+
28+
private Button _button;
29+
private bool _isOutdated = false;
2230

2331
public SystemInfoApp(int width, int height, int x = 0, int y = 0) : base(ApplicationName, width, height, x, y)
2432
{
33+
string text = "Check update";
34+
_button = new Button(text, (Width / 2) - ((text.Length * Kernel.font.Width) / 2), 5 * Kernel.font.Height + 2, text.Length * Kernel.font.Width + 6, Kernel.font.Height + 6);
35+
_button.Click = new Action(() =>
36+
{
37+
if (NetworkStack.ConfigEmpty())
38+
{
39+
_version = "Aura [version " + Kernel.Version + "-" + Kernel.Revision + "]";
40+
}
41+
else
42+
{
43+
(string latestVersion, string latestRevision, string latestReleaseUrl) = Network.Version.GetLastVersionInfo();
44+
45+
int versionComparisonResult = Network.Version.CompareVersions(Kernel.Version, latestVersion);
2546

47+
if (string.IsNullOrEmpty(Kernel.Version) || string.IsNullOrEmpty(latestVersion) || string.IsNullOrEmpty(Kernel.Revision) || string.IsNullOrEmpty(latestRevision))
48+
{
49+
_version = "Failed to parse os.json.";
50+
}
51+
else
52+
{
53+
if (versionComparisonResult > 0)
54+
{
55+
_version = "You are on a dev version (last release is " + latestVersion + "-" + latestRevision + ").";
56+
}
57+
else if (versionComparisonResult < 0)
58+
{
59+
_version = "Your version is outdated (last release is " + latestVersion + "-" + latestRevision + ").";
60+
_isOutdated = true;
61+
}
62+
else
63+
{
64+
int revisionComparisonResult = Network.Version.CompareRevisions(Kernel.Revision, latestRevision);
65+
if (revisionComparisonResult > 0)
66+
{
67+
_version = "You are on a dev version (last release is " + latestVersion + "-" + latestRevision + ").";
68+
}
69+
else if (revisionComparisonResult < 0)
70+
{
71+
_version = "Your revision is outdated (last release is " + latestVersion + "-" + latestRevision + ").";
72+
_isOutdated = true;
73+
}
74+
else
75+
{
76+
_version = "You are up to date.";
77+
}
78+
}
79+
}
80+
}
81+
_button.Visible = false;
82+
MarkDirty();
83+
});
84+
AddChild(_button);
85+
}
86+
87+
public override void Update()
88+
{
89+
base.Update();
90+
91+
_button.Update();
2692
}
2793

2894
public override void Draw()
@@ -34,13 +100,23 @@ public override void Draw()
34100
DrawString(_title, Cosmos.System.Graphics.Fonts.PCScreenFont.Default, Kernel.BlackColor, 0 + Width / 2 - _title.Length * Cosmos.System.Graphics.Fonts.PCScreenFont.Default.Width / 2, 0 + 1 * Kernel.font.Height);
35101
DrawString(version, Kernel.font, Kernel.BlackColor, 0 + Width / 2 - version.Length * Kernel.font.Width / 2, 0 + 2 * Kernel.font.Height);
36102

37-
DrawString(_credit, Kernel.font, Kernel.BlackColor, 0 + Width / 2 - _credit.Length * Kernel.font.Width / 2, 0 + 5 * Kernel.font.Height);
38-
DrawString(_website, Kernel.font, _greenPen, 0 + Width / 2 - _website.Length * Kernel.font.Width / 2, 0 + 6 * Kernel.font.Height);
103+
DrawString(_credit, Kernel.font, Kernel.BlackColor, 0 + Width / 2 - _credit.Length * Kernel.font.Width / 2, 0 + 5 * Kernel.font.Height + 4);
104+
DrawString(_website, Kernel.font, _greenPen, 0 + Width / 2 - _website.Length * Kernel.font.Width / 2, 0 + 6 * Kernel.font.Height + 4);
39105

40106
DrawImage(Kernel.AuraLogo, 0 + Width / 2 - (int)Kernel.AuraLogo.Width / 2, 0 + 8 * Kernel.font.Height);
41107

42108
DrawString(_website2, Kernel.font, _greenPen, 0 + Width / 2 - _website2.Length * Kernel.font.Width / 2, 0 + 18 * Kernel.font.Height);
43109
DrawImage(Kernel.CosmosLogo, 0 + Width / 2 - (int)Kernel.CosmosLogo.Width / 2, 0 + 20 * Kernel.font.Height);
110+
111+
if (!string.IsNullOrEmpty(_version))
112+
{
113+
DrawString(_version, Kernel.font, _isOutdated ? _redPen : _greenPen, 0 + Width / 2 - _version.Length * Kernel.font.Width / 2, 3 * Kernel.font.Height);
114+
}
115+
else
116+
{
117+
_button.Draw();
118+
_button.DrawInParent();
119+
}
44120
}
45121
}
46122
}

SRC/Aura_OS/System/Processing/Interpreter/Commands/Information/Version.cs

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public CommandVersion(string[] commandvalues) : base(commandvalues)
2828
/// </summary>
2929
public override ReturnInfo Execute()
3030
{
31+
bool isOutdated = false;
32+
3133
Console.ForegroundColor = ConsoleColor.White;
3234

3335
if (NetworkStack.ConfigEmpty())
@@ -36,35 +38,9 @@ public override ReturnInfo Execute()
3638
}
3739
else
3840
{
39-
string json = Http.DownloadFile("http://aura.valentin.bzh/os.json");
40-
41-
JsonReader rdr = new(json);
42-
rdr.ReadObjectStart();
43-
44-
string latestVersion = null;
45-
string latestRevision = null;
46-
47-
while (rdr.NextProperty())
48-
{
49-
var charSegment = rdr.ReadPropertyName();
50-
string propertyName = new string(charSegment.Array, charSegment.Offset, charSegment.Count);
51-
52-
if (propertyName.Equals("last-version"))
53-
{
54-
var latestVersionCharSegment = rdr.ReadString();
55-
latestVersion = new string(latestVersionCharSegment.Array, latestVersionCharSegment.Offset, latestVersionCharSegment.Count);
56-
}
57-
else if (propertyName.Equals("last-revision"))
58-
{
59-
60-
var latestRevisionCharSegment = rdr.ReadString();
61-
latestRevision = new string(latestRevisionCharSegment.Array, latestRevisionCharSegment.Offset, latestRevisionCharSegment.Count);
62-
}
63-
}
64-
65-
rdr.ReadEof();
41+
(string latestVersion, string latestRevision, string latestReleaseUrl) = System.Network.Version.GetLastVersionInfo();
6642

67-
int versionComparisonResult = CompareVersions(Kernel.Version, latestVersion);
43+
int versionComparisonResult = System.Network.Version.CompareVersions(Kernel.Version, latestVersion);
6844

6945
if (string.IsNullOrEmpty(Kernel.Version) || string.IsNullOrEmpty(latestVersion) || string.IsNullOrEmpty(Kernel.Revision) || string.IsNullOrEmpty(latestRevision))
7046
{
@@ -79,20 +55,35 @@ public override ReturnInfo Execute()
7955
else if (versionComparisonResult < 0)
8056
{
8157
Console.WriteLine("Aura [version " + Kernel.Version + "-" + Kernel.Revision + "], your version is outdated (last release is " + latestVersion + "-" + latestRevision + ").");
58+
isOutdated = true;
8259
}
8360
else
8461
{
85-
int revisionComparisonResult = string.Compare(Kernel.Revision, latestRevision);
86-
if (revisionComparisonResult < 0)
62+
int revisionComparisonResult = System.Network.Version.CompareRevisions(Kernel.Revision, latestRevision);
63+
if (revisionComparisonResult > 0)
8764
{
88-
Console.WriteLine("Aura [version " + Kernel.Version + "-" + Kernel.Revision + "], your version is outdated (last release is " + latestVersion + "-" + latestRevision + ").");
65+
Console.WriteLine("Aura [version " + Kernel.Version + "-" + Kernel.Revision + "], you are on a dev version (last release is " + latestVersion + "-" + latestRevision + ").");
66+
}
67+
else if (revisionComparisonResult < 0)
68+
{
69+
Console.WriteLine("Aura [version " + Kernel.Version + "-" + Kernel.Revision + "], your revision is outdated (last release is " + latestVersion + "-" + latestRevision + ").");
70+
isOutdated = true;
8971
}
9072
else
9173
{
9274
Console.WriteLine("Aura [version " + Kernel.Version + "-" + Kernel.Revision + "], you are up to date.");
9375
}
9476
}
9577
}
78+
79+
if (isOutdated)
80+
{
81+
Console.ForegroundColor = ConsoleColor.Green;
82+
Console.WriteLine("Download last .iso at: " + latestReleaseUrl);
83+
Console.ForegroundColor = ConsoleColor.White;
84+
85+
Console.WriteLine();
86+
}
9687
}
9788

9889
Console.WriteLine("Created by Alexy DA CRUZ and Valentin CHARBONNIER.");
@@ -104,21 +95,5 @@ public override ReturnInfo Execute()
10495

10596
return new ReturnInfo(this, ReturnCode.OK);
10697
}
107-
108-
int CompareVersions(string version1, string version2)
109-
{
110-
var version1Parts = version1.Split('.').Select(v => int.TryParse(v, out int val) ? val : 0).ToArray();
111-
var version2Parts = version2.Split('.').Select(v => int.TryParse(v, out int val) ? val : 0).ToArray();
112-
113-
for (int i = 0; i < Math.Min(version1Parts.Length, version2Parts.Length); i++)
114-
{
115-
if (version1Parts[i] > version2Parts[i])
116-
return 1;
117-
if (version1Parts[i] < version2Parts[i])
118-
return -1;
119-
}
120-
121-
return version1Parts.Length.CompareTo(version2Parts.Length);
122-
}
12398
}
12499
}

0 commit comments

Comments
 (0)