forked from LANraragi/Karen
Make DistroInstaller use wsl.exe if the build version allows it
+ new mica API
This commit is contained in:
parent
3d50b496de
commit
0c1108f790
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Windows.ApplicationModel;
|
||||
@ -104,26 +105,71 @@ namespace LANraragi.DistroInstaller
|
||||
|
||||
private static void Install(string distro)
|
||||
{
|
||||
WslApi.WslRegisterDistribution(distro, "package.tar");
|
||||
WslApi.WslLaunchInteractive(distro, "/bin/rm /etc/resolv.conf", true, out uint code);
|
||||
new Process
|
||||
// Check for package.tar file first
|
||||
if (!File.Exists("package.tar"))
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
Console.WriteLine("package.tar not found. Please run this program from the LANraragi folder.");
|
||||
Console.ReadKey();
|
||||
return;
|
||||
}
|
||||
|
||||
// If Windows build number > 18362, just use wsl.exe --import which is more reliable
|
||||
var buildNumber = Environment.OSVersion.Version.Build;
|
||||
if (buildNumber >= 18362) // 1903
|
||||
{
|
||||
Console.WriteLine("\nUsing WSL CLI");
|
||||
var wslProc = new Process
|
||||
{
|
||||
FileName = "wslconfig.exe",
|
||||
Arguments = "/terminate " + distro,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true,
|
||||
}
|
||||
}.Start();
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "wsl.exe",
|
||||
Arguments = $"--import {distro} \"Distro\" \"package.tar\"",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true,
|
||||
}
|
||||
};
|
||||
wslProc.Start();
|
||||
wslProc.WaitForExit();
|
||||
|
||||
Console.WriteLine("Exit code of wsl.exe is " + wslProc.ExitCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use legacy WSL API
|
||||
Console.WriteLine("\nUsing WSL API");
|
||||
WslApi.WslRegisterDistribution(distro, "package.tar");
|
||||
}
|
||||
|
||||
if (Settings != null)
|
||||
Settings.Values["Version"] = GetVersion().ToString();
|
||||
}
|
||||
|
||||
private static void UnInstall(string distro)
|
||||
{
|
||||
WslApi.WslUnregisterDistribution(distro);
|
||||
var buildNumber = Environment.OSVersion.Version.Build;
|
||||
if (buildNumber >= 18362) // 1903
|
||||
{
|
||||
Console.WriteLine("\nUsing WSL CLI");
|
||||
var wslProc = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "wsl.exe",
|
||||
Arguments = $"--unregister {distro}",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true,
|
||||
}
|
||||
};
|
||||
wslProc.Start();
|
||||
wslProc.WaitForExit();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("\nUsing WSL API");
|
||||
WslApi.WslUnregisterDistribution(distro);
|
||||
}
|
||||
Settings?.Values.Remove("Version");
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,8 @@ namespace Karen.Interop
|
||||
public enum DwmWindowAttribute : uint
|
||||
{
|
||||
DWMWA_USE_IMMERSIVE_DARK_MODE = 20,
|
||||
DWMWA_WINDOW_CORNER_PREFERENCE = 33,
|
||||
DWMWA_WINDOW_CORNER_PREFERENCE = 33,
|
||||
DWMWA_SYSTEMBACKDROP_TYPE = 38,
|
||||
DWMWA_MICA_EFFECT = 1029
|
||||
}
|
||||
|
||||
@ -57,13 +58,23 @@ namespace Karen.Interop
|
||||
int trueValue = 0x01;
|
||||
int falseValue = 0x00;
|
||||
|
||||
int micaValue = 0x02;
|
||||
|
||||
// Set dark mode before applying the material, otherwise you'll get an ugly flash when displaying the window.
|
||||
if (darkThemeEnabled)
|
||||
DwmSetWindowAttribute(source.Handle, DwmWindowAttribute.DWMWA_USE_IMMERSIVE_DARK_MODE, ref trueValue, Marshal.SizeOf(typeof(int)));
|
||||
else
|
||||
DwmSetWindowAttribute(source.Handle, DwmWindowAttribute.DWMWA_USE_IMMERSIVE_DARK_MODE, ref falseValue, Marshal.SizeOf(typeof(int)));
|
||||
|
||||
var hr = DwmSetWindowAttribute(source.Handle, DwmWindowAttribute.DWMWA_MICA_EFFECT, ref trueValue, Marshal.SizeOf(typeof(int)));
|
||||
if (Environment.OSVersion.Version.Build >= 22523)
|
||||
{
|
||||
DwmSetWindowAttribute(source.Handle, DwmWindowAttribute.DWMWA_SYSTEMBACKDROP_TYPE, ref micaValue, Marshal.SizeOf(typeof(int)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Old undocumented API
|
||||
DwmSetWindowAttribute(source.Handle, DwmWindowAttribute.DWMWA_MICA_EFFECT, ref trueValue, Marshal.SizeOf(typeof(int)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@
|
||||
<Separator Height="11.5" Margin="0"/>
|
||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}">
|
||||
You're using the <Hyperlink NavigateUri="https://github.com/Difegue/Karen" RequestNavigate="Hyperlink_RequestNavigate">Karen</Hyperlink> Bootstrapper for <Hyperlink NavigateUri="https://github.com/Difegue/LANraragi" RequestNavigate="Hyperlink_RequestNavigate">LANraragi</Hyperlink>,
|
||||
<LineBreak/> Version 2.3 <emoji:TextBlock Text="🐝"/>
|
||||
<LineBreak/> Version 2.4 <emoji:TextBlock Text="🐝"/>
|
||||
<LineBreak/>
|
||||
<emoji:TextBlock Text="✨"/> Consider installing <Hyperlink NavigateUri="ms-windows-store://pdp/?ProductId=9MZ6BWWVSWJH" RequestNavigate="Hyperlink_RequestNavigate">LRReader</Hyperlink> from the Microsoft Store! <emoji:TextBlock Text="✨"/>
|
||||
<LineBreak/>
|
||||
|
@ -102,7 +102,7 @@ namespace Setup
|
||||
public static ActionResult RegisterWslDistro(Session session)
|
||||
{
|
||||
#if DEBUG
|
||||
System.Diagnostics.Debugger.Launch();
|
||||
Debugger.Launch();
|
||||
#endif
|
||||
var result = UnRegisterWslDistro(session);
|
||||
|
||||
@ -114,7 +114,7 @@ namespace Setup
|
||||
|
||||
return session.HandleErrors(() =>
|
||||
{
|
||||
// Use wsl.exe to either install or uninstall the WSL distro.
|
||||
// Use distroinstaller to either install or uninstall the WSL distro.
|
||||
session.Log("Installing WSL Distro from package.tar");
|
||||
session.Log("package.tar location: " + packageLocation);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user