Skip to content

Commit

Permalink
Just set row count to 0 when modifying FMsViewList
Browse files Browse the repository at this point in the history
  • Loading branch information
FenPhoenix committed May 1, 2019
1 parent 5138824 commit baec6cb
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 115 deletions.
188 changes: 94 additions & 94 deletions AngelLoader/FindFMs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,144 +21,144 @@ internal static void Find(List<FanMission> 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<FanMission>();
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<FanMission>();
foreach (var fm in fmDataIniList) backupList.Add(fm);

var viewBackupList = new List<FanMission>();
foreach (var fm in Core.FMsViewList) viewBackupList.Add(fm);
var viewBackupList = new List<FanMission>();
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<string>();
var t2InstalledFMDirs = new List<string>();
var t3InstalledFMDirs = new List<string>();
// 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<string>();
var t2InstalledFMDirs = new List<string>();
var t3InstalledFMDirs = new List<string>();

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<string>();
var fmArchives = new List<string>();

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<FanMission>();
var t2List = new List<FanMission>();
var t3List = new List<FanMission>();
var t1List = new List<FanMission>();
var t2List = new List<FanMission>();
var t3List = new List<FanMission>();

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<string> fmArchives, List<FanMission> fmDataIniList)
Expand Down
37 changes: 16 additions & 21 deletions AngelLoader/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit baec6cb

Please sign in to comment.