示例#1
0
        public void Reload()
        {
            Cursor.Current = Cursors.WaitCursor;

            listFiles.Items.Clear();
            string[] files       = Directory.GetFiles(CurrentPath, SearchPattern);
            string[] directories = Directory.GetDirectories(CurrentPath);

            if (!CurrentPath.Equals(PathRoot))
            {
                ListViewItem itemBack = new ListViewItem(GoBack);
                listFiles.Items.Add(itemBack);
                itemBack.ImageIndex = (int)FileIcon.Back;
            }

            foreach (string directory in directories)
            {
                ListViewItem item = new ListViewItem(Path.GetFileName(directory));
                item.ImageIndex = (int)GetFileIcon(directory);
                listFiles.Items.Add(item);
            }

            foreach (string file in files)
            {
                ListViewItem item = new ListViewItem(Path.GetFileName(file));
                item.ImageIndex = (int)GetFileIcon(file);
                listFiles.Items.Add(item);
            }

            txtFileName.Text   = string.Empty;
            lblFilesCount.Text = (files.Length + directories.Length).ToString() + " " + Translations["objects"];

            Cursor.Current = Cursors.Default;
        }
示例#2
0
 private void Directories(string previousPath)
 {
     try
     {
         if (!CurrentPath.Equals(RootPath))
         {
             if (!CurrentPath.Equals(previousPath))
             {
                 greenNames.Clear();
             }
             ClearLists();
             string[] dirs  = Directory.GetDirectories(CurrentPath);
             string[] files = Directory.GetFiles(CurrentPath);
             for (int i = 0; i < dirs.Length; i++)
             {
                 DirectoryInfo dirInfo = new DirectoryInfo(dirs[i]);
                 catalogs.Add(dirs[i]);
                 catalogsName.Add(dirInfo.Name);
             }
             for (int i = 0; i < files.Length; i++)
             {
                 DirectoryInfo dirInfo = new DirectoryInfo(files[i]);
                 this.files.Add(files[i]);
                 filesName.Add(dirInfo.Name);
             }
         }
     }
     catch (UnauthorizedAccessException)
     { }
 }
示例#3
0
        private DataTable GetFolderInfo()
        {
            DataTable dtDlls = new DataTable();

            dtDlls.Columns.Add("FileName");
            dtDlls.Columns.Add("FileVersion");
            dtDlls.Columns.Add("LastWriteTime");
            dtDlls.Columns.Add("FileLength");
            dtDlls.Columns.Add("FileFullPath");

            if (!CurrentPath.Equals(RootPath))
            {
                dtDlls.Rows.Add("..",
                                "",
                                "",
                                "",
                                "");
            }

            DirectoryInfo updateDir = new DirectoryInfo(CurrentPath);

            if (!updateDir.Exists)
            {
                return(dtDlls);
            }
            DirectoryInfo[] dirs = updateDir.GetDirectories();
            foreach (DirectoryInfo dir in dirs)
            {
                dtDlls.Rows.Add(dir.Name,
                                "",
                                dir.LastWriteTime.ToShortDateString() + " " + dir.LastWriteTime.ToShortTimeString(),
                                "",
                                dir.FullName);
            }
            return(dtDlls);
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            pFoot.InnerHtml = String.Format("UpdateServer({0}) at {1}"
                                            , System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
                                            , Request.Headers["host"]
                                            );
            if (!IsPostBack)
            {
                softHelper = new SoftwareHelper(RootPath);
                if (CurrentPath == null || !CurrentPath.Contains(RootPath))
                {
                    CurrentPath = RootPath;
                }

                if (CurrentPath.Equals(RootPath))
                {
                    lblCurrentPath.Text = "\\";
                }
                else
                {
                    lblCurrentPath.Text = CurrentPath.ToString().Substring(RootPath.Length);
                }


                if (String.IsNullOrEmpty(ClientQueryString))
                {
                    //如果没有QueryString,则显示文件列表
                    BindFolderInfoData();
                    BindFileInfoData();
                }
                else
                {
                    //动作
                    String Action = Request.QueryString["Action"];
                    if (Action == null)
                    {
                        Action = String.Empty;
                    }

                    //更新器版本
                    String UpdaterVersion = Request.QueryString["UpdaterVersion"];

                    //写到客户端的字符串
                    String ToWriteString = String.Empty;
                    switch (Action)
                    {
                        #region 获取软件列表 - Action:GetSoftwareList
                    case "GetSoftwareList":
                    {
                        //获取软件列表

                        Response.ContentType = "text/xml";
                        ToWriteString        = softHelper.GetSoftwareListXml();
                        break;
                    }
                        #endregion

                        #region 获取软件信息 - Action:GetSoftwareInfo
                    case "GetSoftwareInfo":
                    {
                        //获取软件信息

                        Response.ContentType = "text/xml";
                        String SoftwareName = Request.QueryString["SoftwareName"];
                        if (String.IsNullOrEmpty(SoftwareName))
                        {
                            ToWriteString = "请输入软件名称";
                        }
                        else
                        {
                            String ErrMsg;
                            ToWriteString = softHelper.GetSoftwareInfoXml(SoftwareName, out ErrMsg);
                            if (ToWriteString == null)
                            {
                                String tmpSoftwareName = String.Empty;

                                /*
                                 * SetQueryStringEncoding(Encoding.Default);
                                 * tmpSoftwareName = Request.QueryString["SoftwareName"];
                                 * ToWriteString = softHelper.GetSoftwareInfoXml(tmpSoftwareName);
                                 */
                                if (ToWriteString == null)
                                {
                                    ToWriteString = String.Format("未找到软件 {0}({1})。错误描述:{2}", SoftwareName, tmpSoftwareName, ErrMsg);
                                }
                            }
                        }
                        break;
                    }
                        #endregion

                        #region 获取软件LOGO - Action:GetSoftwareLogo
                    case "GetSoftwareLogo":
                    {
                        String SoftwareName = Request.QueryString["SoftwareName"];
                        String LogoSize     = Request.QueryString["LogoSize"];

                        if (String.IsNullOrEmpty(SoftwareName))
                        {
                            ToWriteString = "请输入软件名称";
                        }
                        else
                        {
                            DirectoryInfo dir = softHelper.GetSoftwareDirectoryInfo(SoftwareName);
                            if (dir == null)
                            {
                                String tmpSoftwareName = String.Empty;

                                /*
                                 * SetQueryStringEncoding(Encoding.Default);
                                 * tmpSoftwareName = Request.QueryString["SoftwareName"];
                                 * dir = softHelper.GetSoftwareDirectoryInfo(tmpSoftwareName);
                                 */
                                if (dir == null)
                                {
                                    ToWriteString = String.Format("未找到软件 {0}({1})", SoftwareName, tmpSoftwareName);
                                    break;
                                }
                            }
                            String logoFileFullPath = Path.Combine(dir.FullName, "Logo.png");

                            Response.Clear();
                            if (File.Exists(logoFileFullPath))
                            {
                                Bitmap bmp         = new Bitmap(logoFileFullPath);
                                int    intLogoSize = 32;
                                if (!String.IsNullOrEmpty(LogoSize) && Int32.TryParse(LogoSize, out intLogoSize))
                                {
                                    bmp = new Bitmap(bmp, new Size(intLogoSize, intLogoSize));
                                }
                                MemoryStream ms = new MemoryStream();
                                bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                                ms.Position = 0;

                                FileInfo newFileInfo = new FileInfo(logoFileFullPath);
                                Response.ContentType = "application";
                                Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(newFileInfo.Name, System.Text.Encoding.UTF8));
                                Response.AddHeader("Content-Length", ms.Length.ToString());
                                Response.BinaryWrite(ms.ToArray());
                            }
                            else
                            {
                                Response.AddHeader("Content-Length", "0");
                            }
                            Response.Flush();
                            Response.Close();
                        }
                        break;
                    }
                        #endregion

                        #region 获取文件版本 - Action:GetFileVersion
                    case "GetFileVersion":
                    {
                        //获取文件版本

                        String    FileName    = Request.QueryString["FileName"];
                        DataTable dtFileInfos = GetFileInfos(FileName, RootPath, SearchOption.AllDirectories);
                        if (dtFileInfos.Rows.Count == 0)
                        {
                            return;
                        }

                        String fileVersionString = dtFileInfos.Rows[0]["FileVersion"].ToString();
                        ToWriteString = fileVersionString;
                        break;
                    }
                        #endregion

                        #region  载文件 - Action:DownloadFile
                    case "DownloadFile":
                    {
                        //下载文件
                        String FileName     = Request.QueryString["FileName"];
                        String fileFullPath = String.Empty;

                        bool IsChangedEncoding = false;
                        while (true)
                        {
                            if (!FileName.StartsWith("."))
                            {
                                DataTable dtFileInfos = GetFileInfos(FileName, RootPath, SearchOption.AllDirectories);
                                if (dtFileInfos.Rows.Count != 0)
                                {
                                    fileFullPath = dtFileInfos.Rows[0]["FileFullPath"].ToString();
                                }
                            }
                            else
                            {
                                fileFullPath = RootPath + FileName.Substring(1);
                            }

                            if (File.Exists(fileFullPath))
                            {
                                break;
                            }
                            if (IsChangedEncoding)
                            {
                                break;
                            }

                            //SetQueryStringEncoding(Encoding.Default);
                            FileName          = Request.QueryString["FileName"];
                            IsChangedEncoding = true;
                        }

                        if (!File.Exists(fileFullPath))
                        {
                            ToWriteString = "未找到该文件!";
                            break;
                        }
                        FileInfo newFileInfo = new FileInfo(fileFullPath);
                        Response.ContentType = "application";
                        Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(newFileInfo.Name, System.Text.Encoding.UTF8));
                        Response.AddHeader("Content-Length", newFileInfo.Length.ToString());
                        Response.WriteFile(newFileInfo.FullName);
                        Response.Flush();
                        Response.Close();
                        break;
                    }
                        #endregion

                        #region 清除Session - Action:ClearSession
                    case "ClearSession":
                    {
                        //清除Session
                        Session.Clear();
                        ToWriteString = "Session已清除!";
                        break;
                    }
                        #endregion

                    default:
                    {
                        ToWriteString = "未定义的命令!";
                        break;
                    }
                    }

                    if (!String.IsNullOrEmpty(ToWriteString))
                    {
                        Response.Charset = "utf-8";
                        Response.AddHeader("Content-Length", Encoding.UTF8.GetByteCount(ToWriteString).ToString());
                        Response.Write(ToWriteString);
                        Response.Flush();
                        Response.Close();
                    }
                }
            }
        }