mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-26 05:02:36 +01:00
Don't hang on startup due to bad "RecentFiles" - thx
beeeeswax/Geoff :) Fix #4249
This commit is contained in:
parent
d27bfd2b0d
commit
6983acaefa
@ -3485,22 +3485,19 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
var lowerFileNameList = new List<string>();
|
var lowerFileNameList = new List<string>();
|
||||||
foreach (var file in Configuration.Settings.RecentFiles.Files)
|
foreach (var file in Configuration.Settings.RecentFiles.Files)
|
||||||
{
|
{
|
||||||
if (File.Exists(file.FileName))
|
if (!string.IsNullOrEmpty(file.OriginalFileName) && File.Exists(file.OriginalFileName))
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(file.OriginalFileName) && File.Exists(file.OriginalFileName))
|
dropDownItems.Add(new ToolStripMenuItem(file.FileName + " + " + file.OriginalFileName, null, ReopenSubtitleToolStripMenuItemClick) { Tag = file.FileName });
|
||||||
{
|
|
||||||
dropDownItems.Add(new ToolStripMenuItem(file.FileName + " + " + file.OriginalFileName, null, ReopenSubtitleToolStripMenuItemClick));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!lowerFileNameList.Contains(file.FileName.ToLowerInvariant()))
|
|
||||||
{
|
|
||||||
dropDownItems.Add(new ToolStripMenuItem(file.FileName, null, ReopenSubtitleToolStripMenuItemClick));
|
|
||||||
lowerFileNameList.Add(file.FileName.ToLowerInvariant());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UiUtil.FixFonts(dropDownItems[dropDownItems.Count - 1]);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!lowerFileNameList.Contains(file.FileName.ToLowerInvariant()))
|
||||||
|
{
|
||||||
|
dropDownItems.Add(new ToolStripMenuItem(file.FileName, null, ReopenSubtitleToolStripMenuItemClick) { Tag = file.FileName });
|
||||||
|
lowerFileNameList.Add(file.FileName.ToLowerInvariant());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UiUtil.FixFonts(dropDownItems[dropDownItems.Count - 1]);
|
||||||
}
|
}
|
||||||
reopenToolStripMenuItem.DropDownItems.AddRange(dropDownItems.ToArray());
|
reopenToolStripMenuItem.DropDownItems.AddRange(dropDownItems.ToArray());
|
||||||
}
|
}
|
||||||
@ -3513,6 +3510,50 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
reopenToolStripMenuItem.Visible = reopenToolStripMenuItem.DropDownItems.Count > 0;
|
reopenToolStripMenuItem.Visible = reopenToolStripMenuItem.DropDownItems.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RemoveNotExistingFilesFromRecentFilesUI()
|
||||||
|
{
|
||||||
|
if (!Configuration.Settings.General.ShowRecentFiles || Configuration.Settings.RecentFiles.Files.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bw = new BackgroundWorker();
|
||||||
|
bw.DoWork += (sender, args) =>
|
||||||
|
{
|
||||||
|
var recentFilesList = (List<RecentFileEntry>)args.Argument;
|
||||||
|
var notExistingFiles = new List<string>();
|
||||||
|
foreach (var entry in recentFilesList)
|
||||||
|
{
|
||||||
|
if (!File.Exists(entry.FileName))
|
||||||
|
{
|
||||||
|
notExistingFiles.Add(entry.FileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
args.Result = notExistingFiles;
|
||||||
|
};
|
||||||
|
bw.RunWorkerCompleted += (sender, args) =>
|
||||||
|
{
|
||||||
|
var notExistingFiles = (List<string>)args.Result;
|
||||||
|
if (notExistingFiles.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration.Settings.RecentFiles.Files = Configuration.Settings.RecentFiles.Files
|
||||||
|
.Where(p => !notExistingFiles.Contains(p.FileName)).ToList();
|
||||||
|
for (var index = reopenToolStripMenuItem.DropDownItems.Count - 1; index >= 0; index--)
|
||||||
|
{
|
||||||
|
ToolStripItem item = reopenToolStripMenuItem.DropDownItems[index];
|
||||||
|
if (notExistingFiles.Contains((string)item.Tag))
|
||||||
|
{
|
||||||
|
reopenToolStripMenuItem.DropDownItems.RemoveAt(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
bw.RunWorkerAsync(Configuration.Settings.RecentFiles.Files);
|
||||||
|
}
|
||||||
|
|
||||||
private void ReopenSubtitleToolStripMenuItemClick(object sender, EventArgs e)
|
private void ReopenSubtitleToolStripMenuItemClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ReloadFromSourceView();
|
ReloadFromSourceView();
|
||||||
@ -20435,6 +20476,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
MainResize();
|
MainResize();
|
||||||
_loading = false;
|
_loading = false;
|
||||||
OpenVideo(_videoFileName);
|
OpenVideo(_videoFileName);
|
||||||
|
ShowSubtitleTimer.Stop();
|
||||||
lock (_syncUndo)
|
lock (_syncUndo)
|
||||||
{
|
{
|
||||||
timerTextUndo.Start();
|
timerTextUndo.Start();
|
||||||
@ -20539,17 +20581,19 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
UiUtil.FixFonts(comboBoxSubtitleFormats);
|
UiUtil.FixFonts(comboBoxSubtitleFormats);
|
||||||
UiUtil.FixFonts(comboBoxEncoding);
|
UiUtil.FixFonts(comboBoxEncoding);
|
||||||
UiUtil.FixFonts(toolStripSplitButtonPlayRate);
|
UiUtil.FixFonts(toolStripSplitButtonPlayRate);
|
||||||
_lastTextKeyDownTicks = DateTime.UtcNow.Ticks;
|
|
||||||
ShowSubtitleTimer.Start();
|
|
||||||
|
|
||||||
|
_lastTextKeyDownTicks = DateTime.UtcNow.Ticks;
|
||||||
if (_subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
|
if (_subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
|
||||||
{
|
{
|
||||||
var idx = _subtitleListViewIndex;
|
var idx = _subtitleListViewIndex;
|
||||||
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
|
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
|
||||||
SubtitleListview1.SelectIndexAndEnsureVisibleFaster(idx);
|
SubtitleListview1.SelectIndexAndEnsureVisibleFaster(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTitle();
|
SetTitle();
|
||||||
labelSingleLine.Left = labelTextLineLengths.Left + labelTextLineLengths.Width - 6;
|
labelSingleLine.Left = labelTextLineLengths.Left + labelTextLineLengths.Width - 6;
|
||||||
|
RemoveNotExistingFilesFromRecentFilesUI();
|
||||||
|
ShowSubtitleTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializePlayRateDropDown()
|
private void InitializePlayRateDropDown()
|
||||||
|
Loading…
Reference in New Issue
Block a user