Exemple #1
0
            public uint Def_ReadFile(string filename, IntPtr buffer, uint BufferSize, ref uint NumberByteReadSuccess, long Offset, IntPtr info)
            {
                StringBuilder data  = new StringBuilder();
                VNode         Node  = new VNode(filename);
                string        query = "";

                byte[] file = null;

                Console.WriteLine("reading {0} {1} {2}", Node.isValid, Node.fileName, Node.curDir);
                if (Node.isValid && Node.param.TryGetValue("q", out query))
                {
                    #region This Is google Service
                    if (Node.fileName.StartsWith("google", StringComparison.CurrentCultureIgnoreCase))
                    {
                        Task <Google.Apis.Customsearch.v1.Data.Search> ret;
                        if (Node.param.ContainsKey("n"))
                        {
                            int    n    = 1;
                            string temp = "";
                            Node.param.TryGetValue("n", out temp);
                            int.TryParse(temp, out n);
                            ret = ServiceProvider.SearchGoogle(query, n);
                        }
                        else
                        {
                            ret = ServiceProvider.SearchGoogle(query, 1);
                        }
                        ret.Wait();
                        if (ret.Result.Items != null)
                        {
                            foreach (Google.Apis.Customsearch.v1.Data.Result s in ret.Result.Items)
                            {
                                data.AppendLine(s.Title);
                                data.AppendLine("----------------------------------------------------------------");
                                data.AppendLine(s.Snippet);
                                data.AppendLine(s.Link);
                                data.Append("\n");
                            }
                        }
                        Console.WriteLine(data.ToString());
                        file = System.Text.Encoding.ASCII.GetBytes(data.ToString());
                    }
                    #endregion
                }
                else if (Node.curDir == "ImagePass")
                {
                    if (!Node.fileExtention.EndsWith("inf", StringComparison.CurrentCultureIgnoreCase) && !Node.fileExtention.EndsWith("ini", StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (imageFiles.Any(name => name.StartsWith(Node.fileName)))
                        {
                            Console.WriteLine("Direct Read");
                            KalikoImage image = new KalikoImage(filepath + @"\" + imageFiles.Where(d => d.StartsWith(Node.fileName)).ToList()[0]);
                            Console.WriteLine("HEHFKHLDSKHFLSDHLKFHKD *()&*&(&**&(" + image.ByteArray.Length);
                            string width = "", height = "", OP = "", x = "", y = "";
                            System.IO.MemoryStream ms = new System.IO.MemoryStream();

                            Node.param.TryGetValue("op", out OP);
                            if (OP == "s" && Node.param.TryGetValue("w", out width) && Node.param.TryGetValue("h", out width))
                            {
                                int w = 0, h = 0;
                                if (int.TryParse(width, out w) && int.TryParse(width, out h))
                                {
                                    image.Scale(new FitScaling(w, h)).SavePng(ms);
                                }
                            }
                            if (OP == "c" && Node.param.TryGetValue("w", out width) && Node.param.TryGetValue("h", out width) && Node.param.TryGetValue("x", out x) && Node.param.TryGetValue("y", out y))
                            {
                                int w = 0, h = 0, X, Y;

                                if (int.TryParse(width, out w) && int.TryParse(width, out h) && int.TryParse(x, out X) && int.TryParse(y, out Y))
                                {
                                    image.Crop(X, Y, w, h);
                                }
                                image.SavePng(ms);
                            }

                            string ext = Node.fileExtention.ToLowerInvariant();


                            switch (ext)
                            {
                            case "png":
                                image.LoadImage(ms);
                                image.SavePng(ms);

                                break;

                            case "gif":
                                image.LoadImage(ms);
                                image.SaveGif(ms);
                                break;

                            case "bmp":
                                image.LoadImage(ms);
                                image.SaveBmp(ms);
                                break;

                            default:
                                image.LoadImage(ms);
                                image.SaveJpg(ms, 100);
                                break;
                            }
                            file = ms.ToArray();
                        }
                    }
                }


                if (file != null && file.Length != 0 && Offset < file.Length)
                {
                    if (BufferSize > file.Length - Offset)
                    {
                        NumberByteReadSuccess = (uint)(file.Length - Offset);
                        System.Runtime.InteropServices.Marshal.Copy(file, (int)Offset, buffer, (int)NumberByteReadSuccess);
                    }
                    else
                    {
                        NumberByteReadSuccess = BufferSize;
                        System.Runtime.InteropServices.Marshal.Copy(file, (int)Offset, buffer, (int)BufferSize);
                    }
                    return(0);
                }
                else
                {
                    Console.WriteLine("Error param {0}", Node.fileName);
                    return(0xC000000F);
                }
            }