public static List <DemoItem> GetDemos(string modpath, string demosfolder) { string[] zipfiles = Directory.GetFiles(modpath, "*.pk3"); var result = new List <DemoItem>(); foreach (string file in zipfiles) { if (!file.EndsWith(".pk3", StringComparison.OrdinalIgnoreCase)) { continue; } using (var arc = ZipFile.OpenRead(file)) { foreach (var e in arc.Entries) { string entry = e.FullName; // Skip unrelated files... if (!GameHandler.Current.SupportedDemoExtensions.Contains(Path.GetExtension(entry))) { continue; } // If demosfolder is given, skip items not within said folder... if (!string.IsNullOrEmpty(demosfolder)) { // If demosfolder is given, skip items not within said folder... if (!entry.StartsWith(demosfolder, StringComparison.OrdinalIgnoreCase)) { continue; } // Strip "demos" from the entry name (Q2 expects path relative to "demos" folder) entry = entry.Substring(demosfolder.Length + 1); } using (var stream = e.Open()) { var wrapper = new DeflateStreamWrapper((DeflateStream)stream, e.Length); using (var reader = new BinaryReader(wrapper)) GameHandler.Current.AddDemoItem(entry, result, reader, restype); } } } } return(result); }
public static void GetMaps(string modpath, Dictionary <string, MapItem> mapslist, GameHandler.GetMapInfoDelegate getmapinfo) { string[] zipfiles = Directory.GetFiles(modpath, "*.pk3"); foreach (string file in zipfiles) { if (!file.EndsWith(".pk3", StringComparison.OrdinalIgnoreCase)) { continue; } using (var arc = ZipFile.OpenRead(file)) { foreach (var e in arc.Entries) { if (!GameHandler.Current.EntryIsMap(e.FullName, mapslist)) { continue; } string mapname = Path.GetFileNameWithoutExtension(e.Name); MapItem mapitem; if (getmapinfo != null) { using (var stream = e.Open()) { var wrapper = new DeflateStreamWrapper((DeflateStream)stream, e.Length); using (var reader = new BinaryReader(wrapper)) mapitem = getmapinfo(mapname, reader, restype); } } else { mapitem = new MapItem(mapname, restype); } // Add to collection mapslist.Add(mapname, mapitem); } } } }