コード例 #1
0
        void f_downloadResource(string[] fs, string ext = "")
        {
            List <string> ls = new List <string>();

            if (fs.Length > 0)
            {
                foreach (string url in fs)
                {
                    var uri      = new Uri(url);
                    var fileName = uri.AbsolutePath;

                    string file = fileName.Replace('/', '\\');
                    if (file[0] == '\\')
                    {
                        file = file.Substring(1);
                    }
                    file = Path.Combine(PATH_ROOT, file);

                    if (!File.Exists(file))
                    {
                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                        try
                        {
                            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                            if (response.StatusCode == HttpStatusCode.OK)
                            {
                                Stream       receiveStream = response.GetResponseStream();
                                StreamReader readStream    = new StreamReader(receiveStream, Encoding.UTF8);
                                string       data          = readStream.ReadToEnd();

                                File.WriteAllText(file, data);
                                STORE.cache_Write(fileName, data);

                                response.Close();
                                readStream.Close();

                                ls.Add(url);
                            }
                        }
                        catch { }
                    }
                }
            }
            MessageBox.Show("Download done [" + ext + "]: \r\n" + string.Join(Environment.NewLine, ls));
        }
コード例 #2
0
        static void Main()
        {
            string pathCache = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Cache");

            if (!Directory.Exists(pathCache))
            {
                Directory.CreateDirectory(pathCache);
            }
            if (!Directory.Exists("wcd"))
            {
                Directory.CreateDirectory("wcd");
            }

            CefSettings settings = new CefSettings()
            {
                CachePath = pathCache
            };

            //settings.RemoteDebuggingPort = 55555;
            settings.RegisterScheme(new CefCustomScheme
            {
                SchemeName           = "http",
                DomainName           = "192.168.56.102",
                SchemeHandlerFactory = new CefSharpSchemeHandlerFactory()
            });

            if (!Cef.Initialize(settings))
            {
                Console.WriteLine("Couldn't initialise CEF");
                return;
            }

            //CEF.RegisterScheme("test", new TestSchemeHandlerFactory());
            //CEF.RegisterJsObject("bound", new BoundObject());

            //Application.Run(new TabulationDemoForm());
            Application.Run(new fProxyBrowser());

            STORE.ClearAll();
            Cef.Shutdown();
        }
コード例 #3
0
        public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, IRequest request)
        {
            string url = request.Url;

            STORE.link_Add(url);

            if (request.Method == "POST")
            {
                return(null);
            }
            if (url.Contains("/api/") || url.Contains(".json") || url.Contains(".xml"))
            {
                return(null);
            }

            if (url.Contains(".html") || url.Contains(".css") || url.EndsWith(".js"))
            {
                var uri      = new Uri(url);
                var fileName = uri.AbsolutePath;

                //Debug.WriteLine("----> " + url);
                //if (url.Contains(".html") || url.Contains(".txt") || url.Contains(".js") || url.Contains(".css"))

                string resource;
                string file = fileName.Replace('/', '\\');
                if (file[0] == '\\')
                {
                    file = file.Substring(1);
                }
                file = Path.Combine(PATH_ROOT, file);

                if (File.Exists(file))
                {
                    resource = File.ReadAllText(file);
                    var fileExtension = Path.GetExtension(fileName);
                    return(ResourceHandler.FromString(resource, fileExtension));
                }
            }

            return(null);
        }
コード例 #4
0
        public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            // React to the first ID (show dev tools method)
            if (commandId == (CefMenuCommand)26501)
            {
                browser.GetHost().ShowDevTools();
                return(true);
            }

            // React to the second ID (show dev tools method)
            if (commandId == (CefMenuCommand)26502)
            {
                browser.GetHost().CloseDevTools();
                return(true);
            }

            if (commandId == (CefMenuCommand)26503)
            {
                browser.Reload();
                return(true);
            }

            //Show resources
            if (commandId == (CefMenuCommand)26504)
            {
                string s = STORE.link_getAll();
                File.WriteAllText("url.txt", s);
                Process.Start("url.txt");
                return(true);
            }

            //Write JS resources
            if (commandId == (CefMenuCommand)26505)
            {
                string[] fs = STORE.link_find(x => x.EndsWith(".js"));
                f_downloadResource(fs, "*.JS");
                return(true);
            }

            //Write CSS resources
            if (commandId == (CefMenuCommand)26506)
            {
                string[] fs = STORE.link_find(x => x.EndsWith(".css"));
                f_downloadResource(fs, "*.CSS");
                return(true);
            }

            //Write TXT resources
            if (commandId == (CefMenuCommand)26507)
            {
                string[] fs = STORE.link_find(x => x.EndsWith(".txt"));
                f_downloadResource(fs, "*.TXT");
                return(true);
            }

            //Write JSON resources
            if (commandId == (CefMenuCommand)26508)
            {
                string[] fs = STORE.link_find(x => x.EndsWith(".json"));
                f_downloadResource(fs, "*.JSON");
                return(true);
            }

            //Write HTML resources
            if (commandId == (CefMenuCommand)26509)
            {
                string[] fs = STORE.link_find(x => x.EndsWith(".html"));
                f_downloadResource(fs, "*.HTML");
                return(true);
            }

            //Write HTML resources
            if (commandId == (CefMenuCommand)26510)
            {
                string[] fs = STORE.link_find(x => x.EndsWith(".html"));
                f_downloadResource(fs, "*.HTML");

                fs = STORE.link_find(x => x.EndsWith(".json"));
                f_downloadResource(fs, "*.JSON");

                fs = STORE.link_find(x => x.EndsWith(".js"));
                f_downloadResource(fs, "*.JS");

                fs = STORE.link_find(x => x.EndsWith(".css"));
                f_downloadResource(fs, "*.CSS");

                fs = STORE.link_find(x => x.EndsWith(".txt"));
                f_downloadResource(fs, "*.TXT");

                return(true);
            }

            // Return false should ignore the selected option of the user !
            return(false);
        }