public override bool Run() { if (!CanRun) { return(true); } this.CommandStatus = CommandStatus.Running; foreach (var file in files.OrderBy(x => x)) { if (!File.Exists(file)) { continue; } Watch?.Info($"执行脚本: [{file}]"); var args = $"{config} -i {file}"; if (!Start("sqlcmd.exe", args)) { this.CommandStatus = CommandStatus.Failed; return(false); } Watch?.AddValue(1); } this.CommandStatus = CommandStatus.Complete; return(true); }
public override bool Run() { if (!CanRun) { return(true); } this.CommandStatus = CommandStatus.Running; if (InstallContext.IsMakeStore) { Watch?.Info("正在备份历史文件"); this.Store(); Watch?.AddValue(10); } else if (!Directory.Exists(InstallContext.InstInfo.InstallPath)) { Directory.CreateDirectory(InstallContext.InstInfo.InstallPath); newDirs.Push(InstallContext.InstInfo.InstallPath); } Watch?.Info("开始文件提取"); if (!UnZip(InstallContext.PackageFile, InstallContext.Files, InstallContext.InstInfo.InstallPath)) { Watch?.Faild(); this.CommandStatus = CommandStatus.Failed; return(false); } Watch?.Info("文件提取完成"); this.CommandStatus = CommandStatus.Complete; return(true); }
public override bool Rollback() { if (!this.CanRollback) { return(true); } if (this.CommandStatus != CommandStatus.Complete && this.CommandStatus != CommandStatus.Failed && this.CommandStatus != CommandStatus.Running) { return(true); } this.RollbackStatus = RollbackStatus.Rollbacking; Watch?.SetStep("删除卸载程序"); var uninsDataPath = Path.Combine(InstallContext.InstInfo.InstallPath, "unins.data"); if (File.Exists(uninsDataPath)) { File.Delete(uninsDataPath); } Watch?.AddValue(-10); this.RollbackStatus = RollbackStatus.Complete; return(true); }
private void Store() { var dir = $"Store{DateTime.Now:yyyyMMdd}"; storePath = Path.Combine(this.InstallContext.InstInfo.InstallPath, dir); if (!Directory.Exists(storePath)) { Directory.CreateDirectory(storePath); newDirs.Push(storePath); } foreach (var file in InstallContext.Files) { if (File.Exists(file.Path)) { var name = file.Path.Replace(InstallContext.InstInfo.InstallPath, storePath); var info = new FileInfo(name); if (!Directory.Exists(info.Directory.FullName)) { Directory.CreateDirectory(info.Directory.FullName); newDirs.Push(info.Directory.FullName); } File.Copy(file.Path, name); Watch?.AddValue(1); } } }
public override bool Rollback() { if (!this.CanRollback) { return(true); } if (this.CommandStatus != CommandStatus.Complete && this.CommandStatus != CommandStatus.Failed && this.CommandStatus != CommandStatus.Running) { return(true); } this.RollbackStatus = RollbackStatus.Rollbacking; Watch?.SetStep("删除快捷方式"); Watch?.SetStep("正在删除快捷方式"); foreach (var path in InstallContext.UninstallData.Shortcuts) { File.Delete(path); Watch?.AddValue(-1); } if (createIconDir && Directory.Exists(iconDir)) { Directory.Delete(iconDir, true); } this.RollbackStatus = RollbackStatus.Complete; return(true); }
private bool TryExecute() { if (files.Any(x => x.Status == ScriptStatus.UnRun)) { foreach (var script in files.ToSorted()) { if (script.Status == ScriptStatus.UnChecked) { continue; } var name = script.GetObjectName(); string storeFile = null; if (this.needStore) { if (script.Type == ScriptType.Proc || script.Type == ScriptType.Function || script.Type == ScriptType.View || script.Type == ScriptType.Trigger) { if (sqlHelper.IsExsit(name)) { var path = Path.Combine(storePath, script.Type.ToString()); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); newDirs.Push(path); } storeFile = Path.Combine(path, script.Name + ".sql"); sqlHelper.StoreObj(storeFile, script.Type, name, Watch); } else { if (!this.newObjs.ContainsKey(script.Type)) { this.newObjs.Add(script.Type, new List <string>()); } this.newObjs[script.Type].Add(name); } Watch?.AddValue(1); } } Watch?.Info($"执行脚本 {name} , {script.File}"); var result = TryExecuteFile(script); this.files.Update(script.File, script.Status, storeFile); if (!result) { return(false); } Watch?.AddValue(1); } } return(true); }
public override bool Rollback() { this.RollbackStatus = RollbackStatus.Rollbacking; var result = RestoreBackup(backupName); Watch?.AddValue(-processValue); DoCmd(string.Format(DELETE_BACKUP, backupName)); this.RollbackStatus = result ? RollbackStatus.Complete : RollbackStatus.Failed; return(result); }
private void ReStore() { var files = Directory.GetFiles(storePath, "*", SearchOption.AllDirectories); foreach (var file in files) { var name = file.Replace(storePath, InstallContext.InstInfo.InstallPath); File.Copy(file, name, true); File.Delete(file); Watch?.AddValue(-1); } }
private bool UnZip(string tarFile, List <FileItem> files, string installPath) { using (var archive = ZipArchive.Open(tarFile, Compress.ReaderOptions)) { try { var entries = archive.Entries.ToDictionary(x => x.Key.Replace("/", "\\")); ZipArchiveEntry entry; ExtractionOptions extractionOptions = new ExtractionOptions { ExtractFullPath = true, Overwrite = true, PreserveFileTime = true }; if (entries.ContainsKey(Context.UninstallerKey)) { entry = entries[Context.UninstallerKey]; var path = Path.Combine(installPath, Context.UninstallerKey); entry.WriteToFile(path, extractionOptions); } foreach (var file in files) { if (entries.TryGetValue(file.Key, out entry)) { Watch?.Info($"抽取 [{file.Name}]"); var path = file.Path; FileHelper.RemoveReadonly(path); var info = new FileInfo(path); if (!Directory.Exists(info.Directory.FullName)) { Directory.CreateDirectory(info.Directory.FullName); newDirs.Push(info.Directory.FullName); } var flag = ExtractionFile(entry, info, file.FileOverride, extractionOptions); if (!flag) { return(false); } } Watch?.AddValue(1); } return(true); } catch (Exception e) { Watch?.Error(e.Message); return(false); } } }
private void Restore(ScriptType type) { var path = Path.Combine(storePath, type.ToString()); if (Directory.Exists(path)) { var scripts = Directory.GetFiles(path, "*.sql", SearchOption.TopDirectoryOnly); foreach (var script in scripts) { ExecuteFile(script, out string message); File.Delete(script); Watch?.AddValue(-2); } } }
public override bool Run() { if (!this.CanRun) { return(true); } this.CommandStatus = CommandStatus.Running; Watch?.SetStep("创建卸载程序"); var uninsDataPath = Path.Combine(InstallContext.InstInfo.InstallPath, "unins.data"); InstallContext.UninstallData.SaveToFile(uninsDataPath); Watch?.AddValue(10); this.CommandStatus = CommandStatus.Complete; return(true); }
public override bool Run() { if (!CanRun) { return(true); } this.CommandStatus = CommandStatus.Running; Watch?.SetStep("创建快捷方式"); if (!Directory.Exists(iconDir)) { Directory.CreateDirectory(iconDir); this.createIconDir = true; } foreach (var shortcut in shortCutInfos) { var name = shortcut.Name; if (!name.EndsWith(".url", StringComparison.OrdinalIgnoreCase) && !name.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase)) { name += ".lnk"; } var targetPath = InstallContext.ConvertPath(shortcut.TargetDir); if (Directory.Exists(targetPath)) { var path = Path.Combine(targetPath, name); FileHelper.RemoveReadonly(path); if (name.EndsWith(".url", StringComparison.OrdinalIgnoreCase)) { ShortcutHelper.CreateWebShortcutFile(path, shortcut.TargetDir); } else { var target = InstallContext.ConvertPath(shortcut.Target); ShortcutHelper.CreateShortcutFile(path, target, shortcut.Args); } Watch?.Info("-->" + path); Watch?.AddValue(1); InstallContext.UninstallData.Shortcuts.Add(path); } } this.CommandStatus = CommandStatus.Complete; return(true); }
public override bool Rollback() { if (!this.CanRollback) { return(true); } if (this.CommandStatus != CommandStatus.Complete && this.CommandStatus != CommandStatus.Failed && this.CommandStatus != CommandStatus.Running) { return(true); } this.RollbackStatus = RollbackStatus.Rollbacking; if (this.needStore) { Watch?.Info("正在还原数据库对象"); Restore(ScriptType.Trigger); Restore(ScriptType.Proc); Restore(ScriptType.Function); Restore(ScriptType.View); Watch?.Info("正在删除新增数据库对象"); foreach (var type in newObjs.Keys) { foreach (var name in newObjs[type]) { sqlHelper.DeleteObj(type, name); Watch?.AddValue(-1); } } Watch?.Info("正在删除数据库对象备份文件夹"); while (newDirs.Count > 0) { var dir = newDirs.Pop(); Directory.Delete(dir, true); } } this.RollbackStatus = RollbackStatus.Complete; return(true); }
public override bool Rollback() { if (!this.CanRollback) { return(true); } if (this.CommandStatus != CommandStatus.Complete && this.CommandStatus != CommandStatus.Failed && this.CommandStatus != CommandStatus.Running) { return(true); } this.RollbackStatus = RollbackStatus.Rollbacking; if (InstallContext.IsMakeStore) { Watch?.Info("正在还原历史文件"); this.ReStore(); Watch?.AddValue(-10); } Watch?.SetStep("正在删除文件"); foreach (var newFile in newFiles) { File.Delete(newFile); Watch?.AddValue(-1); } while (newDirs.Count > 0) { var dir = newDirs.Pop(); Directory.Delete(dir, true); } this.RollbackStatus = RollbackStatus.Complete; return(true); }