-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
294 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PublishAot>true</PublishAot> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" /> | ||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using Microsoft.Extensions.Logging; | ||
using System.CommandLine; | ||
using System.Diagnostics; | ||
using System.Text; | ||
|
||
using var factory = LoggerFactory.Create(builder => builder.AddConsole()); | ||
var logger = factory.CreateLogger("AutoUpdate"); | ||
|
||
Option<AutoUpdate.Type> option = new("--type", "The type of update"); | ||
Option<string?> lipPath = new("--lip-path", "The path to your Lip.exe"); | ||
Option<string?> workingDir = new("--working-dir", "The path to your executing program"); | ||
|
||
void Lipui_Handler(string? lipPath, string? workingDir) | ||
{ | ||
if (lipPath is null || workingDir is null) | ||
{ | ||
logger.LogError("--lip-path and --working-dir are required"); | ||
return; | ||
} | ||
|
||
if (File.Exists(lipPath) is false) | ||
logger.LogError("Lip.exe not found"); | ||
|
||
if (Directory.Exists(workingDir) is false) | ||
logger.LogError("LipUI directory not found"); | ||
|
||
var autoupdateDir = Path.Combine(workingDir, ".autoupdate"); | ||
if (Directory.Exists(autoupdateDir)) | ||
Directory.Delete(autoupdateDir, true); | ||
Directory.CreateDirectory(autoupdateDir); | ||
|
||
File.WriteAllText(Path.Combine(autoupdateDir, "current_lipui_path.txt"), workingDir); | ||
logger.LogInformation("Wrote {workingDir} to {autoupdateDir}", workingDir, autoupdateDir); | ||
|
||
var process = new Process() | ||
{ | ||
StartInfo = new(lipPath) | ||
{ | ||
WorkingDirectory = workingDir, | ||
Arguments = "install github.com/lippkg/LipUI --upgrade", | ||
} | ||
}; | ||
logger.LogInformation("Running: {lipPath} install github.com/lippkg/LipUI", lipPath); | ||
process.Start(); | ||
} | ||
|
||
void Lip_Handler() | ||
{ | ||
var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory()); | ||
var path = Path.Combine(currentDir.FullName, "current_lipui_path.txt"); | ||
|
||
if (File.Exists(path) is false) | ||
logger.LogError("LipUI path not found"); | ||
|
||
var lipuiWorkingDir = File.ReadAllText(path); | ||
File.Delete(path); | ||
|
||
|
||
foreach (var file in currentDir.EnumerateFiles()) | ||
{ | ||
File.Move(file.FullName, Path.Combine(lipuiWorkingDir, file.Name), true); | ||
logger.LogInformation("Moved {file} to {lipuiWorkingDir}", file.Name, lipuiWorkingDir); | ||
} | ||
|
||
foreach (var dir in currentDir.EnumerateDirectories()) | ||
{ | ||
Directory.Move(dir.FullName, Path.Combine(lipuiWorkingDir, dir.Name)); | ||
logger.LogInformation("Moved {dir} to {lipuiWorkingDir}", dir.Name, lipuiWorkingDir); | ||
} | ||
|
||
logger.LogInformation("LipUI updated"); | ||
|
||
logger.LogInformation("Clean up"); | ||
var autoupdateDir = Path.Combine(lipuiWorkingDir, ".autoupdate"); | ||
if (Directory.Exists(autoupdateDir)) | ||
Directory.Delete(autoupdateDir); | ||
|
||
Process.Start(Path.Combine(lipuiWorkingDir, "LipUI.exe")); | ||
}; | ||
|
||
RootCommand rootCommand = [option, lipPath, workingDir]; | ||
rootCommand.SetHandler((AutoUpdate.Type type, string? lipPath, string? workingDir) => | ||
{ | ||
switch (type) | ||
{ | ||
case AutoUpdate.Type.lip_postinstall: | ||
Lip_Handler(); | ||
break; | ||
case AutoUpdate.Type.lipui_autoupdate: | ||
Lipui_Handler(lipPath, workingDir); | ||
break; | ||
} | ||
}, option, lipPath, workingDir); | ||
|
||
await Task.Delay(2000); | ||
|
||
return await rootCommand.InvokeAsync(args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AutoUpdate; | ||
|
||
internal enum Type | ||
{ | ||
lip_postinstall, | ||
lipui_autoupdate | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<UserControl | ||
x:Class="LipUI.Pages.Settings.SettingsAndAboutView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:LipUI.Pages.Settings" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<StackPanel | ||
x:Name="SettingsPanel" | ||
Spacing="8"> | ||
|
||
<Button | ||
x:Name="UpdateButton" | ||
Loading="UpdateButton_Loading" | ||
Click="UpdateButton_Click"/> | ||
|
||
|
||
</StackPanel> | ||
|
||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using LipUI.Models; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
|
||
// To learn more about WinUI, the WinUI project structure, | ||
// and more about our project templates, see: http://aka.ms/winui-project-info. | ||
|
||
namespace LipUI.Pages.Settings | ||
{ | ||
public sealed partial class SettingsAndAboutView : UserControl | ||
{ | ||
public SettingsAndAboutView() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
private void UpdateButton_Loading(FrameworkElement sender, object args) | ||
{ | ||
var button = (Button)sender; | ||
button.Content = "localTooth$update".GetLocalized(); | ||
} | ||
|
||
private async void UpdateButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
if (RuntimeInformation.ProcessArchitecture is not Architecture.X64) | ||
throw new NotImplementedException($"{RuntimeInformation.ProcessArchitecture} is not supported yet."); | ||
|
||
var (success, path) = await Main.TryGetLipConsolePathAsync(XamlRoot); | ||
|
||
if (success is false) | ||
await InternalServices.ShowInfoBarAsync( | ||
severity: InfoBarSeverity.Error, | ||
title: "infoBar$error".GetLocalized(), | ||
message: "lipExecution$nullLipPath".GetLocalized()); | ||
|
||
Process.Start( | ||
Path.Combine(Main.WorkingDirectory, "AutoUpdate.exe"), | ||
@$"--type lipui_autoupdate --lip-path ""{path}"" --working-dir ""{Main.WorkingDirectory}"""); | ||
|
||
Environment.Exit(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.