Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: make pngs online.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Oct 22, 2023
1 parent b7b0568 commit 6457d92
Show file tree
Hide file tree
Showing 182 changed files with 31 additions and 22 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 0 additions & 1 deletion RotationSolver/RotationSolver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<ProjectReference Include="..\RotationSolver.Basic\RotationSolver.Basic.csproj" />
<ProjectReference Include="..\ECommons\ECommons\ECommons.csproj" />
<ProjectReference Include="..\XIVPainter\XIVPainter\XIVPainter.csproj" />
<EmbeddedResource Include="Logos\*.png" />

<Using Include="Dalamud.Game.ClientState.Objects.Types" />
<Using Include="RotationSolver.Basic" />
Expand Down
52 changes: 31 additions & 21 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,33 +294,44 @@ private void DrawSideBar()
}

private const int FRAME_COUNT = 180;
private static readonly SortedList<string, IDalamudTextureWrap> _textureWrapList = new(FRAME_COUNT);
private static readonly List<string> _downloadingList = new(FRAME_COUNT);
private static bool GetLocalImage(string name, out IDalamudTextureWrap texture)
{
var url = $"RotationSolver.Logos.{name}.png";
if (_textureWrapList.TryGetValue(name, out texture)) return texture != null;
var dir = $"{Svc.PluginInterface.ConfigDirectory.FullName}\\Images";

using var stream = typeof(RotationConfigWindow).Assembly.GetManifestResourceStream(url);
if (stream == null)
if(!Directory.Exists(dir)) Directory.CreateDirectory(dir);

var file = dir + $"\\{name}.png";


if (Directory.GetFiles(dir, "*.png").Length >= FRAME_COUNT || name == "Logo" && File.Exists(file))
{
Svc.Log.Warning($"Failed to load the pic: {url} when getting the stream from assembly.");
_textureWrapList[url] = null;
return false;
return IconSet.GetTexture(file, out texture);
}

using var memory = new MemoryStream();
stream.CopyTo(memory);
texture = Svc.PluginInterface.UiBuilder.LoadImage(memory.ToArray());
if(texture == null)
if (!File.Exists(file) && !_downloadingList.Contains(name))
{
Svc.Log.Warning($"Failed to load the pic: {url} when convert bytes to image.");
_textureWrapList[url] = null;
return false;
_downloadingList.Add(name);

Task.Run(async () =>
{
var url = $"https://raw.githubusercontent.com/{Service.USERNAME}/{Service.REPO}/main/Images/{name}.png";

using var client = new HttpClient();
var stream = await client.GetStreamAsync(url);

using var fs = new FileStream(file, FileMode.CreateNew);
await stream.CopyToAsync(fs);

_downloadingList.Remove(name);
});
}
_textureWrapList[url] = texture;
return true;

texture = null;
return false;
}



private void DrawHeader(float wholeWidth)
{
var size = MathF.Max(MathF.Min(wholeWidth, Scale * 128), Scale * MIN_COLUMN_WIDTH);
Expand All @@ -340,9 +351,8 @@ private void DrawHeader(float wholeWidth)

var frame = Environment.TickCount / 34 % FRAME_COUNT;
if (frame <= 0) frame += FRAME_COUNT;
if (Service.Config.GetValue(PluginConfigBool.DrawIconAnimation)
? GetLocalImage(frame.ToString("D4"), out var logo)
: IconSet.GetTexture($"https://raw.githubusercontent.com/{Service.USERNAME}/{Service.REPO}/main/Images/Logo.png", out logo))
if ( GetLocalImage(Service.Config.GetValue(PluginConfigBool.DrawIconAnimation)
? frame.ToString("D4") : "Logo", out var logo))
{
ImGui.SetCursorPos(cursor);
ImGui.Image(logo.ImGuiHandle, Vector2.One * size);
Expand Down

0 comments on commit 6457d92

Please sign in to comment.