private static void CheckMultimediaRecord(GDMMultimediaRecord mmRec, GEDCOMFormat format, int fileVer) { for (int i = 0; i < mmRec.FileReferences.Count; i++) { GDMFileReferenceWithTitle fileRef = mmRec.FileReferences[i]; GDMMultimediaFormat mmFormat = fileRef.MultimediaFormat; if (mmFormat == GDMMultimediaFormat.mfUnknown || mmFormat == GDMMultimediaFormat.mfNone) { // tag 'FORM' can be corrupted or GEDCOMCore in past not recognize format attempt recovery fileRef.MultimediaFormat = GDMFileReference.RecognizeFormat(fileRef.StringValue); } if (format == GEDCOMFormat.gf_Native && fileVer == 39) { // the transition to normalized names after GKv39 // only for not direct references AND not relative references (platform specific paths) var mediaStore = GKUtils.GetStoreType(fileRef); if (mediaStore.StoreType != MediaStoreType.mstReference && mediaStore.StoreType != MediaStoreType.mstRelativeReference) { fileRef.StringValue = FileHelper.NormalizeFilename(fileRef.StringValue); } } } }
private void SetFileRef(string fileName) { Text = fileName; Control ctl = null; fImageCtl = null; GDMMultimediaFormat fmt = GDMFileReference.RecognizeFormat(fileName); try { switch (fmt) { case GDMMultimediaFormat.mfBMP: case GDMMultimediaFormat.mfGIF: case GDMMultimediaFormat.mfJPG: case GDMMultimediaFormat.mfPCX: case GDMMultimediaFormat.mfTIF: case GDMMultimediaFormat.mfTGA: case GDMMultimediaFormat.mfPNG: { fImageCtl = new ImageView(); try { using (Stream fs = new FileStream(fileName, FileMode.Open)) { fImageCtl.OpenImage(new Bitmap(fs)); } } catch (Exception ex) { Logger.LogWrite("ImageViewerWin.SetFileRef.0(): " + ex.Message); } ctl = fImageCtl; } break; case GDMMultimediaFormat.mfWAV: case GDMMultimediaFormat.mfAVI: case GDMMultimediaFormat.mfMPG: break; case GDMMultimediaFormat.mfTXT: { TextBox txtBox = new TextBox(); txtBox.Multiline = true; txtBox.ReadOnly = true; txtBox.ScrollBars = ScrollBars.Both; try { using (Stream fs = new FileStream(fileName, FileMode.Open)) { using (StreamReader strd = new StreamReader(fs, Encoding.GetEncoding(1251))) { txtBox.Text = strd.ReadToEnd(); } } } catch (Exception ex) { Logger.LogWrite("ImageViewerWin.SetFileRef.1(): " + ex.Message); } ctl = txtBox; } break; case GDMMultimediaFormat.mfRTF: { RichTextBox rtfBox = new RichTextBox(); rtfBox.ReadOnly = true; try { using (Stream fs = new FileStream(fileName, FileMode.Open)) { using (StreamReader strd = new StreamReader(fs)) { rtfBox.Text = strd.ReadToEnd(); } } } catch (Exception ex) { Logger.LogWrite("ImageViewerWin.SetFileRef.2(): " + ex.Message); } ctl = rtfBox; } break; case GDMMultimediaFormat.mfHTM: { var browser = new WebBrowser(); try { using (Stream fs = new FileStream(fileName, FileMode.Open)) { browser.DocumentStream = fs; } } catch (Exception ex) { Logger.LogWrite("ImageViewerWin.SetFileRef.2(): " + ex.Message); } ctl = browser; } break; } if (ctl != null) { SuspendLayout(); ctl.Dock = DockStyle.Fill; ctl.Location = new Point(0, 50); ctl.Size = new Size(100, 100); Controls.Add(ctl); Controls.SetChildIndex(ctl, 0); ResumeLayout(false); PerformLayout(); } } catch (Exception ex) { if (ctl != null) { ctl.Dispose(); } Logger.LogWrite("ImageViewerWin.SetFileRef()" + ex.Message); } }