コード例 #1
0
        // TOP LEVEL API

        public static MemoryStream GetFileIcon(string name, FileIconSize size)
        {
            Icon icon = FileIconUtils.IconFromExtension(name.GetAfter("."), size);

            using (icon) {
                using (var bmp = icon.ToBitmap()) {
                    MemoryStream ms = new MemoryStream();
                    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    ms.Seek(0, SeekOrigin.Begin);
                    return(ms);
                }
            }
        }
コード例 #2
0
ファイル: SchemeHandler.cs プロジェクト: themaoci/PortDiscrd
        //
        // Summary:
        //     Open the response stream. - To handle the request immediately set handleRequest
        //     to true and return true. - To decide at a later time set handleRequest to false,
        //     return true, and execute callback to continue or cancel the request. - To cancel
        //     the request immediately set handleRequest to true and return false. This method
        //     will be called in sequence but not from a dedicated thread. For backwards compatibility
        //     set handleRequest to false and return false and the CefSharp.IResourceHandler.ProcessRequest(CefSharp.IRequest,CefSharp.ICallback)
        //     method will be called.
        //
        // Parameters:
        //   request:
        //     request
        //
        //   handleRequest:
        //     see main summary
        //
        //   callback:
        //     callback
        //
        // Returns:
        //     see main summary
        public bool Open(IRequest request, out bool handleRequest, ICallback callback)
        {
            Console.WriteLine("Open >> " + request.Url);

            uri      = new Uri(request.Url);
            fileName = uri.AbsolutePath;

            // if url is blocked

            /*if (...request.Url....) {
             *
             *      // cancel the request - set handleRequest to true and return false
             *      handleRequest = true;
             *      return false;
             * }*/

            // if url is browser file
            if (uri.Host == "storage")
            {
                fileName = appPath + uri.Host + fileName;
                Console.WriteLine(File.Exists(fileName) + " - " + fileName);
                if (File.Exists(fileName))
                {
                    Task.Factory.StartNew(() => {
                        using (callback) {
                            FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                            mimeType           = ResourceHandler.GetMimeType(Path.GetExtension(fileName));
                            stream             = fStream;
                            callback.Continue();
                        }
                    });

                    // handle the request at a later time
                    handleRequest = false;
                    return(true);
                }
            }

            // if url is request for icon of another file
            if (uri.Host == "fileicon")
            {
                Task.Factory.StartNew(() => {
                    using (callback) {
                        stream   = FileIconUtils.GetFileIcon(fileName, FileIconSize.Large);
                        mimeType = ResourceHandler.GetMimeType(".png");
                        callback.Continue();
                    }
                });

                // handle the request at a later time
                handleRequest = false;
                return(true);
            }


            // by default reject
            callback.Dispose();

            // cancel the request - set handleRequest to true and return false
            handleRequest = true;
            return(false);
        }