Example #1
0
        private string ParagraphEvaluator2(Match objParaMatch)
        {
            m_nParagraphID++;

            //strip page numbers
            string strParaName=Regex.Replace(objParaMatch.Groups[2].Value,@"[BVPTO]\d\.\d{4}","");
            //strip differences
            strParaName=Regex.Replace(strParaName,@"{.*?}","").Trim();
            int ParentID=m_nParentNodeID;

            if(objParaMatch.Groups[1].Value=="\\c14" && m_nC13NodeID!=-1)
            {
                ParentID=m_nC13NodeID;
                IndexNode objPrevNode=(IndexNode)m_arrChaptersList[m_arrChaptersList.Count-1];
                if(objPrevNode.NodeID==m_nC13NodeID)
                    objPrevNode.HasChildren=true;
            }

            IndexNode objIndexNode=new IndexNode(ParentID,m_nNodeCounter++,strParaName,false,-1,"p"+m_nParagraphID.ToString(),m_nLibFileIndex);
            m_arrChaptersList.Add(objIndexNode);

            if(objParaMatch.Groups[1].Value=="\\c13")
                m_nC13NodeID=objIndexNode.NodeID;

            return objParaMatch.Groups[1].Value+"<a name=\"p"+m_nParagraphID.ToString()+"\">"+objParaMatch.Groups[2].Value.Trim()+"</a>";
        }
Example #2
0
        private void ConvertChapter2(int ParentNodeID,string strChapterName,string strFileName,string strChapterContent,ArrayList objIndexList)
        {
            strChapterName=Regex.Replace(strChapterName,@"[BVPTO]\d\.\d{4}","");
            strChapterName=Regex.Replace(strChapterName,@"{.*?}","").Trim();

            m_nParagraphID=0;
            m_arrChaptersList=new ArrayList();
            m_nParentNodeID=m_nNodeCounter++;
            m_nC13NodeID=-1;

            strChapterContent=Regex.Replace(strChapterContent,@"(\\c1(?:3|4)) (.+)",new MatchEvaluator(ParagraphEvaluator2),RegexOptions.Multiline | RegexOptions.IgnoreCase);

            if(ctlStripPageNumbers.Checked)
                strChapterContent = Regex.Replace(strChapterContent, "([BVTPO])(\\d\\.\\d{4})", "");

            switch(ctlDiffsHandling.SelectedIndex)
            {
                case 1:
                    strChapterContent=Regex.Replace(strChapterContent,@"\{.*?\}",new MatchEvaluator(DiffsEvaluator),RegexOptions.Singleline);
                    break;
                case 2:
                    strChapterContent = Regex.Replace(strChapterContent, @"\{.*?\}", "",RegexOptions.Singleline);
                    break;
            }
            //now format it
            AalekhFormatter objFormatter=new AalekhFormatter(strChapterContent.ToCharArray());
            char[] arrHTML=objFormatter.ToHTML();

            //save content to archive
            byte[] arrFileMarker={0xEF,0xBB,0xBF};
            byte[] arrChapterBuffer=System.Text.Encoding.UTF8.GetBytes(arrHTML);

            if(m_objLibraryStream==null)
            {
                m_nZipFileIndex=0;
                string strLibFileName=String.Format("PocketLib{0}.zip",m_nLibFileIndex);
                m_objLibraryStream=new ZipOutputStream(File.Create(ctlDestFolder.Text+strLibFileName));
                m_objLibraryStream.SetLevel(5);
            }

            ZipEntry objChapterEntry=new ZipEntry(strFileName);
            m_objLibraryStream.PutNextEntry(objChapterEntry);
            m_objLibraryStream.Write(arrFileMarker,0,3);
            m_objLibraryStream.Write(arrChapterBuffer,0,arrChapterBuffer.Length);
            //save index to archive
            IndexNode objIndexNode=new IndexNode(ParentNodeID,m_nParentNodeID,strChapterName,(m_nParagraphID>0),m_nZipFileIndex,m_nLibFileIndex);
            objIndexList.Add(objIndexNode);
            foreach(IndexNode objParagraphNode in m_arrChaptersList)
            {
                objParagraphNode.ZipFileIndex=m_nZipFileIndex;
                objParagraphNode.LibFileIndex=m_nLibFileIndex;
                objIndexList.Add(objParagraphNode);
            }

            if(m_nZipFileIndex>499)
            {
                m_objLibraryStream.Finish();
                m_objLibraryStream.Close();
                m_objLibraryStream=null;
                m_nLibFileIndex++;
            }

            m_nZipFileIndex++;
        }
Example #3
0
        private void CreatePitakaContent2(MatchCollection mc,string strPitakaID,string strPitakaName,ArrayList objIndexList)
        {
            IndexNode objPitakaNode=new IndexNode(0,m_nNodeCounter++,strPitakaName,true,-1,0xFF);
            objIndexList.Add(objPitakaNode);

            ctlMessage.Text="Converting "+strPitakaName;
            ctlConversionProgress.Maximum=mc.Count;
            ctlConversionProgress.Value=0;
            ctlConversionProgress.Step=1;

            IndexNode objNikayaNode=null;

            foreach(Match m in mc)
            {
                if(m.Groups[1].Value.Substring(0,1)==strPitakaID)
                {
                    string strName=FormatName(m.Groups[3].Value);

                    if(Regex.IsMatch(m.Groups[1].Value,@"\d{2}00")) //nikaya
                    {
                        objNikayaNode=new IndexNode(objPitakaNode.NodeID,m_nNodeCounter++,strName,true,-1,0xFF);
                        objIndexList.Add(objNikayaNode);
                    }
                    else
                    {
                        string strAalekhFileName=m.Groups[2].Value;

                        bool bConvert=true;
                        if(!ctlMula.Checked && strAalekhFileName.IndexOf("mul")>-1)
                            bConvert=false;

                        if(!ctlAtthakatha.Checked && strAalekhFileName.IndexOf("att")>-1)
                            bConvert=false;

                        if(!ctlTika.Checked && strAalekhFileName.IndexOf("tik")>-1)
                            bConvert=false;

                        if(!ctlOtherContent.Checked && strAalekhFileName.IndexOf("nrf")>-1)
                            bConvert=false;

                        if(bConvert)
                        {
                            IndexNode objBookNode=null;
                            if(objNikayaNode!=null)
                                objBookNode=new IndexNode(objNikayaNode.NodeID,m_nNodeCounter++,strName,true,-1,0xFF);
                            else
                                objBookNode=new IndexNode(objPitakaNode.NodeID,m_nNodeCounter++,strName,true,-1,0xFF);

                            objIndexList.Add(objBookNode);

                            ConvertBook2(strAalekhFileName,objBookNode,objIndexList);
                        }
                    }
                }
                ctlConversionProgress.PerformStep();
                Application.DoEvents();
            }
        }
Example #4
0
        private void ConvertBook2(string strAalekhFileName,IndexNode objParentNode,ArrayList objIndexList)
        {
            FileStream fs=File.Open(ctlCSCDFolder.Text+@"CSCD\"+strAalekhFileName,FileMode.Open,FileAccess.Read);
            byte[] arrContent=new byte[fs.Length];
            fs.Read(arrContent,0,(int)fs.Length);
            fs.Close();

            AalekhDecoder objDecoder=new AalekhDecoder();
            char[] arrDecoded=objDecoder.AalekhToUnicode(arrContent,false,true);
            string strFileContent=new string(arrDecoded);

            string[] arrChapters=Regex.Split(strFileContent,@"\\c11");

            if(arrChapters.Length>1)
            {//split the book into chapters
                for(int nChapterCounter=1;nChapterCounter<arrChapters.Length;nChapterCounter++)
                {
                    string strFileName="";
                    if(arrChapters.Length==2)
                        strFileName=strAalekhFileName+".htm";
                    else
                        strFileName=strAalekhFileName.Replace(".",nChapterCounter.ToString("_000")+".")+".htm";

                    Match m=Regex.Match(arrChapters[nChapterCounter],".*",RegexOptions.Multiline);//chapter name
                    ConvertChapter2(objParentNode.NodeID,m.Value.Trim(),strFileName,
                        @"\c11"+arrChapters[nChapterCounter],objIndexList);
                }
            }
            else
            {//no chapters in this book. add it
                ConvertChapter2(objParentNode.NodeID,objParentNode.Name,strAalekhFileName+".htm",strFileContent,objIndexList);
            }
        }