Esempio n. 1
0
        public void LinkedFilesRootDirTests()
        {
            //test when LinkedFiles is in the project's root folder
            var projectFolder       = Path.Combine(FwDirectoryFinder.ProjectsDirectory, "TestProjectName");
            var linkedFilesFullPath = Path.Combine(projectFolder, "LinkedFiles");

            Cache.LanguageProject.LinkedFilesRootDir = linkedFilesFullPath;
            var outputLinkedFilesFullPath = Cache.LanguageProject.LinkedFilesRootDir;

            Assert.True(linkedFilesFullPath.Equals(outputLinkedFilesFullPath));

            //test when linked files is in FW Projects folder
            linkedFilesFullPath = Path.Combine(FwDirectoryFinder.ProjectsDirectory, "LinkedFiles");
            Cache.LanguageProject.LinkedFilesRootDir = linkedFilesFullPath;
            outputLinkedFilesFullPath = Cache.LanguageProject.LinkedFilesRootDir;
            Assert.True(linkedFilesFullPath.Equals(outputLinkedFilesFullPath));

            //test when linked files is in the CommonApplicationData shared folder
            linkedFilesFullPath = Path.Combine(DirectoryFinder.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "LinkedFiles");
            Cache.LanguageProject.LinkedFilesRootDir = linkedFilesFullPath;
            outputLinkedFilesFullPath = Cache.LanguageProject.LinkedFilesRootDir;
            Assert.True(linkedFilesFullPath.Equals(outputLinkedFilesFullPath));

            //test when the linked files is in the User's MyDocuments folder
            linkedFilesFullPath = Path.Combine(DirectoryFinder.GetFolderPath(Environment.SpecialFolder.MyDocuments), "LinkedFiles");
            Cache.LanguageProject.LinkedFilesRootDir = linkedFilesFullPath;
            outputLinkedFilesFullPath = Cache.LanguageProject.LinkedFilesRootDir;
            Assert.True(linkedFilesFullPath.Equals(outputLinkedFilesFullPath));

            //test when the linked files is in some other location and therefore is just stored as an absolute full path.
            linkedFilesFullPath = Path.Combine(DirectoryFinder.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "LinkedFiles");
            Cache.LanguageProject.LinkedFilesRootDir = linkedFilesFullPath;
            outputLinkedFilesFullPath = Cache.LanguageProject.LinkedFilesRootDir;
            Assert.True(linkedFilesFullPath.Equals(outputLinkedFilesFullPath));
        }
Esempio n. 2
0
        /// <summary>
        /// Return the fullPath for a project's LinkedFiles based on the relative path that was persisted.
        /// If no match on a relativePath match is made then return the relativePath passed in assuming it
        /// is actually a full path.
        /// </summary>
        /// <param name="projectsPath"></param>
        /// <param name="relativePath"></param>
        /// <param name="projectPath"></param>
        /// <returns></returns>
        public static String GetLinkedFilesFullPathFromRelativePath(string projectsPath, string relativePath, String projectPath)
        {
            String fullPath = null;

            fullPath = GetFullPathForRelativePath(relativePath, ksProjectRelPath, projectPath);

            if (String.IsNullOrEmpty(fullPath))
            {
                fullPath = GetFullPathForRelativePath(relativePath, ksProjectsRelPath,
                                                      projectsPath);
            }
            if (String.IsNullOrEmpty(fullPath))
            {
                fullPath = GetFullPathForRelativePath(relativePath, ksCommonAppDataRelPath,
                                                      DirectoryFinder.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
            }
            if (String.IsNullOrEmpty(fullPath))
            {
                fullPath = GetFullPathForRelativePath(relativePath, ksMyDocsRelPath,
                                                      DirectoryFinder.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            }
            if (String.IsNullOrEmpty(fullPath))
            {
                return(FixPathSlashesIfNeeded(relativePath));
            }
            return(FixPathSlashesIfNeeded(fullPath));
        }
 public void Windows()
 {
     Assert.AreEqual(
         Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
         DirectoryFinder.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
 }
 public void Linux()
 {
     Assert.AreEqual("/bla",
                     DirectoryFinder.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
 }
Esempio n. 5
0
        /// <summary>
        /// Get a relative path for the LinkedFilesPath which we will persist to be used when
        /// restoring a project.
        /// </summary>
        /// <param name="projectsPath"></param>
        /// <param name="linkedFilesFullPath"></param>
        /// <param name="projectPath"></param>
        /// <param name="projectName"></param>
        /// <returns></returns>
        public static string GetLinkedFilesRelativePathFromFullPath(string projectsPath, string linkedFilesFullPath,
                                                                    string projectPath, string projectName)
        {
            var linkedFilesPathLowercaseRoot = GetPathWithLowercaseRoot(linkedFilesFullPath);
            // Case where the ExternalLinks folder is located somewhere under the project folder.
            // This is the default location.
            var relativePath = GetRelativePathIfExists(ksProjectRelPath, linkedFilesPathLowercaseRoot,
                                                       projectPath);

            if (!string.IsNullOrEmpty(relativePath))
            {
                return(FixPathSlashesIfNeeded(relativePath));
            }
            // GetRelativePathIfExists may miss a case where, say, projectPath is
            // \\ls-thomson-0910.dallas.sil.org\Projects\MyProj, and linkedFilesFullPath is
            // C:\Documents and settings\All Users\SIL\FieldWorks\Projects\MyProj\LinkedFiles
            // Even though the MyProj directory in both paths is the same directory.
            // It's important to catch this case and return a relative path.
            var projectFolderName = Path.GetFileName(projectPath);
            var allProjectsName   = Path.GetFileName(Path.GetDirectoryName(projectPath));
            var match             = Path.Combine(allProjectsName, projectFolderName);
            int index             = linkedFilesFullPath.IndexOf(match, StringComparison.InvariantCultureIgnoreCase);

            if (index >= 0)
            {
                // There's a very good chance these are the same folders!
                var alternateProjectPath = linkedFilesFullPath.Substring(0, index + match.Length);
                if (Directory.Exists(alternateProjectPath) &&
                    Directory.GetLastWriteTime(alternateProjectPath) == Directory.GetLastWriteTime(projectPath))
                {
                    // They ARE the same directory! (I suppose we could miss if someone wrote to it at the
                    // exact wrong moment, but we shouldn't be changing this setting while shared, anyway.)
                    return(FixPathSlashesIfNeeded(ksProjectRelPath + linkedFilesFullPath.Substring(index + match.Length)));
                }
            }

            //See if linkedFilesPath begins with one of the other standard paths.

            // Case where user is presumably having a LinkedFiles folder shared among a number
            // of projects under the Projects folder. That would be a good reason to put it in
            // the projects folder common to all projects.
            relativePath = GetRelativePathIfExists(ksProjectsRelPath, linkedFilesPathLowercaseRoot, projectsPath);
            if (!String.IsNullOrEmpty(relativePath))
            {
                return(FixPathSlashesIfNeeded(relativePath));
            }

            // Case where the user has the LinkedFiles folder in a shared folder.
            relativePath = GetRelativePathIfExists(ksCommonAppDataRelPath,
                                                   linkedFilesPathLowercaseRoot, DirectoryFinder.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
            if (!string.IsNullOrEmpty(relativePath))
            {
                return(FixPathSlashesIfNeeded(relativePath));
            }

            // Case where the user has the LinkedFiles folder in their MyDocuments folder
            relativePath = GetRelativePathIfExists(ksMyDocsRelPath,
                                                   linkedFilesPathLowercaseRoot,
                                                   DirectoryFinder.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            if (!string.IsNullOrEmpty(relativePath))
            {
                return(FixPathSlashesIfNeeded(relativePath));
            }

            //Just return the complete path if we cannot find a relative path.
            return(FixPathSlashesIfNeeded(linkedFilesFullPath));
        }