public InstallerInfo LastModified(string url)
 {
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
     var info = new InstallerInfo();
     if (response.StatusCode == HttpStatusCode.OK)
     {
         info.CreationTime = response.LastModified;
         info.Length = response.ContentLength;
     }
     return info;
 }
Example #2
0
        public InstallerInfo LastModified(string url)
        {
            HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            var             info     = new InstallerInfo();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                info.CreationTime = response.LastModified;
                info.Length       = response.ContentLength;
            }
            return(info);
        }
Example #3
0
        public PluginExecuteResult Load()
        {
            http = new HttpClient();
            down = new Downloader();
            down.ResponseHandler += SetResponseInfo;
            down.ProgressHandler += Progress;
            down.DoneHandler += Done;

            settings = IniFile.FromFile(Default.Name);
            latest = new InstallerInfo();
            latest.Version = settings[info.Name]["Version"] ?? "-";
            long ticks;
            if (long.TryParse(settings[info.Name]["Time"], out ticks))
            {
                latest.CreationTime = new DateTime(ticks);
            }
            long length;
            if (long.TryParse(settings[info.Name]["Length"], out length))
            {
                latest.Length = length;
            }
            if (latest.CreationTime != DateTime.MinValue || latest.Length != 0)
                EventStart(this, new PluginEventArgs(string.Format("Version: {0} (Date: {1}, Length: {2})", latest.Version, latest.CreationTime, latest.Length)));
            return PluginExecuteResult.Successfull;
        }
Example #4
0
 private void NewLatestVersion(InstallerInfo installerInfo)
 {
     settings[info.Name]["Version"] = installerInfo.Version;
     settings[info.Name]["Time"] = installerInfo.CreationTime.Ticks.ToString();
     settings[info.Name]["Length"] = installerInfo.Length.ToString();
     settings.Save(Default.Name);
 }
Example #5
0
        public PluginExecuteResult Execute()
        {
            EventProcessing(this, new PluginEventArgs(string.Format("Checking for {0}...", this)));

            bool newVersion = false;
            InstallerInfo installerInfo = http.LastModified(siteInfo.InstallerUrl);
            if(installerInfo.CreationTime.Date > latest.CreationTime.Date)
            {
                newVersion = true;
            }
            else if(installerInfo.Length != latest.Length)
            {
                newVersion = true;
            }
            if (newVersion)
            {
                EventUpdate(this, new PluginEventArgs("New version found!"));
                NewLatestVersion(installerInfo);
                latest = installerInfo;
                string path = PluginSaveHelper.BuildSavePath(info, latest.CreationTime);
                if(!File.Exists(path))
                    down.FileAsync(siteInfo.InstallerUrl);
                else
                {
                    EventProcessing(this, new PluginEventArgs("File already exists already"));
                    BuildVersion(path);
                }

            }

            return PluginExecuteResult.Failed;
        }