Example #1
0
        public void CmFileFinder_NoPreExistingCmFile()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);

            using (DummyFileMaker maker = new DummyFileMaker("junk56.jpg", true))
            {
                ICmFile file = CmFile.FindOrCreateFile(folder, maker.Filename);
                Assert.IsNotNull(file, "null CmFile returned");
                Assert.IsNotNull(file.InternalPath, "Internal path not set correctly");
                Assert.IsTrue(file.AbsoluteInternalPath == file.InternalPath, "Files outside LangProject.ExtLinkRootDir are stored as absolute paths");
                m_internalFilesToDelete.Add(file.AbsoluteInternalPath);
                Assert.IsTrue(m_pict.PictureFileRAHvo != file.Hvo);
            }
        }
Example #2
0
        public void CmFileFinder_OrigFilesMatch()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);

            using (DummyFileMaker maker = new DummyFileMaker("garbage.jpg", true))
            {
                ICmFile fileOrig = new CmFile();
                folder.FilesOC.Add(fileOrig);
                fileOrig.InternalPath = maker.Filename;

                ICmFile file = CmFile.FindOrCreateFile(folder, maker.Filename);
                Assert.AreEqual(fileOrig, file);
            }
        }
Example #3
0
        public override void Display(IVwEnv vwenv, int hvo, int frag)
        {
            CheckDisposed();

            switch (frag)
            {
            case AudioVisualView.kfragPathname:
                // Display the filename.
                ILgWritingSystemFactory wsf =
                    m_cache.LanguageWritingSystemFactoryAccessor;
                vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
                                      (int)FwTextPropVar.ktpvDefault,
                                      (int)TptEditable.ktptNotEditable);
                ITsString tss;
                Debug.Assert(hvo != 0);
                Debug.Assert(m_cache != null);
                ICmFile file = CmFile.CreateFromDBObject(m_cache, hvo);
                Debug.Assert(file != null);
                string path;
                if (Path.IsPathRooted(file.InternalPath))
                {
                    path = file.InternalPath;
                }
                else
                {
                    path = Path.Combine(m_cache.LangProject.ExternalLinkRootDir,
                                        file.InternalPath);
                }
                tss = m_cache.MakeUserTss(path);
                vwenv.OpenParagraph();
                vwenv.AddString(tss);
                vwenv.CloseParagraph();
                break;

            default:
                throw new ArgumentException(
                          "Don't know what to do with the given frag.", "frag");
            }
        }
Example #4
0
        public void CmFileFinder_OrigFileMissing()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);
            string origFile = m_pict.PictureFileRA.AbsoluteInternalPath;

            try
            {
                File.Delete(origFile);
            }
            catch
            {
            }
            Assert.IsFalse(File.Exists(origFile),
                           "Test cannot proceed. Unable to delete Original file.");

            // Test
            ICmFile file = CmFile.FindOrCreateFile(folder, origFile);
        }
Example #5
0
        /// <summary>
        /// Handle launching of the media player.
        /// </summary>
        protected override void HandleChooser()
        {
            CmFile file = m_obj as CmFile;

            // Open the file with Media Player or whatever the user has set up.
            try
            {
                string sPathname = FileUtils.ActualFilePath(file.AbsoluteInternalPath);
                if (IsWavFile(sPathname))
                {
                    System.Media.SoundPlayer simpleSound = new System.Media.SoundPlayer(sPathname);
                    simpleSound.Play();
                }
                else
                {
                    System.Diagnostics.Process.Start(sPathname);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, DetailControlsStrings.ksNoPlayMedia);
            }
        }
Example #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initialize a new CmPicture by creating a copy of the file in the given folder and
        /// hooking everything up.
        /// </summary>
        /// <param name="srcFilename">The path to the original filename (an internal copy will
        /// be made in this method)</param>
        /// <param name="captionTss">The caption (in the given Writing System)</param>
        /// <param name="description">Illustration description in English. This is not
        /// published.</param>
        /// <param name="layoutPos">Indication of where in the column/page the picture is to be
        /// laid out.</param>
        /// <param name="scaleFactor">Integral percentage by which picture is grown or shrunk.</param>
        /// <param name="locationRangeType">Indicates the type of data contained in LocationMin
        /// and LocationMax.</param>
        /// <param name="locationMin">The minimum Scripture reference at which this picture can
        /// be laid out.</param>
        /// <param name="locationMax">The maximum Scripture reference at which this picture can
        /// be laid out.</param>
        /// <param name="copyright">Publishable information about the copyright that should
        /// appear on the copyright page of the publication.</param>
        /// <param name="sFolder">The name of the CmFolder where picture should be stored
        /// </param>
        /// <param name="ws">The WS of the caption and copyright</param>
        /// ------------------------------------------------------------------------------------
        public void InitializeNewPicture(string srcFilename, ITsString captionTss,
                                         string description, PictureLayoutPosition layoutPos, int scaleFactor,
                                         PictureLocationRangeType locationRangeType, int locationMin, int locationMax,
                                         string copyright, string sFolder, int ws)
        {
            // Set the caption first since creating the CmFile will throw if srcFilename is empty.
            if (captionTss != null)
            {
                Caption.SetAlternative(captionTss, ws);
            }
            // Locate CmFolder with given name or create it, if neccessary
            ICmFolder folder = CmFolder.FindOrCreateFolder(m_cache, (int)LangProject.LangProjectTags.kflidPictures, sFolder);

            PictureFileRA = CmFile.FindOrCreateFile(folder, srcFilename);
            int wsEn = Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en");

            if (!String.IsNullOrEmpty(description) && wsEn > 0)
            {
                Description.SetAlternative(description, wsEn);
            }
            LayoutPos         = layoutPos;
            ScaleFactor       = scaleFactor;
            LocationRangeType = locationRangeType;
            LocationMin       = locationMin;
            LocationMax       = locationMax;
            if (!string.IsNullOrEmpty(copyright))
            {
                string sExistingCopyright = PictureFileRA.Copyright.GetAlternative(ws).Text;
                if (sExistingCopyright != null && sExistingCopyright != copyright)
                {
                    Logger.WriteEvent("Could not update copyright for picture " +
                                      PictureFileRA.AbsoluteInternalPath + " to '" + copyright + "'");
                    return;
                }
                PictureFileRA.Copyright.SetAlternative(copyright, ws);
            }
        }
Example #7
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a ScrImportFileInfo from a CmFile owned by a BT source. This is
 /// used when populating the file list from the database.
 /// </summary>
 /// <param name="file">The CmFile</param>
 /// <param name="mappingList">Sorted list of mappings to which newly found mappings
 /// should (and will) be added</param>
 /// <param name="domain">The import domain to which this file belongs</param>
 /// <param name="icuLocale">The ICU locale of the source to which this file belongs
 /// (null for Scripture source)</param>
 /// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers
 /// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers
 /// must start on a new line, but Paratext considers all backslashes in the data to be
 /// SF markers.)</param>
 /// ------------------------------------------------------------------------------------
 public ScrImportFileInfo(CmFile file, ScrMappingList mappingList, ImportDomain domain,
                          string icuLocale, bool scanInlineBackslashMarkers) :
     this(file, mappingList, domain, icuLocale, 0, scanInlineBackslashMarkers)
 {
 }