Skip to content

Commit

Permalink
feat: auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
Pd233 committed Mar 5, 2024
1 parent 2521ad1 commit 20af15a
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
dotnet-version: 8.0.x

- run: |
dotnet publish src/AutoUpdate/AutoUpdate.csproj -c Release -o bin -r ${{ matrix.runtime }}
dotnet build src/LipUI/LipUI.csproj -c Release -o bin -r ${{ matrix.runtime }} `
-p:DebugType=none -p:Platform=${{ matrix.platform }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
dotnet-version: 8.0.x

- run: |
dotnet publish src/AutoUpdate/AutoUpdate.csproj -c Release -o bin -r ${{ matrix.runtime }}
dotnet build src/LipUI/LipUI.csproj -c Release -o bin -r ${{ matrix.runtime }} `
-p:DebugType=none -p:Platform=${{ matrix.platform }}
Expand Down
22 changes: 22 additions & 0 deletions lipui.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,48 @@ VisualStudioVersion = 17.8.34408.163
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LipUI", "src\LipUI\LipUI.csproj", "{E0A3F349-6972-4266-8730-9E983EEFCA0D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoUpdate", "src\AutoUpdate\AutoUpdate.csproj", "{184A05DC-72A5-47D9-AFCB-0228CD8C563F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|Any CPU.ActiveCfg = Debug|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|Any CPU.Build.0 = Debug|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|Any CPU.Deploy.0 = Debug|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|ARM64.ActiveCfg = Debug|ARM64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|ARM64.Build.0 = Debug|ARM64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|ARM64.Deploy.0 = Debug|ARM64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|x64.ActiveCfg = Debug|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|x64.Build.0 = Debug|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Debug|x64.Deploy.0 = Debug|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|Any CPU.ActiveCfg = Release|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|Any CPU.Build.0 = Release|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|Any CPU.Deploy.0 = Release|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|ARM64.ActiveCfg = Release|ARM64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|ARM64.Build.0 = Release|ARM64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|ARM64.Deploy.0 = Release|ARM64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|x64.ActiveCfg = Release|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|x64.Build.0 = Release|x64
{E0A3F349-6972-4266-8730-9E983EEFCA0D}.Release|x64.Deploy.0 = Release|x64
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Debug|ARM64.Build.0 = Debug|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Debug|x64.ActiveCfg = Debug|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Debug|x64.Build.0 = Debug|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Release|Any CPU.Build.0 = Release|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Release|ARM64.ActiveCfg = Release|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Release|ARM64.Build.0 = Release|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Release|x64.ActiveCfg = Release|Any CPU
{184A05DC-72A5-47D9-AFCB-0228CD8C563F}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
17 changes: 17 additions & 0 deletions src/AutoUpdate/AutoUpdate.csproj
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>
97 changes: 97 additions & 0 deletions src/AutoUpdate/Program.cs
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);
13 changes: 13 additions & 0 deletions src/AutoUpdate/Type.cs
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
}
3 changes: 3 additions & 0 deletions src/LipUI/Language/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@
<data name="serverSelection$existed" xml:space="preserve">
<value>Server path already exists!</value>
</data>
<data name="settingsAndAbout$title" xml:space="preserve">
<value>Settings &amp; About</value>
</data>
<data name="startServer.Text" xml:space="preserve">
<value>Start server</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/LipUI/Language/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@
<data name="serverSelection$existed" xml:space="preserve">
<value>服务器路径已存在!</value>
</data>
<data name="settingsAndAbout$title" xml:space="preserve">
<value>设置 &amp; 关于</value>
</data>
<data name="startServer.Text" xml:space="preserve">
<value>启动服务器</value>
</data>
Expand Down
17 changes: 17 additions & 0 deletions src/LipUI/LipUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@
<Nullable>enable</Nullable>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<PackageCertificateThumbprint>EECEBA1A034834A8FCA2C7E7B8878D2477C1AC0B</PackageCertificateThumbprint>
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundle>Auto</AppxBundle>
<AppxBundlePlatforms>x64|arm64</AppxBundlePlatforms>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<WindowsPackageType>None</WindowsPackageType>

</PropertyGroup>
<ItemGroup>
<None Remove="BuiltInPlugins\LipPanel\LipPanelPage.xaml" />
<None Remove="Pages\Settings\SettingsAndAboutView.xaml" />
</ItemGroup>

<ItemGroup>
Expand All @@ -37,6 +48,12 @@
<ProjectCapability Include="Msix" />
</ItemGroup>

<ItemGroup>
<Page Update="Pages\Settings\SettingsAndAboutView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<ItemGroup>
<Page Update="BuiltInPlugins\LipPanel\LipPanelPage.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down
4 changes: 2 additions & 2 deletions src/LipUI/Models/Plugin/PluginConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void Load()
{
lock (pluginConfigs)
{
var dir = new DirectoryInfo(DefaultSettings.ConfigsDirectory);
var dir = new DirectoryInfo(Path.Combine(Main.WorkingDirectory, DefaultSettings.ConfigsDirectory));
if (dir.Exists is false)
dir.Create();

Expand All @@ -70,7 +70,7 @@ public static void Save(in PluginConfigFileInfo info, ConfigCollection config)
if (config.Changed is false)
return;

var path = Path.Combine(DefaultSettings.ConfigsDirectory, $"{info.AssemblyName}+{info.Name}+{info.Guid}.json");
var path = Path.Combine(Main.WorkingDirectory, DefaultSettings.ConfigsDirectory, $"{info.AssemblyName}+{info.Name}+{info.Guid}.json");
if (File.Exists(path))
File.Delete(path);
File.WriteAllText(path, config.Serialize());
Expand Down
23 changes: 23 additions & 0 deletions src/LipUI/Pages/Settings/SettingsAndAboutView.xaml
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>
57 changes: 57 additions & 0 deletions src/LipUI/Pages/Settings/SettingsAndAboutView.xaml.cs
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);
}
}
}
6 changes: 6 additions & 0 deletions src/LipUI/Pages/Settings/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
Tag="personalizationSettings"/>
</ListViewItem>

<ListViewItem>
<TextBlock
x:Uid="settingsAndAbout$title"
Tag="settingsAndAbout"/>
</ListViewItem>

<ListViewItem>
<TextBlock
x:Uid="lipSettings$title"
Expand Down
4 changes: 4 additions & 0 deletions src/LipUI/Pages/Settings/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ private void ListView_ItemClick(object sender, ItemClickEventArgs e)
SettingsBorder.Child = new PersonalizationSettingsView();
break;

case "settingsAndAbout":
SettingsBorder.Child = new SettingsAndAboutView();
break;

case "lipSettings":
SettingsBorder.Child = new LipSettingsView();
break;
Expand Down
Loading

0 comments on commit 20af15a

Please sign in to comment.