public ReleaseInfo GetCurrentRelease()
 {
     try
     {
         var serializer = new XmlSerializer(typeof(ReleaseInfo));
         var reader = new StreamReader("release_info.xml");
         currentRelease = (ReleaseInfo)serializer.Deserialize(reader);
         reader.Close();
     }
     catch { }
     return currentRelease;
 }
 public ArchiveDownloadEventArgs(ReleaseInfo releaseInfo, ArchiveDownloadStatus status)
 {
     this.ReleaseInfo = releaseInfo;
     this.Status = status;
 }
        public List<string> DownloadAndUncompress(ReleaseInfo releaseInfo)
        {
            if (ArchiveDownloadUpdate != null) ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.DOWNLOADING));
            //
            string destinationFolder = Path.Combine(updateFolder, "files");
            string archiveName = Path.Combine(updateFolder, "archives", "hg_update_" + releaseInfo.Version.Replace(" ", "_").Replace(".", "_") + ".zip");
            if (!Directory.Exists(Path.GetDirectoryName(archiveName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(archiveName));
            }
            var client = new WebClient();
            client.Headers.Add("user-agent", "HomeGenieUpdater/1.0 (compatible; MSIE 7.0; Windows NT 6.0)");
            try
            {
                client.DownloadFile(releaseInfo.DownloadUrl, archiveName);
            }
            catch (Exception)
            {
                if (ArchiveDownloadUpdate != null) ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.ERROR));
                return null;
                //                throw;
            }

            // Unarchive (unzip)
            if (ArchiveDownloadUpdate != null) ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.DECOMPRESSING));

            bool errorOccurred = false;
            var files = new List<string>();
            try
            {
                using (ZipPackage package = (ZipPackage)Package.Open(archiveName, FileMode.Open, FileAccess.Read))
                {
                    foreach (PackagePart part in package.GetParts())
                    {
                        string target = Path.Combine(destinationFolder, part.Uri.OriginalString.Substring(1)).TrimStart(Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()).ToArray()).TrimStart('/');
                        if (!Directory.Exists(Path.GetDirectoryName(target)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(target));
                        }

                        if (File.Exists(target)) File.Delete(target);

                        using (Stream source = part.GetStream(
                            FileMode.Open, FileAccess.Read))
                        using (Stream destination = File.OpenWrite(target))
                        {
                            byte[] buffer = new byte[4096];
                            int read;
                            while ((read = source.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                destination.Write(buffer, 0, read);
                            }
                        }
                        files.Add(target);
                        //Console.WriteLine("Deflated {0}", target);
                    }
                }
            }
            catch (Exception)
            {
                errorOccurred = true;
            }

            if (ArchiveDownloadUpdate != null)
            {
                if (errorOccurred)
                    ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.ERROR));
                else
                    ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.COMPLETED));
            }

            return files;
        }
Exemple #4
0
        public List<string> DownloadAndUncompress(ReleaseInfo releaseInfo)
        {
            if (ArchiveDownloadUpdate != null) ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.DOWNLOADING));
            //
            string destinationFolder = Path.Combine(updateFolder, "files");
            string archiveName = Path.Combine(updateFolder, "archives", "hg_update_" + releaseInfo.Version.Replace(" ", "_").Replace(".", "_") + ".zip");
            if (!Directory.Exists(Path.GetDirectoryName(archiveName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(archiveName));
            }
            using (var client = new WebClient())
            {
                client.Headers.Add("user-agent", "HomeGenieUpdater/1.0 (compatible; MSIE 7.0; Windows NT 6.0)");
                try
                {
                    client.DownloadFile(releaseInfo.DownloadUrl, archiveName);
                }
                catch (Exception)
                {
                    if (ArchiveDownloadUpdate != null)
                        ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.ERROR));
                    return null;
                    //                throw;
                }
                finally
                {
                    client.Dispose();
                }
            }

            // Unarchive (unzip)
            if (ArchiveDownloadUpdate != null)
                ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.DECOMPRESSING));

            bool errorOccurred = false;
            var files = Utility.UncompressZip(archiveName, destinationFolder);
            errorOccurred = (files.Count == 0);

            if (ArchiveDownloadUpdate != null)
            {
                if (errorOccurred)
                    ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.ERROR));
                else
                    ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.COMPLETED));
            }

            return files;
        }
Exemple #5
0
 public List<ReleaseInfo> GetGitHubUpdates()
 {
     GetCurrentRelease();
     //githubReleases
     using (var client = new WebClient())
     {
         client.Headers.Add("user-agent", "HomeGenieUpdater/1.0 (compatible; MSIE 7.0; Windows NT 6.0)");
         try
         {
             bool collectingComplete = false;
             string releaseJson = client.DownloadString(githubReleases);
             var deserializerSettings = new JsonSerializerSettings()
             {
                 DateParseHandling = Newtonsoft.Json.DateParseHandling.None
             };
             dynamic releases = JsonConvert.DeserializeObject(releaseJson, deserializerSettings) as JArray;
             if (remoteUpdates != null)
                 remoteUpdates.Clear();
             else
                 remoteUpdates = new List<ReleaseInfo>();
             foreach(var rel in releases)
             {
                 foreach(dynamic relFile in (rel.assets as JArray))
                 {
                     if (relFile.browser_download_url.ToString().EndsWith(".tgz"))
                     {
                         var releaseDate = DateTime.ParseExact(relFile.updated_at.ToString(), "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
                         if (currentRelease.ReleaseDate < releaseDate && remoteUpdates.Count == 0)
                         {
                             var r = new ReleaseInfo();
                             r.Name = githubRepository;
                             r.Version = rel.tag_name.ToString();
                             r.Description = rel.name.ToString();
                             r.ReleaseNote = rel.body.ToString();
                             r.RequireRestart = false; // this flag is now useless since "restart" flag is dynamically computed by update process
                             r.UpdateBreak = true; // TODO: store this flag somewhere in the github entry
                             r.DownloadUrl = relFile.browser_download_url.ToString();
                             r.ReleaseDate = releaseDate;
                             remoteUpdates.Add(r);
                         }
                         else if (currentRelease.ReleaseDate < releaseDate)
                         {
                             string relInfo = String.Format("\r\n\r\n[{0} {1:yyyy-MM-dd}]\r\n{2}", rel.tag_name.ToString(), releaseDate, rel.body.ToString());
                             remoteUpdates[0].ReleaseNote += relInfo;
                         }
                         else
                         {
                             collectingComplete = true;
                         }
                     }
                 }
                 // updates from github contains the whole HG bundle so we always consider the most recent one
                 if (collectingComplete)
                     break;
             }
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
             remoteUpdates = null;
         }
         finally
         {
             client.Dispose();
         }
     }
     return remoteUpdates;
 }
Exemple #6
0
 public ReleaseInfo GetCurrentRelease()
 {
     return currentRelease = GetReleaseFile(releaseFile);
 }
Exemple #7
0
        public List<string> DownloadAndUncompress(ReleaseInfo releaseInfo)
        {
            if (ArchiveDownloadUpdate != null)
                ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.DOWNLOADING));
            //
            string destinationFolder = Path.Combine(updateFolder, "files");
            string archiveName = Path.Combine(updateFolder, "archives", "hg_update_" + releaseInfo.Version.Replace(" ", "_").Replace(".", "_") + ".zip");
            if (!Directory.Exists(Path.GetDirectoryName(archiveName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(archiveName));
            }
            using (var client = new WebClient())
            {
                client.Headers.Add("user-agent", "HomeGenieUpdater/1.0 (compatible; MSIE 7.0; Windows NT 6.0)");
                try
                {
                    client.DownloadFile(releaseInfo.DownloadUrl, archiveName);
                }
                catch (Exception)
                {
                    if (ArchiveDownloadUpdate != null)
                        ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.ERROR));
                    return null;
                    //                throw;
                }
                finally
                {
                    client.Dispose();
                }
            }

            // Unarchive (unzip)
            if (ArchiveDownloadUpdate != null)
                ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.DECOMPRESSING));

            bool errorOccurred = false;
            var files = Utility.UncompressTgz(archiveName, destinationFolder);
            errorOccurred = (files.Count == 0);

            if (ArchiveDownloadUpdate != null)
            {
                if (errorOccurred)
                    ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.ERROR));
                else
                    ArchiveDownloadUpdate(this, new ArchiveDownloadEventArgs(releaseInfo, ArchiveDownloadStatus.COMPLETED));
            }

            // update release_info.xml file with last releaseInfo ReleaseDate field in order to reflect github release date
            if (files.Contains(Path.Combine("homegenie", releaseFile)))
            {
                var ri = GetReleaseFile(Path.Combine(destinationFolder, "homegenie", releaseFile));
                ri.ReleaseDate = releaseInfo.ReleaseDate.ToUniversalTime();
                XmlSerializer serializer = new XmlSerializer(typeof(ReleaseInfo));
                using (TextWriter writer = new StreamWriter(Path.Combine(destinationFolder, "homegenie", releaseFile)))
                {
                    serializer.Serialize(writer, ri);
                }
            }

            return files;
        }