Example #1
0
        /// <summary>
        /// Compare this instance to the object
        /// </summary>
        /// <param name="obj">Object to compare</param>
        /// <returns>Less than 0 - This instance is less than obj
        /// Zero - This instance is equal to obj
        /// Greater than 0 - This instance is greater than obj</returns>
        public int CompareTo(Object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            if (obj.GetType() != GetType())
            {
                throw new ArgumentException(SR.Get(SRID.ExpectedVersionPairObject));
            }

            VersionPair v = (VersionPair)obj;

            //PRESHARP:Parameter to this public method must be validated:  A null-dereference can occur here.
            //    Parameter 'v' to this public method must be validated:  A null-dereference can occur here.
            //This is a false positive as the checks above can gurantee no null dereference will occur
#pragma warning disable 6506
            if (this.Equals(obj))   // equal
            {
                return(0);
            }
            // less than
            else if (this < v)
            {
                return(-1);
            }
#pragma warning restore 6506
            // greater than
            return(1);
        }
Example #2
0
        /// <summary>
        /// Constructor for FormatVersion with given featureId and reader, updater,
        /// and writer version
        /// </summary>
        /// <param name="featureId">feature identifier</param>
        /// <param name="writerVersion">Writer Version</param>
        /// <param name="readerVersion">Reader Version</param>
        /// <param name="updaterVersion">Updater Version</param>
        public FormatVersion(String featureId,
                             VersionPair writerVersion,
                             VersionPair readerVersion,
                             VersionPair updaterVersion)
        {
            if (featureId == null)
            {
                throw new ArgumentNullException("featureId");
            }
            if (writerVersion == null)
            {
                throw new ArgumentNullException("writerVersion");
            }
            if (readerVersion == null)
            {
                throw new ArgumentNullException("readerVersion");
            }
            if (updaterVersion == null)
            {
                throw new ArgumentNullException("updaterVersion");
            }

            if (featureId.Length == 0)
            {
                throw new ArgumentException(SR.Get(SRID.ZeroLengthFeatureID));
            }

            _featureIdentifier = featureId;
            _reader            = readerVersion;
            _updater           = updaterVersion;
            _writer            = writerVersion;
        }
Example #3
0
        public ServerStatus()
        {
            Version     = new VersionPair(MinecraftServer.FrontendVersion);
            Players     = new PlayersStatus();
            Description = ChatMessageServer.CreateText(MinecraftServer.PingReplyMessage).Json;

            //Favicon - nothing seem to work but the gist says it should

            /*Favicon = "http://mctraveler.eu/icon.png";
             * //http://status.mctraveler.eu/logo.png";
             *
             * Bitmap b = new Bitmap(16, 16);
             * using (var g = Graphics.FromImage(b))
             * {
             *  g.FillEllipse(Brushes.Red, 1, 2, 5, 6);
             * }
             * using (var ms = new MemoryStream())
             * {
             *  b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
             *  Favicon = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
             * }*/
            string faviconPath = "icon.png";

            if (File.Exists(faviconPath))
            {
                Favicon = "data:image/png;base64," + Convert.ToBase64String(File.ReadAllBytes(faviconPath));
            }
        }
Example #4
0
        /// <summary>
        /// Eaual comparison operator
        /// </summary>
        /// <param name="obj">Object to compare</param>
        /// <returns>true if the object is equal to this instance</returns>
        public override bool Equals(Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj.GetType() != GetType())
            {
                return(false);
            }

            VersionPair v = (VersionPair)obj;

            //PRESHARP:Parameter to this public method must be validated:  A null-dereference can occur here.
            //    Parameter 'v' to this public method must be validated:  A null-dereference can occur here.
            //This is a false positive as the checks above can gurantee no null dereference will occur
#pragma warning disable 6506
            if (this != v)
            {
                return(false);
            }
#pragma warning restore 6506

            return(true);
        }
Example #5
0
        /// <summary>
        /// Check if a component with the given version can update this format version safely
        /// </summary>
        /// <param name="version">version of a component</param>
        /// <returns>true if this format version can be updated safely by the component
        /// with the given version, otherwise false</returns>
        /// <remarks>
        /// The given version is checked against UpdaterVersion
        /// </remarks>
        public bool IsUpdatableBy(VersionPair version)
        {
            if (version == null)
            {
                throw new ArgumentNullException("version");
            }

            return(_updater <= version);
        }
Example #6
0
        public VersionPair GetVersion()
        {
            VersionPair result = new VersionPair {
                AssayVersion    = _dataContext.CurveFile.Select(cf => cf.AssayVersion).Distinct().ToList().ToArray(),
                SoftwareVersion = _dataContext.CurveFile.Select(cf => cf.SoftwareVersion).Distinct().ToList().ToArray()
            };
            string delim = "";

            result.AssayVersion    = result.AssayVersion.Where(val => val != delim).ToArray();
            result.SoftwareVersion = result.SoftwareVersion.Where(val => val != delim).ToArray();


            return(result);
        }
 private async Task <bool> BeginUpdate(VersionPair versionPair)
 {
     if (!await CheckGameAccessLoop())
     {
         return(false);
     }
     if (!UpdateManager.DownloadUpdates(ProfileManager.CurrentProfile.GameModel, versionPair))
     {
         DialogManager.ShowMessageDialog(LanguageManager.Model.ErrorOccured, LanguageManager.Model.ConnectionError);
     }
     if (!await CheckGameAccessLoop())
     {
         return(false);
     }
     return(await ImportPackages());
 }
Example #8
0
    static CompareSet CreateCompareSet(List <string> feeds, string package, VersionPair versions)
    {
        var nugetDownloader = new NuGetDownloader(package, feeds);

        Console.Out.Write("Preparing {0}-{1}", package, versions);

        var leftAssemblyGroup  = new AssemblyGroup(nugetDownloader.DownloadAndExtractVersion(versions.LeftVersion));
        var rightAssemblyGroup = new AssemblyGroup(nugetDownloader.DownloadAndExtractVersion(versions.RightVersion));

        Console.Out.WriteLine(" done");

        return(new CompareSet
        {
            Name = package,
            RightAssemblyGroup = rightAssemblyGroup,
            LeftAssemblyGroup = leftAssemblyGroup,
            Versions = versions
        });
    }
Example #9
0
        public ServerStatus()
        {
            Version = new VersionPair(MinecraftServer.FrontendVersion);
            Players = new PlayersStatus();
            Description = ChatMessageServer.CreateText(MinecraftServer.PingReplyMessage).Json;
            
            //Favicon - nothing seem to work but the gist says it should
            /*Favicon = "http://mctraveler.eu/icon.png";
            //http://status.mctraveler.eu/logo.png";

            Bitmap b = new Bitmap(16, 16);
            using (var g = Graphics.FromImage(b))
            {
                g.FillEllipse(Brushes.Red, 1, 2, 5, 6); 
            }
            using (var ms = new MemoryStream())
            {
                b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                Favicon = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
            }*/
            string faviconPath = "icon.png";
            if (File.Exists(faviconPath))
                Favicon = "data:image/png;base64," + Convert.ToBase64String(File.ReadAllBytes(faviconPath));
        }
        public PackageSet GetOrCreatePackageSet(PackageId package)
        {
            PackageSet set;

            if (packageSets.TryGetValue(package, out set))
            {
                return(set);
            }
            else
            {
                set                  = new PackageSet();
                set.PackageId        = package;
                set.Dependencies     = new HashSet <PackageId>();
                packageSets[package] = set;

                NuGet.Versioning.NuGetVersion version = null;
                NuGet.Versioning.NuGetVersion.TryParse(package.Version, out version);
                versions[package] = new VersionPair()
                {
                    rawVersion = package.Version, version = version
                };
                return(set);
            }
        }
        /// <summary>
        /// Constructor for FormatVersion with given featureId and reader, updater,
        /// and writer version
        /// </summary>
        /// <param name="featureId">feature identifier</param>
        /// <param name="writerVersion">Writer Version</param>
        /// <param name="readerVersion">Reader Version</param>
        /// <param name="updaterVersion">Updater Version</param>
        public FormatVersion(String featureId,
                                VersionPair writerVersion,
                                VersionPair readerVersion,
                                VersionPair updaterVersion)
        {
            if (featureId == null)
                throw new ArgumentNullException("featureId");
            if (writerVersion == null)
                throw new ArgumentNullException("writerVersion");
            if (readerVersion == null)
                throw new ArgumentNullException("readerVersion");
            if (updaterVersion == null)
                throw new ArgumentNullException("updaterVersion");

            if (featureId.Length == 0)
            {
                throw new ArgumentException(SR.Get(SRID.ZeroLengthFeatureID));
            }

            _featureIdentifier = featureId;
            _reader = readerVersion;
            _updater = updaterVersion;
            _writer = writerVersion;
        }
 /// <summary>
 /// Constructor for FormatVersion with given featureId and version
 /// </summary>
 /// <param name="featureId">feature identifier</param>
 /// <param name="version">version</param>
 /// <remarks>reader, updater, and writer versions are set to version</remarks>
 public FormatVersion(string featureId, VersionPair version)
     : this(featureId, version, version, version)
 {
 }
        public bool DownloadUpdates(GameModel model, VersionPair versionPair)
        {
            if (model == null)
            {
                throw new ArgumentException("model argument cannot be null");
            }
            if (versionPair == null)
            {
                throw new ArgumentException("versionPair argument cannot be null");
            }
            bool   updateSuccess           = true;
            double downloadedContentLenght = 0;
            double WholeContentLength      = 0;

            Dictionary <int, double> contentLenght = new Dictionary <int, double>();

            try {
                for (int i = versionPair.Local + 1; i <= versionPair.Remote; i++)
                {
                    double patchSize = GetFileLength(new Uri(string.Format(ConfigurationManager.GetConfiguration(model).PatchRemoteURL, i)));
                    WholeContentLength += patchSize;
                    contentLenght.Add(i, patchSize);
                }
            } catch (WebException) {
                return(false);
            }

            for (int i = versionPair.Local + 1; i <= versionPair.Remote; i++)
            {
                Uri    patchUri    = new Uri(string.Format(ConfigurationManager.GetConfiguration(model).PatchRemoteURL, i));
                string packageFile = Path.Combine(ConfigurationManager.GetGamePath(model), string.Format("UPDATE{0}.zip", i));

                OnStatusChanged(UpdateStatusEventArgs.Stage.DOWNLOADING, i, versionPair.Remote, downloadedContentLenght, WholeContentLength, 0, 100);
                double CurrentContentLength = 0;
                if (!contentLenght.TryGetValue(i, out CurrentContentLength))
                {
                    updateSuccess = false;
                    break;
                }

                int  downloadAttempts = 5;
                bool patchSuccess     = false;
                while (downloadAttempts > 0 && !patchSuccess)
                {
                    try {
                        if (File.Exists(packageFile))
                        {
                            File.Delete(packageFile);
                        }
                    } catch {
                        updateSuccess = false;
                        break;
                    }

                    using (WebClientEx webClient = new WebClientEx()) {
                        DownloadProgressChangedEventHandler progressChangedEventHandler = (s, e) => {
                            double dataReceived = (e.BytesReceived / (1024.0 * 1024.0));
                            double dataTotal    = (e.TotalBytesToReceive / (1024.0 * 1024.0));
                            OnStatusChanged(UpdateStatusEventArgs.Stage.DOWNLOADING,
                                            i, versionPair.Remote,
                                            downloadedContentLenght + e.BytesReceived, WholeContentLength,
                                            dataReceived, dataTotal);
                        };

                        webClient.DownloadProgressChanged += progressChangedEventHandler;
                        try {
                            webClient.DownloadFileAsync(patchUri, packageFile);
                            while (webClient.IsBusy)
                            {
                                System.Threading.Thread.Sleep(100);
                            }
                            downloadedContentLenght += CurrentContentLength;
                        } catch {
                            downloadAttempts--;
                            continue;
                        } finally {
                            webClient.DownloadProgressChanged -= progressChangedEventHandler;
                        }
                    }
                    if (!ConfigurationManager.CheckUpdateAccess(model))
                    {
                        updateSuccess = false;
                        break;
                    }
                    if (ExtractUpdate(i, versionPair.Remote,
                                      downloadedContentLenght, WholeContentLength,
                                      packageFile, ConfigurationManager.GetGamePath(model), true))
                    {
                        try {
                            string versionFile = ConfigurationManager.GetLocalVersionFile(model);
                            string directory   = Path.GetDirectoryName(versionFile);
                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }
                            File.WriteAllLines(versionFile, new string[] { "[VERSION]", "version=" + i.ToString() });
                        } catch {
                            updateSuccess = false;
                            break;
                        }
                        patchSuccess = true;
                    }
                    downloadAttempts--;
                }
                if (!patchSuccess)
                {
                    updateSuccess = false;
                    break;
                }
            }
            return(updateSuccess);
        }
        /// <summary>
        /// Check if a component with the given version can update this format version safely
        /// </summary>
        /// <param name="version">version of a component</param>
        /// <returns>true if this format version can be updated safely by the component
        /// with the given version, otherwise false</returns>
        /// <remarks>
        /// The given version is checked against UpdaterVersion
        /// </remarks>
        public bool IsUpdatableBy(VersionPair version)
        {
            if (version == null)
            {
                throw new ArgumentNullException("version");
            }

            return (_updater <= version);
        }
Example #15
0
 static BamlVersionHeader()
 {
     // Initialize the Version number this way so that it can be
     // seen in the Lutz Reflector.
     BamlWriterVersion = new VersionPair(0, 96);
 }
Example #16
0
 /// <summary>
 /// Constructor for FormatVersion with given featureId and version
 /// </summary>
 /// <param name="featureId">feature identifier</param>
 /// <param name="version">version</param>
 /// <remarks>reader, updater, and writer versions are set to version</remarks>
 public FormatVersion(string featureId, VersionPair version)
     : this(featureId, version, version, version)
 {
 }
Example #17
0
 static BamlVersionHeader()
 {
     // Initialize the Version number this way so that it can be
     // seen in the Lutz Reflector.
     BamlWriterVersion = new VersionPair(0, 96);
 }
        private async void CheckWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() {
                //Добавляем задачу обновления
                TaskManager.AquireLock(UpdateTask);
                ProfileManager.OnProfileLocked(true);
                EnvironmentManager.OnFileSystemLocked(true);
                EnvironmentManager.OnClosingLocked(true);
                UpdateRequired        = false;
                StartButton.IsEnabled = false;
                StartButton.SetBinding(Button.ContentProperty, WaitingButtonBinding);
            }));

            GameModel model = ProfileManager.CurrentProfile.GameModel;

            //Проверяем наличие необходимых файлов игры
            if (!ConfigurationManager.CheckGame(model))
            {
                SetStartEnabled(false); //Если необходимых файлов нет, просто вызываю этот метод. он при вышеуказанном условии покажет неактивную кнопку и сообщение о неправильном пути
                return;                 //Далее идти нет смысла
            }

            //Проверяем наличие обновления Pack01 файлами. Возвражающее значение говорит, можно ли проходить далее по алгоритму
            if (!await ImportPackages())
            {
                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() {
                    RemoveTask();
                    ProfileManager.OnProfileLocked(false);
                    EnvironmentManager.OnFileSystemLocked(false);
                    EnvironmentManager.OnClosingLocked(false);
                }));
                return;
            }

            //Проверяем наличие новых обновлений
            VersionPair pair = UpdateManager.CheckUpdates(ProfileManager.CurrentProfile.GameModel);

            if (pair == null)
            {
                SetStartEnabled(false);
                DialogManager.ShowMessageDialog(LanguageManager.Model.ErrorOccured, LanguageManager.Model.ConnectionError);
                return;
            }
            //Если обновление требуется
            if (pair.IsUpdateRequired)
            {
                //Если включен интегрированных движок обновления, пытаемся обновиться
                if (ProfileManager.CurrentProfile.UpdateEngineEnabled)
                {
                    ShowProgressBar();
                    SetStartEnabled(await BeginUpdate(pair));
                }
                else     //Если интегрированный движок отключен - показываем кнопку "Обновить игру"
                {
                    SetUpdateEnabled(true);
                }
            }
            else     //Если обновление не требуется, показываем кнопку "Начать игру".
            {
                SetStartEnabled(true);
            }
        }