예제 #1
0
        // Gets Far description for a FS item.
        internal static string Get(string path)
        {
            //! trim '\': FullName may have it after MoveTo() for directories
            path = path.TrimEnd('\\');
            string directory = Path.GetDirectoryName(path);

            lock (WeakCache)
            {
                // strong cache ASAP
                DescriptionMap cache = (DescriptionMap)WeakCache.Target;

                // description file, if any
                string descriptionFile = GetDescriptionFile(directory, out bool exists);
                if (!exists)
                {
                    return(string.Empty);
                }

                // update the cache
                if (cache == null || !string.Equals(directory, cache.Directory, StringComparison.OrdinalIgnoreCase) || File.GetLastWriteTime(descriptionFile) != cache.Timestamp)
                {
                    cache            = new DescriptionMap(directory, File.GetLastWriteTime(descriptionFile), Import(descriptionFile));
                    WeakCache.Target = cache;
                }

                // description from cache, if any
                return(cache.Map.TryGetValue(Path.GetFileName(path), out string value) ? value : string.Empty);
            }
        }
예제 #2
0
        // Gets Far description for a FS item.
        internal static string Get(string path)
        {
            //! trim '\': FullName may have it after MoveTo() for directories
            path = path.TrimEnd('\\');
            string directory = Path.GetDirectoryName(path);

            lock (WeakCache)
            {
                // strong cache ASAP
                DescriptionMap cache = (DescriptionMap)WeakCache.Target;

                // description file, if any
                bool exists;
                string descriptionFile = GetDescriptionFile(directory, out exists);
                if (!exists)
                    return string.Empty;

                // update the cache
                if (cache == null || !string.Equals(directory, cache.Directory, StringComparison.OrdinalIgnoreCase) || File.GetLastWriteTime(descriptionFile) != cache.Timestamp)
                {
                    cache = new DescriptionMap(directory, File.GetLastWriteTime(descriptionFile), Import(descriptionFile));
                    WeakCache.Target = cache;
                }

                // description from cache, if any
                string value;
                return cache.Map.TryGetValue(Path.GetFileName(path), out value) ? value : string.Empty;
            }
        }