public Version GetVersionOfDefaultDownload() { string site; using (var client = HttpUtility.CreateWebClient()) { site = client.DownloadString(WebResourceUrls.SiteContainingCurrentVersion); } var match = Regex.Match(site, @"OutlookCalDavSynchronizer-(?<Major>\d+).(?<Minor>\d+).(?<Build>\d+).zip"); if (match.Success) { var availableVersion = new Version( int.Parse(match.Groups["Major"].Value), int.Parse(match.Groups["Minor"].Value), int.Parse(match.Groups["Build"].Value)); return(availableVersion); } else { return(null); } }
private void installButton_Click(object sender, EventArgs e) { try { var archivePath = Path.GetTempFileName(); using (var client = HttpUtility.CreateWebClient()) { client.DownloadFile(_newVersionDownloadUrl, archivePath); } var extractDirectory = Path.Combine(Path.GetTempPath(), "CalDavSynchronizer", Guid.NewGuid().ToString()); Directory.CreateDirectory(extractDirectory); ZipFile.ExtractToDirectory(archivePath, extractDirectory); File.Delete(archivePath); MessageBox.Show( "You need to restart Outlook after installing the new version!", "Outlook Restart required", MessageBoxButtons.OK, MessageBoxIcon.Information); // process hast to be a GC root to prevent it from being garbage collected. _latestSetupProcess = Process.Start(Path.Combine(extractDirectory, "setup.exe")); if (_latestSetupProcess != null) { _latestSetupProcess.EnableRaisingEvents = true; _latestSetupProcess.Exited += delegate { try { _latestSetupProcess = null; Process.Start(WebResourceUrls.ReadMeFileDownloadSite.ToString()); } catch (Exception x) { s_logger.Error("Error while downloading readme.md", x); } }; } DialogResult = DialogResult.OK; } catch (Exception ex) { s_logger.Warn("Can't download and extract new version", ex); MessageBox.Show("Can't download and extract new version!", "CalDav Synchronizer Download failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void installButton_Click(object sender, EventArgs e) { try { using (var client = HttpUtility.CreateWebClient()) { client.DownloadProgressChanged += client_DownloadProgressChanged; client.DownloadFileCompleted += client_DownloadFileCompleted; _progressBar.Visible = true; client.DownloadFileAsync(_newVersionDownloadUrl, _archivePath); } } catch (Exception ex) { s_logger.Warn("Can't download new version", ex); MessageBox.Show("Can't download new version!", "CalDav Synchronizer Download failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public string GetWhatsNewNoThrow(Version oldVersion, Version newVersion) { try { string readme; using (var client = HttpUtility.CreateWebClient()) { readme = client .DownloadString(WebResourceUrls.ReadMeFile) .Replace("\n", Environment.NewLine).Replace("\t", " "); } var start = Find(readme, newVersion); var end = Find(readme, oldVersion); if (start == -1 || end == -1) { if (start == -1) { s_logger.ErrorFormat("Did not find Version '{0}' in readme.md", newVersion); } if (end == -1) { s_logger.ErrorFormat("Did not find Version '{0}' in readme.md", oldVersion); } return(Strings.Get($"Did not find any news.")); } return(readme.Substring(start, end - start)); } catch (Exception x) { s_logger.Error(null, x); return(Strings.Get($"Error while trying to fetch the news.\r\nPlease see logfile for details.")); } }
private async Task MapPhoto2To1(vCard source, ContactItem target, IEntityMappingLogger logger) { if (source.Photos.Count > 0) { if (target.HasPicture && _configuration.KeepOutlookPhoto) { return; } vCardPhoto contactPhoto = source.Photos[0]; string picturePath = Path.GetTempPath() + @"\Contact_" + target.EntryID + ".jpg"; try { if (!contactPhoto.IsLoaded && contactPhoto.Url != null) { using (var client = HttpUtility.CreateWebClient()) { await client.DownloadFileTaskAsync(contactPhoto.Url, picturePath); } } else if (contactPhoto.IsLoaded) { File.WriteAllBytes(picturePath, contactPhoto.GetBytes()); } else { s_logger.Warn("Could not load picture for contact."); logger.LogMappingWarning("Could not load picture for contact."); return; } try { target.AddPicture(picturePath); } catch (COMException x) { s_logger.Warn("Could not add picture for contact.", x); logger.LogMappingWarning("Could not add picture for contact.", x); } File.Delete(picturePath); } catch (Exception ex) { s_logger.Warn("Could not add picture for contact.", ex); logger.LogMappingWarning("Could not add picture for contact.", ex); } } else { if (target.HasPicture) { try { target.RemovePicture(); } catch (COMException x) { s_logger.Warn("Could not remove picture for contact.", x); logger.LogMappingWarning("Could not remove picture for contact.", x); } } } }