private void Log(string s)
{
if (InvokeRequired) {
Invoke(new LogDelegate(Log), s);
return;
}
if (s.Contains("Saving ")) {
outputName = s;
int sIdx = s.IndexOf(" to ") + 4;
int endIdx = s.IndexOf(", quality");
if (endIdx == -1) endIdx = s.IndexOf(", compression");
if (endIdx == -1) return;
string file = s.Substring(sIdx, endIdx - sIdx);
rtbLog.AppendText(s.Substring(0, sIdx));
rtbLog.AppendText("file:///" + Uri.EscapeUriString(file));
rtbLog.AppendText(s.Substring(endIdx));
}
else {
rtbLog.Text += s + "\r\n";
}
rtbLog.SelectionStart = rtbLog.TextLength - 1;
rtbLog.SelectionLength = 1;
rtbLog.ScrollToCaret();
var progressEntry = _progressIndicators.FirstOrDefault(kvp => s.Contains(kvp.Value));
if (!progressEntry.Equals(default(KeyValuePair<int, string>))) {
if (s.Contains("Saving")) {
UpdateStatus("saving: " + progressEntry.Key + "%", progressEntry.Key);
}
else {
UpdateStatus("preparing: " + progressEntry.Key + "%", progressEntry.Key);
}
}
// tiles and objects is progress 27%-90%, program automatically
// determines ratios for tiles/objects
if (s.Contains("Drawing tiles") || s.Contains("Drawing objects")) {
int idx = s.LastIndexOf(" ") + 1;
double pct = Math.Round(27 + (90.0 - 27.0) * int.Parse(s.Substring(idx, s.Length - idx - 1)) / 100.0, 0);
UpdateStatus("rendering, " + pct + "%", (int)pct);
}
}