コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("vpm at your service!");
            Console.ResetColor();
            try
            {
                VpmConfig.Instance.Arguments = Args.Parse <VpmArgs>(args);
            }
            catch (ArgException ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                Console.ResetColor();
                Console.WriteLine(ArgUsage.GenerateUsageFromTemplate <VpmArgs>());
                VpmUtils.CleanUp();
                Environment.Exit(0);
            }
            try
            {
                UpdateTimer.Instance.Reset();
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Parsing input Pack");
                Console.ResetColor();
                var vpxml = VpmUtils.ParseAndValidateXmlFile(VpmConfig.Instance.Arguments.VPackFile);

                var namenode    = vpxml.SelectSingleNode("/vpack/meta/name");
                var srcnode     = vpxml.SelectSingleNode("/vpack/meta/source");
                var aliasesnode = vpxml.SelectSingleNode("/vpack/meta/aliases");

                if (namenode == null)
                {
                    throw new Exception("VPack name is not specified");
                }

                var name = namenode.InnerText.Trim();

                var src = "";
                if (srcnode != null)
                {
                    src = srcnode.InnerText.Trim();
                }

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Input pack is " + name);
                Console.ResetColor();

                VpmConfig.Instance.WaitSignal = true;
                VpmConfig.Instance.WinApp.BeginInvoke(() =>
                {
                    var winapp        = VpmConfig.Instance.WinApp;
                    var window        = VpmConfig.Instance.DirWindow = new ChooseDir(VpmConfig.Instance.Arguments.VVVVDir);
                    winapp.MainWindow = window;
                    window.Show();
                });
                VpmUtils.Wait();
                var dirwindow = (ChooseDir)VpmConfig.Instance.DirWindow;
                if (dirwindow.Cancelled)
                {
                    //VpmUtils.CleanUp();
                    Environment.Exit(0);
                }
                VpmConfig.Instance.Arguments.VVVVDir = dirwindow.PathResult;

                if (!Directory.Exists(VpmConfig.Instance.Arguments.VVVVDir))
                {
                    Console.WriteLine("Destination directory doesn't exist. Creating it.");
                    try
                    {
                        Directory.CreateDirectory(VpmConfig.Instance.Arguments.VVVVDir);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Couldn't do that.");
                        throw;
                    }
                }

                List <string> aliaslist = null;
                if (aliasesnode != null)
                {
                    var antext = aliasesnode.InnerText;
                    aliaslist = antext.Split(',').ToList();
                    for (int j = 0; j < aliaslist.Count; j++)
                    {
                        aliaslist[j] = aliaslist[j].Trim();
                    }
                }
                string matchalias;
                if (VpmUtils.IsPackExisting(name, aliaslist, out matchalias))
                {
                    Console.WriteLine("Input pack seems to be already existing as " + matchalias);
                    if (VpmUtils.PromptYayOrNay("Do you want to overwrite?"))
                    {
                        var packdir = Path.Combine(VpmConfig.Instance.Arguments.VVVVDir, "packs", matchalias);
                        VpmUtils.DeleteDirectory(packdir, true);
                    }
                    else
                    {
                        VpmUtils.CleanUp();
                        Environment.Exit(0);
                    }
                }
                var vpack = new VPack(name, src, aliaslist, vpxml);

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Initialization complete.");
                Console.ResetColor();

                if (!VpmConfig.Instance.Arguments.Quiet)
                {
                    if (!VpmUtils.PromptYayOrNay(
                            "Vpm does not ask individual licenses anymore. " +
                            "It is the user's responsibility to know and fully comply with the licenses " +
                            "of the currently installed pack and all of its dependencies.\n" +
                            "Do you agree?"))
                    {
                        VpmUtils.CleanUp();
                        Environment.Exit(0);
                    }
                }

                vpack.Install();
                VpmUtils.CleanUp();

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("All good in theory.");
                Console.WriteLine("Enjoy!");
                Thread.Sleep(5000);
            }
            catch (Exception e)
            {
                Console.WriteLine("Something went wrong:");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Message);
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine(e.StackTrace);
                VpmUtils.CleanUp();
                Console.ResetColor();
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey(true);
                Environment.Exit(0);
            }
        }
コード例 #2
0
        public VPack(string name, string source, IEnumerable <string> aliases = null, XmlDocument srcxml = null)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Initializing " + name);
            Console.ResetColor();

            Name    = name;
            Source  = source;
            TempDir = VpmConfig.Instance.VpmTempDir + "\\" + name;
            if (aliases != null)
            {
                Aliases.AddRange(aliases);
            }

            var authornode = srcxml?.SelectSingleNode("/vpack/meta/author");

            if (authornode != null)
            {
                Author = authornode.InnerText.Trim();
            }

            Directory.CreateDirectory(TempDir);

            var xmldoc = srcxml;

            if (source.StartsWith("vpm://", true, CultureInfo.InvariantCulture) ||
                source.StartsWith("vpms://", true, CultureInfo.InvariantCulture))
            {
                xmldoc = VpmUtils.ParseAndValidateXmlFile(source);
            }

            if (CloneFromGit(true))
            {
                var vpackfiles = Directory.GetFiles(TempDir, "*.vpack");
                if ((vpackfiles.Length > 0) && (xmldoc == null))
                {
                    xmldoc = VpmUtils.ParseAndValidateXmlFile(vpackfiles[0]);
                }
            }
            if (xmldoc != null)
            {
                RawXml = xmldoc.ToString();
                var licensenode = xmldoc.SelectSingleNode("/vpack/meta/license");
                LicenseUrl = licensenode?.InnerText.Trim() ?? "http://www.imxprs.com/free/microdee/vpmnolicense";

                var namenode = xmldoc.SelectSingleNode("/vpack/meta/name");
                if (namenode == null)
                {
                    Console.WriteLine(
                        "WARNING: VPack XML doesn't contain name. Using " + Name + " from other sources.");
                }
                else
                {
                    if (!string.Equals(Name.Trim(), namenode.InnerText.Trim(), StringComparison.CurrentCultureIgnoreCase))
                    {
                        Console.WriteLine(
                            "WARNING: VPack XML says pack is called " + namenode.InnerText.Trim() +
                            ", but using " + Name + " to avoid conflicts");
                    }
                }
                var installnode = xmldoc.SelectSingleNode("/vpack/install");
                if (installnode == null)
                {
                    throw new Exception("VPack doesn't contain installing script.");
                }
                InstallScript = installnode.InnerText;

                var nugetnode = xmldoc.SelectSingleNode("/vpack/nuget");
                if (nugetnode != null)
                {
                    NugetPackages = nugetnode.ChildNodes;
                }

                var dependenciesnode = xmldoc.SelectSingleNode("/vpack/meta/dependencies");
                if (dependenciesnode != null)
                {
                    var nodelist = dependenciesnode.ChildNodes;
                    for (int i = 0; i < nodelist.Count; i++)
                    {
                        var dependencynode = nodelist.Item(i);
                        if (dependencynode == null)
                        {
                            continue;
                        }
                        if (dependencynode.Name != "dependency")
                        {
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine("Unknown node in Dependencies: " + dependencynode.Name + ". Moving on.");
                            Console.ResetColor();
                            continue;
                        }
                        var dnamenode    = dependencynode["name"];
                        var dsrcnode     = dependencynode["source"];
                        var daliasesnode = dependencynode["aliases"];

                        if ((dnamenode == null) || (dsrcnode == null))
                        {
                            throw new Exception("Insufficient data to parse dependency.");
                        }

                        var dname = dnamenode.InnerText.Trim();
                        if (VpmUtils.IsPackAlreadyInTemp(dname))
                        {
                            Console.WriteLine(dname + " is already in vpm temp folder. Ignoring");
                            continue;
                        }
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine("Parsing " + dname);
                        Console.ResetColor();
                        var dsrc = dsrcnode.InnerText.Trim();

                        List <string> aliaslist = null;
                        if (daliasesnode != null)
                        {
                            var dantext = daliasesnode.InnerText;
                            aliaslist = dantext.Split(',').ToList();
                            for (int j = 0; j < aliaslist.Count; j++)
                            {
                                aliaslist[j] = aliaslist[j].Trim();
                            }
                        }
                        string matchedname;
                        if (VpmUtils.IsPackExisting(dname, aliaslist, out matchedname))
                        {
                            Console.WriteLine(dname + " seems to be there already.");
                            var replaceit = !Args.GetAmbientArgs <VpmArgs>().Quiet;
                            if (replaceit)
                            {
                                replaceit = VpmUtils.PromptYayOrNay(
                                    "Do you want to replace it?",
                                    "WARNING: Original pack will be deleted!\nWARNING: If anything goes wrong during installation original pack won't be recovered.");
                            }
                            if (!replaceit)
                            {
                                continue;
                            }
                            var aliasdir = Path.Combine(Args.GetAmbientArgs <VpmArgs>().VVVVDir, "packs", matchedname);
                            VpmUtils.DeleteDirectory(aliasdir, true);
                        }
                        var newvpack = new VPack(dname, dsrc, aliaslist);
                        Dependencies.Add(newvpack);
                    }
                }
            }
            else
            {
                ScriptSource();
            }
            VpmConfig.Instance.PackList.Add(this);
        }
コード例 #3
0
ファイル: scriptglobals.cs プロジェクト: vvvvpm/vpm
 public VpmGlobals(VPack currentPack)
 {
     Pack = currentPack;
 }