private void ctlStartConversion2_Click(object sender, System.EventArgs e) { Validate(); if(IsCSCDFolderValid && IsDestFolderValid) { try { ctlStartConversion2.Enabled=false; if(!ctlCSCDFolder.Text.EndsWith(@"\")) ctlCSCDFolder.Text+=@"\"; if(!ctlDestFolder.Text.EndsWith(@"\")) ctlDestFolder.Text+=@"\"; FileStream fs=File.Open(ctlCSCDFolder.Text+@"\CSCD\open.ale",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,false); string strFileContent=new string(arrDecoded); MatchCollection mc=Regex.Matches(strFileContent,@"^(\d{4})~([^#]*)#([^#]+)",RegexOptions.IgnoreCase | RegexOptions.Multiline); ArrayList objIndexList=new ArrayList(3000); if(ctlVinaya.Checked) CreatePitakaContent2(mc,"1","Vinaya pitaka",objIndexList); if(ctlSutta.Checked) CreatePitakaContent2(mc,"2","Sutta pitaka",objIndexList); if(ctlAbidhamma.Checked) CreatePitakaContent2(mc,"3","Abidhamma pitaka",objIndexList); if(ctlOther.Checked) CreatePitakaContent2(mc,"4","Others",objIndexList); if(m_objLibraryStream!=null) { m_objLibraryStream.Finish(); m_objLibraryStream.Close(); } objIndexList.Sort(); if(objIndexList.Count>0) { fs = new FileStream(ctlDestFolder.Text+"lib_index.dat", FileMode.Create); BinaryWriter bw=new BinaryWriter(fs,Encoding.UTF8); foreach(IndexNode objNode in objIndexList) { objNode.Write(bw); } bw.Close(); fs.Close(); // StreamWriter objSW=new StreamWriter(ctlDestFolder.Text+"lib_index.txt",false); // foreach(IndexNode objNode in objIndexList) // objNode.Write(objSW); // objSW.Close(); } if(!File.Exists(ctlDestFolder.Text+"pali_dic.txt")) File.Copy(Application.ExecutablePath.Replace("CSCDBookConverter.exe","pali_dic.txt"),ctlDestFolder.Text+"pali_dic.txt"); ctlMessage.Text="Done!"; } catch(Exception ex) { MessageBox.Show(ex.Message); } finally { ctlStartConversion2.Enabled=true; } } }
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); } }