Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions EmoTracker.Data/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public bool FastToolTips
string mLastActivePackageVariant;
string mCommandLinePackage;
string mCommandLinePackageVariant;
bool mNoAsyncImages;

ObservableCollection<string> mPackageRepositories = new ObservableCollection<string>();

Expand Down Expand Up @@ -180,6 +181,17 @@ public string CommandLinePackageVariant
set { SetProperty(ref mCommandLinePackageVariant, value); }
}

/// <summary>
/// When true, disables async background image pre-caching and forces
/// synchronous image resolution on the UI thread (the pre-refactor
/// behavior). Set via the <c>--no-async-images</c> command-line flag.
/// </summary>
public bool NoAsyncImages
{
get { return mNoAsyncImages; }
set { SetProperty(ref mNoAsyncImages, value); }
}

public string TwitchChannelName
{
get { return mTwitchChannelName; }
Expand Down Expand Up @@ -317,6 +329,11 @@ private void LoadSettings()

}

if (String.Equals(cargs[n], "--no-async-images"))
{
NoAsyncImages = true;
}

}
}
catch
Expand Down
25 changes: 11 additions & 14 deletions EmoTracker.Data/ItemDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,26 @@ public bool IncrementalLoad(string path, IGamePackage package, bool bLegacy = fa
{
try
{
LocationDatabase.Instance.SuspendRefresh = true;

using (StreamReader reader = new StreamReader(package.Open(path)))
using (new LocationDatabase.SuspendRefreshScope())
{
JArray items = (JArray)JToken.ReadFrom(new JsonTextReader(reader));
foreach (JObject item in items)
using (StreamReader reader = new StreamReader(package.Open(path)))
{
ITrackableItem instance = ItemBase.CreateItem(item, package);
if (instance != null)
mItems.Add(instance);
JArray items = (JArray)JToken.ReadFrom(new JsonTextReader(reader));
foreach (JObject item in items)
{
ITrackableItem instance = ItemBase.CreateItem(item, package);
if (instance != null)
mItems.Add(instance);
}
}
}

bSuccess = true;
bSuccess = true;
}
}
catch (Exception e)
{
ScriptManager.Instance.OutputException(e);
}
finally
{
LocationDatabase.Instance.SuspendRefresh = false;
}
}

return bSuccess;
Expand Down
54 changes: 37 additions & 17 deletions EmoTracker.Data/LocationDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ public class LocationDatabase : ObservableSingleton<LocationDatabase>, ICodeProv
{
public class SuspendRefreshScope : IDisposable
{
bool mbSuspend;

public SuspendRefreshScope()
{
mbSuspend = LocationDatabase.Instance.SuspendRefresh;
LocationDatabase.Instance.SuspendRefresh = true;
LocationDatabase.Instance.PushSuspendRefresh();
}

public virtual void Dispose()
{
LocationDatabase.Instance.SuspendRefresh = mbSuspend;
LocationDatabase.Instance.PopSuspendRefresh();
}
}

Expand All @@ -39,13 +36,37 @@ public virtual void Dispose()

public bool SuspendRefresh
{
get { return mbSuspendRefresh; }
get { return mSuspendRefreshCount > 0; }
set
{
if (SetProperty(ref mbSuspendRefresh, value) && !mbSuspendRefresh)
{
RefeshAccessibility(bPendingOnly: true);
}
// Legacy compatibility: direct assignment is discouraged.
// Prefer SuspendRefreshScope for reentrant-safe scoping.
if (value)
PushSuspendRefresh();
else
PopSuspendRefresh();
}
}

internal void PushSuspendRefresh()
{
++mSuspendRefreshCount;
}

internal void PopSuspendRefresh()
{
if (mSuspendRefreshCount <= 0)
{
ScriptManager.Instance.OutputError("PopSuspendRefresh called with no matching Push — possible over-close bug");
System.Diagnostics.Debug.Fail("PopSuspendRefresh: underflow — more Pops than Pushes");
return;
}

--mSuspendRefreshCount;

if (mSuspendRefreshCount == 0)
{
RefeshAccessibility(bPendingOnly: true);
}
}

Expand Down Expand Up @@ -141,7 +162,7 @@ internal bool IncrementalLoad(string path, IGamePackage package, bool bLegacy =
{
try
{
mbSuspendRefresh = true;
PushSuspendRefresh();

using (Stream s = package.Open(path))
{
Expand Down Expand Up @@ -170,7 +191,7 @@ internal bool IncrementalLoad(string path, IGamePackage package, bool bLegacy =
}
finally
{
mbSuspendRefresh = false;
PopSuspendRefresh();
}

RefeshAccessibility();
Expand Down Expand Up @@ -279,13 +300,13 @@ public void UnpinLocation(Location location)
mPinnedLocations.Remove(location);
}

bool mbSuspendRefresh = false;
int mSuspendRefreshCount = 0;
bool mbInRefresh = false;
uint mPendingRefreshCount = 0;

internal void RefeshAccessibility(bool bPendingOnly = false)
{
if (!mbSuspendRefresh)
if (mSuspendRefreshCount == 0)
{
if (!bPendingOnly)
++mPendingRefreshCount;
Expand Down Expand Up @@ -595,10 +616,9 @@ internal void Save(JObject root)

internal bool Load(JObject root)
{
PushSuspendRefresh();
try
{
SuspendRefresh = true;

JObject locationDatabaseData = root.GetValue<JObject>("location_database");
if (locationDatabaseData == null)
return true;
Expand Down Expand Up @@ -665,7 +685,7 @@ internal bool Load(JObject root)
}
finally
{
SuspendRefresh = false;
PopSuspendRefresh();
}
}

Expand Down
Loading
Loading