Skip to content

Commit

Permalink
Merge pull request #17 from Goose-Bomb/dev
Browse files Browse the repository at this point in the history
Ready for 7th release version
  • Loading branch information
Nullkooland authored Nov 24, 2019
2 parents f05b9fe + eea5b06 commit 8227d08
Show file tree
Hide file tree
Showing 29 changed files with 388 additions and 47 deletions.
Binary file modified GBCLV3/Bootstrapper.cs
Binary file not shown.
5 changes: 2 additions & 3 deletions GBCLV3/GBCLV3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishReadyToRun>true</PublishReadyToRun>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

Expand All @@ -25,15 +24,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fody" Version="6.0.4-beta.2">
<PackageReference Include="Fody" Version="6.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Ookii.Dialogs.Wpf" Version="1.1.0" />
<PackageReference Include="PropertyChanged.Fody" Version="3.1.3" />
<PackageReference Include="Stylet" Version="1.3.0" />
<PackageReference Include="AdonisUI" Version="1.12.1" />
<PackageReference Include="AdonisUI.ClassicTheme" Version="1.12.1" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="1.1.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion GBCLV3/Models/Launcher/Asset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AssetObject
/// <summary>
/// Relative path to ./assets/objects directory
/// </summary>
public string Path => $"{Hash.Substring(0, 2)}/{Hash}";
public string Path => $"{Hash[..2]}/{Hash}";

/// <summary>
/// Size of asset file
Expand Down
16 changes: 16 additions & 0 deletions GBCLV3/Models/Skin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Media.Imaging;

namespace GBCLV3.Models
{
class Skin
{
public bool IsSlim { get; set; }

public BitmapImage Body { get; set; }

public BitmapImage Cape { get; set; }
}
}
4 changes: 2 additions & 2 deletions GBCLV3/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
[assembly: AssemblyCopyright("Copyright © Goose Bomb 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("3.0.6.54")]
[assembly: AssemblyFileVersion("3.0.6.54")]
[assembly: AssemblyVersion("3.0.7.59")]
[assembly: AssemblyFileVersion("3.0.6.59")]

[assembly: ComVisible(false)]

Expand Down
Binary file added GBCLV3/Resources/Images/enderman.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GBCLV3/Resources/Images/steve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion GBCLV3/Resources/Languages/EN-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@
<s:String x:Key="Mods">Mods</s:String>
<s:String x:Key="Resourcepacks">Resourcepacks</s:String>
<s:String x:Key="Saves">Saves</s:String>
<s:String x:Key="Skins">Skins</s:String>
<s:String x:Key="About">About</s:String>
<s:String x:Key="Accessories">Accessories</s:String>
<s:String x:Key="Auxiliaries">Auxiliaries</s:String>

<s:String x:Key="FlowerOfHope">Flower of Hope 🎵</s:String>
<s:String x:Key="DontStop">DON'T YOU EVER STOP!</s:String>
Expand Down
3 changes: 2 additions & 1 deletion GBCLV3/Resources/Languages/ZH-CN.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@
<s:String x:Key="Mods">模组管理</s:String>
<s:String x:Key="Resourcepacks">资源包管理</s:String>
<s:String x:Key="Saves">存档管理</s:String>
<s:String x:Key="Skins">皮肤管理</s:String>
<s:String x:Key="About">关于</s:String>
<s:String x:Key="Accessories">辅助功能</s:String>
<s:String x:Key="Auxiliaries">辅助功能</s:String>

<s:String x:Key="FlowerOfHope">希望之花🎵</s:String>
<s:String x:Key="DontStop">不要停下来啊!</s:String>
Expand Down
3 changes: 1 addition & 2 deletions GBCLV3/Resources/Styles/ScrollBarStyle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
<Style x:Key="{x:Type ScrollBar}" TargetType="ScrollBar">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Width" Value="13"/>
<Setter Property="Margin" Value="1,2,1,1"/>
<Setter Property="Width" Value="12"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ScrollBar">
Expand Down
2 changes: 1 addition & 1 deletion GBCLV3/Services/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Load()
{
Username = "Steve",
OfflineMode = true,
JavaMaxMem = SystemUtil.GetRecommendedMemory(),
JavaMaxMem = NativeUtil.GetRecommendedMemory(),
WindowWidth = 854,
WindowHeight = 480,
AfterLaunch = AfterLaunchBehavior.Hide,
Expand Down
2 changes: 1 addition & 1 deletion GBCLV3/Services/LanguageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public string ReplaceKeyToEntry(string src)
{
return Regex.Replace(src ?? string.Empty, "\\${.*?}", match =>
{
string key = match.Value.Substring(2, match.Length - 3);
string key = match.Value[2..^1];
return this.GetEntry(key);
});
}
Expand Down
8 changes: 4 additions & 4 deletions GBCLV3/Services/Launcher/VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public async Task<IEnumerable<VersionDownload>> GetDownloadListAsync()
new VersionDownload
{
ID = download.id,
Url = download.url.Substring(32),
Url = download.url[32..],
ReleaseTime = download.releaseTime,
Type = download.type == "release" ? VersionType.Release : VersionType.Snapshot,
});
Expand Down Expand Up @@ -272,7 +272,7 @@ private static Version Load(string json)
JarID = jver.jar ?? jver.id,
Size = jver.downloads?.client.size ?? 0,
SHA1 = jver.downloads?.client.sha1,
Url = jver.downloads?.client.url.Substring(28),
Url = jver.downloads?.client.url[28..],
InheritsFrom = jver.inheritsFrom,
MainClass = jver.mainClass,
Libraries = new List<Library>(),
Expand Down Expand Up @@ -361,7 +361,7 @@ private static Version Load(string json)
jlib.url == "http://files.minecraftforge.net/maven/")
{
lib.Type = LibraryType.Maven;
lib.Url = jlib.downloads?.artifact.url.Substring(39);
lib.Url = jlib.downloads?.artifact.url[39..];
}
else if (jlib.url == "https://maven.fabricmc.net/")
{
Expand All @@ -371,7 +371,7 @@ private static Version Load(string json)
else
{
lib.Type = LibraryType.Minecraft;
lib.Url = jlib.downloads?.artifact.url.Substring(32);
lib.Url = jlib.downloads?.artifact.url[32..];
}

version.Libraries.Add(lib);
Expand Down
105 changes: 105 additions & 0 deletions GBCLV3/Services/SkinService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using GBCLV3.Models;

namespace GBCLV3.Services
{
class SkinService
{
#region Private Members

private const string _profileServer = "https://sessionserver.mojang.com/session/minecraft/profile/";

private static readonly HttpClient _client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) };

private static readonly JsonSerializerOptions _jsonOptions
= new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };

#endregion

public async Task<Skin> GetSkinAsync(string uuid)
{
try
{
string profileJson = await _client.GetStringAsync(_profileServer + uuid);
using var profileDoc = JsonDocument.Parse(profileJson);

string profile = profileDoc.RootElement
.GetProperty("properties")[0]
.GetProperty("value")
.GetString();

string skinJson = Encoding.UTF8.GetString(Convert.FromBase64String(profile));
using var skinDoc = JsonDocument.Parse(skinJson);
var textures = skinDoc.RootElement.GetProperty("textures");

var skin = new Skin();

if (textures.TryGetProperty("SKIN", out var body))
{
string url = body.GetProperty("url").GetString();
skin.IsSlim = body.TryGetProperty("metadata", out _);

var httpStream = await _client.GetStreamAsync(url);
skin.Body = await DownloadImage(httpStream);
}

if (textures.TryGetProperty("CAPE", out var cape))
{
string url = cape.GetProperty("url").GetString();
var httpStream = await _client.GetStreamAsync(url);
skin.Cape = await DownloadImage(httpStream);
}

return skin;
}
catch (HttpRequestException ex)
{
Debug.WriteLine(ex.ToString());
return null;
}
catch (OperationCanceledException)
{
Debug.WriteLine("[ERROR] Index json download time out");
return null;
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
return null;
}
}

public CroppedBitmap GetFace(BitmapImage bodySkin)
{
int regionSize = bodySkin.PixelWidth / 8;
return new CroppedBitmap(bodySkin, new Int32Rect(regionSize, regionSize, regionSize, regionSize));
}

#region Private Methods

private static async Task<BitmapImage> DownloadImage(Stream httpStream)
{
using var memStream = new MemoryStream();
await httpStream.CopyToAsync(memStream);

var img = new BitmapImage();
img.BeginInit();
img.StreamSource = memStream;
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
img.Freeze();

return img;
}

#endregion
}
}
37 changes: 24 additions & 13 deletions GBCLV3/Utils/NativeUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@ public static Color GetSystemColorByName(string colorName)
);
}

public static bool MoveFileOnReboot(string dstPath, string srcPath)
=> MoveFileEx(srcPath, dstPath, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
public static uint GetAvailablePhysicalMemory()
{
var status = new MemoryStatusEx { Length = (uint)Marshal.SizeOf(typeof(MemoryStatusEx)) };
GlobalMemoryStatusEx(ref status);
return (uint)(status.AvailablePhysicalMemory / (1024 * 1024));
}

public static uint GetRecommendedMemory() =>
(uint)Math.Pow(2.0, Math.Floor(Math.Log(GetAvailablePhysicalMemory(), 2.0)));

#endregion

Expand Down Expand Up @@ -106,21 +113,25 @@ private enum WindowCompositionAttribute

#endregion

#region Update
#region Memory Info

[Flags]
enum MoveFileFlags
[StructLayout(LayoutKind.Sequential)]
private struct MemoryStatusEx
{
MOVEFILE_REPLACE_EXISTING = 0x00000001,
MOVEFILE_COPY_ALLOWED = 0x00000002,
MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004,
MOVEFILE_WRITE_THROUGH = 0x00000008,
MOVEFILE_CREATE_HARDLINK = 0x00000010,
MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x00000020
public uint Length;
public uint MemoryLoad;
public ulong TotalPhysicalMemory;
public ulong AvailablePhysicalMemory;
public ulong TotalPageFile;
public ulong AvailablePageFile;
public ulong TotalVirtualMemory;
public ulong AvailableVirtualMemory;
public ulong AvailableExtendedVirtualMemory;
}

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFileFlags dwFlags);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll")]
static extern bool GlobalMemoryStatusEx(ref MemoryStatusEx lpBuffer);

#endregion
}
Expand Down
8 changes: 0 additions & 8 deletions GBCLV3/Utils/SystemUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ public static void OpenLink(string url)
});
}

public static uint GetAvailableMemory()
{
using var counter = new PerformanceCounter("Memory", "Available MBytes", true);
return (uint)counter.NextValue();
}

public static uint GetRecommendedMemory() => (uint)Math.Pow(2.0, Math.Floor(Math.Log(GetAvailableMemory(), 2.0)));

public static async Task SendDirToRecycleBin(string path)
{
if (!Directory.Exists(path))
Expand Down
14 changes: 10 additions & 4 deletions GBCLV3/ViewModels/GameSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public uint JavaMaxMemory
get => _config.JavaMaxMem;
set
{
if (value > SystemUtil.GetAvailableMemory())
if (value > NativeUtil.GetAvailablePhysicalMemory())
{
_config.JavaMaxMem = SystemUtil.GetRecommendedMemory();
_config.JavaMaxMem = NativeUtil.GetRecommendedMemory();
NotifyOfPropertyChange(nameof(JavaMaxMemory));
}
else
Expand All @@ -75,8 +75,7 @@ public bool IsDebugMode
set => _config.JavaDebugMode = value;
}

public string AvailableMemory =>
_languageService.GetEntry("AvailableMem") + $" {SystemUtil.GetAvailableMemory()} MB";
public string AvailableMemory { get; private set; }

public string GameDir
{
Expand Down Expand Up @@ -203,6 +202,12 @@ public void SelectGameDir()
}
}

public void UpdateAvailableMemoryDisplay()
{
AvailableMemory =
_languageService.GetEntry("AvailableMem") + $" {NativeUtil.GetAvailablePhysicalMemory()} MB";
}

#endregion

#region Private Methods
Expand All @@ -217,6 +222,7 @@ protected override void OnViewLoaded()
!(string.IsNullOrEmpty(_config.JvmArgs) && string.IsNullOrEmpty(_config.ExtraMinecraftArgs));

NotifyOfPropertyChange(nameof(IsUseToken));
UpdateAvailableMemoryDisplay();
}

#endregion
Expand Down
Loading

0 comments on commit 8227d08

Please sign in to comment.