public void Update() { if (this.updatedManifest == null) { throw new UpdateException("You must call CheckForUpdate first to determine if an update is available."); } if (this.updateAvailable) { if (Directory.Exists(this.updateTempFolder)) { Directory.Delete(updateTempFolder, true); } Directory.CreateDirectory(this.updateTempFolder); InstallInfo info = new InstallInfo(); info.ZipFile = Path.Combine(updateTempFolder, "update.zip"); info.SetupFile = Path.Combine(updateTempFolder, "setup.exe"); info.Folder = updateTempFolder; Growl.CoreLibrary.WebClientEx downloader = new Growl.CoreLibrary.WebClientEx(); using (downloader) { downloader.Headers.Add("User-Agent", "Element.AutoUpdate.Updater"); downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged); downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted); downloader.DownloadFileAsync(new Uri(this.updatedManifest.InstallerLocation), info.ZipFile, info); } } }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing) { if (this.wc != null) { wc.DownloadProgressChanged -= new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged); wc.DownloadFileCompleted -= new AsyncCompletedEventHandler(wc_DownloadFileCompleted); wc.Dispose(); wc = null; } if (this.mre != null) { mre.Close(); } if (this.are != null) { are.Close(); } if (this.components != null) { components.Dispose(); } } base.Dispose(disposing); }
private void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { Kill(); if (this.timer != null) { this.timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); this.timer.Dispose(); this.timer = null; } if (this.webclient != null) { this.webclient.OpenReadCompleted -= new OpenReadCompletedEventHandler(webclient_OpenReadCompleted); this.webclient.Dispose(); this.webclient = null; } } this.disposed = true; } }
private void SendAsync(object state) { try { // data System.Collections.Specialized.NameValueCollection data = (System.Collections.Specialized.NameValueCollection)state; // prepare the WebClient Uri uri = new Uri(URL); Growl.CoreLibrary.WebClientEx wc = new Growl.CoreLibrary.WebClientEx(); using (wc) { wc.Headers.Add(System.Net.HttpRequestHeader.UserAgent, "Growl for Windows/2.0"); wc.Headers.Add(System.Net.HttpRequestHeader.ContentType, "application/x-www-form-urlencoded"); // do it try { byte[] bytes = wc.UploadValues(uri, "POST", data); string response = System.Text.Encoding.ASCII.GetString(bytes); Utility.WriteDebugInfo(String.Format("Prowl forwarding response: {0}", response)); } catch (Exception ex) { Utility.WriteDebugInfo(String.Format("Prowl forwarding failed: {0}", ex.Message)); } } } catch (Exception ex) { Utility.WriteDebugInfo(ex.ToString()); } }
private void SendAsync(object state) { try { byte[] data = (byte[])state; string url = "http://twitter.com/statuses/update.xml"; string credentials = String.Format("{0}:{1}", this.Username, this.Password); string encodedCredentials = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(credentials)); string authorizationHeaderValue = String.Format("Basic {0}", encodedCredentials); Growl.CoreLibrary.WebClientEx wc = new Growl.CoreLibrary.WebClientEx(); wc.Headers.Add(System.Net.HttpRequestHeader.UserAgent, "Growl for Windows/2.0"); wc.Headers.Add(System.Net.HttpRequestHeader.Authorization, authorizationHeaderValue); wc.Headers.Add(System.Net.HttpRequestHeader.ContentType, "application/x-www-form-urlencoded"); using (wc) { try { byte[] bytes = wc.UploadData(url, "POST", data); string response = System.Text.Encoding.ASCII.GetString(bytes); Utility.WriteDebugInfo(String.Format("Twitter forwarding response: {0}", response)); } catch (Exception ex) { Utility.WriteDebugInfo(String.Format("Twitter forwarding failed: {0}", ex.Message)); } } } catch (Exception ex) { Utility.WriteDebugInfo(ex.ToString()); } }
private Updater(string appPath, string currentVersion, string updateLocation) { this.appPath = appPath; this.manifestFile = Path.Combine(this.appPath, MANIFEST_FILE_NAME); this.currentVersion = currentVersion; this.updateLocation = updateLocation; this.updateTempFolder = Path.Combine(Utility.UserSettingFolder, UPDATE_FOLDER); this.checker = new Growl.CoreLibrary.WebClientEx(); checker.Headers.Add("User-Agent", "Element.AutoUpdate.Updater"); checker.DownloadStringCompleted += new DownloadStringCompletedEventHandler(checker_DownloadStringCompleted); }
private Updater(string appPath, string currentVersion, string updateLocation) { this.appPath = appPath; this.manifestFile = Path.Combine(this.appPath, MANIFEST_FILE_NAME); this.currentVersion = currentVersion; this.updateLocation = updateLocation; this.updateTempFolder = Path.Combine(Utility.UserSettingFolder, UPDATE_FOLDER); this.checker = new Growl.CoreLibrary.WebClientEx(); checker.Headers.Add("User-Agent", "Element.AutoUpdate.Updater"); checker.DownloadStringCompleted += new DownloadStringCompletedEventHandler(checker_DownloadStringCompleted); }
private void Initialize() { this.timer = new System.Timers.Timer(); this.timer.AutoReset = false; this.timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); this.webclient = new Growl.CoreLibrary.WebClientEx(); this.webclient.Encoding = Encoding.UTF8; this.webclient.OpenReadCompleted += new OpenReadCompletedEventHandler(webclient_OpenReadCompleted); this.ntNewFeedItem = new NotificationType("New Feed Item", "New Feed Item"); this.ntFeedError = new NotificationType("Feed Error", "Feed Error"); }
private void Initialize() { this.timer = new System.Timers.Timer(); this.timer.AutoReset = false; this.timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); this.webclient = new Growl.CoreLibrary.WebClientEx(); this.webclient.Encoding = Encoding.UTF8; this.webclient.OpenReadCompleted += new OpenReadCompletedEventHandler(webclient_OpenReadCompleted); this.ntNewFeedItem = new NotificationType("New Feed Item", "New Feed Item"); this.ntFeedError = new NotificationType("Feed Error", "Feed Error"); }
private void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (this.checker != null) { this.checker.DownloadStringCompleted -= new DownloadStringCompletedEventHandler(checker_DownloadStringCompleted); this.checker.Dispose(); this.checker = null; } } this.disposed = true; } }
/// <summary> /// Called when a notification is received by GfW. /// </summary> /// <param name="notification">The notification information</param> /// <param name="callbackContext">The callback context.</param> /// <param name="requestInfo">The request info.</param> /// <param name="isIdle"><c>true</c> if the user is currently idle;<c>false</c> otherwise</param> /// <param name="callbackFunction">The function GfW will run if this notification is responded to on the forwarded computer</param> /// <remarks> /// Unless your forwarder is going to handle socket-style callbacks from the remote computer, you should ignore /// the <paramref name="callbackFunction"/> parameter. /// </remarks> public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardDestination.ForwardedNotificationCallbackHandler callbackFunction) { try { QuerystringBuilder qsb = new QuerystringBuilder(); qsb.Add("app", notification.ApplicationName); qsb.Add("id", notification.ID); qsb.Add("type", notification.Name); qsb.Add("title", notification.Title); qsb.Add("text", notification.Text); qsb.Add("sticky", notification.Sticky); qsb.Add("priority", (int)notification.Priority); qsb.Add("coalescingid", notification.CoalescingID); if (notification.CustomTextAttributes != null) { foreach (KeyValuePair <string, string> item in notification.CustomTextAttributes) { qsb.Add(item.Key, item.Value); } } string data = qsb.ToPostData(); Growl.CoreLibrary.WebClientEx wc = new Growl.CoreLibrary.WebClientEx(); using (wc) { wc.Headers.Add(HttpRequestHeader.UserAgent, "Growl for Windows Webhook Plugin/1.0"); string result = wc.UploadString(this.url, data); Console.WriteLine(result); } } catch (Exception ex) { // this is an example of writing to the main GfW debug log: Growl.CoreLibrary.DebugInfo.WriteLine(String.Format("Webhook forwarding failed: {0}", ex.Message)); } }
void downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { if (e.Error != null) { UpdateErrorEventArgs args = new UpdateErrorEventArgs(e.Error, "An error occurred while downloading the necessary update files. Please try again later."); this.OnUpdateError(args); } else if (e.Cancelled) { UpdateException ex = new UpdateException("Update was cancelled"); UpdateErrorEventArgs args = new UpdateErrorEventArgs(ex, "Update cancelled."); this.OnUpdateError(args); } else { this.OnDownloadComplete(EventArgs.Empty); // unzip files InstallInfo info = (InstallInfo)e.UserState; Installation.Unzipper.UnZipFiles(info.ZipFile, info.Folder, false); // start the update installer string setupFile = info.SetupFile; System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(setupFile); System.Diagnostics.Process.Start(si); // exit this application ApplicationMain.Program.ExitApp(); } Growl.CoreLibrary.WebClientEx downloader = (Growl.CoreLibrary.WebClientEx)sender; downloader.DownloadProgressChanged -= new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged); downloader.DownloadFileCompleted -= new AsyncCompletedEventHandler(downloader_DownloadFileCompleted); downloader.Dispose(); downloader = null; }
public bool LaunchInstaller(string uri, bool appIsAlreadyRunning, ref List <InternalNotification> queuedNotifications, ref int cultureCodeHash) { bool languageInstalled = false; this.uri = uri; this.appIsAlreadyRunning = appIsAlreadyRunning; try { // handle special case where we are resetting the value if (uri == "reset") { Properties.Settings.Default.CultureCode = ""; Properties.Settings.Default.Save(); cultureCodeHash = 0; languageInstalled = true; return(languageInstalled); } this.wc = new Growl.CoreLibrary.WebClientEx(); wc.Headers.Add("User-Agent", USER_AGENT); byte[] data = wc.DownloadData(this.uri); string definition = Encoding.UTF8.GetString(data).Trim(); LanguageInfo info = LanguageInfo.Parse(definition); if (info != null) { this.InfoLabel.Text = String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_Prompt), info.Name); this.YesButton.Visible = true; this.NoButton.Visible = true; this.OKButton.Visible = false; /* NOTE: there is a bug that is caused when Growl is launched via protocol handler (growl:) from Opera. * * when that happens, the call to ShowDialog hangs. * * i could not find any documentation on this or any reason why it would be happening (not on a non-ui thread, windows handle is already created, etc). * * the only fix i could find was to Show/Hide the form before calling ShowDialog. i dont even know why this works, but it does. * * */ this.Show(); this.Hide(); DialogResult result = this.ShowDialog(); if (result == DialogResult.Yes) { this.InfoLabel.Text = Utility.GetResourceString(Properties.Resources.LanguageInstaller_Installing); this.progressBar1.Value = 0; this.progressBar1.Visible = true; this.YesButton.Enabled = false; this.NoButton.Enabled = false; this.Show(); this.Refresh(); if (Directory.Exists(this.tempFolder)) { Directory.Delete(this.tempFolder, true); } Directory.CreateDirectory(this.tempFolder); string guid = System.Guid.NewGuid().ToString(); string zipFileName = GetTempZipFileName(guid); info.LocalZipFileLocation = zipFileName; wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged); wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted); StartDownload(info); Utility.WriteDebugInfo(String.Format("Downloading language pack '{0}' to {1}", info.Name, info.LocalZipFileLocation)); System.Threading.WaitHandle[] handles = new System.Threading.WaitHandle[] { are, mre }; while (System.Threading.WaitHandle.WaitAny(handles) == 0) { lock (this.progress_lock) { this.progressBar1.Value = this.progress.ProgressPercentage; Application.DoEvents(); } } this.progressBar1.Value = 100; Application.DoEvents(); Utility.WriteDebugInfo(String.Format("Finished downloading language pack '{0}' to {1}", info.Name, info.LocalZipFileLocation)); if (this.errorMessage == null) { // unzip files to the correct location string languageFolder = GetLanguageFolder(info.CultureCode); if (!ApplicationMain.HasProgramLaunchedYet || !Directory.Exists(languageFolder)) { Utility.WriteDebugInfo(String.Format("Language '{0}' downloaded - starting unzip.", info.Name)); // NOTE: installing a language pack requires elevated privileges (to write the resource assemblies to the bin folder). // as such, we have to be elevated first if (UserAccountControlHelper.IsElevated()) { cultureCodeHash = UnzipFilesToBin(info.Name, info.LocalZipFileLocation, info.CultureCode, ref queuedNotifications); } else { string argument = String.Format("growl:languageelevatedinstall*{0}~{1}~{2}", info.CultureCode, info.Name, guid); UserAccountControlHelper.LaunchElevatedApplication(System.Windows.Forms.Application.ExecutablePath, argument, true); } this.Close(); } else { // display with the same name aleady exists... ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_AlreadyInstalled), info.Name), true); } } else { Utility.WriteDebugInfo(String.Format("Error downloading language pack '{0}'.", info.Name)); ShowMessage(errorMessage, true); } } } else { // definition file was malformed ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_BadDefinitionFile), this.uri), true); } } catch (Exception ex) { // error downloading definition file Utility.WriteDebugInfo(String.Format("Error downloading language pack. {0} - {1}", ex.Message, ex.StackTrace)); ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_NonexistentDefinitionFile), this.uri), true); } return(languageInstalled); }
public bool LaunchInstaller(string uri, bool appIsAlreadyRunning, ref List <InternalNotification> queuedNotifications, ref int cultureCodeHash) { bool installed = false; this.uri = uri; this.appIsAlreadyRunning = appIsAlreadyRunning; this.tempFolder = Path.Combine(Utility.UserSettingFolder, TEMP_FOLDER); try { this.wc = new Growl.CoreLibrary.WebClientEx(); wc.Headers.Add("User-Agent", USER_AGENT); byte[] data = wc.DownloadData(this.uri); string definition = Encoding.UTF8.GetString(data).Trim(); SubscriberInfo info = SubscriberInfo.Parse(definition); if (info != null) { this.InfoLabel.Text = String.Format(Utility.GetResourceString(Properties.Resources.SubscriberInstaller_Prompt), info.Name, info.Author, info.Description); this.YesButton.Visible = true; this.NoButton.Visible = true; this.OKButton.Visible = false; /* NOTE: there is a bug that is caused when Growl is launched via protocol handler (growl:) from Opera. * * when that happens, the call to ShowDialog hangs. * * i could not find any documentation on this or any reason why it would be happening (not on a non-ui thread, windows handle is already created, etc). * * the only fix i could find was to Show/Hide the form before calling ShowDialog. i dont even know why this works, but it does. * * */ this.Show(); this.Hide(); DialogResult result = this.ShowDialog(); if (result == DialogResult.Yes) { this.InfoLabel.Text = Utility.GetResourceString(Properties.Resources.SubscriberInstaller_Installing); this.progressBar1.Value = 0; this.progressBar1.Visible = true; this.YesButton.Enabled = false; this.NoButton.Enabled = false; this.Show(); this.Refresh(); if (Directory.Exists(this.tempFolder)) { Directory.Delete(this.tempFolder, true); } Directory.CreateDirectory(this.tempFolder); string zipFileName = Path.Combine(this.tempFolder, String.Format("{0}.zip", System.Guid.NewGuid().ToString())); info.LocalZipFileLocation = zipFileName; wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged); wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted); StartDownload(info); Utility.WriteDebugInfo(String.Format("Downloading subscriber plugin '{0}' to {1}", info.Name, info.LocalZipFileLocation)); System.Threading.WaitHandle[] handles = new System.Threading.WaitHandle[] { are, mre }; while (System.Threading.WaitHandle.WaitAny(handles) == 0) { lock (this.progress_lock) { this.progressBar1.Value = this.progress.ProgressPercentage; Application.DoEvents(); } } this.progressBar1.Value = 100; Application.DoEvents(); Utility.WriteDebugInfo(String.Format("Finished downloading subscriber plugin '{0}' to {1}", info.Name, info.LocalZipFileLocation)); if (this.errorMessage == null) { // unzip files to the correct location string folder = Path.Combine(SubscriptionManager.UserPluginDirectory, Growl.CoreLibrary.PathUtility.GetSafeFolderName(info.Name)); if (!ApplicationMain.HasProgramLaunchedYet || !Directory.Exists(folder)) { Utility.WriteDebugInfo(String.Format("Subscriber '{0}' downloaded - starting unzip.", info.Name)); Unzipper.UnZipFiles(info.LocalZipFileLocation, folder, false); string text = String.Format(Properties.Resources.SubscriberInstaller_InstalledText, info.Name); InternalNotification n = new InternalNotification(Properties.Resources.SubscriberInstaller_InstalledTitle, Utility.GetResourceString(text), null); queuedNotifications.Add(n); installed = true; this.Close(); } else { // display with the same name aleady exists... ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.SubscriberInstaller_AlreadyInstalled), info.Name), true); } // clean up Utility.WriteDebugInfo(String.Format("Deleteing '{0}' zip file at {1}", info.Name, info.LocalZipFileLocation)); if (File.Exists(info.LocalZipFileLocation)) { File.Delete(info.LocalZipFileLocation); } } else { Utility.WriteDebugInfo(String.Format("Error downloading subscriber plugin '{0}'.", info.Name)); ShowMessage(errorMessage, true); } } } else { // definition file was malformed ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.SubscriberInstaller_BadDefinitionFile), this.uri), true); } } catch (Exception ex) { // error downloading definition file Utility.WriteDebugInfo(String.Format("Error downloading subscriber plugin. {0} - {1}", ex.Message, ex.StackTrace)); ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.SubscriberInstaller_NonexistentDefinitionFile), this.uri), true); } return(installed); }
public bool LaunchInstaller(string uri, bool appIsAlreadyRunning, ref List<InternalNotification> queuedNotifications, ref int cultureCodeHash) { bool languageInstalled = false; this.uri = uri; this.appIsAlreadyRunning = appIsAlreadyRunning; try { // handle special case where we are resetting the value if (uri == "reset") { Properties.Settings.Default.CultureCode = ""; Properties.Settings.Default.Save(); cultureCodeHash = 0; languageInstalled = true; return languageInstalled; } this.wc = new Growl.CoreLibrary.WebClientEx(); wc.Headers.Add("User-Agent", USER_AGENT); byte[] data = wc.DownloadData(this.uri); string definition = Encoding.UTF8.GetString(data).Trim(); LanguageInfo info = LanguageInfo.Parse(definition); if (info != null) { this.InfoLabel.Text = String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_Prompt), info.Name); this.YesButton.Visible = true; this.NoButton.Visible = true; this.OKButton.Visible = false; /* NOTE: there is a bug that is caused when Growl is launched via protocol handler (growl:) from Opera. * when that happens, the call to ShowDialog hangs. * i could not find any documentation on this or any reason why it would be happening (not on a non-ui thread, windows handle is already created, etc). * the only fix i could find was to Show/Hide the form before calling ShowDialog. i dont even know why this works, but it does. * */ this.Show(); this.Hide(); DialogResult result = this.ShowDialog(); if (result == DialogResult.Yes) { this.InfoLabel.Text = Utility.GetResourceString(Properties.Resources.LanguageInstaller_Installing); this.progressBar1.Value = 0; this.progressBar1.Visible = true; this.YesButton.Enabled = false; this.NoButton.Enabled = false; this.Show(); this.Refresh(); if (Directory.Exists(this.tempFolder)) Directory.Delete(this.tempFolder, true); Directory.CreateDirectory(this.tempFolder); string guid = System.Guid.NewGuid().ToString(); string zipFileName = GetTempZipFileName(guid); info.LocalZipFileLocation = zipFileName; wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged); wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted); StartDownload(info); Utility.WriteDebugInfo(String.Format("Downloading language pack '{0}' to {1}", info.Name, info.LocalZipFileLocation)); System.Threading.WaitHandle[] handles = new System.Threading.WaitHandle[] { are, mre }; while (System.Threading.WaitHandle.WaitAny(handles) == 0) { lock (this.progress_lock) { this.progressBar1.Value = this.progress.ProgressPercentage; Application.DoEvents(); } } this.progressBar1.Value = 100; Application.DoEvents(); Utility.WriteDebugInfo(String.Format("Finished downloading language pack '{0}' to {1}", info.Name, info.LocalZipFileLocation)); if (this.errorMessage == null) { // unzip files to the correct location string languageFolder = GetLanguageFolder(info.CultureCode); if (!ApplicationMain.HasProgramLaunchedYet || !Directory.Exists(languageFolder)) { Utility.WriteDebugInfo(String.Format("Language '{0}' downloaded - starting unzip.", info.Name)); // NOTE: installing a language pack requires elevated privileges (to write the resource assemblies to the bin folder). // as such, we have to be elevated first if (UserAccountControlHelper.IsElevated()) { cultureCodeHash = UnzipFilesToBin(info.Name, info.LocalZipFileLocation, info.CultureCode, ref queuedNotifications); } else { string argument = String.Format("growl:languageelevatedinstall*{0}~{1}~{2}", info.CultureCode, info.Name, guid); UserAccountControlHelper.LaunchElevatedApplication(System.Windows.Forms.Application.ExecutablePath, argument, true); } this.Close(); } else { // display with the same name aleady exists... ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_AlreadyInstalled), info.Name), true); } } else { Utility.WriteDebugInfo(String.Format("Error downloading language pack '{0}'.", info.Name)); ShowMessage(errorMessage, true); } } } else { // definition file was malformed ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_BadDefinitionFile), this.uri), true); } } catch (Exception ex) { // error downloading definition file Utility.WriteDebugInfo(String.Format("Error downloading language pack. {0} - {1}", ex.Message, ex.StackTrace)); ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_NonexistentDefinitionFile), this.uri), true); } return languageInstalled; }
private void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { Kill(); if (this.timer != null) { this.timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); this.timer.Dispose(); this.timer = null; } if (this.webclient != null) { this.webclient.OpenReadCompleted -= new OpenReadCompletedEventHandler(webclient_OpenReadCompleted); this.webclient.Dispose(); this.webclient = null; } } this.disposed = true; } }
private void SendAsync(object state) { try { // data System.Collections.Specialized.NameValueCollection data = (System.Collections.Specialized.NameValueCollection)state; // prepare the WebClient Uri uri = new Uri(URL); Growl.CoreLibrary.WebClientEx wc = new Growl.CoreLibrary.WebClientEx(); using (wc) { wc.Headers.Add(System.Net.HttpRequestHeader.UserAgent, "Growl for Windows/2.0"); wc.Headers.Add(System.Net.HttpRequestHeader.ContentType, "application/x-www-form-urlencoded"); // do it try { byte[] bytes = wc.UploadValues(uri, "POST", data); string response = System.Text.Encoding.ASCII.GetString(bytes); Utility.WriteDebugInfo(String.Format("Prowl forwarding response: {0}", response)); } catch(Exception ex) { Utility.WriteDebugInfo(String.Format("Prowl forwarding failed: {0}", ex.Message)); } } } catch(Exception ex) { Utility.WriteDebugInfo(ex.ToString()); } }
/// </summary> /// <param name="notification">The notification information</param> /// <summary> /// Called when a notification is received by GfW. /// </summary> /// <param name="notification">The notification information</param> /// <param name="callbackContext">The callback context.</param> /// <param name="requestInfo">The request info.</param> /// <param name="isIdle"><c>true</c> if the user is currently idle;<c>false</c> otherwise</param> /// <param name="callbackFunction">The function GfW will run if this notification is responded to on the forwarded computer</param> public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardDestination.ForwardedNotificationCallbackHandler callbackFunction) { if ((isIdle == false && sendIfIdle == true) || !((int)notification.Priority >= converttolocal(this.selectedpriority))) { return; } try { QuerystringBuilder qsb = new QuerystringBuilder(); qsb.Add("token", APP_API_KEY); qsb.Add("user", api); qsb.Add("title", notification.Title); qsb.Add("sound", sounds[selectedSound]); qsb.Add("message",notification.Text); qsb.Add("priority", ConvertNotificationStyle(notification)); if (selectedSound != 0) { qsb.Add("sound", sounds[selectedSound]); } if (device.Length > 0) { qsb.Add("device", device); } string data = qsb.ToPostData(); Growl.CoreLibrary.WebClientEx wc = new Growl.CoreLibrary.WebClientEx(); using (wc) { wc.Headers.Add(HttpRequestHeader.UserAgent, "Pushover GfW Plugin/1.0"); string result = wc.UploadString(DEST, data); Console.WriteLine(result); } } catch (Exception ex) { Growl.CoreLibrary.DebugInfo.WriteLine(String.Format("Pushover forwarding failed: {0}", ex.Message)); } }
public void Update() { if (this.updatedManifest == null) throw new UpdateException("You must call CheckForUpdate first to determine if an update is available."); if (this.updateAvailable) { if (Directory.Exists(this.updateTempFolder)) Directory.Delete(updateTempFolder, true); Directory.CreateDirectory(this.updateTempFolder); InstallInfo info = new InstallInfo(); info.ZipFile = Path.Combine(updateTempFolder, "update.zip"); info.SetupFile = Path.Combine(updateTempFolder, "setup.exe"); info.Folder = updateTempFolder; Growl.CoreLibrary.WebClientEx downloader = new Growl.CoreLibrary.WebClientEx(); using (downloader) { downloader.Headers.Add("User-Agent", "Element.AutoUpdate.Updater"); downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged); downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted); downloader.DownloadFileAsync(new Uri(this.updatedManifest.InstallerLocation), info.ZipFile, info); } } }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing) { if (this.wc != null) { wc.DownloadProgressChanged -= new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged); wc.DownloadFileCompleted -= new AsyncCompletedEventHandler(wc_DownloadFileCompleted); wc.Dispose(); wc = null; } if (this.mre != null) mre.Close(); if (this.are != null) are.Close(); if (this.components != null) components.Dispose(); } base.Dispose(disposing); }
/// <summary> /// Called when a notification is received by GfW. /// </summary> /// <param name="notification">The notification information</param> /// <param name="callbackContext">The callback context.</param> /// <param name="requestInfo">The request info.</param> /// <param name="isIdle"><c>true</c> if the user is currently idle;<c>false</c> otherwise</param> /// <param name="callbackFunction">The function GfW will run if this notification is responded to on the forwarded computer</param> /// <remarks> /// Unless your forwarder is going to handle socket-style callbacks from the remote computer, you should ignore /// the <paramref name="callbackFunction"/> parameter. /// </remarks> public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardDestination.ForwardedNotificationCallbackHandler callbackFunction) { try { QuerystringBuilder qsb = new QuerystringBuilder(); qsb.Add("app", notification.ApplicationName); qsb.Add("id", notification.ID); qsb.Add("type", notification.Name); qsb.Add("title", notification.Title); qsb.Add("text", notification.Text); qsb.Add("sticky", notification.Sticky); qsb.Add("priority", (int)notification.Priority); qsb.Add("coalescingid", notification.CoalescingID); if (notification.CustomTextAttributes != null) { foreach (KeyValuePair<string, string> item in notification.CustomTextAttributes) { qsb.Add(item.Key, item.Value); } } string data = qsb.ToPostData(); Growl.CoreLibrary.WebClientEx wc = new Growl.CoreLibrary.WebClientEx(); using (wc) { wc.Headers.Add(HttpRequestHeader.UserAgent, "Growl for Windows Webhook Plugin/1.0"); string result = wc.UploadString(this.url, data); Console.WriteLine(result); } } catch (Exception ex) { // this is an example of writing to the main GfW debug log: Growl.CoreLibrary.DebugInfo.WriteLine(String.Format("Webhook forwarding failed: {0}", ex.Message)); } }
public bool LaunchInstaller(string uri, bool appIsAlreadyRunning, ref List<InternalNotification> queuedNotifications) { bool newDisplayLoaded = false; this.uri = uri; this.appIsAlreadyRunning = appIsAlreadyRunning; this.tempFolder = Path.Combine(Utility.UserSettingFolder, TEMP_FOLDER); try { this.wc = new Growl.CoreLibrary.WebClientEx(); wc.Headers.Add("User-Agent", USER_AGENT); byte[] data = wc.DownloadData(this.uri); string definition = Encoding.UTF8.GetString(data).Trim(); DisplayInfo info = DisplayInfo.Parse(definition); if (info != null) { this.InfoLabel.Text = String.Format(Utility.GetResourceString(Properties.Resources.DisplayInstaller_Prompt), info.Name, info.Author, info.Description); this.YesButton.Visible = true; this.NoButton.Visible = true; this.OKButton.Visible = false; /* NOTE: there is a bug that is caused when Growl is launched via protocol handler (growl:) from Opera. * when that happens, the call to ShowDialog hangs. * i could not find any documentation on this or any reason why it would be happening (not on a non-ui thread, windows handle is already created, etc). * the only fix i could find was to Show/Hide the form before calling ShowDialog. i dont even know why this works, but it does. * */ this.Show(); this.Hide(); DialogResult result = this.ShowDialog(); if (result == DialogResult.Yes) { this.InfoLabel.Text = Utility.GetResourceString(Properties.Resources.DisplayInstaller_Installing); this.progressBar1.Value = 0; this.progressBar1.Visible = true; this.YesButton.Enabled = false; this.NoButton.Enabled = false; this.Show(); this.Refresh(); if (Directory.Exists(this.tempFolder)) Directory.Delete(this.tempFolder, true); Directory.CreateDirectory(this.tempFolder); string zipFileName = Path.Combine(this.tempFolder, String.Format("{0}.zip", System.Guid.NewGuid().ToString())); info.LocalZipFileLocation = zipFileName; wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged); wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted); StartDownload(info); Utility.WriteDebugInfo(String.Format("Downloading display '{0}' to {1}", info.Name, info.LocalZipFileLocation)); System.Threading.WaitHandle[] handles = new System.Threading.WaitHandle[] { are, mre }; while (System.Threading.WaitHandle.WaitAny(handles) == 0) { lock (this.progress_lock) { this.progressBar1.Value = this.progress.ProgressPercentage; Application.DoEvents(); } } this.progressBar1.Value = 100; Application.DoEvents(); Utility.WriteDebugInfo(String.Format("Finished downloading display '{0}' to {1}", info.Name, info.LocalZipFileLocation)); if (this.errorMessage == null) { // unzip files to the correct location string newDisplayFolder = Path.Combine(DisplayStyleManager.UserDisplayStyleDirectory, Growl.CoreLibrary.PathUtility.GetSafeFolderName(info.Name)); if (!ApplicationMain.HasProgramLaunchedYet || !Directory.Exists(newDisplayFolder)) { Utility.WriteDebugInfo(String.Format("Display '{0}' downloaded - starting unzip.", info.Name)); Unzipper.UnZipFiles(info.LocalZipFileLocation, newDisplayFolder, false); InternalNotification n = new InternalNotification(Properties.Resources.DisplayInstaller_NewDisplayInstalledTitle, String.Format(Utility.GetResourceString(Properties.Resources.DisplayInstaller_NewDisplayInstalledText), info.Name), info.Name); queuedNotifications.Add(n); newDisplayLoaded = true; this.Close(); } else { // display with the same name aleady exists... ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.DisplayInstaller_AlreadyInstalled), info.Name)); } // clean up Utility.WriteDebugInfo(String.Format("Deleteing '{0}' zip file at {1}", info.Name, info.LocalZipFileLocation)); if (File.Exists(info.LocalZipFileLocation)) File.Delete(info.LocalZipFileLocation); } else { Utility.WriteDebugInfo(String.Format("Error downloading display '{0}'.", info.Name)); ShowMessage(errorMessage); } } } else { // definition file was malformed ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.DisplayInstaller_BadDefinitionFile), this.uri)); } } catch (Exception ex) { // error downloading definition file Utility.WriteDebugInfo(String.Format("Error downloading display. {0} - {1}", ex.Message, ex.StackTrace)); ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.DisplayInstaller_NonexistentDefinitionFile), this.uri)); } return newDisplayLoaded; }
private void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (this.checker != null) { this.checker.DownloadStringCompleted -= new DownloadStringCompletedEventHandler(checker_DownloadStringCompleted); this.checker.Dispose(); this.checker = null; } } this.disposed = true; } }