now it works
This commit is contained in:
36
Mlaumcherb.Client.Avalonia/холопы/ErrorHelper.cs
Normal file
36
Mlaumcherb.Client.Avalonia/холопы/ErrorHelper.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Avalonia.Controls;
|
||||
using DTLib.Demystifier;
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Dto;
|
||||
using MsBox.Avalonia.Enums;
|
||||
using MsBox.Avalonia.Models;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
public static class ErrorHelper
|
||||
{
|
||||
internal static void ShowMessageBox(string context, Exception err)
|
||||
=> ShowMessageBox(context, err.ToStringDemystified());
|
||||
|
||||
internal static async void ShowMessageBox(string context, string err)
|
||||
{
|
||||
LauncherApp.Logger.LogError(context, err);
|
||||
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
|
||||
{
|
||||
ButtonDefinitions = new List<ButtonDefinition> { new() { Name = "пон" } },
|
||||
ContentTitle = "ОШИБКА",
|
||||
ContentMessage = err,
|
||||
Icon = Icon.Error,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterOwner,
|
||||
CanResize = true,
|
||||
MaxWidth = 1000,
|
||||
MaxHeight = 1000,
|
||||
SizeToContent = SizeToContent.WidthAndHeight,
|
||||
ShowInCenter = true,
|
||||
Topmost = true
|
||||
}
|
||||
);
|
||||
await box.ShowAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
26
Mlaumcherb.Client.Avalonia/холопы/LZMAHelper.cs
Normal file
26
Mlaumcherb.Client.Avalonia/холопы/LZMAHelper.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
/// <summary>
|
||||
/// https://gist.github.com/ststeiger/cb9750664952f775a341
|
||||
/// </summary>
|
||||
public static class LZMAHelper
|
||||
{
|
||||
public static void Decompress(Stream inputStream, Stream outputStream)
|
||||
{
|
||||
var decoder = new SevenZip.Compression.LZMA.Decoder();
|
||||
var properties = new byte[5];
|
||||
// Read decoder properties
|
||||
if (inputStream.Read(properties, 0, 5) != 5)
|
||||
throw new Exception("lzma stream is too short");
|
||||
decoder.SetDecoderProperties(properties);
|
||||
|
||||
// Read decompressed data size
|
||||
var fileLengthBytes = new byte[8];
|
||||
if(inputStream.Read(fileLengthBytes, 0, 8) != 8)
|
||||
throw new Exception("lzma stream is too short");
|
||||
long fileLength = BitConverter.ToInt64(fileLengthBytes, 0);
|
||||
|
||||
// Decode
|
||||
decoder.Code(inputStream, outputStream, -1, fileLength, null);
|
||||
}
|
||||
}
|
||||
57
Mlaumcherb.Client.Avalonia/холопы/PathHelper.cs
Normal file
57
Mlaumcherb.Client.Avalonia/холопы/PathHelper.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
public static class PathHelper
|
||||
{
|
||||
public static IOPath GetRootFullPath() =>
|
||||
System.IO.Path.GetFullPath(new IOPath(LauncherApp.Config.minecraft_dir).ToString());
|
||||
|
||||
public static IOPath GetAssetsDir() =>
|
||||
Path.Concat(GetRootFullPath(), "assets");
|
||||
|
||||
public static IOPath GetAssetIndexFilePath(string id) =>
|
||||
Path.Concat(GetAssetsDir(), $"assets/indexes/{id}.json");
|
||||
|
||||
public static IOPath GetVersionDescriptorPath(string id) =>
|
||||
Path.Concat(GetVersionDir(id), id + ".json");
|
||||
|
||||
public static IOPath GetVersionsDir() =>
|
||||
Path.Concat(GetRootFullPath(), "versions");
|
||||
|
||||
public static IOPath GetVersionDir(string id) =>
|
||||
Path.Concat(GetVersionsDir(), id);
|
||||
|
||||
public static IOPath GetVersionJarFilePath(string id) =>
|
||||
Path.Concat(GetVersionDir(id), id + ".jar");
|
||||
|
||||
public static IOPath GetLibrariesDir() =>
|
||||
Path.Concat(GetRootFullPath(), "libraries");
|
||||
|
||||
public static IOPath GetNativeLibrariesDir(string id) =>
|
||||
Path.Concat(GetVersionDir(id), "natives", PlatformHelper.GetOsAndArch());
|
||||
|
||||
public static IOPath GetJavaRuntimesDir() =>
|
||||
Path.Concat(GetRootFullPath(), "java");
|
||||
|
||||
|
||||
public static IOPath GetJavaRuntimeDir(string id) =>
|
||||
Path.Concat(GetJavaRuntimesDir(), PlatformHelper.GetOsAndArch(), id);
|
||||
|
||||
public static IOPath GetJavaBinDir(string id) =>
|
||||
Path.Concat(GetJavaRuntimeDir(id), "bin");
|
||||
public static IOPath GetJavaExecutablePath(string id, bool debug)
|
||||
{
|
||||
string executable_name = "java";
|
||||
if (debug)
|
||||
executable_name += "w";
|
||||
if(OperatingSystem.IsWindows())
|
||||
executable_name += ".exe";
|
||||
return Path.Concat(GetJavaBinDir(id), executable_name);
|
||||
}
|
||||
|
||||
public static string GetLog4jConfigFileName() => "log4j.xml";
|
||||
|
||||
public static IOPath GetLog4jConfigFilePath() =>
|
||||
Path.Concat(GetAssetsDir(), GetLog4jConfigFileName());
|
||||
}
|
||||
55
Mlaumcherb.Client.Avalonia/холопы/PlatformHelper.cs
Normal file
55
Mlaumcherb.Client.Avalonia/холопы/PlatformHelper.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
// ReSharper disable CollectionNeverUpdated.Global
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
public static class PlatformHelper
|
||||
{
|
||||
public static bool CheckOs(Os os) =>
|
||||
os.name switch
|
||||
{
|
||||
null => true,
|
||||
"osx" => OperatingSystem.IsMacOS(),
|
||||
"linux" => OperatingSystem.IsLinux(),
|
||||
"windows" => OperatingSystem.IsWindows(),
|
||||
_ => throw new ArgumentOutOfRangeException(os.name)
|
||||
}
|
||||
&& os.arch switch
|
||||
{
|
||||
null => true,
|
||||
"i386" or "x86" => RuntimeInformation.OSArchitecture == Architecture.X86,
|
||||
"x64" => RuntimeInformation.OSArchitecture == Architecture.X64,
|
||||
"arm64" => RuntimeInformation.OSArchitecture == Architecture.Arm64,
|
||||
_ => false
|
||||
};
|
||||
|
||||
public static string GetOs() =>
|
||||
Environment.OSVersion.Platform switch
|
||||
{
|
||||
PlatformID.Win32NT => "windows",
|
||||
PlatformID.Unix => "linux",
|
||||
PlatformID.MacOSX => "osx",
|
||||
_ => throw new PlatformNotSupportedException("OS not supported")
|
||||
};
|
||||
|
||||
public static string GetArch() =>
|
||||
RuntimeInformation.OSArchitecture switch
|
||||
{
|
||||
Architecture.X86 => "x86",
|
||||
Architecture.X64 => "x64",
|
||||
Architecture.Arm64 => "arm64",
|
||||
_ => throw new PlatformNotSupportedException("OS not supported")
|
||||
};
|
||||
|
||||
public static string GetArchOld() =>
|
||||
RuntimeInformation.OSArchitecture switch
|
||||
{
|
||||
Architecture.X86 => "32",
|
||||
Architecture.X64 => "64",
|
||||
_ => throw new PlatformNotSupportedException("OS not supported")
|
||||
};
|
||||
|
||||
public static string GetOsAndArch() => GetOs() + '-' + GetArch();
|
||||
}
|
||||
Reference in New Issue
Block a user