Skip to content

Commit 255f79c

Browse files
authored
Merge pull request #21 from TheyCreeper/main
OTA updates
2 parents 9b8fc71 + 2513ec5 commit 255f79c

File tree

9 files changed

+125
-8
lines changed

9 files changed

+125
-8
lines changed

AtlasToolbox/AtlasToolbox.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.1.240916" />
6161
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.1.240916" />
6262
<PackageReference Include="ICSharpCode.Decompiler" Version="9.0.0.7889" />
63+
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
6364
<PackageReference Include="Microsoft.Dism" Version="3.3.0" />
6465
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
6566
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.3" />

AtlasToolbox/MainWindow.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ public async void ContentDialogContoller(string type)
187187

188188
switch (type)
189189
{
190+
case "newUpdate":
191+
title = App.GetValueFromItemList("NewUpdate");
192+
desc = App.GetValueFromItemList("NewUpdateDesc");
193+
primBtnTxt = App.GetValueFromItemList("Yes");
194+
command = new RelayCommand(ToolboxUpdateHelper.InstallUpdate);
195+
break;
190196
case "restartApp":
191197
title = App.GetValueFromItemList("RestartApp");
192198
desc = App.GetValueFromItemList("RestartAppDesc");

AtlasToolbox/Utils/CommandPromptHelper.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class CommandPromptHelper
1616
/// </summary>
1717
/// <param name="command">command</param>
1818
/// <param name="noWindow">True by default</param>
19-
public static void RunCommand(string command, bool noWindow= true)
19+
public static void RunCommand(string command, bool noWindow= true, bool waitForExit = true)
2020
{
2121
Process commandPrompt = new Process();
2222
commandPrompt.StartInfo.FileName = "cmd.exe";
@@ -25,7 +25,7 @@ public static void RunCommand(string command, bool noWindow= true)
2525
commandPrompt.StartInfo.UseShellExecute = false;
2626

2727
commandPrompt.Start();
28-
commandPrompt.WaitForExit();
28+
if (waitForExit) commandPrompt.WaitForExit();
2929
}
3030
/// <summary>
3131
/// Restarts explorer.exe
@@ -51,5 +51,20 @@ public static void RestartExplorer()
5151
startExplorer.Start();
5252
startExplorer.WaitForExit();
5353
}
54+
55+
public static string ReturnRunCommand(string command)
56+
{
57+
Process commandPrompt = new Process();
58+
commandPrompt.StartInfo.FileName = "cmd.exe";
59+
commandPrompt.StartInfo.Arguments = $"/c {command}";
60+
commandPrompt.StartInfo.CreateNoWindow = true;
61+
commandPrompt.StartInfo.UseShellExecute = false;
62+
commandPrompt.StartInfo.RedirectStandardOutput = true;
63+
64+
commandPrompt.Start();
65+
string output = commandPrompt.StandardOutput.ReadToEnd();
66+
commandPrompt.WaitForExit();
67+
return output;
68+
}
5469
}
5570
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net.Http;
5+
using System.Text.Json;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using static System.Runtime.InteropServices.JavaScript.JSType;
9+
using Newtonsoft.Json;
10+
using WinRT;
11+
using System.IO;
12+
using ICSharpCode.Decompiler.CSharp.Syntax;
13+
14+
namespace AtlasToolbox.Utils
15+
{
16+
public class ToolboxUpdateHelper
17+
{
18+
const string RELEASE_URL = "https://api.github.com/repos/atlas-os/atlas-toolbox/releases/latest";
19+
public static string commandUpdate;
20+
public static bool CheckUpdates()
21+
{
22+
// get the api result
23+
string htmlContent = CommandPromptHelper.ReturnRunCommand("curl " + RELEASE_URL);
24+
var result = JsonDocument.Parse(htmlContent);
25+
string tagName = result.RootElement.GetProperty("tag_name").GetString();
26+
27+
// Format everything to compare
28+
int version = int.Parse(RegistryHelper.GetValue($@"HKLM\SOFTWARE\AtlasOS\Toolbox", "Version").ToString().Replace(".", ""));
29+
30+
if (int.Parse(tagName.Replace(".", "").Replace("v", "")) > version)
31+
{
32+
// get the download link and create a temporary directory
33+
string downloadUrl = result.RootElement.GetProperty("assets")[0].GetProperty("browser_download_url").GetString();
34+
string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
35+
Directory.CreateDirectory(tempDirectory);
36+
37+
CommandPromptHelper.RunCommand($"cd {tempDirectory} && curl -LSs {downloadUrl} -O \"setup.exe\"");
38+
commandUpdate = $"{tempDirectory}\\{downloadUrl.Split('/').Last()} /silent /install";
39+
return true;
40+
}
41+
return false;
42+
}
43+
44+
public static void InstallUpdate()
45+
{
46+
// Call the installer and close Toolbox
47+
CommandPromptHelper.RunCommand(commandUpdate, true, false);
48+
Environment.Exit(0);
49+
}
50+
}
51+
}

AtlasToolbox/ViewModels/SettingsPageViewModel.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
using AtlasToolbox.Utils;
1212
using AtlasToolbox.Views;
1313
using CommunityToolkit.Mvvm.ComponentModel;
14+
using CommunityToolkit.Mvvm.Input;
1415
using Newtonsoft.Json;
1516

1617
namespace AtlasToolbox.ViewModels
1718
{
18-
public class SettingsPageViewModel : INotifyPropertyChanged
19+
public partial class SettingsPageViewModel : INotifyPropertyChanged
1920
{
2021
public Language _currentLanguage { get; set; }
2122
public Language CurrentLanguage
@@ -49,5 +50,17 @@ public SettingsPageViewModel()
4950
string lang = (string)RegistryHelper.GetValue(@"HKLM\Software\AtlasOS\Toolbox", "lang");
5051
CurrentLanguage = Languages.Where(item => item.Key == lang).FirstOrDefault();
5152
}
53+
54+
public bool CheckUpdates()
55+
{
56+
if (ToolboxUpdateHelper.CheckUpdates())
57+
{
58+
App.ContentDialogCaller("newUpdate");
59+
return false;
60+
}else
61+
{
62+
return true;
63+
}
64+
}
5265
}
5366
}

AtlasToolbox/Views/SettingsPage.xaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
</Style>
2020
</Page.Resources>
2121
<StackPanel Margin="55,0,0,0">
22-
2322
<TextBlock
2423
x:Name="TitleTxt"
2524
Grid.Row="0"
@@ -44,6 +43,16 @@
4443
</ComboBox.ItemTemplate>
4544
</ComboBox>
4645
</controls:SettingsCard>
46+
<controls:SettingsCard x:Name="Update" Style="{StaticResource ConfigurationSettingsCardTemplate}">
47+
<StackPanel Orientation="Horizontal">
48+
<TextBlock
49+
x:Name="NoUpdatesBar"
50+
Margin="0,0,16,0"
51+
VerticalAlignment="Center"
52+
Visibility="Collapsed" />
53+
<Button x:Name="CheckUpdateButton" Click="CheckUpdateButton_Click" />
54+
</StackPanel>
55+
</controls:SettingsCard>
4756
</StackPanel>
4857
<StackPanel>
4958
<TextBlock x:Name="AboutHeader" Style="{StaticResource CategoryTitle}" />

AtlasToolbox/Views/SettingsPage.xaml.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public SettingsPage()
3434
ConfigSwitch.Loaded += (s, e) =>
3535
{
3636
ConfigSwitch.SelectionChanged += ConfigSwitch_SelectionChanged;
37-
;
3837
};
39-
4038
}
4139

4240
public void LoadText()
@@ -49,6 +47,9 @@ public void LoadText()
4947
bugRequestCard.Header = App.GetValueFromItemList("BugReportCard");
5048
WarningHeader.Header = App.GetValueFromItemList("WarningHeader");
5149
LanguageHeader.Header = App.GetValueFromItemList("Language");
50+
Update.Header = App.GetValueFromItemList("CheckUpdates");
51+
CheckUpdateButton.Content = App.GetValueFromItemList("CheckUpdatesBtn");
52+
NoUpdatesBar.Text = App.GetValueFromItemList("LatestVer");
5253
}
5354

5455
private void KeepBackground_Toggled(object sender, RoutedEventArgs e)
@@ -72,5 +73,14 @@ private void ConfigSwitch_SelectionChanged(object sender, SelectionChangedEventA
7273
{
7374
App.ContentDialogCaller("restartApp");
7475
}
76+
77+
private void CheckUpdateButton_Click(object sender, RoutedEventArgs e)
78+
{
79+
SettingsPageViewModel vm = this.DataContext as SettingsPageViewModel;
80+
if (vm.CheckUpdates())
81+
{
82+
NoUpdatesBar.Visibility = Visibility.Visible;
83+
}
84+
}
7585
}
7686
}

AtlasToolbox/lang/en_us.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,11 @@
193193
"RestartBtn": "Restart now",
194194
"RelogApply": "Relog to apply",
195195
"ReloadApplyDesc": "To apply these changes, please relog.",
196-
"RelogBtn": "Log off"
196+
"RelogBtn": "Log off",
197+
"CheckUpdates": "Check for updates",
198+
"CheckUpdatesBtn": "Check now",
199+
"LatestVer": "There are no updates available",
200+
"NewUpdate": "Update",
201+
"NewUpdateDesc": "There is a new update available. Would you like to install it now ?",
202+
"InstallNow": "Install now"
197203
}

AtlasToolbox/lang/fr_fr.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,11 @@
191191
"RestartPCDesc": "Pour appliquer ces changements, veuillez redémarrer votre ordinateur.",
192192
"RelogApply": "Appliquer les changements",
193193
"ReloadApplyDesc": "Pour appliquer ces changements, veuillez vous reconnecter",
194-
"RelogBtn": "Déconnecter"
194+
"RelogBtn": "Déconnecter",
195+
"CheckUpdates": "Vérifier pour une mise-à-jour",
196+
"CheckUpdatesBtn": "Vérifier maintenent",
197+
"LatestVer": "Il n'y à aucune mise-à-jour disponible'",
198+
"NewUpdate": "Mettre à jour",
199+
"NewUpdateDesc": "Il y a une nouvelle mise-à-jour disponible. Voulez-vous l'installer maintenent ?",
200+
"InstallNow": "Installer maintenent"
195201
}

0 commit comments

Comments
 (0)