When using mono, remove images from the help file. Mono blows up when reading the images for some reason.

This commit is contained in:
Tim Young 2017-06-14 13:53:39 -05:00
parent fc52fe3236
commit ab060f622d

View File

@ -10,6 +10,7 @@ using System.Windows.Forms;
using System.IO;
using System.Globalization;
using System.Resources;
using System.Text.RegularExpressions;
namespace EduNetworkBuilder
@ -81,21 +82,117 @@ namespace EduNetworkBuilder
}
if (WhatToShow == RTFWindowContents.help)
{
myRTF = Properties.Resources.Help;
myRTF = SafeRTF(Properties.Resources.Help);
rtbContent.Rtf = myRTF;
}
else if (WhatToShow == RTFWindowContents.about)
{
myRTF = Properties.Resources.about;
myRTF = SafeRTF(Properties.Resources.about);
rtbContent.Rtf = myRTF;
}
else if (WhatToShow == RTFWindowContents.release_notes)
{
myRTF = Properties.Resources.ReleaseNotes;
myRTF = SafeRTF(Properties.Resources.ReleaseNotes);
rtbContent.Rtf = myRTF;
}
}
/// <summary>
/// When running using Mono (on Linux) the RTF reader fails on some images.
/// </summary>
/// <param name="inRTF"></param>
/// <returns></returns>
public string SafeRTF(string inRTF)
{
string What = string.Copy(inRTF);
if (!NB.IsRunningOnMono()) return What;
string newWhat = "";
List<string> ToMatch = new List<string>();
ToMatch.Add(@"{\nonshppict");
ToMatch.Add(@"{\*\shppict");
ToMatch.Add(@"{\pict");
string MatchedSoFar = "";
int count = 0;
int posincompare = 0;
bool Foundit = false;
bool FoundPartMatch = false;
int posinfile = 0;
using (var ms = new MemoryStream())
{
var sw = new StreamWriter(ms);
foreach (char c in What)
{
posinfile++;
if (posinfile % 10000 == 0)
Console.WriteLine(" Place " + posinfile);
if (Foundit)
{
if (c == '{') count++;
if (c == '}') count--;
if (count == 0)
{
Foundit = false; //We have finished finding it.
posincompare = 0;//start from the beginning again
}
}
else
{
MatchedSoFar += c;
FoundPartMatch = false;
for(int i=0; i< ToMatch.Count; i++)
{
int howfar = MatchedSoFar.Length;
if (ToMatch[i].Length < howfar) howfar = ToMatch[i].Length;
if (MatchedSoFar.Equals(ToMatch[i].Substring(0,howfar)))
{
FoundPartMatch = true;
break;
}
}
if (FoundPartMatch)
{
posincompare++;
for (int i = 0; i < ToMatch.Count; i++)
{
if (ToMatch[i].Equals(MatchedSoFar))
Foundit = true;
}
if (Foundit)
{
posincompare = 0;
Foundit = true;
count = 1; //There is one { in the compare string
MatchedSoFar = "";//reset it
}
}
else
{
if (posincompare > 0)
{
//newWhat += picstart.Substring(0, posincompare);
sw.Write(MatchedSoFar); //What has matched up to this point
posincompare = 0;
}
else
{
//newWhat += c;
sw.Write(c);
}
MatchedSoFar = ""; //reset it
}
}
}
Console.WriteLine(" Place " + posinfile);
sw.Flush();
ms.Position = 0;
var sr = new StreamReader(ms);
newWhat = sr.ReadToEnd();
}
return newWhat;
}
public void JumpToSelection(string WhatToFind)
{
int indexToText = rtbContent.Find(WhatToFind);