private void Form1_Shown(object sender, EventArgs e) { Task.Run(() => { if (File.Exists(downloadFile)) { try { ZipArchive zip = new ZipArchive(new MemoryStream(File.ReadAllBytes(downloadFile))); ZipArchiveExtensions.ExtractToDirectory(zip, extractLocation, true); File.Delete(downloadFile); } catch (Exception ex) { } var process = new Process { StartInfo = new ProcessStartInfo { FileName = startAfter // Arguments = string.Join(" ", Environment.GetCommandLineArgs()) } }; process.Start(); process.WaitForInputIdle(); Application.Exit(); Environment.Exit(0); } else { var process = new Process { StartInfo = new ProcessStartInfo { FileName = startAfter // Arguments = string.Join(" ", Environment.GetCommandLineArgs()) } }; process.Start(); process.WaitForInputIdle(); Application.Exit(); Environment.Exit(0); } }); }
private void timer_update_Tick(object sender, EventArgs e) { string[] updateDownload; using (var wc = new WebClient()) updateDownload = wc.DownloadString(ini.IniReadValue("VERSION", "UpdateDownloadUrl")).Split(new[] { '\r', '\n' }); if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); lbl_action.Text = "Create temp download folder"; } string zip_path = tempFolder + "\\" + Guid.NewGuid() + ".zip"; updateActionLabel("Downloading update"); using (WebClient wc = new WebClient()) { wc.DownloadFile( // download link new Uri(updateDownload[0]), // physical link zip_path ); } updateActionLabel("Extracting files and updating CODEx"); string install_path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); using (var strm = File.OpenRead(zip_path)) using (ZipArchive archive = new ZipArchive(strm)) ZipArchiveExtensions.ExtractToDirectory(archive, install_path, true); updateActionLabel("Updating CODEx config file"); ini.IniWriteValue("VERSION", "CurrentVersion", new WebClient().DownloadString(ini.IniReadValue("VERSION", "LastestVersionUrl"))); updateActionLabel("Update is done"); pnl_loading.Dispose(); btn_end.Visible = true; timer_update.Stop(); }
public DtoModuleResult Run() { Logger.Info("Running File Copy Module: " + _module.DisplayName); if (_module.Destination.Equals("[toec-appdata]")) { Logger.Debug("Module Has No Destination. Module Is Cached Only."); } else { if (!_fileSystemService.CreateDestinationDirectory(_module.Destination)) { _moduleResult.Success = false; _moduleResult.ExitCode = "-1"; _moduleResult.ErrorMessage = "Could Not Create Destination Directory"; return(_moduleResult); } } foreach (var file in _module.Files) { Logger.Debug(string.Format("Processing File {0}", file.FileName)); if (!File.Exists(Path.Combine(DtoGobalSettings.BaseCachePath, _module.Guid, file.FileName))) { Logger.Debug("File No Longer Exists: " + Path.Combine(DtoGobalSettings.BaseCachePath, _module.Guid, file.FileName)); _moduleResult.Success = false; _moduleResult.ExitCode = "-1"; _moduleResult.ErrorMessage = "The File No Longer Exists."; return(_moduleResult); } var extension = Path.GetExtension(file.FileName); if (_module.Unzip && !string.IsNullOrEmpty(extension) && extension.ToLower().Equals(".zip")) { if (_module.Destination.Equals("[toec-appdata]")) { _module.Destination = Path.Combine(DtoGobalSettings.BaseCachePath, _module.Guid); } try { var path = Path.Combine(DtoGobalSettings.BaseCachePath, _module.Guid, file.FileName); using (FileStream zipToOpen = new FileStream(path, FileMode.Open)) { using (ZipArchive archive = new ZipArchive(zipToOpen)) { ZipArchiveExtensions.ExtractToDirectory(archive, _module.Destination, true); } } } catch (Exception ex) { Logger.Error("Could Not Unzip File"); Logger.Error(ex.Message); _moduleResult.Success = false; _moduleResult.ExitCode = "-1"; _moduleResult.ErrorMessage = "Could Not Unzip File To Destination"; return(_moduleResult); } } else if (_module.Destination.Equals("[toec-appdata]")) { //do nothing, file was already copied during cacheing } else { if ( !_fileSystemService.CopyFile( Path.Combine(DtoGobalSettings.BaseCachePath, _module.Guid, file.FileName), Path.Combine(_module.Destination, file.FileName))) { _moduleResult.Success = false; _moduleResult.ExitCode = "-1"; _moduleResult.ErrorMessage = "Could Not Copy File To Destination"; return(_moduleResult); } } } Logger.Info($"File Copy Module {_module.DisplayName} Completed"); return(_moduleResult); }