Skip to content

Commit

Permalink
Merge pull request #10 from Goose-Bomb/dev
Browse files Browse the repository at this point in the history
Ready for 3rd release version
  • Loading branch information
Nullkooland authored Aug 28, 2019
2 parents ad0a18b + db31ad3 commit 9993ec9
Show file tree
Hide file tree
Showing 28 changed files with 164 additions and 79 deletions.
1 change: 0 additions & 1 deletion GBCLV3.Tests/GBCLV3.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<Compile Include="AssetTest.cs" />
<Compile Include="LibraryTest.cs" />
<Compile Include="LaunchTest.cs" />
<Compile Include="AuthTest.cs" />
<Compile Include="ModTest.cs" />
<Compile Include="ResourcePackTest.cs" />
<Compile Include="InstallTest.cs" />
Expand Down
Binary file modified GBCLV3/App.xaml
Binary file not shown.
Binary file modified GBCLV3/Bootstrapper.cs
Binary file not shown.
2 changes: 1 addition & 1 deletion GBCLV3/Models/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Config

public bool UseSystemColor { get; set; }

public string ThemeColor { get; set; }
public string AccentColor { get; set; }

#endregion
}
Expand Down
6 changes: 5 additions & 1 deletion GBCLV3/Models/Forge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace GBCLV3.Models
{
class Forge
{
public string Version { get; set; }

public int Build { get; set; }

public DateTime ReleaseTime { get; set; }
Expand All @@ -12,6 +14,8 @@ class Forge

public string GameVersion { get; set; }

public string Version { get; set; }
public bool IsAutoInstall { get; set; }

public bool HasSuffix { get; set; }
}
}
5 changes: 0 additions & 5 deletions GBCLV3/Models/Launcher/Launch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,4 @@ class LaunchProfile

public string ExtraArgs { get; set; }
}

class LaunchResult
{
public bool IsSuccessful { 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.2.38")]
[assembly: AssemblyFileVersion("3.0.2.38")]
[assembly: AssemblyVersion("3.0.3.41")]
[assembly: AssemblyFileVersion("3.0.3.41")]

[assembly: ComVisible(false)]

Expand Down
22 changes: 13 additions & 9 deletions GBCLV3/Resources/Styles/Icons.xaml

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions GBCLV3/Resources/Styles/TabControlStyle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

<TabPanel Grid.Row="0"
IsItemsHost="True"
Background="#80FFFFFF"/>
Background="{DynamicResource LightTranslucentBrush}"/>

<Rectangle Grid.Row="1" Opacity="0.25"
Fill="{DynamicResource {x:Static adonisUI:Brushes.AccentBrush}}"/>

<Border Grid.Row="1" Background="#50999999">
<Border Grid.Row="1" Background="{DynamicResource DarkTranslucentBrush}">
<ContentPresenter x:Name="PART_SelectedContentHost"
ContentSource="SelectedContent"/>
</Border>
Expand Down Expand Up @@ -69,7 +69,8 @@

<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=Border, Path=IsMouseOver}" Value="True">
<Setter TargetName="Border" Property="Background" Value="#B0CCCCCC"/>
<Setter TargetName="Border" Property="Background"
Value="{DynamicResource ControlTranslucentBrush}"/>
</DataTrigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="SlectionIdentifier" Property="Visibility" Value="Visible"/>
Expand Down
2 changes: 1 addition & 1 deletion GBCLV3/Services/DownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void DownloadTask(DownloadItem item)

try
{
using (var fs = File.OpenWrite(item.Path))
using (var fs = new FileStream(item.Path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
{
var waitResponceTask = _client.GetStreamAsync(item.Url);

Expand Down
43 changes: 33 additions & 10 deletions GBCLV3/Services/ForgeInstallService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using GBCLV3.Models;
using GBCLV3.Models.JsonClasses;
Expand Down Expand Up @@ -57,14 +58,33 @@ public async Task<IEnumerable<Forge>> GetDownloadListAsync(string id)
string json = await _client.GetStringAsync(FORGE_LIST_URL + id);
var forgeList = JsonSerializer.Deserialize<List<JForgeVersion>>(json);

var nums = id.Split('.')
.Select(numStr =>
{
if (int.TryParse(numStr, out int num))
{
return num;
}
else
{
return -1;
}
})
.ToArray();

bool hasSuffix = ((nums[1] == 7 || nums[1] == 8) && nums[2] != 2);
bool isAutoInstall = (nums[1] < 13);

return forgeList.Select(jforge =>
new Forge
{
Version = jforge.version,
Build = jforge.build,
ReleaseTime = jforge.modified,
Branch = jforge.branch,
GameVersion = jforge.mcversion,
Version = jforge.version,
HasSuffix = hasSuffix,
IsAutoInstall = isAutoInstall,
}
).OrderByDescending(forge => forge.Build);
}
Expand All @@ -81,19 +101,19 @@ public async Task<IEnumerable<Forge>> GetDownloadListAsync(string id)
}
}

public IEnumerable<DownloadItem> GetDownload(Forge forge, bool isAutoInstall)
public IEnumerable<DownloadItem> GetDownload(Forge forge)
{
string fullName = $"{forge.GameVersion}-{forge.Version}";
string fullName = $"{forge.GameVersion}-{forge.Version}" + (forge.HasSuffix ? $"-{forge.GameVersion}" : null);

var item = new DownloadItem
{
Name = $"Forge-{fullName}",

Path = isAutoInstall ? $"{_gamePathService.ForgeLibDir}/{fullName}/forge-{fullName}.jar"
: $"{_gamePathService.RootDir}/{fullName}-installer.jar",
Path = forge.IsAutoInstall ? $"{_gamePathService.ForgeLibDir}/{fullName}/forge-{fullName}.jar"
: $"{_gamePathService.RootDir}/{fullName}-installer.jar",

Url = isAutoInstall ? $"{_urlService.Base.Forge}{fullName}/forge-{fullName}-universal.jar"
: $"{_urlService.Base.Forge}{fullName}/forge-{fullName}-installer.jar",
Url = forge.IsAutoInstall ? $"{_urlService.Base.Forge}{fullName}/forge-{fullName}-universal.jar"
: $"{_urlService.Base.Forge}{fullName}/forge-{fullName}-installer.jar",

IsCompleted = false,
DownloadedBytes = 0,
Expand Down Expand Up @@ -132,7 +152,7 @@ public async Task<Version> ManualInstall(Forge forge)

public Version AutoInstall(Forge forge)
{
string fullName = $"{forge.GameVersion}-{forge.Version}";
string fullName = $"{forge.GameVersion}-{forge.Version}" + (forge.HasSuffix ? $"-{forge.GameVersion}" : null);
string jarPath = $"{_gamePathService.ForgeLibDir}/{fullName}/forge-{fullName}.jar";

if (!File.Exists(jarPath))
Expand All @@ -146,12 +166,15 @@ public Version AutoInstall(Forge forge)

using (var reader = new StreamReader(entry.Open(), Encoding.UTF8))
{
return _versionService.AddNew(reader.ReadToEnd());
string json = reader.ReadToEnd();
string versionID = $"{forge.GameVersion}-forge-{forge.Version}";

json = Regex.Replace(json, "\"id\":\\s\".*\"", $"\"id\": \"{versionID}\"");
return _versionService.AddNew(json);
}
}
}

#endregion

}
}
2 changes: 1 addition & 1 deletion GBCLV3/Services/Launcher/GamePathService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GamePathService

public string SavesDir => WorkingDir + "/saves";

public string LogDir => WorkingDir + "/logs";
public string LogsDir => WorkingDir + "/logs";

public string JreExecutablePath => _config.JreDir + (_config.JavaDebugMode ? "/java.exe" : "/javaw.exe");

Expand Down
10 changes: 7 additions & 3 deletions GBCLV3/Services/Launcher/LaunchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using GBCLV3.Models.Launcher;
using GBCLV3.Utils;
Expand Down Expand Up @@ -43,7 +44,7 @@ public LaunchService(GamePathService gamePathService)

#region Public Methods

public async Task<LaunchResult> LaunchGameAsync(LaunchProfile profile, Version version)
public async Task<bool> LaunchGameAsync(LaunchProfile profile, Version version)
{
bool isDebugMode = _gamePathService.JreExecutablePath.EndsWith("java.exe");

Expand Down Expand Up @@ -74,10 +75,13 @@ public async Task<LaunchResult> LaunchGameAsync(LaunchProfile profile, Version v
_gameProcess.OutputDataReceived += (s, e) => LogReceived?.Invoke(e.Data);
_gameProcess.BeginOutputReadLine();

await Task.Run(() => _gameProcess.WaitForInputIdle());
if (!_gameProcess.HasExited)
{
await Task.Run(() => _gameProcess.WaitForInputIdle());
}
}

return new LaunchResult { IsSuccessful = true };
return !_gameProcess.HasExited;
}

#endregion
Expand Down
11 changes: 8 additions & 3 deletions GBCLV3/Services/Launcher/VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,13 @@ private static Version Load(string json)

if (args.Any(arg => arg.Contains("fml")))
{
// Invalid forge version
if (version.InheritsFrom == null) return null;
if (version.InheritsFrom == null)
{
// For 1.7.2 and earlier forge version, there's no 'inheritsFrom' property
// So it needs to be assigned in order to launch correctly
version.InheritsFrom = version.ID.Split('-')[0];
}

string[] idNums = version.InheritsFrom.Split('.');
version.Type = (int.Parse(idNums[1]) >= 13) ? VersionType.NewForge : VersionType.Forge;
}
Expand Down Expand Up @@ -438,7 +443,7 @@ private void InheritParentProperties(Version version)
}
}

version.Libraries = parent.Libraries.Union(version.Libraries).ToList();
version.Libraries = version.Libraries.Union(parent.Libraries).ToList();
version.AssetsInfo = parent.AssetsInfo;
version.Size = parent.Size;
version.SHA1 = parent.SHA1;
Expand Down
53 changes: 48 additions & 5 deletions GBCLV3/Services/ThemeService.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GBCLV3.Models;
using GBCLV3.Utils;
using Stylet;
using StyletIoC;

namespace GBCLV3.Services
{
class ThemeService : PropertyChangedBase
{
#region Properties
#region Binding Properties

public BitmapImage BackgroundImage { get; private set; }

public StreamGeometry BackgroundIcon { get; private set; }

public string FontFamily
{
get => _config.FontFamily;
Expand All @@ -33,7 +38,15 @@ public string FontWeight

#region Private Members

private const string ICONS_SOURCE = "/GBCL;component/Resources/Styles/Icons.xaml";
private const string DEFAULT_BACKGROUND_IMAGE = "pack://application:,,,/Resources/Images/default_background.png";

private static readonly Color REF_COLOR_SPIKE = Color.FromRgb(15, 105, 200);
private static readonly Color REF_COLOR_BULLZEYE = Color.FromRgb(115, 25, 10);
private static readonly Color REF_COLOR_TBONE = Color.FromRgb(165, 125, 10);
private static readonly Color REF_COLOR_STEGZ = Color.FromRgb(105, 175, 5);
private const float COLOR_L2_THRESHOLD = 0.0075f;

private readonly Config _config;

#endregion
Expand Down Expand Up @@ -96,10 +109,6 @@ public void UpdateBackgroundImage()
BackgroundImage.Freeze();
}

#endregion

#region Public Methods

public string[] GetSystemFontNames()
{
return Fonts.SystemFontFamilies.Select(fontFamily =>
Expand Down Expand Up @@ -137,6 +146,40 @@ public string[] GetFontWeights()
return fontWeights.Select(weight => weight.ToString()).ToArray();
}

public void LoadBackgroundIcon(Color accentColor)
{
ResourceDictionary iconsDict = null;
foreach (var dict in Application.Current.Resources.MergedDictionaries)
{
if (dict.Source?.ToString() == ICONS_SOURCE)
{
iconsDict = dict;
break;
}
}

if (ColorUtil.CalcL2Norm(accentColor, REF_COLOR_SPIKE) < COLOR_L2_THRESHOLD)
{
BackgroundIcon = iconsDict["Spike"] as StreamGeometry;
}
//else if (ColorUtil.CalcL2Norm(accentColor, REF_COLOR_BULLZEYE) < COLOR_L2_THRESHOLD)
//{
// BackgorundIcon = iconsDict["Bullzeye"] as StreamGeometry;
//}
//else if (ColorUtil.CalcL2Norm(accentColor, REF_COLOR_TBONE) < COLOR_L2_THRESHOLD)
//{
// BackgorundIcon = iconsDict["TBone"] as StreamGeometry;
//}
//else if (ColorUtil.CalcL2Norm(accentColor, REF_COLOR_STEGZ) < COLOR_L2_THRESHOLD)
//{
// BackgorundIcon = iconsDict["Stegz"] as StreamGeometry;
//}
else
{
BackgroundIcon = iconsDict["DragonIcon"] as StreamGeometry;
}
}

#endregion
}
}
9 changes: 9 additions & 0 deletions GBCLV3/Utils/ColorUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,14 @@ public static Color LuminanceGamma(Color color, double gamma)

return color;
}

public static float CalcL2Norm(Color a, Color b)
{
float dR = a.ScR - b.ScR;
float dG = a.ScG - b.ScG;
float dB = a.ScB - b.ScB;

return (dR * dR + dG * dG + dB * dB) / 3.0f;
}
}
}
Loading

0 comments on commit 9993ec9

Please sign in to comment.