Skip to content

Commit 680fb03

Browse files
author
Stewart Miles
committed
Fixed Version Handler obsolete files dialog on refresh.
In some cases an asset database refresh does not result in a reload of the app domain (e.g non-DLL files are changed) in which case the obsolete files dialog was not being displayed. This changes the Version Handler to cache whether obsolete files were found and an update should be performed when the asset database refresh is complete, at which point the obsolete files dialog is displayed prompting users to clean up old plugin components. Change-Id: I82796786615dbeb64d462dd5591c52c0b01e702f
1 parent c62736e commit 680fb03

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

source/VersionHandlerImpl/src/VersionHandlerImpl.cs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,9 @@ private string LibraryPrefix {
21542154
// Path of the file that indicates whether the asset database is currently being refreshed
21552155
// due to this module.
21562156
private const string REFRESH_PATH = "Temp/VersionHandlerImplRefresh";
2157+
// Path of the file that indicates whether files need to be cleaned up after an asset database
2158+
// refresh.
2159+
private const string CLEANUP_FILES_PENDING_PATH = "Temp/VersionHandlerImplCleanupFilesPending";
21572160

21582161
// Whether compilation is currently occuring.
21592162
private static bool compiling = false;
@@ -2231,6 +2234,26 @@ private static bool Refreshing {
22312234
}
22322235
}
22332236

2237+
/// <summary>
2238+
/// Whether files need to be cleaned up after an asset database refresh.
2239+
/// </summary>
2240+
private static bool CleanupFilesPending {
2241+
get {
2242+
return File.Exists(CLEANUP_FILES_PENDING_PATH);
2243+
}
2244+
2245+
set {
2246+
bool pending = CleanupFilesPending;
2247+
if (pending != value) {
2248+
if (value) {
2249+
File.WriteAllText(CLEANUP_FILES_PENDING_PATH, "Cleanup files after refresh");
2250+
} else {
2251+
File.Delete(CLEANUP_FILES_PENDING_PATH);
2252+
}
2253+
}
2254+
}
2255+
}
2256+
22342257
/// <summary>
22352258
/// Whether all editor DLLs have been loaded into the app domain.
22362259
/// </summary>
@@ -2289,7 +2312,16 @@ private static void NotifyWhenCompliationComplete(bool forceNotification) {
22892312
// If a refresh was initiated by this module, clear the refresh flag.
22902313
var wasRefreshing = Refreshing;
22912314
Refreshing = false;
2292-
if (wasRefreshing || forceNotification) NotifyUpdateCompleteMethods();
2315+
if (wasRefreshing || forceNotification) {
2316+
if (CleanupFilesPending) {
2317+
CleanupFilesPending = false;
2318+
RunOnMainThread.Run(() => {
2319+
UpdateVersionedAssetsOnMainThread(false, () => {},
2320+
setCleanupFilesPending: false);
2321+
}, runNow: false);
2322+
}
2323+
NotifyUpdateCompleteMethods();
2324+
}
22932325
return true;
22942326
});
22952327
}
@@ -2638,8 +2670,9 @@ public static void UpdateVersionedAssets(bool forceUpdate) {
26382670
/// <param name="complete">Called when this is method is complete.</param>
26392671
public static void UpdateVersionedAssets(bool forceUpdate, Action complete) {
26402672
CancelUpdateVersionedAssets();
2641-
RunOnMainThread.Run(() => { UpdateVersionedAssetsOnMainThread(forceUpdate, complete); },
2642-
runNow: false);
2673+
RunOnMainThread.Run(() => {
2674+
UpdateVersionedAssetsOnMainThread(forceUpdate, complete); },
2675+
runNow: false);
26432676
}
26442677

26452678
/// <summary>
@@ -2650,7 +2683,11 @@ public static void UpdateVersionedAssets(bool forceUpdate, Action complete) {
26502683
/// </summary>
26512684
/// <param name="forceUpdate">Whether to force an update.</param>
26522685
/// <param name="complete">Called when this is method is complete.</param>
2653-
private static void UpdateVersionedAssetsOnMainThread(bool forceUpdate, Action complete) {
2686+
/// <param name="setCleanupFilesPending">Whether to set the CleanupFilesPending flag to run
2687+
/// this method again after an asset database refresh is complete.</param>
2688+
private static void UpdateVersionedAssetsOnMainThread(bool forceUpdate,
2689+
Action complete,
2690+
bool setCleanupFilesPending = true) {
26542691
// If this module is disabled do nothing.
26552692
if (!forceUpdate && !Enabled) {
26562693
complete();
@@ -2709,7 +2746,8 @@ private static void UpdateVersionedAssetsOnMainThread(bool forceUpdate, Action c
27092746
}
27102747
}
27112748

2712-
if (cleanupFiles.Count > 0 && !Refreshing) {
2749+
bool cleanupFilesPending = cleanupFiles.Count > 0;
2750+
if (cleanupFilesPending && !Refreshing) {
27132751
var window = MultiSelectWindow.CreateMultiSelectWindow(PLUGIN_NAME);
27142752
Action<string> logObsoleteFile = (filename) => {
27152753
Log("Leaving obsolete file: " + filename, verbose: true);
@@ -2749,6 +2787,7 @@ private static void UpdateVersionedAssetsOnMainThread(bool forceUpdate, Action c
27492787
window.OnCancel = leaveFiles;
27502788
window.Show();
27512789
} else {
2790+
if (cleanupFilesPending && setCleanupFilesPending) CleanupFilesPending = true;
27522791
complete();
27532792
}
27542793

0 commit comments

Comments
 (0)