Example #1
0
        private static string GetFullPathAndValidateCase(LanguageContext /*!*/ context, string path, bool isDir)
        {
#if !SILVERLIGHT
            // check for a match in the case of the filename, unfortunately we can't do this
            // in Silverlight becauase there's no way to get the original filename.

            PlatformAdaptationLayer pal = context.DomainManager.Platform;
            string dir = pal.GetDirectoryName(path);
            if (!pal.DirectoryExists(dir))
            {
                return(null);
            }

            try {
                string   file  = pal.GetFileName(path);
                string[] files = pal.GetFileSystemEntries(dir, file, !isDir, isDir);

                if (files.Length != 1 || pal.GetFileName(files[0]) != file)
                {
                    return(null);
                }

                return(pal.GetFullPath(files[0]));
            } catch (IOException) {
                return(null);
            }
#else
            return(path);
#endif
        }
        private static IEnumerable <string> /*!*/ GetAbsolutePaths(PlatformAdaptationLayer /*!*/ pal, string /*!*/ path)
        {
            if (pal.IsAbsolutePath(path))
            {
                yield return(path);
            }
            else
            {
                yield return(pal.GetFullPath(path));

                string var = pal.GetEnvironmentVariable("PATH");
                if (!String.IsNullOrEmpty(var))
                {
                    foreach (var prefix in var.Split(Path.PathSeparator))
                    {
                        if (prefix.Length > 0)
                        {
                            yield return(Path.Combine(prefix, path));
                        }
                    }
                }

                var = Environment.GetFolderPath(Environment.SpecialFolder.System);
                if (!String.IsNullOrEmpty(var))
                {
                    yield return(Path.Combine(var, path));
                }

                var = pal.GetEnvironmentVariable("SystemRoot");
                if (!String.IsNullOrEmpty(var))
                {
                    yield return(Path.Combine(var, path));
                }
            }
        }
Example #3
0
        private static string GetFullPathAndValidateCase(LanguageContext /*!*/ context, string path, bool isDir)
        {
            // Check for a match in the case of the filename.
            PlatformAdaptationLayer pal = context.DomainManager.Platform;
            string dir = pal.GetDirectoryName(path);

            if (!pal.DirectoryExists(dir))
            {
                return(null);
            }

            try {
                string   file  = pal.GetFileName(path);
                string[] files = pal.GetFileSystemEntries(dir, file, !isDir, isDir);

                if (files.Length != 1 || pal.GetFileName(files[0]) != file)
                {
                    return(null);
                }

                return(pal.GetFullPath(files[0]));
            } catch (IOException) {
                return(null);
            }
        }