Example #1
0
        /// <summary>
        /// Checks if a certain resource does exist under a certain file system.
        /// </summary>
        /// <param name="system"></param>
        /// <param name="pather"></param>
        /// <param name="magicChecked"></param>
        /// <returns></returns>
        private static bool Exists(IFileSystem system, Pather pather, bool magicChecked)
        {
            // If said file exists, good
            if (system.Exists(pather.RootlessPath))
                return true;

            // If we already tried our magic
            if (magicChecked)
            {
                // Pop the magic again.
                pather.Pop();

                // Second-to-last resort: Extension is .lua, so there might be a luac somewhere.
                if (pather.Last.EndsWith(".lua") && system.Exists(pather.RootlessPath + "c"))
                    return true;

                // Last resort: .lua or .luac extension
                if (system.Exists(pather.RootlessPath + ".lua") || system.Exists(pather.RootlessPath + ".luac"))
                {
                    string script = pather.Last;
                    pather.Pop();
                    script += system.Exists(script + ".lua") ? ".lua" : ".luac";
                    pather.Add(script);
                    return true;
                }

                return false;
            }
            else
            {
                // Try it for an alias
                if (ParseAlias(pather.ToString()) != null)
                    return true;
            }

            // Since we can't check for zip files, try this.
            // It's not exactly a beautiful approach but it's an allnighter here, so \o/
            pather.Add(pather.Last + ".json");

            // Just call us again, this time without magic. If we ever redo this part, this would be nice.
            return Exists(system, pather, true);
        }