Esempio n. 1
0
        private static LibraryInformation FilterByVersionAndArchitecture(params LibraryInformation[] libraries)
        {
            LibraryArchitecture targetArchictecture = Environment.Is64BitProcess ? LibraryArchitecture.amd64 : LibraryArchitecture.i386;
            LibraryInformation  result = libraries[0];

            foreach (LibraryInformation library in libraries)
            {
                if (IsNewer(result.Version, library.Version) && library.Architecture == targetArchictecture)
                {
                    result = library;
                }
            }

            return(result);
        }
Esempio n. 2
0
        private static LibraryInformation[] FilterPaths(string name, string[] paths)
        {
            Regex regex = new Regex(string.Format(REGEX_TEMPLATE, name));
            Stack <LibraryInformation> buffer = new Stack <LibraryInformation>();

            foreach (string path in paths)
            {
                Match match = regex.Match(path);
                if (!match.Success)
                {
                    continue;
                }
                if (Path.GetFileName(path) != match.Value)
                {
                    continue;
                }

                bool prefixed = match.Groups[1].Length > 0;

                string nameString = match.Groups[2].Value;

                string versionString =
                    match.Groups[3].Length > 0 ? match.Groups[3].Value :
                    match.Groups[6].Length > 0 ? match.Groups[6].Value :
                    "0";

                string[] versionSplit = versionString.Split('.', '-', '_');
                short[]  version      = new short[versionSplit.Length];

                string architectureString        = match.Groups[4].Value;
                LibraryArchitecture architecture = LibraryArchitecture.i386;

                if (architectureString == null)
                {
                    if (Environment.Is64BitProcess)
                    {
                        architecture = LibraryArchitecture.amd64;
                    }
                }
                else
                {
                    architecture = StringToArchitecture(architectureString);
                }

                for (int i = 0; i < version.Length; i++)
                {
                    short.TryParse(versionSplit[i], out version[i]);
                }

                // Add to buffer
                buffer.Push(new LibraryInformation()
                {
                    Prefixed     = prefixed,
                    Name         = nameString,
                    Version      = version,
                    Architecture = architecture,

                    Path = path
                });
            }

            return(buffer.ToArray());
        }