Beispiel #1
0
        public void Extract(string src, string dstdir)
        {
            var archive = OpenArchive(src);

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Extracting " + src);
            Console.WriteLine("To " + dstdir);
            Console.WriteLine("");
            Console.ForegroundColor = ConsoleColor.Gray;
            foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
            {
                if (UpdateTimer.Instance.Update())
                {
                    VpmUtils.ConsoleClearLine();
                    Console.WriteLine(entry.Key);
                }
                entry.WriteToDirectory(dstdir, new ExtractionOptions
                {
                    ExtractFullPath = true,
                    Overwrite       = true
                });
            }
            archive.Dispose();
            Console.ResetColor();
            Console.WriteLine("Done");
        }
Beispiel #2
0
        public void Download(string src, string dst)
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Downloading " + src);
            Console.WriteLine("To " + dst);
            Console.WriteLine("");
            var client = new WebClient();

            Console.ForegroundColor         = ConsoleColor.Gray;
            client.DownloadProgressChanged += (sender, args) =>
            {
                if (UpdateTimer.Instance.Update())
                {
                    VpmUtils.ConsoleClearLine();
                    Console.WriteLine("Progress: {0} / {1}, {2}%", args.BytesReceived, args.TotalBytesToReceive, args.ProgressPercentage);
                }
            };
            var dltask = client.DownloadFileTaskAsync(src, dst);

            try
            {
                dltask.Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine("Problem with waiting for downloader. Skipping wait.");
            }
            Console.ResetColor();
            Console.WriteLine("Done");
        }
Beispiel #3
0
 protected bool CloneFromGit(bool submodules)
 {
     if (Source.EndsWith(".git"))
     {
         Console.WriteLine("Cloning git repository of " + Name);
         Console.WriteLine("To: " + TempDir);
         VpmUtils.CloneGit(Source, TempDir, true);
         return(true);
     }
     return(false);
 }
Beispiel #4
0
 public void CopyDir(string srcdir, string dstdir, string[] ignore = null, string[] match = null)
 {
     Console.ForegroundColor = ConsoleColor.White;
     Console.WriteLine("Copy folder:");
     Console.WriteLine("From: " + srcdir);
     Console.WriteLine("To: " + dstdir);
     Console.WriteLine("");
     VpmUtils.CopyDirectory(srcdir, dstdir, ignore, match, o =>
     {
         if (o is FileInfo)
         {
             if (UpdateTimer.Instance.Update())
             {
                 VpmUtils.ConsoleClearLine();
                 Console.ForegroundColor = ConsoleColor.Gray;
                 Console.WriteLine("File: " + ((FileInfo)o).Name);
             }
         }
     });
     Console.ResetColor();
 }
Beispiel #5
0
        public override void ValidateAlways(CommandLineArgument argument, ref string arg)
        {
            if (string.IsNullOrEmpty(arg))
            {
                var exeName = Assembly.GetExecutingAssembly().Location;
                if (VpmUtils.PromptYayOrNay(
                        "Do you want to register this vpm instance? (Open vpm:// or vpms:// url's and open .vpack files)",
                        "It makes life so much easier."))
                {
                    try
                    {
                        VpmUtils.RegisterURIScheme("vpm");
                        VpmUtils.RegisterURIScheme("vpms");

                        var fai = new FileAssociationInfo(".vpack");
                        if (!fai.Exists)
                        {
                            fai.Create("vpm");
                            fai.ContentType = "text/vpack";
                        }
                        var pai      = new ProgramAssociationInfo(fai.ProgID);
                        var progverb = new ProgramVerb("Open", exeName + " %1");
                        if (pai.Exists)
                        {
                            foreach (var pv in pai.Verbs)
                            {
                                pai.RemoveVerb(pv);
                            }
                            pai.AddVerb(progverb);
                        }
                        else
                        {
                            pai.Create("VVVV Package Definition", progverb);
                            pai.DefaultIcon = new ProgramIcon(exeName);
                        }

                        Console.WriteLine("Registered protocols successfully");
                    }
                    catch (Exception)
                    {
                        if (VpmUtils.PromptYayOrNay("Can't write to registry. Retry as Admin?"))
                        {
                            try
                            {
                                var startInfo = new ProcessStartInfo(exeName)
                                {
                                    Arguments = "-RegisterVpmUri",
                                    Verb      = "runas"
                                };
                                Process.Start(startInfo);
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Error occured while trying to run elevated process.");
                                Thread.Sleep(5000);
                            }
                            Environment.Exit(0);
                        }
                    }
                }

                Console.WriteLine("Alright, enjoy!");
                Thread.Sleep(5000);
                Environment.Exit(0);
            }
            arg = arg.Trim('"');
            if (arg.StartsWith("vpm://", true, CultureInfo.InvariantCulture))
            {
                if (arg.EndsWith(".vpack", true, CultureInfo.InvariantCulture))
                {
                    return;
                }
            }
            if (arg.StartsWith("vpms://", true, CultureInfo.InvariantCulture))
            {
                if (arg.EndsWith(".vpack", true, CultureInfo.InvariantCulture))
                {
                    return;
                }
            }
            if (File.Exists(arg))
            {
                if (arg.EndsWith(".vpack", true, CultureInfo.InvariantCulture))
                {
                    arg = Path.GetFullPath(arg);
                    return;
                }
            }
            throw new ValidationArgException("File not found or file is not .vpack");
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public void Install()
        {
            foreach (var d in Dependencies)
            {
                d.Install();
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Installing " + Name);
            Console.ResetColor();

            var vpmglobal       = new VpmGlobals(this);
            var assemblies      = VpmConfig.Instance.ReferencedAssemblies;
            var nugetassemblies = new List <Assembly>();

            if (NugetPackages != null && NugetPackages.Count > 0)
            {
                Console.WriteLine("Initializing Nuget for this pack");
                var packdir     = Path.Combine(TempDir, "NugetPackages");
                var packdirinfo = Directory.CreateDirectory(packdir);
                var repo        = VpmConfig.Instance.DefaultNugetRepository;
                var packman     = new PackageManager(repo, packdir);
                packman.PackageInstalled += (sender, args) =>
                {
                    Console.WriteLine("Installed " + args.Package.Id);
                };
                for (int i = 0; i < NugetPackages.Count; i++)
                {
                    var packnode = NugetPackages[i];
                    Console.WriteLine("Installing Nuget Package " + packnode.InnerText);
                    var version = packnode.Attributes?["version"]?.Value;

                    var      packages = repo.FindPackagesById(packnode.InnerText);
                    IPackage package  = null;
                    foreach (var p in packages)
                    {
                        bool versioncheck = p.IsLatestVersion;
                        if (version != null)
                        {
                            versioncheck = SemanticVersion.Parse(version) == p.Version;
                        }

                        if (versioncheck)
                        {
                            package = p;
                            break;
                        }
                    }
                    if (package == null)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("No nuget package found with those conditions");
                        Console.ResetColor();
                    }
                    else
                    {
                        packman.InstallPackage(package, false, true);
                    }
                }
                var dlls = packdirinfo.EnumerateDirectories().Where(info => info.GetDirectories("lib").Length > 0).Select(packinfo =>
                {
                    var libdir     = packinfo.GetDirectories("lib")[0];
                    var netversion = libdir.EnumerateDirectories("net*").Max(libinfo =>
                    {
                        var regexc  = new Regex(@"net(\d*?$)");
                        var matches = regexc.Matches(libinfo.Name);
                        if (matches.Count == 0)
                        {
                            return(0);
                        }
                        return(int.Parse(matches[0].Groups[1].Value));
                    });
                    return(libdir.GetDirectories("net" + netversion)[0].GetFiles("*.dll"));
                });
                foreach (var fileInfos in dlls)
                {
                    foreach (var file in fileInfos)
                    {
                        try
                        {
                            var ass = Assembly.LoadFrom(file.FullName);
                            Console.WriteLine("Loaded assembly " + file.Name);
                            if (!(assemblies.Contains(ass) || nugetassemblies.Contains(ass)))
                            {
                                nugetassemblies.Add(ass);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            try
            {
                if (VpmConfig.Instance.Arguments.UseEmbeddedScript)
                {
                    ScriptDebug.SelectedDebugScript(vpmglobal);
                }
                else
                {
                    CSharpScript.EvaluateAsync(InstallScript,
                                               globals: vpmglobal,
                                               options: ScriptOptions.Default.WithReferences(assemblies.Concat(nugetassemblies)));
                }
            }
            catch (Exception e)
            {
                if (e is CompilationErrorException)
                {
                    var ee = (CompilationErrorException)e;
                    Console.WriteLine("Compilation error:");
                    Console.WriteLine(string.Join(Environment.NewLine, ee.Diagnostics));
                }
                else
                {
                    Console.WriteLine("Script error:");
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                }
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey(true);
                VpmUtils.CleanUp();
                Environment.Exit(0);
            }
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
 public void GitClone(string srcrepo, string dstdir, bool submodules = false, string branch = "")
 {
     VpmUtils.CloneGit(srcrepo, dstdir, submodules, branch);
 }