Esempio n. 1
0
        // creates version config and uploads it (async)
        private void UploadVersionConfigs(DelegateTransfer callback)
        {
            var files = new List <TransferFile>();

            // check if version should be a full version
            if (ulFullVersion)
            {
                // create a new full version config and save it to temp folder
                var xmlFullVersion = new XmlFullVersion(ulFiles);
                xmlFullVersion.Save(localPath + fullVersionConfig);
                files.Add(new TransferFile(fullVersionConfig));
            }

            // create a new update config and save it to temp folder
            var xmlUpdate = new XmlUpdate(ulNewFiles, ulDeletedFiles);

            xmlUpdate.Save(localPath + updateConfig);
            files.Add(new TransferFile(updateConfig));

            Uri address = new Uri(remotePath + ulVersion + "/");

            // try to upload configs async
            fileTransfer.UploadFilesAsync(files, false, address, localPath,
                                          delegate(FileTransferResult result)
            {
                callback(result == FileTransferResult.Success);
            });
        }
Esempio n. 2
0
        // returns file list of a specific version
        private Dictionary <string, TransferFile> GetVersionFiles(string fullVersion, List <string> updates)
        {
            var newFiles     = new Dictionary <string, TransferFile>();
            var deletedFiles = new Dictionary <string, TransferFile>();
            var files        = new Dictionary <string, TransferFile>();

            XmlUpdate      xmlUpdate      = new XmlUpdate();
            XmlFullVersion xmlFullVersion = new XmlFullVersion();

            // order the update configs descending (start with the last update)
            updates = versions.OrderVersions(updates, true);
            foreach (string update in updates)
            {
                // load the update config
                xmlUpdate.Load(localPath + update + "/" + updateConfig, update);

                // add every new file to the list of new files (if it hasn't been added before)
                foreach (TransferFile file in xmlUpdate.NewFiles)
                {
                    if (!newFiles.ContainsKey(file.name) &&
                        !deletedFiles.ContainsKey(file.name))
                    {
                        newFiles.Add(file.name, file);
                    }
                }

                // add every deleted file to the list of files to delete (if it hasn't been added before)
                foreach (TransferFile file in xmlUpdate.DeletedFiles)
                {
                    if (!newFiles.ContainsKey(file.name) &&
                        !deletedFiles.ContainsKey(file.name))
                    {
                        deletedFiles.Add(file.name, file);
                    }
                }
            }

            // load the full version config
            xmlFullVersion.Load(localPath + fullVersion + "/" + fullVersionConfig, fullVersion);

            // add every new file to the list of version files
            foreach (TransferFile file in newFiles.Values)
            {
                files.Add(file.name, file);
            }

            // add every full version file to the list of version files (if it hasn't been added before)
            foreach (TransferFile file in xmlFullVersion.Files)
            {
                if (!files.ContainsKey(file.name) &&
                    !deletedFiles.ContainsKey(file.name))
                {
                    files.Add(file.name, file);
                }
            }

            return(files);
        }
Esempio n. 3
0
        public void XmlUpdateExecute()
        {
            XmlUpdate task = new XmlUpdate();
            task.BuildEngine = new MockBuild();

            task.Prefix = "n";
            task.Namespace = "http://schemas.microsoft.com/developer/msbuild/2003";
            task.XmlFileName = testFile;
            task.XPath = "/n:Project/n:PropertyGroup/n:LastUpdate";
            task.Value = DateTime.Now.ToLongDateString();

            Assert.IsTrue(task.Execute(), "Execute Failed");
        }
Esempio n. 4
0
        public void XmlUpdateDelete()
        {
            XmlUpdate task = new XmlUpdate();

            task.BuildEngine = new MockBuild();

            task.Prefix      = "n";
            task.Namespace   = "http://schemas.microsoft.com/developer/msbuild/2003";
            task.XmlFileName = testFile;
            task.XPath       = "/n:Project/n:PropertyGroup/n:LastUpdate";
            task.Delete      = true;

            Assert.IsTrue(task.Execute(), "Execute Failed");
        }
Esempio n. 5
0
        public UpdateForm(XmlUpdate xmlUpdate, bool selfUpdate)
        {
            if (DesignMode)
            {
                return;
            }

            _xmlUpdate  = xmlUpdate;
            _selfUpdate = selfUpdate;
            InitializeComponent();
            Text = _xmlUpdate.AppName + @" v" + _xmlUpdate.Version;
            if (_xmlUpdate.DeployDate.HasValue)
            {
                Text += @" (" + _xmlUpdate.DeployDate.Value.ToString("G") + @")";
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Checks if new update is available.
        /// </summary>
        /// <returns>returns true if new new update is available.</returns>
        private static bool CheckForUpdates()
        {
            if (string.IsNullOrWhiteSpace(AppConfig.UpdateUrl))
            {
                return(false);
            }

            var errorText = string.Empty;

            try
            {
                //var randUrl = AppConfig.UpdateUrl + (AppConfig.UpdateUrl.Contains('?') ? "&" : "?") + "rand=" + Guid.NewGuid().ToString();
                //var xml = Ext.ReadFile() Ext.DownloadString(randUrl, AppConfig.Proxy, AppConfig.ProxyUrl, AppConfig.ProxyUserName, AppConfig.ProxyPassword);
                var xml = Ext.ReadUpdateUrlFile();
                if (_debug)
                {
                    ShowDebugForm(AppConfig.UpdateUrl, xml);
                }

                errorText  = "Error in xml file structure which was downloaded from server.\n";
                _xmlUpdate = Ext.DeserializeXml <XmlUpdate>(xml);

                foreach (var file in _xmlUpdate.Files)
                {
                    var tmpFile = Path.Combine(AppConfig.AppExeFolder, file.File);
                    if (!File.Exists(tmpFile))
                    {
                        return(true);
                    }

                    var hash = Ext.MD5HexFile(tmpFile);
                    if (file.Hash != hash)
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}{1}\nUrl: {2}\n", errorText, ex.Message, AppConfig.UpdateUrl), ex);
            }

            return(false);
        }
Esempio n. 7
0
        /// <summary>
        /// Checks if new update is available.
        /// </summary>
        /// <returns>returns true if new new update is available.</returns>
        private static bool CheckForNewUpdater()
        {
            if (string.IsNullOrWhiteSpace(AppConfig.UpdaterUrl) || string.IsNullOrWhiteSpace(Ext.ExeMD5Hex))
            {
                return(false);
            }
            var errorText = string.Empty;

            try
            {
                var xml = Ext.ReadUpdaterUrlFile();
                if (_debug)
                {
                    ShowDebugForm(AppConfig.UpdaterUrl, xml);
                }

                errorText  = "Error in xml file structure which was downloaded from server.\n";
                _xmlUpdate = Ext.DeserializeXml <XmlUpdate>(xml);

                var updaterFile = _xmlUpdate.Files.FirstOrDefault(x => x.File == _xmlUpdate.AppExeName);
                return(updaterFile != null && updaterFile.Hash != Ext.ExeMD5Hex);


                //foreach (var file in XmlUpdate.Files)
                //{
                //    var tmpFile = Path.Combine(AppConfig.AppExeFolder, file.File);
                //    if (!File.Exists(tmpFile))
                //        return true;

                //    var hash = Ext.MD5HexFile(tmpFile);
                //    if (file.Hash != hash)
                //        return true;
                //}
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}{1}\nUrl: {2}\n", errorText, ex.Message, AppConfig.UpdaterUrl), ex);
            }
        }
Esempio n. 8
0
        private void bsDeploy_DoWork(object sender, DoWorkEventArgs e)
        {
            var updateDir      = txtDirectoryUpdate.Text.Trim();
            var destinationDir = txtDirectoryDestination.Text.Trim();
            var xmlFile        = Path.Combine(destinationDir, "update.txt");

            var xml = (XmlUpdate)e.Argument;

            //add files into xml
            foreach (var item in _fileInfo.Where(x => x.Checked))
            {
                xml.Files.Add(new XmlUpdate.XmlFile(item.Path, item.Path.Substring(updateDir.Length + 1), item.Hash));
            }
            var compressDir = Path.Combine(destinationDir, xml.CompressFolderName);

            if (!Directory.Exists(compressDir))
            {
                Directory.CreateDirectory(compressDir);
            }

            var deleteFiles = Directory.GetFiles(destinationDir).ToList();

            if (deleteFiles.Contains(xmlFile))
            {
                deleteFiles.Remove(xmlFile);
            }
            var deleteCompressedFiles = Directory.GetFiles(compressDir);

            var comparer = new PropertyComparer <XmlUpdate.XmlFile>("Hash");
            var distinct = xml.Files.Distinct(comparer).ToList();

            decimal max = deleteFiles.Count + deleteCompressedFiles.Length + distinct.Count;


            var oldCompressEqualsCurrent = false;

            if (File.Exists(xmlFile))
            {
                XmlUpdate oldXml = null;//Creating old serialized XmlUpdate from xml file
                try { oldXml = Ext.DeserializeXml <XmlUpdate>(File.ReadAllBytes(xmlFile)); }
                catch { }
                oldCompressEqualsCurrent = oldXml != null && oldXml.Compress == xml.Compress;
            }

            for (int i = 0; i < deleteFiles.Count; i++)
            {
                bsDeploy.ReportProgress((int)((1m + i) * progressFiles.Maximum / max), "Deleting: " + Path.GetFileName(deleteFiles[i]));
                File.Delete(deleteFiles[i]);
            }

            for (int i = 0; i < deleteCompressedFiles.Length; i++)
            {
                var file = Path.GetFileName(deleteCompressedFiles[i]);
                //if old compressed file equals current then just skip.
                if (oldCompressEqualsCurrent && distinct.Any(x => x.Hash + xml.Extension == file))
                {
                    continue;
                }

                bsDeploy.ReportProgress((int)((1m + deleteFiles.Count + i) * progressFiles.Maximum / max), "Deleting: " + file);
                File.Delete(deleteCompressedFiles[i]);
            }


            for (int i = 0; i < distinct.Count; i++)
            {
                var item = distinct[i];
                var file = Path.Combine(compressDir, item.Hash + xml.Extension);
                if (File.Exists(file))
                {
                    continue;                   //if old compressed file already exists then skip
                }
                bsDeploy.ReportProgress((int)((1 + deleteFiles.Count + deleteCompressedFiles.Length + i) * progressFiles.Maximum / max), "Compressing: " + Path.GetFileName(item.Path) + "  To: " + item.Hash + xml.Extension);
                switch (xml.Compress.ToLowerInvariant())
                {
                case "":
                    File.Copy(item.Path, file);
                    break;

                case "gzip":
                    GZipHelper.CompressFile(item.Path, file);
                    break;

                //case "zip":
                //    SharpZLibHelper.CompressFile(item.Path, Path.Combine(compressFolder, item.Hash + xml.Extension));
                //    progressFiles.PerformStep();
                //    break;

                case "7zip":
                    SevenZipHelper.CompressFileLZMA(item.Path, file);
                    break;

                default:
                    throw new ArgumentException("Invalid compress type (use: gzip, 7zip).");
                }
            }
            File.WriteAllText(xmlFile, Ext.SerializeXml(xml));
        }