Exemple #1
0
        /// <summary>
        /// 升级前备份旧系统文件
        /// </summary>
        /// <param name="rootPath">系统根目录</param>
        /// <param name="backupPath">备份目录</param>
        public static string BackupOldFiles(string rootPath, string backupPath)
        {
            //检查文件夹是否存在
            string tempPath = Path.Combine(rootPath, "_temp\\backupBeforeUpdate");

            if (Directory.Exists(tempPath))
            {
                DirectoryInfo d = new DirectoryInfo(tempPath);
                We7Helper.DeleteFileTree(d);
            }

            //不需要复制的文件夹
            string[] folderList = new string[] { "_data", "_skins",
                                                 "_temp", "_backup", "Plugins", "log" };

            ArrayList     folders = ArrayList.Adapter(folderList);
            DirectoryInfo di      = new DirectoryInfo(rootPath);

            DirectoryInfo[] ds = di.GetDirectories();

            //复制当前网站目录结构,到tempPath
            foreach (DirectoryInfo d in ds)
            {
                if (!folders.Contains(d.Name.ToLower()))
                {
                    We7Helper.CopyDirectory(d.FullName, Path.Combine(tempPath, d.Name));
                }
            }

            FileInfo[] files = di.GetFiles();
            foreach (FileInfo f in files)
            {
                File.Copy(f.FullName, Path.Combine(tempPath, f.Name));
            }

            if (!Directory.Exists(backupPath))
            {
                Directory.CreateDirectory(backupPath);
            }

            string[] FileProperties = new string[2];
            FileProperties[0] = tempPath;                                                                                                           //临时目录,将被压缩
            FileProperties[1] = Path.Combine(backupPath, "backup-" + DateTime.Today.ToString("yyyy-MM-dd-") + DateTime.Now.GetHashCode() + ".zip"); //压缩后的目录

            //压缩文件
            try
            {
                ZipClass.ZipFileMain(FileProperties);

                //压缩之后删除临时文件
                DirectoryInfo d = new DirectoryInfo(tempPath);
                We7Helper.DeleteFileTree(d);

                return(FileProperties[1]);
            }
            catch
            {
            }
            return("");
        }
Exemple #2
0
 /// <summary>
 /// 布署
 /// </summary>
 public void Deploy()
 {
     if (Directory.Exists(BasePath))
     {
         if (!Directory.Exists(SkinPath))
         {
             Directory.CreateDirectory(SkinPath);
         }
         We7Helper.CopyDirectory(BasePath, SkinPath);
     }
 }
Exemple #3
0
        private void CopyFilesButton_Click(object sender, EventArgs e)
        {
            //configuration文件夹改名 兼容2.7以前版本方法
            string oldConfigPath = Path.Combine(Server.MapPath("~/"), "configuration");

            if (Directory.Exists(oldConfigPath))
            {
                string destDirName = Path.Combine(Server.MapPath("~/"), "config");
                if (Directory.Exists(destDirName))
                {
                    Directory.Delete(destDirName, true);
                }
                Directory.Move(oldConfigPath, Path.Combine(Server.MapPath("~/"), "config"));
            }

            if (BackUpPanel.Visible)
            {
                if (BackUpCheckBox.Checked)
                {
                    Installer.BackupOldFiles(Server.MapPath("~/"), Server.MapPath("~/_backup/update/"));
                }

                //检查是否有冗余文件
                if (ClearOldCheckBox.Visible && ClearOldCheckBox.Checked)
                {
                    //此处应该返回错误信息,目前存储在LOG文件中
                    DeleteFiles();
                }
            }

            string ext = Path.GetExtension(UploadFile);

            switch (ext.ToLower())
            {
            case ".zip":
                try
                {
                    //DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath("~/bin"));
                    //Helper.DeleteFileTree(directoryInfo, false);
                    We7Helper.CopyDirectory(UnZipPath, Server.MapPath("~/"));

                    Directory.Delete(UnZipPath, true);
                    //

                    /*
                     *
                     * 保存新版本号
                     * GeneralConfigInfo si = GeneralConfigs.GetConfig();
                     * if (si != null)
                     * {
                     *  //si.ProductVersion = NewVersion;
                     *  GeneralConfigs.SaveConfig(si);
                     * }
                     */
                    RegisterScript("alert('操作成功!');location.href='upgrade-db.aspx?from=upgrade.aspx'");
                }
                catch (IOException ex)
                {
                    RegisterScript("alert('文件复制失败。原因:" + ex.Message + "');");
                }
                break;

            case ".dll":
                try
                {
                    string targetfile = Path.Combine(Server.MapPath("~/bin/"), Path.GetFileName(UploadFile));
                    File.Copy(UploadFile, targetfile, true);
                    RegisterScript("alert('文件更新成功!');");
                }
                catch (IOException ex)
                {
                    RegisterScript("alert('文件复制失败。原因:" + ex.Message + "');");
                }
                break;

            case ".xml":
                try
                {
                    //读取默认db.config文件内容
                    BaseConfigInfo bci = BaseConfigs.GetBaseConfig();
                    if (bci != null && bci.DBType != "" && bci.DBConnectionString != "")
                    {
                        Installer.ExcuteSQL(bci, UploadFile);
                    }
                    RegisterScript("alert('XML文件执行成功!');");
                }
                catch (IOException ex)
                {
                    RegisterScript("alert(''XML文件执行出现错误。原因:" + ex.Message + "');");
                }
                break;
            }
        }