Ejemplo n.º 1
0
 public unsafe Apt(string name)
 {
     byte[] buffer = FileLoader.GetFileBuffer(out _name, "Data", "AptUI", name, "$NAME$.apt".FormatNamed("name", name));
     if (buffer == null)
     {
         return;
     }
     _loadedApts.Add(name, this);
     _aptConst = new AptConst();
     _aptConst.Load(FileLoader.GetFileBuffer("Data", "AptUI", name, "$NAME$.const".FormatNamed("name", name)));
     _aptDat = new AptDat();
     _aptDat.Load(FileLoader.GetFileBuffer("Data", "AptUI", name, "$NAME$.dat".FormatNamed("name", name)));
     fixed (byte* pBufferF = &buffer[0])
     {
         byte* pBuffer = pBufferF;
         string header = BufferReader.ReadString(&pBuffer);
         header = header.Substring(0, header.Length - 1);
         header = header.Substring(_aptHeader.Length);
         switch (header)
         {
             case "6":
                 _version = AptVersion.VERSION_6;
                 break;
             case "64":
                 _version = AptVersion.VERSION_64;
                 break;
             case "7":
                 _version = AptVersion.VERSION_7;
                 break;
             case "74":
                 _version = AptVersion.VERSION_74;
                 break;
         }
         if (*(int*)pBuffer == 0)
         {
             pBuffer += 4;
         }
         pBuffer = pBufferF + _aptConst.AptDataOffset;
         _window = new MovieClip(pBuffer, pBufferF);
     }
     //
     // LOAD GEOMETRY
     //
     _aptGeometries = new SortedDictionary<uint, AptGeometry>();
     AptGeometry geometry = new AptGeometry(5);
     geometry.Load(FileLoader.GetFileBuffer("Data", "AptUI", name, "$NAME$_geometry".FormatNamed("name", name), "$ID$.ru".FormatNamed("id", geometry.Id)));
 }
Ejemplo n.º 2
0
        public void Install()
        {
            _logger.LogInformation("Updating the package cache...");
            _aptGetService.Update();

            var image = GetImage();

            _logger.LogInformation("Getting all package names...");
            var packageNames = _aptCacheService.Packages();

            _logger.LogInformation("Looking for all the essential/required/important packages...");
            var policies     = _aptCacheService.Policy(packageNames);
            var packageInfos = _aptCacheService.Show(packageNames.ToDictionary(x => x,
                                                                               x => new AptVersion(policies[x].CandidateVersion, null)));

            var packages = new Dictionary <string, AptVersion>();

            foreach (var packageName in packageNames)
            {
                var policy      = policies[packageName];
                var packageInfo = packageInfos[packageName].Single(x => x.Key.Version == policy.CandidateVersion).Value;

                if (string.IsNullOrEmpty(packageInfo.Priority) && !string.IsNullOrEmpty(packageInfo.Essential) && packageInfo.Essential == "yes")
                {
                    packages.Add(packageName, new AptVersion(null, null));
                    continue;
                }

                if (packageInfo.Priority == "required")
                {
                    _logger.LogInformation("Adding required package: {package}", packageName);
                    packages.Add(packageName, AptVersion.Unspecified);
                }
                else if (packageInfo.Priority == "important")
                {
                    if (!image.ExcludeImportant)
                    {
                        _logger.LogInformation("Adding important package: {package}", packageName);
                        packages.Add(packageName, AptVersion.Unspecified);
                    }
                }
            }

            if (image.Packages != null)
            {
                foreach (var package in image.Packages.Keys)
                {
                    if (string.IsNullOrEmpty(image.Packages[package]))
                    {
                        throw new Exception("Empty version field detected.");
                    }

                    if (image.Packages[package] == "latest")
                    {
                        if (packages.ContainsKey(package))
                        {
                            packages[package] = AptVersion.Unspecified;
                        }
                        else
                        {
                            packages.Add(package, AptVersion.Unspecified);
                        }
                    }
                    else
                    {
                        if (packages.ContainsKey(package))
                        {
                            packages[package] = new AptVersion(image.Packages[package], null);
                        }
                        else
                        {
                            packages.Add(package, new AptVersion(image.Packages[package], null));
                        }
                    }
                }
            }

            _logger.LogInformation("Declared packages:");
            foreach (var package in packages)
            {
                if (package.Value.Equals(AptVersion.Unspecified))
                {
                    _logger.LogInformation($"\t{package.Key}:latest", package.Key, "latest");
                }
                else
                {
                    _logger.LogInformation($"\t{package.Value.ToCommandParameter(package.Key)}");
                }
            }

            _logger.LogInformation("Calculating all the packages that need to be installed...");
            var packagesToInstall = _aptGetService.SimulateInstall(packages)
                                    .ToDictionary(x => x.Key, x => new ImageLock.PackageEntry
            {
                Version = x.Value,
                Source  = new ImageLock.PackageSource
                {
                    Name    = packageInfos[x.Key][x.Value].SourcePackage,
                    Version = packageInfos[x.Key][x.Value].SourceVersion
                }
            });

            _logger.LogInformation("Resolved packages:");
            foreach (var packageToInstall in packagesToInstall)
            {
                _logger.LogInformation($"\t{packageToInstall.Value.Version.ToCommandParameter(packageToInstall.Key)}");
            }

            _logger.LogInformation("Saving image-lock.json...");
            var lockFile = Path.Combine(_workspaceConfig.RootDirectory, "image-lock.json");

            if (File.Exists(lockFile))
            {
                File.Delete(lockFile);
            }
            File.WriteAllText(lockFile, JsonConvert.SerializeObject(new ImageLock
            {
                InstalledPackages = packagesToInstall
            }, _jsonSerializerSettings));

            _logger.LogInformation("Done!");
        }