Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions PCL2.Neo/Helpers/ThemeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ public void Refresh(ThemeVariant themeVariant)
brushTitle.GradientStops.Add(new GradientStop
{
Offset = 0,
Color = new MyColor().FromHsl2(_colorHue - _colorHueTopbarDelta, _colorSat, 48 + _colorLightAdjust)
Color = MyColor.FromHsl2(_colorHue - _colorHueTopbarDelta, _colorSat,
48 + _colorLightAdjust)
});
brushTitle.GradientStops.Add(new GradientStop
{
Offset = 0.5,
Color = new MyColor().FromHsl2(_colorHue, _colorSat, 54 + _colorLightAdjust)
Offset = 0.5, Color = MyColor.FromHsl2(_colorHue, _colorSat, 54 + _colorLightAdjust)
});
brushTitle.GradientStops.Add(new GradientStop
{
Offset = 1,
Color = new MyColor().FromHsl2(_colorHue + _colorHueTopbarDelta, _colorSat, 48 + _colorLightAdjust)
Color = MyColor.FromHsl2(_colorHue + _colorHueTopbarDelta, _colorSat,
48 + _colorLightAdjust)
});

_mainWindow.NavBackgroundBorder.Background = brushTitle;
Expand All @@ -90,17 +91,18 @@ public void Refresh(ThemeVariant themeVariant)
brushBackground.GradientStops.Add(new GradientStop
{
Offset = -0.1,
Color = new MyColor().FromHsl2(_colorHue - 20, Math.Min(60, _colorSat) * 0.5, 80 * lightAdjust)
Color = MyColor.FromHsl2(_colorHue - 20, Math.Min(60, _colorSat) * 0.5f,
80 * lightAdjust)
});
brushBackground.GradientStops.Add(new GradientStop
{
Offset = 0.4,
Color = new MyColor().FromHsl2(_colorHue, _colorSat * 0.9, 90 * lightAdjust)
Offset = 0.4, Color = MyColor.FromHsl2(_colorHue, _colorSat * 0.9f, 90 * lightAdjust)
});
brushBackground.GradientStops.Add(new GradientStop
{
Offset = 1.1,
Color = new MyColor().FromHsl2(_colorHue + 20, Math.Min(60, _colorSat) * 0.5, 80 * lightAdjust)
Color = MyColor.FromHsl2(_colorHue + 20, Math.Min(60, _colorSat) * 0.5f,
80 * lightAdjust)
});

_mainWindow.MainBorder.Background = brushBackground;
Expand Down
4 changes: 2 additions & 2 deletions PCL2.Neo/Models/Minecraft/Java/Java.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public static async Task<IEnumerable<JavaEntity>> SearchJava()
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return Unix.SearchJava();
return await Unix.SearchJava();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return Unix.SearchJava();
return await Unix.SearchJava();
}
else
{
Expand Down
61 changes: 32 additions & 29 deletions PCL2.Neo/Models/Minecraft/Java/Unix.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace PCL2.Neo.Models.Minecraft.Java
{
/// <summary>
/// 处理Unix系统下的java
/// </summary>
internal class Unix
internal static class Unix
{
#warning "该方法未在 Linux 上测试,可能无法正常工作 Unix/SearchJava"
public static IEnumerable<JavaEntity> SearchJava() =>
FindJavaExecutablePath().Select(it => new JavaEntity(it));
#warning "该方法未经过测试,可能无法正常工作 Unix/SearchJava"

Check warning on line 16 in PCL2.Neo/Models/Minecraft/Java/Unix.cs

View workflow job for this annotation

GitHub Actions / build

#warning: '"该方法未经过测试,可能无法正常工作 Unix/SearchJava"'

Check warning on line 16 in PCL2.Neo/Models/Minecraft/Java/Unix.cs

View workflow job for this annotation

GitHub Actions / build

#warning: '"该方法未经过测试,可能无法正常工作 Unix/SearchJava"'

Check warning on line 16 in PCL2.Neo/Models/Minecraft/Java/Unix.cs

View workflow job for this annotation

GitHub Actions / build

#warning: '"该方法未经过测试,可能无法正常工作 Unix/SearchJava"'
public static async Task<IEnumerable<JavaEntity>> SearchJava() =>
await Task.Run(() => FindJavaExecutablePath().Select(it => new JavaEntity(it)));

private static HashSet<string> FindJavaExecutablePath()
{
var foundJava = new HashSet<string>();

GetPontentialJavaDir()
.Where(Directory.Exists)
.ToList().ForEach(it => SearchDirectoryForJava(it, foundJava));

return foundJava;
}
private static IEnumerable<string> FindJavaExecutablePath() =>
GetPotentialJavaDir()
.Where(Directory.Exists)
.SelectMany(SearchJavaExecutables)
.Distinct();

private static bool IsValidJavaExecutable(string filePath)
{
// if (Directory.Exists(filePath))
// return false;

// return !filePath.EndsWith(".jar") && !filePath.EndsWith(".zip") && !filePath.EndsWith(".so") &&
// !filePath.EndsWith(".dylib");
// TODO: check execute permission
return File.Exists(filePath);
}

private static void SearchDirectoryForJava(string basePath, HashSet<string> foundJava)
private static IEnumerable<string> SearchJavaExecutables(string basePath)
{
try
{
var binDirs = Directory.EnumerateDirectories(basePath, "bin", SearchOption.AllDirectories);
binDirs
.SelectMany(binDir => Directory.EnumerateFiles(binDir, "java", SearchOption.TopDirectoryOnly))
.Where(IsValidJavaExecutable)
.ToList().ForEach(it => foundJava.Add(it));
return Directory
.EnumerateFiles(basePath, "java", new EnumerationOptions
{
RecurseSubdirectories = true,
MaxRecursionDepth = 7,
IgnoreInaccessible = true
})
.Where(IsValidJavaExecutable);
}
catch (Exception)
{
// TODO: Logger handling exceptions
}
catch (UnauthorizedAccessException) { }

return [];
}

private static IEnumerable<string> GetPontentialJavaDir()
private static IEnumerable<string> GetPotentialJavaDir()
{
var paths = new List<string>();
var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

// add path
paths.AddRange(Environment.GetEnvironmentVariable("PATH")?.Split(':') ?? []);

// add system paths
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Expand Down Expand Up @@ -87,6 +90,7 @@
}

// add home dirs
var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
if (!string.IsNullOrEmpty(homeDir))
{
paths.AddRange([
Expand Down Expand Up @@ -114,7 +118,6 @@
paths.Add(parent);
}


return paths.Distinct();
}
}
Expand Down
80 changes: 62 additions & 18 deletions PCL2.Neo/Models/MyColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PCL2.Neo.Models;

public class MyColor
public class MyColor : IEquatable<MyColor>
{
private Vector4 _color;

Expand Down Expand Up @@ -163,9 +163,51 @@ public MyColor(SolidColorBrush brush)
this._color = new Vector4(color.A, color.R, color.G, color.B);
}

// IEquatable

public bool Equals(MyColor? other)
{
if (other is null)
{
return false;
}

if (ReferenceEquals(this, other))
{
return true;
}

return _color.Equals(other._color);
}

public override bool Equals(object? obj)
{
if (obj is null)
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

if (obj.GetType() != GetType())
{
return false;
}

return Equals((MyColor)obj);
}

public override int GetHashCode()
{
return _color.GetHashCode();
}

// HSL

public double Hue(double v1, double v2, double vH)
public static double Hue(double v1, double v2, double vH)
{
if (vH < 0) vH += 1;
if (vH > 1) vH -= 1;
Expand All @@ -175,13 +217,14 @@ public double Hue(double v1, double v2, double vH)
return v1;
}

public MyColor FromHsl(double sH, double sS, double sL)
public static MyColor FromHsl(double sH, double sS, double sL)
{
var color = new MyColor();
if (sS == 0)
{
R = (float)(sL * 2.55);
G = R;
B = R;
color.R = (float)(sL * 2.55);
color.G = color.R;
color.B = color.R;
}
else
{
Expand All @@ -190,22 +233,23 @@ public MyColor FromHsl(double sH, double sS, double sL)
double l = sL / 100;
s = l < 0.5 ? s * l + l : s * (1.0 - l) + l;
l = 2 * l - s;
R = (float)(255 * Hue(l, s, h + 1 / 3.0));
G = (float)(255 * Hue(l, s, h));
B = (float)(255 * Hue(l, s, h - 1 / 3.0));
color.R = (float)(255 * Hue(l, s, h + 1 / 3.0));
color.G = (float)(255 * Hue(l, s, h));
color.B = (float)(255 * Hue(l, s, h - 1 / 3.0));
}

A = 255;
return this;
color.A = 255;
return color;
}

public MyColor FromHsl2(double sH, double sS, double sL)
public static MyColor FromHsl2(double sH, double sS, double sL)
{
var color = new MyColor();
if (sS == 0)
{
R = (float)(sL * 2.55);
G = R;
B = R;
color.R = (float)(sL * 2.55);
color.G = color.R;
color.B = color.R;
}
else
{
Expand All @@ -226,10 +270,10 @@ public MyColor FromHsl2(double sH, double sS, double sL)

sL = sL < center ? sL / center : 1 + (sL - center) / (100 - center);
sL *= 50;
FromHsl(sH, sS, sL);
color = FromHsl(sH, sS, sL);
}

A = 255;
return this;
color.A = 255;
return color;
}
}
6 changes: 4 additions & 2 deletions PCL2.NeoTests/Models/MainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public class MainTests
[TestMethod]
public async Task JavaSearchTest()
{
foreach (var javaEntity in await Java.SearchJava()) {
Console.WriteLine(javaEntity.Path);
var result = Minecraft.Java.Java.SearchJava().Result;
foreach (var item in result)
{
Console.WriteLine(item.Path);
}
}
}
Expand Down
Loading