Skip to content

Commit b9c5bc8

Browse files
committed
allow viewing of incomplete/partial objects returned from the object service
1 parent 3feea3b commit b9c5bc8

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

AvaGui/Models/ObjectEditorModel.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public bool TryLoadObject(FileSystemItem filesystemItem, out UiLocoFile? uiLocoF
179179

180180
if (!OnlineCache.TryGetValue(uniqueObjectId, out var locoObj))
181181
{
182-
Logger.Debug($"Didn't find object {filesystemItem.Name} with unique id {uniqueObjectId} in cache - downloading it");
182+
Logger.Debug($"Didn't find object {filesystemItem.Name} with unique id {uniqueObjectId} in cache - downloading it from {WebClient.BaseAddress}");
183183
locoObj = Task.Run(async () => await Client.GetObjectAsync(WebClient, uniqueObjectId, true)).Result;
184184

185185
if (locoObj == null)
@@ -194,32 +194,31 @@ public bool TryLoadObject(FileSystemItem filesystemItem, out UiLocoFile? uiLocoF
194194
}
195195
else if (locoObj.OriginalBytes == null || locoObj.OriginalBytes.Length == 0)
196196
{
197-
Logger.Error($"Unable to load object {filesystemItem.Name} with unique id {uniqueObjectId} from online - received no object data");
198-
return false;
197+
Logger.Warning($"Unable to load object {filesystemItem.Name} with unique id {uniqueObjectId} from online - received no DAT object data");
199198
}
200199

201-
Logger.Error($"Added object {filesystemItem.Name} with unique id {uniqueObjectId} to local cache");
200+
Logger.Info($"Added object {filesystemItem.Name} with unique id {uniqueObjectId} to local cache");
202201
OnlineCache.Add(uniqueObjectId, locoObj);
203202
}
204203
else
205204
{
206205
Logger.Debug($"Found object {filesystemItem.Name} with unique id {uniqueObjectId} in cache - reusing it");
207206
}
208207

209-
if (locoObj.OriginalBytes == null)
210-
{
211-
Logger.Error($"Received no data for {filesystemItem.Name}");
212-
return false;
213-
}
214-
var obj = SawyerStreamReader.LoadFullObjectFromStream(Convert.FromBase64String(locoObj.OriginalBytes), Logger, $"{filesystemItem.Filename}-{filesystemItem.Name}", true);
215-
if (obj == null)
208+
if (locoObj != null && locoObj.OriginalBytes?.Length > 0)
216209
{
217-
Logger.Error($"Unable to load {filesystemItem.Name} from the received data");
218-
return false;
210+
var obj = SawyerStreamReader.LoadFullObjectFromStream(Convert.FromBase64String(locoObj.OriginalBytes), Logger, $"{filesystemItem.Filename}-{filesystemItem.Name}", true);
211+
if (obj == null)
212+
{
213+
Logger.Warning($"Unable to load {filesystemItem.Name} from the received DAT object data");
214+
}
215+
else
216+
{
217+
fileInfo = obj?.DatFileInfo;
218+
locoObject = obj?.LocoObject;
219+
}
219220
}
220221

221-
fileInfo = obj.Value.DatFileInfo;
222-
locoObject = obj.Value.LocoObject;
223222
metadata = new MetadataModel(locoObj.OriginalName, locoObj.OriginalChecksum)
224223
{
225224
Description = locoObj.Description,
@@ -233,9 +232,12 @@ public bool TryLoadObject(FileSystemItem filesystemItem, out UiLocoFile? uiLocoF
233232
Licence = locoObj.Licence,
234233
};
235234

236-
foreach (var i in locoObject?.G1Elements)
235+
if (locoObject != null)
237236
{
238-
images.Add(PaletteMap.ConvertG1ToRgba32Bitmap(i));
237+
foreach (var i in locoObject.G1Elements)
238+
{
239+
images.Add(PaletteMap.ConvertG1ToRgba32Bitmap(i));
240+
}
239241
}
240242
}
241243
else
@@ -262,7 +264,7 @@ public bool TryLoadObject(FileSystemItem filesystemItem, out UiLocoFile? uiLocoF
262264
return false;
263265
}
264266

265-
if (locoObject == null || fileInfo == null)
267+
if (locoObject == null && fileInfo == null && metadata == null && images == null)
266268
{
267269
Logger.Error($"Unable to load {filesystemItem.Filename}");
268270
uiLocoFile = null;

0 commit comments

Comments
 (0)