예제 #1
0
        static Version GetLatestWakaTimeCliVersion()
        {
            var regex        = new Regex(@"(__version_info__ = )(\(( ?\'[0-9]+\'\,?){3}\))");
            var aboutFileUrl = new Uri("https://raw.githubusercontent.com/wakatime/wakatime/master/wakatime/__about__.py");

            try
            {
                var client = new WebClient
                {
                    Proxy = WakaTimeConfigFile.GetProxy()
                };
                var about = client.DownloadString(aboutFileUrl);
                var match = regex.Match(about);
                if (match.Success)
                {
                    var groupVersion = match.Groups[2];
                    var regexVersion = new Regex(@"\'(?<major>\d+)\'\,\s?\'(?<minor>\d+)\'\,\s?\'(?<build>\d+)\'");
                    var versionMatch = regexVersion.Match(groupVersion.Value);
                    return(new Version(
                               int.Parse(versionMatch.Groups["major"].Value),
                               int.Parse(versionMatch.Groups["minor"].Value),
                               int.Parse(versionMatch.Groups["build"].Value)));
                }
                Logger.Warning("Couldn't auto resolve wakatime cli version");
            }
            catch (Exception ex)
            {
                Logger.Error("Exception when checking current wakatime cli version: ", ex);
            }
            return(new Version());
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
        }