private void HandleFolder(string to, UpgradeConf conf) { if (conf.opt == OptType.delete && Directory.Exists(to)) { _logger.LogInfo(string.Format("删除目录:{0}", to)); try { Directory.Delete(to, true); } catch (Exception ex) { _logger.LogInfo(string.Format("删除目录:{0}失败", to), ex); } } else if (conf.opt == OptType.add && !Directory.Exists(to)) { _logger.LogInfo(string.Format("添加目录:{0}", to)); Directory.CreateDirectory(to); } }
private void HandleFile(string from, string to, UpgradeConf conf) { //文件 if (!File.Exists(from) && conf.opt != OptType.delete) { _logger.LogInfo(string.Format("未找到升级文件from:{0}", from)); return; } if (File.Exists(to)) { _logger.LogInfo(string.Format("删除文件:{0}", to)); try { File.Delete(to); } catch (Exception ex) { _logger.LogInfo(string.Format("删除文件:{0}失败", to), ex); } } if (conf.opt != OptType.delete) { var dir = new FileInfo(to).Directory; if (!dir.Exists) { _logger.LogInfo(string.Format("创建目录:{0}", dir.FullName)); dir.Create(); } _logger.LogInfo(string.Format("复制文件:from\t{0}\tto\t{1}", from, to)); try { File.Copy(from, to); } catch (Exception ex) { _logger.LogInfo(string.Format("复制文件:{0}失败", to), ex); } } }