static public void DownloadCli() { Logger.Debug("Downloading wakatime cli..."); var tempDir = Path.GetTempPath(); var localZipFile = Path.Combine(tempDir, "wakatime-cli.zip"); var client = new WebClient { Proxy = WakaTimeConfigFile.GetProxy() // Check for proxy setting }; // Download wakatime cli DownloadProgress.Show(CliUrl); client.DownloadProgressChanged += (s, e) => { DownloadProgress.Report(e); }; client.DownloadFileCompleted += (s, e) => { try { DownloadProgress.Complete(e); Logger.Debug("Finished downloading wakatime cli."); // Extract wakatime cli zip file #if NET35 || NET40 using (var zipFile = new ZipFile(localZipFile)) { zipFile.ExtractAll(ConfigDir, ExtractExistingFileAction.OverwriteSilently); } #else ZipFile.ExtractToDirectory(localZipFile, ConfigDir); #endif Logger.Debug(string.Format("Finished extracting wakatime cli: {0}", GetCliPath())); // Delete downloaded file File.Delete(localZipFile); } catch (Exception ex) { Logger.Error("Failed to download and/or extract WakaTime Cli", ex); } finally { OnInitialized(); } }; Logger.Warning("DownloadProgress.Show"); try { client.DownloadFileAsync(new Uri(CliUrl), localZipFile); } catch (Exception ex) { Logger.Error("Failed to download WakaTime Cli", ex); } }
private void Initialize() { try { Logger.Initialize(GetLogger()); } catch { Logger.Initialize(GetConsoleLogger()); // fall-back on console logger } try { editorInfo = GetEditorInfo(); Logger.Info(string.Format("Initializing WakaTime v{0}", editorInfo.PluginVersion)); WakaTimeCli.Initialized += (s, e) => { if (string.IsNullOrEmpty(WakaTimeConfigFile.ApiKey)) { PromptApiKey(); } BindEditorEvents(); // Setup timer to process queued heartbeats every 8 seconds timer.Interval = 1000 * 8; timer.Elapsed += ProcessHeartbeats; timer.Start(); Logger.Info(string.Format("Finished initializing WakaTime v{0}", editorInfo.PluginVersion)); }; DownloadProgress.Initialize(() => { return(GetReporter()); }); PythonManager.Initialized += (s, e) => { WakaTimeCli.Initialize(); }; CheckPrerequisites(); } catch (WebException ex) { Logger.Error("Are you behind a proxy? Try setting a proxy in WakaTime Settings with format https://user:pass@host:port. Exception Traceback:", ex); } catch (Exception ex) { Logger.Error("Error initializing Wakatime", ex); } }
static public void DownloadPython() { Logger.Debug("Downloading python..."); var tempDir = Path.GetTempPath(); var localFile = Path.Combine(tempDir, "python.zip"); var client = new WebClient { Proxy = WakaTimeConfigFile.GetProxy() // Check for proxy setting }; // Download embeddable python DownloadProgress.Show(PythonDownloadUrl); client.DownloadProgressChanged += (s, e) => { DownloadProgress.Report(e); }; client.DownloadFileCompleted += (s, e) => { try { DownloadProgress.Complete(e); Logger.Debug("Finished downloading python."); // Extract wakatime cli zip file var appDataPath = GetAppDataDirectory(); // Extract wakatime cli zip file #if NET35 || NET40 using (var zipFile = new ZipFile(localFile)) { zipFile.ExtractAll(Path.Combine(appDataPath, "python"), ExtractExistingFileAction.OverwriteSilently); } #else ZipFile.ExtractToDirectory(localFile, Path.Combine(appDataPath, "python")); #endif Logger.Debug(string.Format("Finished extracting python: {0}", Path.Combine(appDataPath, "python"))); // Delete downloaded file File.Delete(localFile); } finally { OnInitialized(); } }; client.DownloadFileAsync(new Uri(PythonDownloadUrl), localFile); }