Exemplo n.º 1
0
        public IEnumerable <string> GetFiles(string path, string filter, MySearchOption searchOption)
        {
            MyZipArchive zipFile = TryDoZipAction(path, TryGetZipArchive, null);

            string subpath = "";

            if (searchOption == MySearchOption.TopDirectoryOnly)
            {
                subpath = TryDoZipAction(path, TryGetSubpath, null);
            }

            if (zipFile != null)
            {
                string pattern = Regex.Escape(filter).Replace(@"\*", ".*").Replace(@"\?", ".");
                pattern += "$";
                foreach (var fileName in zipFile.FileNames)
                {
                    if (searchOption == MySearchOption.TopDirectoryOnly)
                    {
                        if (fileName.Count((x) => x == '\\') != subpath.Count((x) => x == '\\') + 1)
                        {
                            continue;
                        }
                    }
                    if (Regex.IsMatch(fileName, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
                    {
                        yield return(Path.Combine(zipFile.ZipPath, fileName));
                    }
                }

                zipFile.Dispose();
            }
        }
Exemplo n.º 2
0
        private Image TryGetPlanetTexture(string name, MyModContext context, string p, out string fullPath)
        {
            bool   flag  = false;
            string text1 = name + p;

            name     = text1;
            fullPath = Path.Combine(context.ModPathData, "PlanetDataFiles", name) + ".png";
            if (!context.IsBaseGame)
            {
                if (MyFileSystem.FileExists(fullPath))
                {
                    flag = true;
                }
                else
                {
                    fullPath = Path.Combine(context.ModPathData, "PlanetDataFiles", name) + ".dds";
                    if (MyFileSystem.FileExists(fullPath))
                    {
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                string str = Path.Combine(MyFileSystem.ContentPath, PlanetDataFilesPath);
                fullPath = Path.Combine(str, name) + ".png";
                if (!MyFileSystem.FileExists(fullPath))
                {
                    fullPath = Path.Combine(str, name) + ".dds";
                    if (!MyFileSystem.FileExists(fullPath))
                    {
                        return(null);
                    }
                }
            }
            if (fullPath.Contains(MyWorkshop.WorkshopModSuffix))
            {
                string       path    = fullPath.Substring(0, fullPath.IndexOf(MyWorkshop.WorkshopModSuffix) + MyWorkshop.WorkshopModSuffix.Length);
                string       str3    = fullPath.Replace(path + @"\", "");
                MyZipArchive archive = MyZipArchive.OpenOnFile(path, FileMode.Open, FileAccess.Read, FileShare.Read, false);
                try
                {
                    return(Image.Load(archive.GetFile(str3).GetStream(FileMode.Open, FileAccess.Read)));
                }
                catch (Exception)
                {
                    MyLog.Default.Error("Failed to load existing " + p + " file mod archive. " + fullPath, Array.Empty <object>());
                    return(null);
                }
                finally
                {
                    if (archive != null)
                    {
                        archive.Dispose();
                    }
                }
            }
            return(Image.Load(fullPath));
        }
Exemplo n.º 3
0
        public IEnumerable <string> GetFiles(string path, string filter, MySearchOption searchOption)
        {
            MyZipArchive zipFile = TryDoZipAction(path, TryGetZipArchive, null);

            string subpath = "";

            if (searchOption == MySearchOption.TopDirectoryOnly)
            {
                subpath = TryDoZipAction(path, TryGetSubpath, null);
            }

            if (zipFile != null)
            {
#if XB1
                System.Diagnostics.Debug.Assert(false, "TODO for XB1.");
                if (filter == "hgdshfjghjdsghj")
                {
                    yield return("");
                }
#else // !XB1
                string pattern = Regex.Escape(filter).Replace(@"\*", ".*").Replace(@"\?", ".");
                pattern += "$";
                foreach (var fileName in zipFile.FileNames)
                {
                    if (searchOption == MySearchOption.TopDirectoryOnly)
                    {
                        if (fileName.Count((x) => x == '\\') != subpath.Count((x) => x == '\\') + 1)
                        {
                            continue;
                        }
                    }
                    if (Regex.IsMatch(fileName, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
                    {
                        yield return(Path.Combine(zipFile.ZipPath, fileName));
                    }
                }
#endif // !XB1

                zipFile.Dispose();
            }
        }