Ejemplo n.º 1
0
        public int ReadFile(
            string filename,
            byte[] buffer,
            ref uint readBytes,
            long offset,
            DokanFileInfo info)
        {
            string[] nameParts = filename.Split('\\');
            string rootFileName = nameParts[1].Trim();
            string fileNameLast = nameParts[nameParts.Count()-1].Trim().Replace('_',':');

            if (fileNameLast.StartsWith(".") || fileNameLast == "folder.jpg" || fileNameLast == "desktop.ini")
            {
                return 0;
            }

            Console.WriteLine("Root: "+rootFileName);
            Console.WriteLine("Read file: "+filename);
            Console.WriteLine("offset:"+offset);
            Console.WriteLine("readBytes: "+readBytes);

            try
            {

                switch (rootFileName)
                {
                    case "Main namespace":
                    case "Categories":
                    case "Properties":
                    case "Forms":
                    case "Templates":

                        //Get page
                        Console.WriteLine("Opening page " + fileNameLast);

                        Page p = new Page(wiki, fileNameLast);
                        p.LoadInfo();
                        p.LoadText();

                        string pText = p.Text;

                        MemoryStream ms = new MemoryStream();
                        StreamWriter sw = new StreamWriter(ms);
                        sw.Write(pText);
                        sw.Flush();
                        ms.Position = 0;
                        StreamReader sr = new StreamReader(ms);

                        //Read
                        sr.BaseStream.Seek(offset, SeekOrigin.Begin);
                        readBytes = (uint) sr.BaseStream.Read(buffer, 0, buffer.Length);

                        break;
                }

                return 0;

            }
            catch (Exception)
            {
                return -1;
            }
        }