Ejemplo n.º 1
0
 public Setup(Uri uri, Repository repo)
 {
     using (var rs = _wc.OpenRead(new Uri(uri, string.Format("setup.dat?rnd={0}", new Random().Next())))) // remote access to compressed data
     using (var ds = new DeflateStream(rs, SharpCompress.Compressor.CompressionMode.Decompress)) // decompress (deflate)
         _doc.Load(ds); // load xml
     Repository = repo;
 }
Ejemplo n.º 2
0
        public Package(XmlNode packageNode, Repository repository)
        {
            _packageXmlNode = packageNode;
            _repository = repository;

            var metadataNodes = new[] {
                packageNode.SelectSingleNode("child::name"),
                packageNode.SelectSingleNode("child::version"),
                packageNode.SelectSingleNode("child::description")
            };

            if (metadataNodes[0] == null)
                throw new InvalidOperationException("Package XML is missing a name tag.");
            if (metadataNodes[1] == null)
                throw new InvalidOperationException("Package XML is missing a version tag.");

            Name = metadataNodes[0].InnerText;
            Version = metadataNodes[1].InnerText;
            Description = metadataNodes[2] != null ? metadataNodes[2].InnerText : string.Empty;

            _resolvers = ResolverUtil.GetResolverChain(this);

            var optionsNode = packageNode.SelectSingleNode("child::options");
            if (optionsNode != null)
                Selectors = (from xmlNode in optionsNode.SelectNodes("child::selector").OfType<XmlNode>()
                             select new Selector(xmlNode)).ToArray();
            else
                Selectors = new Selector[] { };

            Log.DebugFormat("Opened package, ID is {0}, Name is {1}, Version is {2}", ID, Name, Version);
        }
        public void UpdateMinecraft()
        {
            SetProgress();
            SetStatus("Fetching packages...");

            var uri = new Uri("http://repo.update.modernminas.de/");

            CacheFile cache = new CacheFile(System.IO.Path.Combine(App.GamePath, "installation.cache"));
            Repository repository = new Repository(uri, cache) { TargetDirectory = new System.IO.DirectoryInfo(App.GamePath) };
            Setup setup = new Setup(uri, repository);

            Dictionary<string, float> progress = new Dictionary<string,float>();
            foreach (var package in setup.Packages)
            {
                progress.Add(package.ID + "_preinstall", 0);
                progress.Add(package.ID + "_download", 0);
                progress.Add(package.ID + "_install", 0);
                progress.Add(package.ID + "_uninstall", 0);
            }

            int i = 0;
            repository.StatusChanged += (sender, e) =>
            {
                switch (e.Status)
                {
                    case StatusType.Finished:
                        if (!progress.ContainsKey(e.Package.ID + "_install"))
                            break;
                        if (progress[e.Package.ID + "_uninstall"] < 1)
                            progress[e.Package.ID + "_uninstall"] = 1;
                        if (progress[e.Package.ID + "_preinstall"] < 1)
                            progress[e.Package.ID + "_preinstall"] = 1;
                        if (progress[e.Package.ID + "_download"] < 1)
                            progress[e.Package.ID + "_download"] = 1;
                        if(progress[e.Package.ID + "_install"] < 1)
                            progress[e.Package.ID + "_install"] = 1;
                        break;
                    case StatusType.Parsing:
                    case StatusType.Installing:
                        if (!progress.ContainsKey(e.Package.ID + "_install"))
                            break;
                        progress[e.Package.ID + "_install"] = e.Progress;
                        if(progress[e.Package.ID + "_uninstall"] < 1)
                            progress[e.Package.ID + "_uninstall"] = 1;
                        if(progress[e.Package.ID + "_preinstall"] < 1)
                            progress[e.Package.ID + "_preinstall"] = 1;
                        if(progress[e.Package.ID + "_download"] < 1)
                            progress[e.Package.ID + "_download"] = 1;
                        break;
                    case StatusType.Downloading:
                        if (progress.ContainsKey(e.Package.ID + "_download"))
                        {
                            if (progress[e.Package.ID + "_preinstall"] < 1)
                                progress[e.Package.ID + "_preinstall"] = 1;
                            progress[e.Package.ID + "_download"] = e.Progress;
                        }
                        break;
                    case StatusType.CheckingDependencies:
                    case StatusType.InstallingDependencies:
                        if (progress.ContainsKey(e.Package.ID + "_preinstall"))
                            progress[e.Package.ID + "_preinstall"] = e.Progress;
                        break;
                    case StatusType.Uninstalling:
                        SetStatus(string.Format("Package {0}/{1}: Updating...", i, setup.Packages.Count()));
                        if (progress.ContainsKey(e.Package.ID + "_uninstall"))
                            progress[e.Package.ID + "_uninstall"] = e.Progress;
                        break;
                }
                SetProgress(progress.Sum(v => v.Value));
                foreach (var j in progress.Keys)
                {
                    Debug.WriteLine(string.Format("{0}: {1}", j, progress[j]));
                }
            };
            SetProgress(0, setup.Packages.Count() * 4);
            SetStatus("Updating...");
            foreach (var package in setup.Packages)
            {
                i++;
                Debug.WriteLine(string.Format("Current package: {0}", package.ID, null));

                SetProgress(progress.Sum(v => v.Value));

                if (package.IsInstalled)
                {
                    SetStatus(string.Format("Package {0}/{1}: Checking for updates...", i, setup.Packages.Count()));
                    package.Update();
                }
                else
                {
                    SetStatus(string.Format("Package {0}/{1}: Installing...", i, setup.Packages.Count()));
                    package.Install();
                }
            }
            foreach (var package in from p in setup.Packages where !cache.GetAllCachedPackageIDs().Contains(p.ID) select p)
            {
                repository.UninstallPackage(package.ID);
            }

            SetStatus("Update finished");
            SetProgress(1, 1);

            App.StartupClasspath = setup.GetStartupClasspath();
            App.StartupLibrarypath = setup.GetStartupLibrarypath();
        }
Ejemplo n.º 4
0
 public SetupPackage(XmlNode xml, Repository repository)
 {
     _repository = repository;
     _xml = xml;
 }