Ejemplo n.º 1
0
        //[Ignore][Explicit]
        public void TestModifyYaml()
        {
            //string yamlFile = @"V:\projects_os_git\winget-pkgs\manifests\7Zip\7Zip\19.0.0.yaml";
            //string yamlFileTarget = @"e:\7Zip_19.0.0.yaml";
            string                yamlFile       = @"V:\projects_os_git\winget-pkgs\manifests\a\AcroSoftware\CutePDFWriter\4.0.1.1\AcroSoftware.CutePDFWriter.yaml";
            string                yamlFileTarget = @"e:\cutepdf4.yaml";
            YamlFileHelper        yamlFileHelper = new YamlFileHelper();
            ManifestPackage_1_0_0 package        = yamlFileHelper.ReadYamlFile(yamlFile).Manifest;

            package.Installers[0].InstallerUrl = "cutepdf.exe";
            yamlFileHelper.WriteYamlFile(yamlFileTarget, package);
        }
Ejemplo n.º 2
0
        private static List <NewDownload> FindNewDownloads(YamlFileHelper yamlFileHelper, Dictionary <string, string> packageIds, IEnumerable <ManifestPackageVM> manifestPackages)
        {
            List <Tuple <ManifestPackageVM, string> > idFileTuples = manifestPackages.Join(packageIds, manifestPackage => manifestPackage.Id.ToLower(), i => i.Key, (mpvm, kvp) => Tuple.Create(mpvm, kvp.Value)).ToList();

            List <NewDownload> result = new List <NewDownload>();

            foreach (Tuple <ManifestPackageVM, string> idFileTuple in idFileTuples)
            {
                ManifestPackageVM manifestPackage = idFileTuple.Item1;
                string            idFilePath      = idFileTuple.Item2;

                string[] versionsToIgnoreDownload = Helpers.GetVersionsToIgnoreDownload(idFilePath);

                string idFileFolder  = Path.GetDirectoryName(idFilePath);
                string versionFolder = Path.Combine(idFileFolder, ConvertVersionToDirectoryName(manifestPackage.Version));                 // illegal chars in version shouldn't be a problem, because yaml files are stored in folders with version as name
                bool   exists        = versionsToIgnoreDownload.Any(v => v == manifestPackage.Version) || Directory.Exists(versionFolder);
                //if (manifestPackage.Version == "latest" && exists)
                if (false)                //TODO: the following code crashes when downloaded yaml-files are not version 1.0.0
                {
                    string downloadedYamlFilePath = Path.Combine(versionFolder, "latest.yaml");
                    ManifestPackage_1_0_0 downloadedManifestPackage = yamlFileHelper.ReadYamlFile(downloadedYamlFilePath).Manifest;
                    //TODO test all installers when winget supports multiple installers
                    if (manifestPackage.Installers[0].Sha256 != downloadedManifestPackage.Installers[0].InstallerSha256)
                    {
                        FileInfo fi            = new FileInfo(downloadedYamlFilePath);
                        string   versionSuffix = fi.LastWriteTime.ToString("_yyyy-MM-dd");
                        downloadedManifestPackage.PackageVersion += versionSuffix;
                        yamlFileHelper.WriteYamlFile(downloadedYamlFilePath, downloadedManifestPackage);
                        Directory.Move(versionFolder, versionFolder + versionSuffix);
                        exists = Directory.Exists(versionFolder);
                    }
                }
                if (manifestPackage.Version != "latest")                //TODO!!!!
                {
                    if (!exists)
                    {
                        NewDownload dl = new NewDownload()
                        {
                            MultiFileYaml = manifestPackage.MultiFileYaml,
                            VersionFolder = versionFolder,
                            IdFilePath    = idFilePath
                        };
                        result.Add(dl);
                    }
                }
            }
            return(result);
        }