diff --git a/AngelLoader/CustomControls/RichTextBoxCustom.cs b/AngelLoader/CustomControls/RichTextBoxCustom.cs index 00588bf79..546f42231 100644 --- a/AngelLoader/CustomControls/RichTextBoxCustom.cs +++ b/AngelLoader/CustomControls/RichTextBoxCustom.cs @@ -320,12 +320,17 @@ private static string GLMLToRTF(string text) else if (tag == "NL") { lastTagWasLineBreak = true; - sb.Append(@"\line "); if (alignLeftOnNextLine) { - sb.Append(@"\ql "); + // For newest rtfbox on Win10, we need to use \par instead of \line or + // else the \ql doesn't take. This works on Win7 too. + sb.Append(@"\par\ql "); alignLeftOnNextLine = false; } + else + { + sb.Append(@"\line "); + } } else if (tag == "LINE") { diff --git a/AngelLoader/FMCache.cs b/AngelLoader/FMCache.cs index 9a20bd661..9730c4af0 100644 --- a/AngelLoader/FMCache.cs +++ b/AngelLoader/FMCache.cs @@ -44,36 +44,39 @@ internal static async Task GetCacheableData(FanMission fm, ProgressPa { if (!fm.InstalledDir.IsEmpty()) { - var fmCachePath = Path.Combine(Paths.FMsCache, fm.InstalledDir); - if (!fmCachePath.TrimEnd('\\').EqualsI(Paths.FMsCache.TrimEnd('\\')) && Directory.Exists(fmCachePath)) - { - try - { - foreach (var f in Directory.EnumerateFiles(fmCachePath, "*", - SearchOption.TopDirectoryOnly)) - { - File.Delete(f); - } - - foreach (var d in Directory.EnumerateDirectories(fmCachePath, "*", - SearchOption.TopDirectoryOnly)) - { - Directory.Delete(d, recursive: true); - } - } - catch (Exception ex) - { - Log("Exception enumerating files or directories in cache for " + fm.Archive + " / " + - fm.InstalledDir, ex); - } - } + ClearCacheDir(fm); } return new CacheData(); } return FMIsReallyInstalled(fm) - ? FMCache.GetCacheableDataInFMInstalledDir(fm) - : await FMCache.GetCacheableDataInFMCacheDir(fm, ProgressBox); + ? GetCacheableDataInFMInstalledDir(fm) + : await GetCacheableDataInFMCacheDir(fm, ProgressBox); + } + + private static void ClearCacheDir(FanMission fm) + { + var fmCachePath = Path.Combine(Paths.FMsCache, fm.InstalledDir); + if (!fmCachePath.TrimEnd('\\').EqualsI(Paths.FMsCache.TrimEnd('\\')) && Directory.Exists(fmCachePath)) + { + try + { + foreach (var f in Directory.EnumerateFiles(fmCachePath, "*", SearchOption.TopDirectoryOnly)) + { + File.Delete(f); + } + + foreach (var d in Directory.EnumerateDirectories(fmCachePath, "*", SearchOption.TopDirectoryOnly)) + { + Directory.Delete(d, recursive: true); + } + } + catch (Exception ex) + { + Log("Exception enumerating files or directories in cache for " + fm.Archive + " / " + + fm.InstalledDir, ex); + } + } } private static void RemoveEmptyFiles(List files) @@ -153,6 +156,7 @@ internal static async Task GetCacheableDataInFMCacheDir(FanMission fm } readmes.Clear(); + ClearCacheDir(fm); var fmArchivePath = FindFMArchive(fm); diff --git a/AngelLoader/Forms/MainForm.cs b/AngelLoader/Forms/MainForm.cs index b356d92ec..3b8eb52d3 100644 --- a/AngelLoader/Forms/MainForm.cs +++ b/AngelLoader/Forms/MainForm.cs @@ -2663,25 +2663,17 @@ private async Task DisplaySelectedFM(bool refreshReadme = false) #region Readme var readmeFiles = cacheData.Readmes; + readmeFiles.Sort(); if (!readmeFiles.ContainsI(fm.SelectedReadme)) fm.SelectedReadme = null; using (new DisableEvents(this)) ChooseReadmeComboBox.ClearFullItems(); - void FillAndSelectReadmeFromMulti(string readme) - { - using (new DisableEvents(this)) - { - ChooseReadmeComboBox.AddRangeFull(readmeFiles); - ChooseReadmeComboBox.SelectBackingIndexOf(readme); - } - } - if (!fm.SelectedReadme.IsEmpty()) { if (readmeFiles.Count > 1) { - FillAndSelectReadmeFromMulti(fm.SelectedReadme); + ReadmeCB_FillAndSelect(readmeFiles, fm.SelectedReadme); } else { @@ -2708,7 +2700,7 @@ void FillAndSelectReadmeFromMulti(string readme) if (!safeReadme.IsEmpty()) { fm.SelectedReadme = safeReadme; - FillAndSelectReadmeFromMulti(safeReadme); + ReadmeCB_FillAndSelect(readmeFiles, safeReadme); } else { @@ -2735,21 +2727,61 @@ void FillAndSelectReadmeFromMulti(string readme) ChooseReadmePanel.Hide(); + LoadReadme(fm); + + #endregion + } + + private void ReadmeCB_FillAndSelect(List readmeFiles, string readme) + { + using (new DisableEvents(this)) + { + ChooseReadmeComboBox.AddRangeFull(readmeFiles); + ChooseReadmeComboBox.SelectBackingIndexOf(readme); + } + } + + private void LoadReadme(FanMission fm) + { try { var (path, type) = Core.GetReadmeFileAndType(fm); - ReadmeLoad(path, type); + #region Debug + + // Tells me whether a readme got reloaded more than once, which should never be allowed to happen + // due to performance concerns. +#if !ReleasePublic + DebugLabel.Text = int.TryParse(DebugLabel.Text, out var result) ? (result + 1).ToString() : "1"; +#endif + + #endregion + + if (type == ReadmeType.HTML) + { + ViewHTMLReadmeButton.Show(); + ShowReadme(false); + // In case the cursor is over the scroll bar area + if (CursorOverReadmeArea()) ShowReadmeControls(true); + } + else + { + ShowReadme(true); + ViewHTMLReadmeButton.Hide(); + var fileType = type == ReadmeType.PlainText + ? RichTextBoxStreamType.PlainText + : RichTextBoxStreamType.RichText; + + ReadmeRichTextBox.LoadContent(path, fileType); + } } catch (Exception ex) { - Log(nameof(DisplaySelectedFM) + ": " + nameof(ReadmeLoad) + " failed.", ex); + Log(nameof(LoadReadme) + " failed.", ex); ViewHTMLReadmeButton.Hide(); ShowReadme(true); ReadmeRichTextBox.SetText(LText.ReadmeArea.UnableToLoadReadme); } - - #endregion } #region Progress window @@ -3190,9 +3222,9 @@ private void AddTagMenuCustomItem_Click(object sender, EventArgs e) #region Choose readme - private async void ChooseReadmeButton_Click(object sender, EventArgs e) + private void ChooseReadmeButton_Click(object sender, EventArgs e) { - if (ChooseReadmeListBox.Items.Count == 0) return; + if (ChooseReadmeListBox.Items.Count == 0 || ChooseReadmeListBox.SelectedIndex == -1) return; var fm = GetSelectedFM(); fm.SelectedReadme = ChooseReadmeListBox.SelectedBackingItem(); @@ -3207,15 +3239,28 @@ private async void ChooseReadmeButton_Click(object sender, EventArgs e) ShowReadme(true); } - await RefreshSelectedFM(refreshReadme: true); + if (ChooseReadmeListBox.Items.Count > 1) + { + ReadmeCB_FillAndSelect(ChooseReadmeListBox.BackingItems, fm.SelectedReadme); + ShowReadmeControls(CursorOverReadmeArea()); + } + else + { + using (new DisableEvents(this)) ChooseReadmeComboBox.ClearFullItems(); + ChooseReadmeComboBox.Hide(); + } + + LoadReadme(fm); } - private async void ChooseReadmeComboBox_SelectedIndexChanged(object sender, EventArgs e) + private void ChooseReadmeComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (EventsDisabled) return; var fm = GetSelectedFM(); fm.SelectedReadme = ChooseReadmeComboBox.SelectedBackingItem(); - await RefreshSelectedFM(refreshReadme: true); + // Just load the readme; don't call DisplaySelectedFM() because that will re-get readmes and screw + // things up + LoadReadme(fm); } private void ChooseReadmeComboBox_DropDownClosed(object sender, EventArgs e) @@ -3233,39 +3278,6 @@ private void ChooseReadmeComboBox_DropDownClosed(object sender, EventArgs e) private void ResetZoomButton_Click(object sender, EventArgs e) => ReadmeRichTextBox.ResetZoomFactor(); - /// - /// - private void ReadmeLoad(string path, ReadmeType readmeType) - { - #region Debug - - // Tells me whether a readme got reloaded more than once, which should never be allowed to happen - // due to performance concerns. -#if !ReleasePublic - DebugLabel.Text = int.TryParse(DebugLabel.Text, out var result) ? (result + 1).ToString() : "1"; -#endif - - #endregion - - if (readmeType == ReadmeType.HTML) - { - ViewHTMLReadmeButton.Show(); - ShowReadme(false); - // In case the cursor is over the scroll bar area - if (CursorOverReadmeArea()) ShowReadmeControls(true); - } - else - { - ShowReadme(true); - ViewHTMLReadmeButton.Hide(); - var fileType = readmeType == ReadmeType.PlainText - ? RichTextBoxStreamType.PlainText - : RichTextBoxStreamType.RichText; - - ReadmeRichTextBox.LoadContent(path, fileType); - } - } - private void ShowReadme(bool enabled) { ReadmeRichTextBox.Visible = enabled;