Ejemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();

            _gridViewManifestsRowPopup = new GridRowPopupMenuBehavior(gridView1);
            _gridViewManifestsRowPopup.SetMenuItems(CreateMenuItemsManifestsPopup());
            _yamlFileHelper = new YamlFileHelper();
        }
Ejemplo n.º 2
0
        public NewDownloadsForm(YamlFileHelper yamlFileHelper)
        {
            InitializeComponent();

            _gridViewDownloadRowPopup = new GridRowPopupMenuBehavior(gridView1);
            _gridViewDownloadRowPopup.SetMenuItems(CreateMenuItemsDownloadPopup());
            _yamlFileHelper = yamlFileHelper;
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            new YamlTest().TestDeserializeYaml();
            //new YamlTest().TestModifyYaml();
            return;

            string yamlFileTarget         = @"e:\7Zip_19.0.0.yaml";
            ManifestPackage_1_0_0 package = new YamlFileHelper().ReadYamlFile(yamlFileTarget).Manifest;
        }
Ejemplo n.º 4
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.º 5
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);
        }
Ejemplo n.º 6
0
 //[Ignore][Explicit]
 public void TestDeserializeYaml()
 {
     string yamlFile = @"V:\projects_os_git\winget-pkgs\manifests\7\7zip\7zip\19.0.0\7zip.7zip.yaml";
     ManifestPackage_1_0_0 package = new YamlFileHelper().ReadYamlFile(yamlFile).Manifest;
     string locale = package.PackageLocale;
 }
Ejemplo n.º 7
0
 //[Ignore][Explicit]
 public void TestLoadMultiFileYaml()
 {
     const string  MainYamlFilePath = @"V:\projects_os_git\winget-pkgs\manifests\a\AxisCommunications\AxisCameraStation\5.37.301\AxisCommunications.AxisCameraStation.yaml";
     MultiFileYaml mfy = new YamlFileHelper().LoadMultiFileYaml(MainYamlFilePath);
 }
Ejemplo n.º 8
0
        private void ProcessOneNewDownload(NewDownload newDownload)
        {
            string versionFolder = newDownload.VersionFolder;
            // create a fresh instance, otherwise the changes we will make would be visible in the GUI-grid
            MultiFileYaml mfy = new YamlFileHelper().LoadMultiFileYaml(newDownload.MultiFileYaml.MainYamlFilePath);

            var installersWithMatchingLocale = mfy.Installers.Where(i => HasMatchingLocale(i, LocalesToDownload));

            foreach (ManifestInstaller_1_0_0 manifestInstaller in installersWithMatchingLocale)
            {
                string downloadUrl      = manifestInstaller.InstallerUrl;
                string downloadFileName = _installerDownloader.GetFileNameFromUrl(downloadUrl, out Uri responseUri);
                if (responseUri != null)
                {
                    // this download url returns html instead of the .exe
                    // https://sourceforge.net/projects/keepass/files/KeePass%202.x/2.46/KeePass-2.46-Setup.exe/download
                    // but the returned responseUri works:
                    // https://downloads.sourceforge.net/project/keepass/KeePass%202.x/2.46/KeePass-2.46-Setup.exe
                    downloadUrl = responseUri.ToString();
                }
                if (downloadFileName == null)
                {
                    AddLogLineBackground("Error: Unable to determine filename from download-url!");
                    continue;
                }
                try
                {
                    AddLogLineBackground("Creating directory: " + versionFolder);
                    Directory.CreateDirectory(versionFolder);
                    string downloadFolder = versionFolder;
                    if (newDownload.MultiFileYaml.Installers.Count > 1)
                    {
                        string archAndLocale = $"{manifestInstaller.Architecture ?? "null"}_{manifestInstaller.InstallerLocale ?? "null"}";
                        downloadFolder = Path.Combine(versionFolder, archAndLocale);
                        Directory.CreateDirectory(downloadFolder);
                    }

                    string downloadFilePath = Path.Combine(downloadFolder, downloadFileName);
                    AddLogLineBackground("Downloading: " + downloadUrl + " -> " + downloadFilePath);
                    _installerDownloader.DownloadFile(downloadUrl, downloadFilePath);
                    if (backgroundWorker1.CancellationPending)
                    {
                        return;
                    }

                    AddLogLineBackground("Calculating Sha256-Hash from file");
                    Helpers.CalculateFileHashResult calculateFileHashResult = Helpers.CalculateSha256HashFromFile(downloadFilePath);
                    if (calculateFileHashResult.ErrorMessage == null)
                    {
                        string calculatedHash = calculateFileHashResult.Hash;
                        string expectedHash   = manifestInstaller.InstallerSha256.ToLower();
                        if (calculatedHash != expectedHash)
                        {
                            AddLogLineBackground($"Error: Sha256-Hash mismatch (expected {expectedHash} - calculated {calculatedHash})");
                            ++_errorCount;
                        }
                    }
                    else
                    {
                        AddLogLineBackground($"Error: Calculating Sha256-Hash: {calculateFileHashResult.ErrorMessage}");
                        ++_errorCount;
                    }

                    manifestInstaller.InstallerUrl = downloadFileName + " |# " + manifestInstaller.InstallerUrl;                     //HACK!!!

                    if (backgroundWorker1.CancellationPending)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ++_errorCount;
                    AddLogLineBackground(ex.ToString());
                    if (Directory.GetFiles(versionFolder).Length == 0)
                    {
                        Directory.Delete(versionFolder);
                    }
                }
            }

            if (Directory.Exists(versionFolder))
            {
                //save modified manifest to download-folder
                _yamlFileHelper.SaveMultiFileYaml(mfy, versionFolder);
            }
        }