private static void ScanAssetDatabase(ProgressBarEnum <RefreshSteps> mainProgress) { string[] allAssetPaths = AssetDatabase.GetAllAssetPaths(); Dictionary <Guid, FileEntry> fileLookup = Connection.Table <FileEntry>().ToDictionary(f => f.Guid); ProgressBarCounted scanProgress = new ProgressBarCounted(mainProgress.StartStep(RefreshSteps.ScanFiles), allAssetPaths.Length); for (int i = 0; i < allAssetPaths.Length; i++) { string path = allAssetPaths[i]; if (!IsValidFile(path)) { continue; } scanProgress.StartStep(i, "Scanning " + Path.GetFileNameWithoutExtension(path)); Guid fileGuid = new Guid(AssetDatabase.AssetPathToGUID(path)); fileLookup.Remove(fileGuid); UpdateAssetInGuidDatabase(path, fileGuid, false); } ProgressBarCounted deleteProgress = new ProgressBarCounted(mainProgress.StartStep(RefreshSteps.RemoveOldFiles), fileLookup.Count); int step = 0; foreach (FileEntry file in fileLookup.Values) { deleteProgress.StartStep(step, "Deleting " + file.DisplayPath); RemoveFileByGuid(file.Guid, file.Path); step++; } }
public static void Refresh() { Init(); Connection.DropTable <FileEntry>(); Connection.DropTable <UsageEntry>(); Debug.Log($"<color=#cc00ff>AssetUsages</color> : Refreshing DB. (Last Refresh: {s_LastScan})"); ProgressBarEnum <RefreshSteps> mainProgress = new ProgressBarEnum <RefreshSteps>("Refreshing Guid Reference Database", true); try { Connection.CreateTable <FileEntry>(); Connection.CreateTable <UsageEntry>(); Connection.CreateIndex(nameof(UsageEntry), "UserGuid"); Connection.CreateIndex(nameof(UsageEntry), "ResourceGuid"); } catch (DllNotFoundException) { s_Connection = null; Debug.LogError("<color=#cc00ff>AssetUsages</color> : DB refresh failed. SQLite DLL not found. Please restart Unity."); return; } mainProgress.StartStep(RefreshSteps.GatherFiles); DateTime startTime = DateTime.Now; Connection.BeginTransaction(); try { //ScanFilesManually(mainProgress); ScanAssetDatabase(mainProgress); } catch (ProgressBar.UserCancelledException) { Debug.LogWarning("Scan incomplete due to cancellation."); } Connection.Commit(); s_LastScan = startTime; EditorPrefs.SetString(kLastScanKey, s_LastScan.ToString(CultureInfo.InvariantCulture)); mainProgress.Done(); RaiseUpdated(); }