//ライセンス情報はAgeOnフォルダのLISENCEフォルダを参照してください
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace nispi.Analysis
{
    /*class AnalysisImageHtmlWriter
    {
        private List<AnalysisImageList> analysisImageList;
        private string pageTopHtml1;
        private string pageTopHtml2;
        private DatInfo dat;
        string VIEWTYPE;

        public AnalysisImageHtmlWriter(List<AnalysisImageList> analysisImageList, DatInfo dat, string VIEWTYPE)
        {
            this.analysisImageList = analysisImageList;
            this.dat = dat;
            this.VIEWTYPE = VIEWTYPE;
            this.pageTopHtml1 = "<html><head>";
            this.pageTopHtml2 = "<style type=\"text/css\">" +
                "body { font-size: 10pt;" +
                "background-color:#f1f1f1;" + 
                "font-family: \"ＭＳ Ｐゴシック\";}" +
                Const.Default_Style_Sheet +
                "</style></head><body>";
        }

        public string WriteImageListFromDat(int pageNum)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.Append(pageTopHtml1);
            sb.Append(string.Format("<title>{0}:{1}</title>",pageNum, dat.thread_name));
            sb.Append(pageTopHtml2);

            sb.Append(GetImageIndexHtml(dat.dat_url));
            sb.Append(string.Format("{0}ページ: 全{1}枚: {2}<br><br>\r\n",
                pageNum, analysisImageList.Count, dat.thread_name));
            int count = 0;
            foreach (AnalysisImageList ail in analysisImageList)
            {
                //ページの分だけシークする
                if (count < pageNum * 20 - 20)
                {
                    count += 1;
                    continue;
                }
                //２０個書き込んだらbreakする
                if (count >= pageNum * 20)
                    break;
                sb.Append(string.Format(
                    "<div class='res_title'>[<a name='res{0}' href='javascript:void(0);#res{0}#{1}'>&gt;&gt;{0}</a>]　", ail.num, dat.dat_url));

                if (VIEWTYPE.CompareTo("Link") == 0)
                    sb.Append(string.Format("<a href='javascript:void(0);h{0}'>h{0}</a><br>\r\n", ail.imageAddress));
                else if (VIEWTYPE.CompareTo("Thumbnail") == 0)
                    sb.Append(string.Format("<script>var image = new Image();image.src = \"h{0}\";document.body.appendChild(image);</script>", ail.imageAddress));
                    //sb.Append(string.Format("<img src='h{0}' width='200' height'140'><a href='javascript:void(0);h{0}'>h{0}</a><br>\r\n", ail.imageAddress));

                sb.Append("</div>");
                count += 1;
            }
            sb.Append("</body></html>");

            return sb.ToString();
        }

        //HTML形式で保存する
        public void WriteImageListToFileFromDat()
        {
            int count = 0;
            int num = 0;
            string dir = Util.DatUrlToDatDirPath(dat.dat_url);
            string folder = Util.DatUrlToThreadID(dat.dat_url);

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            string link = "";

            //ページの先頭の記述
            sb.Append(pageTopHtml1);
            sb.Append(string.Format("<title>{0}:{1}</title>", count / 20 + 1, dat.thread_name));
            sb.Append(pageTopHtml2);

            link = GetImageIndexHtmlInFile();
            sb.Append(link);
            sb.Append(string.Format("{0}ページ: 全{1}枚: {2}<br><br>\r\n",
                count / 20 + 1, analysisImageList.Count, dat.thread_name));
            foreach (AnalysisImageList ail in analysisImageList)
            {
                sb.Append(string.Format(
                    "<div class='res_title'>[<a href='{0}{1}'>&gt;&gt;{1}</a>]　",
                    Util.DatUrlToThreadUrl(dat.dat_url), ail.num));

                if (VIEWTYPE.CompareTo("LinkBrowser") == 0)
                    sb.Append(string.Format("<a href='h{0}' >h{0}</a><br>\r\n", ail.imageAddress));
                else if (VIEWTYPE.CompareTo("ThumbnailBrowser") == 0)
                    sb.Append(string.Format("<img src='h{0}' width='200' height'140'><a href='h{0}'>h{0}</a><br>\r\n", ail.imageAddress));


                //２０回ごとに実行される。ファイルに書き込む。
                if (((count % 20) == 0) && (count != 0))
                {
                    sb.Append("</div>");
                    sb.Append("<body></html>");
                    num = count / 20;
                    saveFile(dir, folder, VIEWTYPE + num.ToString() + ".html", sb.ToString());

                    sb.Length = 0;

                    //ページの先頭の記述
                    sb.Append(pageTopHtml1);
                    sb.Append(string.Format("<title>{0}:{1}</title>", count / 20 + 1, dat.thread_name));
                    sb.Append(pageTopHtml2);

                    sb.Append(link);
                    sb.Append(string.Format("{0}ページ: 全{1}枚: {2}<br><br>\r\n",
                        count / 20 + 1, analysisImageList.Count, dat.thread_name));
                }
                count += 1;
            }
            //２０に満たない残りがあるときに出力する
            if ((count % 20) != 0)
            {
                sb.Append("</div>");
                sb.Append("</html>");
                num += 1;
                saveFile(dir, folder, VIEWTYPE + num.ToString() + ".html", sb.ToString());
            }
        }

        //ページの上の方にインデックスを作る
        private string GetImageIndexHtmlInFile()
        {
            System.Text.StringBuilder sbLink = new System.Text.StringBuilder();
            int count = 0;
            int num = 0;
            string dir = Util.DatUrlToDatDirPath(dat.dat_url);
            string folder = Util.DatUrlToThreadID(dat.dat_url);

            foreach (AnalysisImageList ail in analysisImageList)
            {
                if (((count % 20) == 0) && (count != 0))
                {
                    num += 1;
                    sbLink.Append(string.Format("[<a href={0}>{1}ページ</a>]",
                        dir + Path.DirectorySeparatorChar + folder + Path.DirectorySeparatorChar + VIEWTYPE + num.ToString() +
                        ".html", num.ToString()));
                }
                count += 1;
            }
            if ((count % 20) != 0)
            {
                num += 1;
                sbLink.Append(string.Format("[<a href={0}>{1}ページ</a>]",
                    dir + Path.DirectorySeparatorChar + folder + Path.DirectorySeparatorChar + VIEWTYPE + num.ToString() +
                    ".html", num.ToString()));
            }
            sbLink.Append("<br><br>\r\n");
            return sbLink.ToString();
        }
        //画像を表示するページを作る
        private string GetImageIndexHtml(string url)
        {
            System.Text.StringBuilder sbLink = new System.Text.StringBuilder();
            int count = 0;
            int num = 0;
            foreach (AnalysisImageList ail in analysisImageList)
            {

                if (((count % 20) == 0) && (count != 0))
                {
                    num += 1;
                    sbLink.Append(string.Format("[<a href='javascript:void(0);#locallink{0}'>{1}ページ</a>]",url,num.ToString()));
                }
                count += 1;
            }
            if ((count % 20) != 0)
            {
                num += 1;
                sbLink.Append(string.Format("[<a href='javascript:void(0);#locallink{0}'>{1}ページ</a>]", url,num.ToString()));
            }
            sbLink.Append("<br><br>\r\n");
            return sbLink.ToString(); 
        }
        //保存する
        public void saveFile(string dir, string folder, string fileName, string data)
        {
            if (System.IO.Directory.Exists(dir) == false)
            {
                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dir);
                di.Create();
            }
            if (System.IO.File.Exists(folder) == false)
            {
                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dir + Path.DirectorySeparatorChar + folder);
                di.Create();
            }
            try
            {
                FileStream fsw = new FileStream(dir + Path.DirectorySeparatorChar + folder + Path.DirectorySeparatorChar + fileName, FileMode.Create);
                StreamWriter sw = new StreamWriter(fsw, System.Text.Encoding.Unicode);
                sw.Write(data);
                sw.Flush();
                sw.Close();
                fsw.Close();
            }
            catch
            {
                return;
            }
        }
    }*/
}