/// <summary> /// 升级后清理旧系统文件 /// </summary> public static void ClearOldFiles(string rootPath) { string[] folderList = new string[] { "_data", "_skins", "_temp", "_backup", "install", "web.config", "global.asax", "app_data", "config", "bin", "cgi-bin" }; ArrayList folders = ArrayList.Adapter(folderList); DirectoryInfo di = new DirectoryInfo(rootPath); DirectoryInfo[] ds = di.GetDirectories(); foreach (DirectoryInfo d in ds) { if (!folders.Contains(d.Name.ToLower())) { We7Helper.DeleteFileTree(d); } } FileInfo[] files = di.GetFiles(); foreach (FileInfo f in files) { if (!folders.Contains(f.Name.ToLower())) { File.SetAttributes(f.FullName, FileAttributes.Normal); File.Delete(f.FullName); } } }
/// <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(""); }
/// <summary> /// 解压 /// </summary> /// <param name="file"></param> /// <returns></returns> string UnZipFile(string file) { string path = ""; if (String.Compare(Path.GetExtension(file), ".zip", true) == 0) { path = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file)); if (Directory.Exists(path)) { DirectoryInfo dir = new DirectoryInfo(path); We7Helper.DeleteFileTree(dir); } FileStream s = File.OpenRead(file); ZipUtils.ExtractZip((Stream)s, path); } return(path); }
public void DeleteTemplateGroup(string groupname) { string target = Path.Combine(TemplateGroupPath, groupname); if (File.Exists(target)) { File.Delete(target); } string targetImage = Path.Combine(TemplateGroupPath, groupname + ".jpg"); if (File.Exists(targetImage)) { File.Delete(targetImage); } string targetFile = Regex.Split(target, ".xm", RegexOptions.IgnoreCase)[0]; if (Directory.Exists(targetFile)) { DirectoryInfo di = new DirectoryInfo(targetFile); We7Helper.DeleteFileTree(di); } }
public void DeleteTemplateGroup(string fileName) { string target = Path.Combine(TemplateGroupPath, fileName); if (File.Exists(target)) { File.Delete(target); } //zn 2007-07-19 删除模板组的预览效果图 string targetImg = Path.Combine(TemplateGroupPath, fileName + ".jpg"); if (File.Exists(targetImg)) { File.Delete(targetImg); } string targetFile = Regex.Split(target, ".xm", RegexOptions.IgnoreCase)[0]; if (Directory.Exists(targetFile)) { DirectoryInfo targetDI = new DirectoryInfo(targetFile); We7Helper.DeleteFileTree(targetDI); } }
public static bool BackupDatabase(BaseConfigInfo bci, string file) { string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "_temp/backupDB"); if (Directory.Exists(tempPath)) { DirectoryInfo d = new DirectoryInfo(tempPath); We7Helper.DeleteFileTree(d); } DatabaseInfo dbi = GetDatabaseInfo(bci); string dbFile = dbi.DBFile.Replace("{$App}", AppDomain.CurrentDomain.BaseDirectory); bool success = false; switch (bci.DBType.ToLower()) { case "sqlite": case "access": File.Copy(dbFile, Path.Combine(tempPath, Path.GetFileName(file)), true); success = true; break; case "sqlserver": string masterString = String.Format("Server={0};Database={1};User={2};Password={3}", dbi.Server, "master", dbi.User, dbi.Password); string sql = String.Format("backup database {0} to disk='{1}' with init", dbi.Database, Path.Combine(tempPath, Path.GetFileName(file))); //创建数据库 IDbDriver driver = new SqlDbDriver(); using (IConnection conn = driver.CreateConnection(masterString)) { SqlStatement st = new SqlStatement(sql); driver.FormatSQL(st); conn.Update(st); } success = true; break; case "mysql": break; } if (success) { string[] FileProperties = new string[2]; FileProperties[0] = tempPath; //压缩目录 FileProperties[1] = file; //压缩后的目录 if (File.Exists(FileProperties[1])) { File.Delete(FileProperties[1]); } //压缩文件 try { ZipClass.ZipFileMain(FileProperties); } catch { } } return(success); }