Ejemplo n.º 1
0
 static string GetHomePage(string localJsonFile)
 {
     try
     {
         using (StreamReader file = File.OpenText(localJsonFile))
         {
             JsonSerializer serializer  = new JsonSerializer();
             VcvPackageJson jsonPackage = (VcvPackageJson)serializer.Deserialize(file, typeof(VcvPackageJson));
             if (string.IsNullOrEmpty(jsonPackage.homepage))
             {
                 return(jsonPackage.source);
             }
             return(jsonPackage.homepage);
         }
     }
     catch (Exception)
     {
         return("");
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("VcvPluginDownload {destPath}");
                Console.WriteLine("");
                Console.WriteLine("Example:");
                Console.WriteLine("VcvPluginDownload c:\\test");
                return;
            }

            string destPath     = args[0];
            string jsonDestPath = $"{destPath}\\JSON";
            string packagesPath = $"{destPath}\\Packages";

            Directory.CreateDirectory(jsonDestPath);
            Directory.CreateDirectory(packagesPath);
            IEnumerable <string> jsonFiles;

            try
            {
                jsonFiles = GetFileListFromGithub("VCVRack", "community", "plugins").Result;
                Console.WriteLine("Got list of VCV Rack plugins files from https://github.com/VCVRack/community/tree/master/plugins");
            }
            catch (Exception e)
            {
                Console.WriteLine("Couldn't get list of JSON files from GitHub");
                Console.WriteLine(e);
                throw;
            }

            bool newPackageSeen = false;

            foreach (var jsonFile in jsonFiles)
            {
                if (jsonFile == "Fundamental.json" ||
                    jsonFile == "VCV-Console.json" ||
                    jsonFile == "VCV-PulseMatrix.json" ||
                    jsonFile == "UnfilteredVolume1.json"
                    )
                {
                    // Skip these
                    try
                    {
                        string localJsonFile = $"{jsonDestPath}\\{jsonFile}";
                        File.Delete(localJsonFile);
                    }
                    catch (Exception)
                    {
                    }
                    continue;
                }

                bool localJsonFilePreviouslySeen = false;
                try
                {
                    string localJsonFile = $"{jsonDestPath}\\{jsonFile}";

                    if (System.IO.File.Exists(localJsonFile))
                    {
                        localJsonFilePreviouslySeen = true;
                    }


                    try
                    {
                        DownloadFile($"https://raw.githubusercontent.com/VCVRack/community/master/plugins/{jsonFile}", localJsonFile);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Couldn't download JSON from https://raw.githubusercontent.com/VCVRack/community/master/plugins/{jsonFile}");
                        Console.WriteLine(e);
                        throw;
                    }

                    try
                    {
                        using (StreamReader file = File.OpenText(localJsonFile))
                        {
                            JsonSerializer serializer  = new JsonSerializer();
                            VcvPackageJson jsonPackage = (VcvPackageJson)serializer.Deserialize(file, typeof(VcvPackageJson));
                            string         zipName     = GetFileNameFromUrl(jsonPackage.downloads.win.download);
                            string         zipFile     = $"{packagesPath}\\{zipName}";

                            if (!System.IO.File.Exists(zipFile))
                            {
                                Console.WriteLine($"Downloading {zipFile}");
                                DownloadFile(jsonPackage.downloads.win.download, zipFile);
                                newPackageSeen = true;
                            }
                        }
                        File.Delete(localJsonFile);
                    }
                    catch (Exception)
                    {
                        if (!localJsonFilePreviouslySeen)
                        {
                            string homePage = GetHomePage(localJsonFile);
                            Console.WriteLine($"Couldn't download package from {jsonFile}. {homePage}");
                            newPackageSeen = true;
                        }
                    }
                }
                catch (Exception)
                {
                }
            }

            if (!newPackageSeen)
            {
                Console.WriteLine($"No new or updated packages detected");
            }
        }