Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Commit 2a1d1f0

Browse files
author
Awbugl
committed
Update Code
1 parent 2309172 commit 2a1d1f0

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

Andreal.Core/Common/Path.cs

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ static Path()
7777

7878
private Path(string rawpath) { _rawpath = rawpath; }
7979

80-
public bool FileExists => File.Exists(this);
80+
private FileInfo? _fileInfo;
81+
82+
public FileInfo FileInfo => _fileInfo ??= new(this);
8183

8284
public static Path BotConfig(uint qqid) => new(AndreaConfigRoot + $"BotInfo/{qqid}.andreal.konata.botinfo");
8385

@@ -92,7 +94,16 @@ public static async Task<Path> ArcaeaSong(ArcaeaChart chart)
9294

9395
var pth = new Path($"{ArcaeaImageRoot}Song/{song}.jpg");
9496

95-
if (!pth.FileExists) await ArcaeaUnlimitedApi.SongAssets(chart.SongID, chart.RatingClass, pth);
97+
if (pth.FileInfo.Exists)
98+
{
99+
if (pth.FileInfo.Length > 10240)
100+
return pth;
101+
else
102+
pth.FileInfo.Delete();
103+
}
104+
105+
await ArcaeaUnlimitedApi.SongAssets(chart.SongID, chart.RatingClass, pth);
106+
96107
return pth;
97108
}
98109

@@ -129,21 +140,50 @@ public static async Task<Path> ArcaeaPartner(int partner, bool awakened)
129140
{
130141
var pth = new Path(ArcaeaImageRoot + $"Char/{partner}{(awakened ? "u" : "")}.png");
131142

132-
if (!pth.FileExists) await ArcaeaUnlimitedApi.CharAssets(partner, awakened, pth);
143+
if (pth.FileInfo.Exists)
144+
{
145+
if (pth.FileInfo.Length > 10240)
146+
return pth;
147+
else
148+
pth.FileInfo.Delete();
149+
}
150+
151+
await ArcaeaUnlimitedApi.CharAssets(partner, awakened, pth);
152+
133153
return pth;
134154
}
135155

136156
public static async Task<Path> ArcaeaPartnerIcon(int partner, bool awakened)
137157
{
138158
var pth = new Path(ArcaeaImageRoot + $"Icon/{partner}{(awakened ? "u" : "")}.png");
139-
if (!pth.FileExists) await ArcaeaUnlimitedApi.IconAssets(partner, awakened, pth);
159+
160+
if (pth.FileInfo.Exists)
161+
{
162+
if (pth.FileInfo.Length > 10240)
163+
return pth;
164+
else
165+
pth.FileInfo.Delete();
166+
}
167+
168+
await ArcaeaUnlimitedApi.IconAssets(partner, awakened, pth);
169+
140170
return pth;
141171
}
142172

143173
public static async Task<Path> ArcaeaChartPreview(ArcaeaChart chart)
144174
{
145175
var pth = new Path(ArcaeaImageRoot + $"Preview/{chart.SongID}_{chart.RatingClass}.jpg");
146-
if (!pth.FileExists) await ArcaeaUnlimitedApi.PreviewAssets(chart.SongID, chart.RatingClass, pth);
176+
177+
if (pth.FileInfo.Exists)
178+
{
179+
if (pth.FileInfo.Length > 10240)
180+
return pth;
181+
else
182+
pth.FileInfo.Delete();
183+
}
184+
185+
await ArcaeaUnlimitedApi.PreviewAssets(chart.SongID, chart.RatingClass, pth);
186+
147187
return pth;
148188
}
149189

Andreal.Core/Executor/PjskExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private MessageChain Chart()
213213
ImageMessage ChartImage(string songId, string dif)
214214
{
215215
var pth = Path.PjskChart(songId, dif);
216-
if (!pth.FileExists)
216+
if (!pth.FileInfo.Exists)
217217
Image.ImageExtend
218218
.PngWithWhiteBg(WebHelper.DownloadImage($"https://minio.dnaroma.eu/sekai-assets/music/charts/{songId.PadLeft(4, '0')}/{dif}.png"),
219219
pth);

Andreal.Core/Model/Pjsk/SongInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ internal static bool CheckFull(string songID) =>
6666
private ImageMessage SongImage()
6767
{
6868
var pth = Path.PjskSong(SongID);
69-
if (pth.FileExists) return ImageMessage.FromPath(pth);
69+
if (!pth.FileInfo.Exists) return ImageMessage.FromPath(pth);
7070

7171
var sid = SongID.PadLeft(3, '0');
7272
WebHelper.DownloadImage($"https://assets.pjsek.ai/file/pjsekai-assets/startapp/music/jacket/jacket_s_{sid}/jacket_s_{sid}.png",

Andreal.Core/UI/ImageGenerator/ArcBackgroundGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal class ArcBackgroundGenerator
1616
internal async Task<BackGround> ArcV1()
1717
{
1818
var path = Path.ArcaeaBackground(1, _info);
19-
return path.FileExists
19+
return path.FileInfo.Exists
2020
? new(path)
2121
: await GenerateArcV1(path);
2222
}
@@ -43,7 +43,7 @@ private async Task<BackGround> GenerateArcV1(Path path)
4343
internal async Task<BackGround> ArcV2()
4444
{
4545
var path = Path.ArcaeaBackground(2, _info);
46-
return path.FileExists
46+
return path.FileInfo.Exists
4747
? new(path)
4848
: await GenerateArcV2(path);
4949
}
@@ -74,7 +74,7 @@ private async Task<BackGround> GenerateArcV2(Path path)
7474
internal async Task<BackGround> ArcV3()
7575
{
7676
var path = Path.ArcaeaBackground(3, _info);
77-
return path.FileExists
77+
return path.FileInfo.Exists
7878
? new(path)
7979
: await GenerateArcV3(path);
8080
}

Andreal.Core/UI/ImageGenerator/PjskCurrentEventImageGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal async Task<ImageMessage> Generate()
5959
private BackGround PjskEvent()
6060
{
6161
var path = Path.PjskEvent(_currentEvent.AssetbundleName);
62-
return path.FileExists
62+
return path.FileInfo.Exists
6363
? new(path)
6464
: GeneratePjskEvent(path);
6565
}

0 commit comments

Comments
 (0)