Example #1
0
        /// <summary>
        /// Loads the package at the specified file path into the engine.
        /// </summary>
        /// <param name="path">The path to the package to load.</param>
        public void LoadPackage(string path)
        {
            if (Util.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException(GetString("err-empty-path"));
            }

            if (Util.IsNullOrWhiteSpace(Path.GetExtension(path)))
            {
                path += RantPackage.EXTENSION;
            }

            LoadPackage(RantPackage.Load(path));
        }
Example #2
0
        /// <summary>
        /// Loads the package at the specified file path into the engine.
        /// </summary>
        /// <param name="path">The path to the package to load.</param>
        /// <param name="mergeBehavior">The table merging strategy to employ.</param>
        public void LoadPackage(string path, TableMergeBehavior mergeBehavior = TableMergeBehavior.Naive)
        {
            if (Util.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("Path cannot be null nor empty.");
            }

            if (Util.IsNullOrWhiteSpace(Path.GetExtension(path)))
            {
                path += ".rantpkg";
            }

            LoadPackage(RantPackage.Load(path), mergeBehavior);
        }
        /// <summary>
        /// Attempts to resolve a depdendency to the appropriate package.
        /// </summary>
        /// <param name="depdendency">The depdendency to resolve.</param>
        /// <param name="package">The package loaded from the depdendency.</param>
        /// <returns></returns>
        public virtual bool TryResolvePackage(RantPackageDependency depdendency, out RantPackage package)
        {
            package = null;
            var path = Path.Combine(Environment.CurrentDirectory, $"{depdendency.ID}.rantpkg");

            if (!File.Exists(path))
            {
                RantPackageVersion version;
                // Fallback to name with version appended
#if UNITY
                path = Directory.GetFiles(Environment.CurrentDirectory, $"{depdendency.ID}*.rantpkg", SearchOption.AllDirectories).FirstOrDefault(p =>
#else
                path = Directory.EnumerateFiles(Environment.CurrentDirectory, "*.rantpkg", SearchOption.AllDirectories).FirstOrDefault(p =>
#endif

                {
                    var match = FallbackRegex.Match(Path.GetFileNameWithoutExtension(p));
                    if (!match.Success)
                    {
                        return(false);
                    }
                    version = RantPackageVersion.Parse(match.Groups["version"].Value);
                    return((depdendency.AllowNewer && version >= depdendency.Version) || depdendency.Version == version);
                });
                if (path == null)
                {
                    return(false);
                }
            }
            try
            {
                var pkg = RantPackage.Load(path);
                                           if (pkg.ID != depdendency.ID)
                {
                    return(false);
                }
                                           if ((depdendency.AllowNewer && pkg.Version >= depdendency.Version) || pkg.Version == depdendency.Version)
                {
                    package = pkg;
                    return(true);
                }
                                           return(false);
            }
            catch
            {
                return(false);
            }
        }