using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack) 
        {
            JudgeBrowser();
            FileManager();
        } 
    }
    protected void FileManager() 
    {
        int dt = 0;
       string[] dictoryNames ={ "admin", "Bin", "Company", "Control", "css", "Images", "img", "install", "js", "login", "member", "News", "Purchase", "Search", "Shops", "ShopTemplate", "Supply", "Templates", "xml"};
       string[] fileNames ={"Default.aspx","Error.aspx", "web.config"};
       string path = HttpContext.Current.Server.MapPath("~/");
       DataTable table = new DataTable();
       DataColumn c1 = new DataColumn("name", typeof(string));
       DataColumn c2 = new DataColumn("imge", typeof(string));
       table.Columns.Add(c1);
       table.Columns.Add(c2);
       for (int i = 0; i < fileNames.Length; i++)
       {
           FileInfo fi = new FileInfo(path + fileNames[i]);
           DataRow row = table.NewRow();
           row[c1] = fi.Name;
           if (fi.Exists)
           {
               if ((File.GetAttributes(path + fileNames[i]) & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
               {
                   row[c2] = "~/install/images/checked.gif";
               }
               else
               {
                   row[c2] = "~/install/images/cancel.gif";
                   dt++;
               }
               
           }
           else
           {
               row[c2] = "~/install/images/cancel.gif";
               dt++;
           }
           table.Rows.Add(row);
       }
       for(int i = 0; i < dictoryNames.Length; i++)
       {
           DirectoryInfo dir = new DirectoryInfo(path + dictoryNames[i]);
           DataRow row = table.NewRow();
           row[c1] = dir.Name;
           if (dir.Exists)
           {
               bool bl = IsFile(path + dictoryNames[i]);
               if (bl == true)
               {
                   row[c2] = "~/install/images/checked.gif";
               }
               else
               {
                   row[c2] = "~/install/images/cancel.gif";
                   dt++;
               }
           }
           else
           {
               row[c2] = "~/install/images/cancel.gif";
               dt++;
           }
           table.Rows.Add(row);
       }
      this.Repeater1.DataSource = table;
      this.Repeater1.DataBind();
      if (dt > 0)
      {
          this.btn_next.Enabled = false;
      }
      else
      {
          this.btn_next.Enabled = true;
      }
    }
    //判断客户端是否安装.net 2.0环境
    protected void JudgeBrowser() 
    {
        string appVersion = HttpContext.Current.Request.UserAgent.ToString();
        //if (appVersion.IndexOf(".NET CLR 2.0") == -1)
        //{
        //    Response.Write("<script>alert('.NET Framework 2.0未安装！');</script>");
        //}
    }
    protected bool IsFile(string path)
    {   
        //检查文件夹的属性
        FileInfo fi = new FileInfo(path+"/temp.txt");
        try
        {
            if (!fi.Exists)
            {
                FileStream fis = fi.Create();
                fis.Close();
            }
            fi.Delete();
            return true;
        }
        catch
        {
            return false;
        }
    }
}