コード例 #1
0
ファイル: MWFS.cs プロジェクト: vedmaka/mediawikifs
        public int WriteFile(
            string filename,
            byte[] buffer,
            ref uint writtenBytes,
            long offset,
            DokanFileInfo info)
        {
            //Extract file name and root directory
            string[] nameParts = filename.Split('\\');
            string rootFileName = nameParts[1].Trim();
            string fileNameLast = nameParts[nameParts.Count() - 1].Trim().Replace('_', ':');

            if (fileNameLast.StartsWith(".") || fileNameLast.EndsWith(".bak"))
            {
                Console.WriteLine("Skip creating temp file");
                return 0;
            }

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

                        //Get page
                        Console.WriteLine("Writing page " + fileNameLast);
                        Page p = new Page(wiki, fileNameLast);

                        if (!wiki.CurrentUserInfo.CanEdit)
                        {
                            Console.WriteLine("User have no edit rights!");
                            return -1;
                        }

                        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);
                        writtenBytes = (uint)buffer.Length;
                        sr.BaseStream.Write(buffer, 0, buffer.Length);
                        sr.BaseStream.Seek(0, SeekOrigin.Begin);
                        pText = sr.ReadToEnd();

                        Console.WriteLine(pText);

                        p.PrepareToEdit();
                        p.SetText(pText);

                        break;
                }

                return 0;

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