From baec6cb041399992774db2e57f2fb4ccdc210716 Mon Sep 17 00:00:00 2001 From: FenPhoenix Date: Tue, 30 Apr 2019 18:52:02 -0700 Subject: [PATCH] Just set row count to 0 when modifying FMsViewList --- AngelLoader/FindFMs.cs | 188 +++++++++++++++++----------------- AngelLoader/Forms/MainForm.cs | 37 +++---- 2 files changed, 110 insertions(+), 115 deletions(-) diff --git a/AngelLoader/FindFMs.cs b/AngelLoader/FindFMs.cs index 2f6dd0fe6..f6081624f 100644 --- a/AngelLoader/FindFMs.cs +++ b/AngelLoader/FindFMs.cs @@ -21,144 +21,144 @@ internal static void Find(List fmDataIniList, bool startup = false) // Make sure we don't lose anything when we re-find! if (!startup) Core.WriteFullFMDataIni(); - // We're modifying the data that FMsDGV pulls from when it redraws. This will at least prevent a - // selection changed event from firing while we do it, as that could be really bad potentially. - using (new DisableEvents((IEventDisabler)Core.View)) - { - // Init or reinit - must be deep-copied or changes propagate back because reference types - DeepCopyGlobalTags(PresetTags, GlobalTags); + // Do this every time we modify FMsViewList in realtime, to prevent FMsDGV from redrawing from the + // list when it's in an indeterminate state (which can cause a selection change (bad) and/or a visible + // change of the list (not really bad but unprofessional looking)) + Core.View.SetRowCount(0); + + // Init or reinit - must be deep-copied or changes propagate back because reference types + DeepCopyGlobalTags(PresetTags, GlobalTags); - #region Back up lists and read FM data file + #region Back up lists and read FM data file - // Copy FMs to backup lists before clearing, in case we can't read the ini file. We don't want to end - // up with a blank or incomplete list and then glibly save it out later. - var backupList = new List(); - foreach (var fm in fmDataIniList) backupList.Add(fm); + // Copy FMs to backup lists before clearing, in case we can't read the ini file. We don't want to end + // up with a blank or incomplete list and then glibly save it out later. + var backupList = new List(); + foreach (var fm in fmDataIniList) backupList.Add(fm); - var viewBackupList = new List(); - foreach (var fm in Core.FMsViewList) viewBackupList.Add(fm); + var viewBackupList = new List(); + foreach (var fm in Core.FMsViewList) viewBackupList.Add(fm); - fmDataIniList.Clear(); - Core.FMsViewList.Clear(); + fmDataIniList.Clear(); + Core.FMsViewList.Clear(); - var fmDataIniExists = File.Exists(Paths.FMDataIni); + var fmDataIniExists = File.Exists(Paths.FMDataIni); - if (fmDataIniExists) + if (fmDataIniExists) + { + try { - try + ReadFMDataIni(Paths.FMDataIni, fmDataIniList); + } + catch (Exception ex) + { + Log("Exception reading FM data ini", ex); + if (startup) { - ReadFMDataIni(Paths.FMDataIni, fmDataIniList); + MessageBox.Show("Exception reading FM data ini. Exiting. Please check " + Paths.LogFile, + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + Environment.Exit(1); } - catch (Exception ex) + else { - Log("Exception reading FM data ini", ex); - if (startup) - { - MessageBox.Show("Exception reading FM data ini. Exiting. Please check " + Paths.LogFile, - "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - Environment.Exit(1); - } - else - { - fmDataIniList.ClearAndAdd(backupList); - Core.FMsViewList.ClearAndAdd(viewBackupList); - return; - } + fmDataIniList.ClearAndAdd(backupList); + Core.FMsViewList.ClearAndAdd(viewBackupList); + return; } } + } - #endregion + #endregion - #region Get installed dirs from disk + #region Get installed dirs from disk - // Could check inside the folder for a .mis file to confirm it's really an FM folder, but that's - // horrendously expensive. Talking like eight seconds vs. < 4ms for the 1098 set. Weird. - var t1InstalledFMDirs = new List(); - var t2InstalledFMDirs = new List(); - var t3InstalledFMDirs = new List(); + // Could check inside the folder for a .mis file to confirm it's really an FM folder, but that's + // horrendously expensive. Talking like eight seconds vs. < 4ms for the 1098 set. Weird. + var t1InstalledFMDirs = new List(); + var t2InstalledFMDirs = new List(); + var t3InstalledFMDirs = new List(); - for (int i = 0; i < 3; i++) - { - var instFMDirs = i == 0 ? t1InstalledFMDirs : i == 1 ? t2InstalledFMDirs : t3InstalledFMDirs; - var instPath = i == 0 ? Config.T1FMInstallPath : i == 1 ? Config.T2FMInstallPath : Config.T3FMInstallPath; + for (int i = 0; i < 3; i++) + { + var instFMDirs = i == 0 ? t1InstalledFMDirs : i == 1 ? t2InstalledFMDirs : t3InstalledFMDirs; + var instPath = i == 0 ? Config.T1FMInstallPath : i == 1 ? Config.T2FMInstallPath : Config.T3FMInstallPath; - if (Directory.Exists(instPath)) + if (Directory.Exists(instPath)) + { + try { - try + foreach (var d in Directory.GetDirectories(instPath, "*", SearchOption.TopDirectoryOnly)) { - foreach (var d in Directory.GetDirectories(instPath, "*", SearchOption.TopDirectoryOnly)) - { - var dirName = d.GetTopmostDirName(); - if (!dirName.EqualsI(".fmsel.cache")) instFMDirs.Add(dirName); - } - } - catch (Exception ex) - { - Log("Exception getting directories in " + instPath, ex); + var dirName = d.GetTopmostDirName(); + if (!dirName.EqualsI(".fmsel.cache")) instFMDirs.Add(dirName); } } + catch (Exception ex) + { + Log("Exception getting directories in " + instPath, ex); + } } + } - #endregion + #endregion - #region Get archives from disk + #region Get archives from disk - var fmArchives = new List(); + var fmArchives = new List(); - foreach (var path in GetFMArchivePaths()) + foreach (var path in GetFMArchivePaths()) + { + try { - try + var files = Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly); + foreach (var f in files) { - var files = Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly); - foreach (var f in files) + if (!fmArchives.ContainsI(f.GetFileNameFast()) && f.ExtIsArchive() && !f.ContainsI(Paths.FMSelBak)) { - if (!fmArchives.ContainsI(f.GetFileNameFast()) && f.ExtIsArchive() && !f.ContainsI(Paths.FMSelBak)) - { - fmArchives.Add(f.GetFileNameFast()); - } + fmArchives.Add(f.GetFileNameFast()); } } - catch (Exception ex) - { - Log("Exception getting files in " + path, ex); - } } + catch (Exception ex) + { + Log("Exception getting files in " + path, ex); + } + } - #endregion + #endregion - #region Build FanMission objects from installed dirs + #region Build FanMission objects from installed dirs - var t1List = new List(); - var t2List = new List(); - var t3List = new List(); + var t1List = new List(); + var t2List = new List(); + var t3List = new List(); - for (int i = 0; i < 3; i++) - { - var instFMDirs = i == 0 ? t1InstalledFMDirs : i == 1 ? t2InstalledFMDirs : t3InstalledFMDirs; - var list = i == 0 ? t1List : i == 1 ? t2List : t3List; - var game = i == 0 ? Game.Thief1 : i == 1 ? Game.Thief2 : Game.Thief3; + for (int i = 0; i < 3; i++) + { + var instFMDirs = i == 0 ? t1InstalledFMDirs : i == 1 ? t2InstalledFMDirs : t3InstalledFMDirs; + var list = i == 0 ? t1List : i == 1 ? t2List : t3List; + var game = i == 0 ? Game.Thief1 : i == 1 ? Game.Thief2 : Game.Thief3; - foreach (var item in instFMDirs) - { - list.Add(new FanMission { InstalledDir = item, Game = game, Installed = true }); - } + foreach (var item in instFMDirs) + { + list.Add(new FanMission { InstalledDir = item, Game = game, Installed = true }); } + } - #endregion + #endregion - MergeNewArchiveFMs(fmArchives, fmDataIniList); + MergeNewArchiveFMs(fmArchives, fmDataIniList); - int instInitCount = fmDataIniList.Count; - if (t1List.Count > 0) MergeNewInstalledFMs(t1List, fmDataIniList, instInitCount); - if (t2List.Count > 0) MergeNewInstalledFMs(t2List, fmDataIniList, instInitCount); - if (t3List.Count > 0) MergeNewInstalledFMs(t3List, fmDataIniList, instInitCount); + int instInitCount = fmDataIniList.Count; + if (t1List.Count > 0) MergeNewInstalledFMs(t1List, fmDataIniList, instInitCount); + if (t2List.Count > 0) MergeNewInstalledFMs(t2List, fmDataIniList, instInitCount); + if (t3List.Count > 0) MergeNewInstalledFMs(t3List, fmDataIniList, instInitCount); - SetArchiveNames(fmArchives, fmDataIniList); + SetArchiveNames(fmArchives, fmDataIniList); - SetInstalledNames(fmDataIniList); + SetInstalledNames(fmDataIniList); - BuildViewList(fmArchives, fmDataIniList, t1InstalledFMDirs, t2InstalledFMDirs, t3InstalledFMDirs); - } + BuildViewList(fmArchives, fmDataIniList, t1InstalledFMDirs, t2InstalledFMDirs, t3InstalledFMDirs); } private static void SetArchiveNames(List fmArchives, List fmDataIniList) diff --git a/AngelLoader/Forms/MainForm.cs b/AngelLoader/Forms/MainForm.cs index e75b46092..609062c9b 100644 --- a/AngelLoader/Forms/MainForm.cs +++ b/AngelLoader/Forms/MainForm.cs @@ -3776,16 +3776,14 @@ private async void ImportFromDarkLoaderMenuItem_Click(object sender, EventArgs e return; } - // We're modifying the data that FMsDGV pulls from when it redraws. This will at least prevent a - // selection changed event from firing while we do it, as that could be really bad potentially. - using (new DisableEvents(this)) - { - bool success = await Core.ImportFromDarkLoader(iniFile, importFMData, importSaves); - //if (!success) return; - } + // Do this every time we modify FMsViewList in realtime, to prevent FMsDGV from redrawing from the + // list when it's in an indeterminate state (which can cause a selection change (bad) and/or a visible + // change of the list (not really bad but unprofessional looking)) + SetRowCount(0); - // Always do this, because if our selection changed without an event, we may be displaying the wrong - // data + bool success = await Core.ImportFromDarkLoader(iniFile, importFMData, importSaves); + + // Do this no matter what; because we set the row count to 0 the list MUST be refreshed await SortAndSetFilter(forceRefreshReadme: true, forceSuppressSelectionChangedEvent: true); } @@ -3808,26 +3806,23 @@ private async Task ImportFromNDLOrFMSel(ImportType importType) return; } - //int successCount = 0; + // Do this every time we modify FMsViewList in realtime, to prevent FMsDGV from redrawing from the + // list when it's in an indeterminate state (which can cause a selection change (bad) and/or a visible + // change of the list (not really bad but unprofessional looking)) + SetRowCount(0); + foreach (var file in iniFiles) { if (file.IsWhiteSpace()) continue; // We're modifying the data that FMsDGV pulls from when it redraws. This will at least prevent a // selection changed event from firing while we do it, as that could be really bad potentially. - using (new DisableEvents(this)) - { - bool success = await (importType == ImportType.FMSel - ? Core.ImportFromFMSel(file) - : Core.ImportFromNDL(file)); - //if (success) successCount++; - } + bool success = await (importType == ImportType.FMSel + ? Core.ImportFromFMSel(file) + : Core.ImportFromNDL(file)); } - //if (successCount == 0) return; - - // Always do this, because if our selection changed without an event, we may be displaying the wrong - // data + // Do this no matter what; because we set the row count to 0 the list MUST be refreshed await SortAndSetFilter(forceRefreshReadme: true, forceSuppressSelectionChangedEvent: true); }