Skip to content

Commit f39f382

Browse files
committed
handle cases where cannot connect to online service
1 parent 777fc6f commit f39f382

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

AvaGui/Models/ObjectEditorModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public class ObjectEditorModel
3232

3333
public ObjectIndex ObjectIndex { get; private set; }
3434

35-
public ObjectIndex ObjectIndexOnline { get; set; }
35+
public ObjectIndex? ObjectIndexOnline { get; set; }
3636

37-
public Dictionary<int, DtoLocoObject> OnlineCache { get; set; } = [];
37+
public Dictionary<int, DtoLocoObject> OnlineCache { get; } = [];
3838

3939
public PaletteMap PaletteMap { get; set; }
4040

@@ -58,7 +58,7 @@ public class ObjectEditorModel
5858

5959
public ObservableCollection<LogLine> LoggerObservableLogs = [];
6060

61-
public HttpClient WebClient { get; }
61+
public HttpClient? WebClient { get; }
6262

6363
public ObjectEditorModel()
6464
{
@@ -203,7 +203,7 @@ public bool TryLoadObject(FileSystemItem filesystemItem, out UiLocoFile? uiLocoF
203203
Logger.Info($"Unable to object {filesystemItem.Name} with unique id {uniqueObjectId} from online - requested object is a vanilla object and it is illegal to distribute copyright material");
204204
return false;
205205
}
206-
else if (locoObj.OriginalBytes == null || locoObj.OriginalBytes.Length == 0)
206+
else if (string.IsNullOrEmpty(locoObj.OriginalBytes))
207207
{
208208
Logger.Warning($"Unable to load object {filesystemItem.Name} with unique id {uniqueObjectId} from online - received no DAT object data");
209209
}
@@ -387,7 +387,7 @@ async Task LoadObjDirectoryAsyncCore(string directory, IProgress<float> progress
387387
exception = true;
388388
}
389389

390-
if (exception || ObjectIndex?.Objects == null || ObjectIndex.Objects.Any(x => string.IsNullOrEmpty(x.Filename) || (x is ObjectIndexEntry xx && string.IsNullOrEmpty(xx.ObjectName))) != false)
390+
if (exception || ObjectIndex?.Objects == null || ObjectIndex.Objects.Any(x => string.IsNullOrEmpty(x.Filename) || (x is ObjectIndexEntry xx && string.IsNullOrEmpty(xx.ObjectName))))
391391
{
392392
Logger.Warning("Index file format has changed or otherwise appears to be malformed - recreating now.");
393393
await RecreateIndex(directory, allFiles, progress);

AvaGui/ViewModels/FolderTreeViewModel.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class FolderTreeViewModel : ReactiveObject
5454
public ReactiveCommand<Unit, Task> RefreshDirectoryItems { get; }
5555

5656
[Reactive]
57-
public ObservableCollection<ObjectDisplayMode> DisplayModeItems { get; set; } = [.. Enum.GetValues<ObjectDisplayMode>()];
57+
public ObservableCollection<ObjectDisplayMode> DisplayModeItems { get; } = [.. Enum.GetValues<ObjectDisplayMode>()];
5858

5959
[Reactive]
6060
public int SelectedTabIndex { get; set; }
@@ -144,7 +144,6 @@ async Task ReloadDirectoryAsync(bool useExistingIndex)
144144
}
145145

146146
await Model.CheckForDatFilesNotOnServer();
147-
148147
}
149148

150149
async Task LoadObjDirectoryAsync(string directory, bool useExistingIndex)
@@ -171,7 +170,7 @@ async Task LoadOnlineDirectoryAsync(bool useExistingIndex)
171170
return;
172171
}
173172

174-
if (!useExistingIndex || Model.ObjectIndexOnline == null)
173+
if ((!useExistingIndex || Model.ObjectIndexOnline == null) && Model.WebClient != null)
175174
{
176175
Model.ObjectIndexOnline = new ObjectIndex()
177176
{
@@ -182,11 +181,14 @@ async Task LoadOnlineDirectoryAsync(bool useExistingIndex)
182181
};
183182
}
184183

185-
OnlineDirectoryItems = ConstructTreeView(
186-
Model.ObjectIndexOnline.Objects.Where(x => (int)x.ObjectType < Limits.kMaxObjectTypes),
187-
FilenameFilter,
188-
DisplayMode,
189-
FileLocation.Online);
184+
if (Model.ObjectIndexOnline != null)
185+
{
186+
OnlineDirectoryItems = ConstructTreeView(
187+
Model.ObjectIndexOnline.Objects.Where(x => (int)x.ObjectType < Limits.kMaxObjectTypes),
188+
FilenameFilter,
189+
DisplayMode,
190+
FileLocation.Online);
191+
}
190192
}
191193

192194
static List<FileSystemItemBase> ConstructTreeView(IEnumerable<ObjectIndexEntryBase> index, string filenameFilter, ObjectDisplayMode displayMode, FileLocation fileLocation)

Definitions/Web/Client.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static async Task<IEnumerable<DtoObjectIndexEntry>> GetObjectListAsync(Ht
4444
logger?.Error($"Received data but couldn't parse it: {response}");
4545
return default;
4646
}
47+
4748
return data;
4849
}
4950
catch (Exception ex)

0 commit comments

Comments
 (0)