Skip to content

Commit

Permalink
Create local font folder on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
floh22 committed Aug 11, 2023
1 parent cb1ceb4 commit c375587
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 55 deletions.
4 changes: 2 additions & 2 deletions LeagueBroadcast.Common/LeagueBroadcast.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AssemblyVersion>1.6.3.0</AssemblyVersion>
<FileVersion>1.6.3.21326</FileVersion>
<AssemblyVersion>1.6.4.0</AssemblyVersion>
<FileVersion>1.6.4.21326</FileVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions LeagueBroadcast.Farsight/LeagueBroadcast.Farsight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<AssemblyVersion>1.6.3.0</AssemblyVersion>
<FileVersion>1.6.3.21326</FileVersion>
<AssemblyVersion>1.6.4.0</AssemblyVersion>
<FileVersion>1.6.4.21326</FileVersion>
<OutputType>Library</OutputType>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions LeagueBroadcast.Update/LeagueBroadcast.Update.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AssemblyVersion>1.6.3.0</AssemblyVersion>
<FileVersion>1.6.3.21326</FileVersion>
<AssemblyVersion>1.6.4.0</AssemblyVersion>
<FileVersion>1.6.4.21326</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
43 changes: 19 additions & 24 deletions LeagueBroadcast/Common/Controllers/ConfigController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

Expand Down Expand Up @@ -37,17 +36,18 @@ public ConfigController()
{
Log.Info("Starting Config Controller");

var controller = JSONConfigProvider.Instance;
JSONConfigProvider controller = JSONConfigProvider.Instance;

controller.ReadConfig(Component);
controller.ReadConfig(PickBan);
controller.ReadConfig(Ingame);

if(PickBan.FileVersion == null || Component.FileVersion == null || Ingame.FileVersion == null)
if (PickBan.FileVersion == null || Component.FileVersion == null || Ingame.FileVersion == null)
{
Log.Warn("Config load failed");
var result = MessageBox.Show("Failed to load configuration. Corrupted Install detected. Try removing Config folder and restarting", "LeagueBroadcast", MessageBoxButton.OK, MessageBoxImage.Error);
Application.Current.Dispatcher.Invoke((Action)delegate {
MessageBoxResult result = MessageBox.Show("Failed to load configuration. Corrupted Install detected. Try removing Config folder and restarting", "LeagueBroadcast", MessageBoxButton.OK, MessageBoxImage.Error);
Application.Current.Dispatcher.Invoke((Action)delegate
{
Application.Current.Shutdown();
});
}
Expand All @@ -56,30 +56,16 @@ public ConfigController()
PickBanWatcher = new("PickBan.json", PickBan);
ComponentWatcher = new("Component.json", Component);
IngameWatcher = new("Ingame.json", Ingame);

//TODO Somehow loading these fonts into a stylesheet
/*
Log.Info("Loading local fonts");
Directory.CreateDirectory(FontLocation);
new ObservableCollection<LocalFont>(Directory
.EnumerateFiles(FontLocation, "*", SearchOption.AllDirectories)
.Select(f => {
var fontLocation = $"/cache/Fonts/{Path.GetFileName(f)}";
var fontName = Path.GetFileNameWithoutExtension(f);
return new LocalFont();
}));
*/
App.Instance.Exit += OnClose;
}

public static void LoadOffsetConfig()
{
JSONConfigProvider.Instance.ReadConfig(Farsight);
if(Farsight.FileVersion == null || !FarsightController.ShouldRun )
if (Farsight.FileVersion == null || !FarsightController.ShouldRun)
{
Log.Warn("Could not load Offsets");
var result = MessageBox.Show("Failed to load offsets. Manually download or write Config/Farsight.json. Check github for current file version. Ingame will not work properly!", "LeagueBroadcast", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBoxResult result = MessageBox.Show("Failed to load offsets. Manually download or write Config/Farsight.json. Check github for current file version. Ingame will not work properly!", "LeagueBroadcast", MessageBoxButton.OK, MessageBoxImage.Error);

/*
Application.Current.Dispatcher.Invoke((Action)delegate {
Expand All @@ -94,7 +80,10 @@ public static void LoadOffsetConfig()
private static ConfigController GetInstance()
{
if (_instance == null)
{
_instance = new();
}

return _instance;
}

Expand All @@ -106,7 +95,7 @@ public static void UpdateConfigFile(JSONConfig config)
private void OnClose(object sender, EventArgs e)
{
Log.Info("Saving all configs to file");
var controller = JSONConfigProvider.Instance;
JSONConfigProvider controller = JSONConfigProvider.Instance;

try
{
Expand All @@ -120,7 +109,8 @@ private void OnClose(object sender, EventArgs e)
controller.WriteConfig(Ingame);

Log.Info("Configs saved");
} catch
}
catch
{
Log.Warn("Could not save all configs");
}
Expand Down Expand Up @@ -160,7 +150,10 @@ public void Stop()
public async void OnChanged(object sender, FileSystemEventArgs e)
{
if (waitingForRead)
{
return;
}

waitingForRead = true;

Log.Info($"{watcher.Filter} change detected");
Expand All @@ -184,7 +177,9 @@ public async void OnChanged(object sender, FileSystemEventArgs e)

}

protected void OnError(object sender, ErrorEventArgs e) =>
protected void OnError(object sender, ErrorEventArgs e)
{
Log.Warn("File Watch error:" + e.GetException());
}
}
}
69 changes: 46 additions & 23 deletions LeagueBroadcast/Common/Data/Provider/DataDragon.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using LeagueBroadcast.Common.Controllers;
using LeagueBroadcast.MVVM.Core;
using LeagueBroadcast.MVVM.ViewModel;
using LeagueBroadcast.Common.Controllers;
using LeagueBroadcast.Common.Data.DTO;
using LeagueBroadcast.Common.Data.RIOT;
using System.Threading;
using Swan.Logging;
using LeagueBroadcast.Common.Utils;
using LeagueBroadcast.MVVM.Core;
using LeagueBroadcast.MVVM.ViewModel;
using LeagueBroadcast.Update.Http;
using System.Text.Json;
using Swan.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Security.AccessControl;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

namespace LeagueBroadcast.Common.Data.Provider
{
Expand Down Expand Up @@ -50,10 +49,25 @@ class DataDragon : ObservableObject
private static TaskCompletionSource<bool>? _downloadComplete;

private static int _toDownload, _downloaded;
private static int IncrementToDownload() => Interlocked.Increment(ref _toDownload);
private static int IncrementToDownload(int count) => Interlocked.Add(ref _toDownload, count);
private static int IncrementDownloaded() => Interlocked.Increment(ref _downloaded);
private static int IncrementDownloaded(int count) => Interlocked.Add(ref _downloaded, count);
private static int IncrementToDownload()
{
return Interlocked.Increment(ref _toDownload);
}

private static int IncrementToDownload(int count)
{
return Interlocked.Add(ref _toDownload, count);
}

private static int IncrementDownloaded()
{
return Interlocked.Increment(ref _downloaded);
}

private static int IncrementDownloaded(int count)
{
return Interlocked.Add(ref _downloaded, count);
}

public static EventHandler FinishLoading, StartLoading;
public static EventHandler<FileLoadProgressEventArgs>? FileDownloadComplete { get; set; }
Expand Down Expand Up @@ -141,15 +155,15 @@ private static async Task GetLatestGameVersion()
GetInstance()._startupContext.Status = "Retrieving latest patch info";
Log.Info("[CDrag] Retrieving latest patch info");

string? rawCDragVersionResponse = JsonDocument.Parse(await RestRequester.GetRaw($"{ConfigController.Component.DataDragon.CDragonRaw}/latest/content-metadata.json")??"").RootElement.GetProperty("version").GetString();
string? rawCDragVersionResponse = JsonDocument.Parse(await RestRequester.GetRaw($"{ConfigController.Component.DataDragon.CDragonRaw}/latest/content-metadata.json") ?? "").RootElement.GetProperty("version").GetString();
if (rawCDragVersionResponse is null)
{
Log.Warn($"[CDrag] {$"{ConfigController.Component.DataDragon.CDragonRaw}/latest/content-metadata.json"} unreachable. Is your internet connection working?");
Log.Warn($"[CDrag] Could not get latest CDragon version. Falling back to latest DDrag version");
using JsonDocument response = JsonDocument.Parse(await RestRequester.GetRaw($"https://ddragon.leagueoflegends.com/realms/{ConfigController.Component.DataDragon.Region}.json")??"", new JsonDocumentOptions { AllowTrailingCommas = true, CommentHandling = JsonCommentHandling.Skip });
using JsonDocument response = JsonDocument.Parse(await RestRequester.GetRaw($"https://ddragon.leagueoflegends.com/realms/{ConfigController.Component.DataDragon.Region}.json") ?? "", new JsonDocumentOptions { AllowTrailingCommas = true, CommentHandling = JsonCommentHandling.Skip });
rawCDragVersionResponse = response.RootElement.GetProperty("n").GetProperty("champion").ToString();

if(rawCDragVersionResponse is null)
if (rawCDragVersionResponse is null)
{
Log.Warn($"[CDrag] DDrag not reachable. Assuming internet connection issues. Cannot retrieve data");
return;
Expand Down Expand Up @@ -186,7 +200,7 @@ private static StringVersion GetLatestLocalPatch()
private static async Task Init()
{
string locale = ConfigController.Component.DataDragon.Locale;
if(locale.Equals("en_US", StringComparison.OrdinalIgnoreCase))
if (locale.Equals("en_US", StringComparison.OrdinalIgnoreCase))
{
locale = "en_gb";
}
Expand All @@ -204,7 +218,7 @@ private static async Task Init()

bool result = await VerifyLocalCache(version.localVersion);

if(!result)
if (!result)
{
Log.Warn("[CDrag] Some downloads failed. Not all assets may be available");
}
Expand All @@ -225,12 +239,18 @@ private static async Task<bool> VerifyLocalCache(StringVersion currentPatch)
string item = patchFolder + "/item";
string spell = patchFolder + "/spell";

//TODO Hack font folder into here since its simplest
string font = cache + "/Fonts";

_ = Directory.CreateDirectory(cache);
_ = Directory.CreateDirectory(patchFolder);
_ = Directory.CreateDirectory(font);
_ = Directory.CreateDirectory(champ);
_ = Directory.CreateDirectory(item);
_ = Directory.CreateDirectory(spell);



GetInstance()._startupContext.Status = "Yeeting old caches onto Dominion";
Directory.EnumerateDirectories(cache).Where(d => StringVersion.TryParse(d.Split("/")[^1].Split("\\")[^1], out StringVersion? dirVersion) && dirVersion < currentPatch).ToList().ForEach(dir =>
{
Expand Down Expand Up @@ -414,9 +434,12 @@ public static void ExtendItemLocal(CDragonItem item, StringVersion version)

public Champion GetChampionById(int champID)
{
var champData = CDragonChampion.All.SingleOrDefault(c => c.ID == champID);
CDragonChampion champData = CDragonChampion.All.SingleOrDefault(c => c.ID == champID);
if (champData is null)
{
return new Champion();
}

return new Champion()
{
id = champData.Alias,
Expand All @@ -436,7 +459,7 @@ public SummonerSpell GetSummonerById(string summonerID)

public ItemData GetItemById(int itemID)
{
var itemData = CDragonItem.All.SingleOrDefault(i => i.ID == itemID);
CDragonItem itemData = CDragonItem.All.SingleOrDefault(i => i.ID == itemID);

return new ItemData(itemData.ID)
{
Expand Down
4 changes: 2 additions & 2 deletions LeagueBroadcast/LeagueBroadcast.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<RepositoryUrl>https://github.com/floh22/LeagueBroadcast</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageIcon>BE_icon.png</PackageIcon>
<AssemblyVersion>1.7.19.0</AssemblyVersion>
<FileVersion>1.7.19.0</FileVersion>
<AssemblyVersion>1.7.22.0</AssemblyVersion>
<FileVersion>1.7.22.0</FileVersion>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
Expand Down

0 comments on commit c375587

Please sign in to comment.