Example #1
0
        private ResultSet GetMediaInfo(ManagerEngine man, Hashtable input)
        {
            ResultSet       rs = new ResultSet(new string[] { "name", "path", "url", "size", "type", "created", "modified", "width", "height", "attribs", "next", "prev", "custom" });
            BasicFileFilter fileFilter;
            IFile           file, parent;

            IFile[]       files;
            string        prev, next, attribs, url, ext;
            int           width, height;
            bool          match;
            Hashtable     customInfo = new Hashtable();
            ManagerConfig config;

            if (input["url"] != null)
            {
                input["path"] = man.ConvertURIToPath(new Uri((string)input["url"]).AbsolutePath);
            }

            file   = man.GetFile(man.DecryptPath((string)input["path"]));
            config = file.Config;
            parent = file.ParentFile;

            if (parent.IsDirectory)
            {
                // Setup file filter
                fileFilter = new BasicFileFilter();
                //fileFilter->setDebugMode(true);
                fileFilter.IncludeDirectoryPattern = config["filesystem.include_directory_pattern"];
                fileFilter.ExcludeDirectoryPattern = config["filesystem.exclude_directory_pattern"];
                fileFilter.IncludeFilePattern      = config["filesystem.include_file_pattern"];
                fileFilter.ExcludeFilePattern      = config["filesystem.exclude_file_pattern"];
                fileFilter.IncludeExtensions       = config["filesystem.extensions"];
                fileFilter.OnlyFiles = true;

                // List files
                files = parent.ListFilesFiltered(fileFilter);
            }
            else
            {
                throw new ManagerException("{#error.file_not_exists}");
            }

            match = false;
            prev  = "";
            next  = "";

            // Find next and prev
            foreach (IFile curFile in files)
            {
                if (curFile.AbsolutePath == file.AbsolutePath)
                {
                    match = true;
                    continue;
                }
                else if (!match)
                {
                    prev = curFile.AbsolutePath;
                }

                if (match)
                {
                    next = curFile.AbsolutePath;
                    break;
                }
            }

            ext = PathUtils.GetExtension(file.Name).ToLower();

            // Input default size?
            MediaInfo size = new MediaInfo(file.AbsolutePath);

            width  = size.Width != -1 ? size.Width : 425;
            height = size.Height != -1 ? size.Height : 350;

            // Get custom info
            man.DispatchEvent(EventType.CustomInfo, file, "info", customInfo);

            attribs = (file.CanRead && config.GetBool("filesystem.readable", true) ? "R" : "-") + (file.CanWrite && config.GetBool("filesystem.writable", true) ? "W" : "-");
            url     = PathUtils.RemoveTrailingSlash(config["preview.urlprefix"]) + man.ConvertPathToURI(file.AbsolutePath);
            rs.Add(file.Name,
                   man.EncryptPath(file.AbsolutePath),
                   url,
                   file.Length,
                   ext,
                   StringUtils.GetDate(file.CreationDate, config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")),
                   StringUtils.GetDate(file.LastModified, config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")),
                   width,
                   height,
                   attribs,
                   man.EncryptPath(next),
                   man.EncryptPath(prev),
                   customInfo);

            return(rs);
        }