diff --git a/OpenRA.Game/FileSystem/BagFile.cs b/OpenRA.Game/FileSystem/BagFile.cs index 812e5359fe..6de2349034 100644 --- a/OpenRA.Game/FileSystem/BagFile.cs +++ b/OpenRA.Game/FileSystem/BagFile.cs @@ -27,11 +27,13 @@ namespace OpenRA.FileSystem readonly Stream s; readonly int bagFilePriority; readonly Dictionary index; + readonly FileSystem context; - public BagFile(string filename, int priority) + public BagFile(FileSystem context, string filename, int priority) { bagFilename = filename; bagFilePriority = priority; + this.context = context; // A bag file is always accompanied with an .idx counterpart // For example: audio.bag requires the audio.idx file @@ -39,14 +41,14 @@ namespace OpenRA.FileSystem // Build the index and dispose the stream, it is no longer needed after this List entries; - using (var indexStream = GlobalFileSystem.Open(indexFilename)) + using (var indexStream = context.Open(indexFilename)) entries = new IdxReader(indexStream).Entries; index = entries.ToDictionaryWithConflictLog(x => x.Hash, "{0} (bag format)".F(filename), null, x => "(offs={0}, len={1})".F(x.Offset, x.Length)); - s = GlobalFileSystem.Open(filename); + s = context.Open(filename); } public int Priority { get { return 1000 + bagFilePriority; } } @@ -159,9 +161,9 @@ namespace OpenRA.FileSystem public IEnumerable AllFileNames() { var lookup = new Dictionary(); - if (GlobalFileSystem.Exists("global mix database.dat")) + if (context.Exists("global mix database.dat")) { - var db = new XccGlobalDatabase(GlobalFileSystem.Open("global mix database.dat")); + var db = new XccGlobalDatabase(context.Open("global mix database.dat")); foreach (var e in db.Entries) { var hash = IdxEntry.HashFilename(e, PackageHashType.CRC32); @@ -175,7 +177,7 @@ namespace OpenRA.FileSystem public void Write(Dictionary contents) { - GlobalFileSystem.Unmount(this); + context.Unmount(this); throw new NotImplementedException("Updating bag files unsupported"); } diff --git a/OpenRA.Game/FileSystem/BigFile.cs b/OpenRA.Game/FileSystem/BigFile.cs index 50e3069a4c..5482f05ac4 100644 --- a/OpenRA.Game/FileSystem/BigFile.cs +++ b/OpenRA.Game/FileSystem/BigFile.cs @@ -22,12 +22,12 @@ namespace OpenRA.FileSystem readonly Dictionary entries = new Dictionary(); readonly Stream s; - public BigFile(string filename, int priority) + public BigFile(FileSystem context, string filename, int priority) { Name = filename; Priority = priority; - s = GlobalFileSystem.Open(filename); + s = context.Open(filename); try { if (s.ReadASCII(4) != "BIGF") diff --git a/OpenRA.Game/FileSystem/D2kSoundResources.cs b/OpenRA.Game/FileSystem/D2kSoundResources.cs index ca21c4f5a5..2b74b133f2 100644 --- a/OpenRA.Game/FileSystem/D2kSoundResources.cs +++ b/OpenRA.Game/FileSystem/D2kSoundResources.cs @@ -24,12 +24,12 @@ namespace OpenRA.FileSystem readonly Dictionary index = new Dictionary(); - public D2kSoundResources(string filename, int priority) + public D2kSoundResources(FileSystem context, string filename, int priority) { this.filename = filename; this.priority = priority; - s = GlobalFileSystem.Open(filename); + s = context.Open(filename); try { filenames = new List(); diff --git a/OpenRA.Game/FileSystem/GlobalFileSystem.cs b/OpenRA.Game/FileSystem/FileSystem.cs similarity index 71% rename from OpenRA.Game/FileSystem/GlobalFileSystem.cs rename to OpenRA.Game/FileSystem/FileSystem.cs index 89813d345f..778f3f5f46 100644 --- a/OpenRA.Game/FileSystem/GlobalFileSystem.cs +++ b/OpenRA.Game/FileSystem/FileSystem.cs @@ -17,55 +17,25 @@ using OpenRA.Primitives; namespace OpenRA.FileSystem { - public interface IFolder : IDisposable + public class FileSystem { - Stream GetContent(string filename); - bool Exists(string filename); - IEnumerable ClassicHashes(); - IEnumerable CrcHashes(); - IEnumerable AllFileNames(); - void Write(Dictionary contents); - int Priority { get; } - string Name { get; } - } + public readonly List FolderPaths = new List(); + public readonly List MountedFolders = new List(); - public static class GlobalFileSystem - { - public static List MountedFolders = new List(); - static Cache> classicHashIndex = new Cache>(_ => new List()); - static Cache> crcHashIndex = new Cache>(_ => new List()); + static readonly Dictionary AssemblyCache = new Dictionary(); - public static List FolderPaths = new List(); + int order; + Cache> crcHashIndex = new Cache>(_ => new List()); + Cache> classicHashIndex = new Cache>(_ => new List()); - static void MountInner(IFolder folder) - { - MountedFolders.Add(folder); - - foreach (var hash in folder.ClassicHashes()) - { - var l = classicHashIndex[hash]; - if (!l.Contains(folder)) - l.Add(folder); - } - - foreach (var hash in folder.CrcHashes()) - { - var l = crcHashIndex[hash]; - if (!l.Contains(folder)) - l.Add(folder); - } - } - - static int order = 0; - - public static IFolder CreatePackage(string filename, int order, Dictionary content) + public IFolder CreatePackage(string filename, int order, Dictionary content) { if (filename.EndsWith(".mix", StringComparison.InvariantCultureIgnoreCase)) - return new MixFile(filename, order, content); + return new MixFile(this, filename, order, content); if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase)) - return new ZipFile(filename, order, content); + return new ZipFile(this, filename, order, content); if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase)) - return new ZipFile(filename, order, content); + return new ZipFile(this, filename, order, content); if (filename.EndsWith(".RS", StringComparison.InvariantCultureIgnoreCase)) throw new NotImplementedException("The creation of .RS archives is unimplemented"); if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase)) @@ -80,7 +50,7 @@ namespace OpenRA.FileSystem return new Folder(filename, order, content); } - public static IFolder OpenPackage(string filename, string annotation, int order) + public IFolder OpenPackage(string filename, string annotation, int order) { if (filename.EndsWith(".mix", StringComparison.InvariantCultureIgnoreCase)) { @@ -88,30 +58,36 @@ namespace OpenRA.FileSystem ? PackageHashType.Classic : FieldLoader.GetValue("(value)", annotation); - return new MixFile(filename, type, order); + return new MixFile(this, filename, type, order); } if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase)) - return new ZipFile(filename, order); + return new ZipFile(this, filename, order); if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase)) - return new ZipFile(filename, order); + return new ZipFile(this, filename, order); if (filename.EndsWith(".RS", StringComparison.InvariantCultureIgnoreCase)) - return new D2kSoundResources(filename, order); + return new D2kSoundResources(this, filename, order); if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase)) - return new InstallShieldPackage(filename, order); + return new InstallShieldPackage(this, filename, order); if (filename.EndsWith(".PAK", StringComparison.InvariantCultureIgnoreCase)) - return new PakFile(filename, order); + return new PakFile(this, filename, order); if (filename.EndsWith(".big", StringComparison.InvariantCultureIgnoreCase)) - return new BigFile(filename, order); + return new BigFile(this, filename, order); if (filename.EndsWith(".bag", StringComparison.InvariantCultureIgnoreCase)) - return new BagFile(filename, order); + return new BagFile(this, filename, order); if (filename.EndsWith(".hdr", StringComparison.InvariantCultureIgnoreCase)) - return new InstallShieldCABExtractor(filename, order); + return new InstallShieldCABExtractor(this, filename, order); return new Folder(filename, order); } - public static void Mount(string name, string annotation = null) + public void Mount(IFolder mount) + { + if (!MountedFolders.Contains(mount)) + MountedFolders.Add(mount); + } + + public void Mount(string name, string annotation = null) { var optional = name.StartsWith("~"); if (optional) @@ -129,7 +105,34 @@ namespace OpenRA.FileSystem a(); } - public static void UnmountAll() + void MountInner(IFolder folder) + { + MountedFolders.Add(folder); + + foreach (var hash in folder.ClassicHashes()) + { + var folderList = classicHashIndex[hash]; + if (!folderList.Contains(folder)) + folderList.Add(folder); + } + + foreach (var hash in folder.CrcHashes()) + { + var folderList = crcHashIndex[hash]; + if (!folderList.Contains(folder)) + folderList.Add(folder); + } + } + + public bool Unmount(IFolder mount) + { + if (MountedFolders.Contains(mount)) + mount.Dispose(); + + return MountedFolders.RemoveAll(f => f == mount) > 0; + } + + public void UnmountAll() { foreach (var folder in MountedFolders) folder.Dispose(); @@ -140,20 +143,7 @@ namespace OpenRA.FileSystem crcHashIndex = new Cache>(_ => new List()); } - public static bool Unmount(IFolder mount) - { - if (MountedFolders.Contains(mount)) - mount.Dispose(); - - return MountedFolders.RemoveAll(f => f == mount) > 0; - } - - public static void Mount(IFolder mount) - { - if (!MountedFolders.Contains(mount)) MountedFolders.Add(mount); - } - - public static void LoadFromManifest(Manifest manifest) + public void LoadFromManifest(Manifest manifest) { UnmountAll(); foreach (var dir in manifest.Folders) @@ -163,7 +153,7 @@ namespace OpenRA.FileSystem Mount(pkg.Key, pkg.Value); } - static Stream GetFromCache(PackageHashType type, string filename) + Stream GetFromCache(PackageHashType type, string filename) { var index = type == PackageHashType.CRC32 ? crcHashIndex : classicHashIndex; var folder = index[PackageEntry.HashFilename(filename, type)] @@ -176,7 +166,7 @@ namespace OpenRA.FileSystem return null; } - public static Stream Open(string filename) + public Stream Open(string filename) { Stream s; if (!TryOpen(filename, out s)) @@ -185,7 +175,7 @@ namespace OpenRA.FileSystem return s; } - public static bool TryOpen(string name, out Stream s) + public bool TryOpen(string name, out Stream s) { var filename = name; var foldername = string.Empty; @@ -229,7 +219,7 @@ namespace OpenRA.FileSystem return false; } - public static bool Exists(string name) + public bool Exists(string name) { var explicitFolder = name.Contains(':') && !Directory.Exists(Path.GetDirectoryName(name)); if (explicitFolder) @@ -243,8 +233,6 @@ namespace OpenRA.FileSystem return MountedFolders.Any(f => f.Exists(name)); } - static Dictionary assemblyCache = new Dictionary(); - public static Assembly ResolveAssembly(object sender, ResolveEventArgs e) { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) @@ -255,15 +243,15 @@ namespace OpenRA.FileSystem var filename = frags[0] + ".dll"; Assembly a; - if (assemblyCache.TryGetValue(filename, out a)) + if (AssemblyCache.TryGetValue(filename, out a)) return a; - if (Exists(filename)) - using (var s = Open(filename)) + if (Game.ModData.ModFiles.Exists(filename)) + using (var s = Game.ModData.ModFiles.Open(filename)) { var buf = s.ReadBytes((int)s.Length); a = Assembly.Load(buf); - assemblyCache.Add(filename, a); + AssemblyCache.Add(filename, a); return a; } diff --git a/OpenRA.Game/FileSystem/IFolder.cs b/OpenRA.Game/FileSystem/IFolder.cs new file mode 100644 index 0000000000..fa5aa4df87 --- /dev/null +++ b/OpenRA.Game/FileSystem/IFolder.cs @@ -0,0 +1,28 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.IO; + +namespace OpenRA.FileSystem +{ + public interface IFolder : IDisposable + { + Stream GetContent(string filename); + bool Exists(string filename); + IEnumerable ClassicHashes(); + IEnumerable CrcHashes(); + IEnumerable AllFileNames(); + void Write(Dictionary contents); + int Priority { get; } + string Name { get; } + } +} diff --git a/OpenRA.Game/FileSystem/InstallShieldCABExtractor.cs b/OpenRA.Game/FileSystem/InstallShieldCABExtractor.cs index 93356786b7..9086d90c33 100644 --- a/OpenRA.Game/FileSystem/InstallShieldCABExtractor.cs +++ b/OpenRA.Game/FileSystem/InstallShieldCABExtractor.cs @@ -14,11 +14,10 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; using ICSharpCode.SharpZipLib.Zip.Compression; -using ICSharpCode.SharpZipLib.Zip.Compression.Streams; namespace OpenRA.FileSystem { - public class InstallShieldCABExtractor : IDisposable, IFolder + public class InstallShieldCABExtractor : IFolder { const uint FileSplit = 0x1; const uint FileObfuscated = 0x2; @@ -187,6 +186,7 @@ namespace OpenRA.FileSystem class CabReader : IDisposable { + readonly FileSystem context; readonly FileDescriptor fileDes; public uint RemainingArchiveStream; public uint RemainingFileStream; @@ -195,11 +195,12 @@ namespace OpenRA.FileSystem ushort volumeNumber; Stream cabFile; - public CabReader(FileDescriptor fileDes, uint index, string commonName) + public CabReader(FileSystem context, FileDescriptor fileDes, uint index, string commonName) { this.fileDes = fileDes; this.index = index; this.commonName = commonName; + this.context = context; volumeNumber = (ushort)((uint)fileDes.Volume - 1u); RemainingArchiveStream = 0; if ((fileDes.Flags & FileCompressed) > 0) @@ -208,7 +209,7 @@ namespace OpenRA.FileSystem RemainingFileStream = fileDes.ExpandedSize; cabFile = null; - NextFile(); + NextFile(context); } public void CopyTo(Stream dest) @@ -258,7 +259,7 @@ namespace OpenRA.FileSystem var read = cabFile.Read(outArray, 0, (int)RemainingArchiveStream); if (RemainingFileStream > RemainingArchiveStream) { - NextFile(); + NextFile(context); RemainingArchiveStream -= (uint)cabFile.Read(outArray, read, (int)count - read); } @@ -271,13 +272,13 @@ namespace OpenRA.FileSystem cabFile.Dispose(); } - public void NextFile() + void NextFile(FileSystem context) { if (cabFile != null) cabFile.Dispose(); ++volumeNumber; - cabFile = GlobalFileSystem.Open("{0}{1}.cab".F(commonName, volumeNumber)); + cabFile = context.Open("{0}{1}.cab".F(commonName, volumeNumber)); if (cabFile.ReadUInt32() != 0x28635349) throw new InvalidDataException("Not an Installshield CAB package"); @@ -329,19 +330,21 @@ namespace OpenRA.FileSystem readonly Dictionary directoryNames = new Dictionary(); readonly Dictionary fileDescriptors = new Dictionary(); readonly Dictionary fileLookup = new Dictionary(); + readonly FileSystem context; int priority; string commonName; public int Priority { get { return priority; } } public string Name { get { return commonName; } } - public InstallShieldCABExtractor(string hdrFilename, int priority = -1) + public InstallShieldCABExtractor(FileSystem context, string hdrFilename, int priority = -1) { var fileGroups = new List(); var fileGroupOffsets = new List(); + hdrFile = context.Open(hdrFilename); this.priority = priority; - hdrFile = GlobalFileSystem.Open(hdrFilename); + this.context = context; // Strips archive number AND file extension commonName = Regex.Replace(hdrFilename, @"\d*\.[^\.]*$", ""); @@ -472,7 +475,7 @@ namespace OpenRA.FileSystem var output = new MemoryStream((int)fileDes.ExpandedSize); - using (var reader = new CabReader(fileDes, index, commonName)) + using (var reader = new CabReader(context, fileDes, index, commonName)) reader.CopyTo(output); if (output.Length != fileDes.ExpandedSize) @@ -497,7 +500,7 @@ namespace OpenRA.FileSystem if ((fileDes.Flags & FileObfuscated) != 0) throw new NotImplementedException("Haven't implemented obfuscated files"); - using (var reader = new CabReader(fileDes, index, commonName)) + using (var reader = new CabReader(context, fileDes, index, commonName)) reader.CopyTo(output); if (output.Length != fileDes.ExpandedSize) diff --git a/OpenRA.Game/FileSystem/InstallShieldPackage.cs b/OpenRA.Game/FileSystem/InstallShieldPackage.cs index c5c5350077..80127f936f 100644 --- a/OpenRA.Game/FileSystem/InstallShieldPackage.cs +++ b/OpenRA.Game/FileSystem/InstallShieldPackage.cs @@ -24,14 +24,14 @@ namespace OpenRA.FileSystem readonly int priority; readonly string filename; - public InstallShieldPackage(string filename, int priority) + public InstallShieldPackage(FileSystem context, string filename, int priority) { this.filename = filename; this.priority = priority; filenames = new List(); - s = GlobalFileSystem.Open(filename); + s = context.Open(filename); try { // Parse package header diff --git a/OpenRA.Game/FileSystem/MixFile.cs b/OpenRA.Game/FileSystem/MixFile.cs index 31d8c9341e..bf65f4fc6d 100644 --- a/OpenRA.Game/FileSystem/MixFile.cs +++ b/OpenRA.Game/FileSystem/MixFile.cs @@ -25,14 +25,16 @@ namespace OpenRA.FileSystem readonly Stream s; readonly int priority; readonly string filename; + readonly FileSystem context; readonly PackageHashType type; // Save a mix to disk with the given contents - public MixFile(string filename, int priority, Dictionary contents) + public MixFile(FileSystem context, string filename, int priority, Dictionary contents) { this.filename = filename; this.priority = priority; this.type = PackageHashType.Classic; + this.context = context; if (File.Exists(filename)) File.Delete(filename); @@ -51,13 +53,14 @@ namespace OpenRA.FileSystem } } - public MixFile(string filename, PackageHashType type, int priority) + public MixFile(FileSystem context, string filename, PackageHashType type, int priority) { this.filename = filename; this.priority = priority; this.type = type; + this.context = context; - s = GlobalFileSystem.Open(filename); + s = context.Open(filename); try { // Detect format type @@ -223,9 +226,9 @@ namespace OpenRA.FileSystem } } - if (GlobalFileSystem.Exists("global mix database.dat")) + if (context.Exists("global mix database.dat")) { - var db = new XccGlobalDatabase(GlobalFileSystem.Open("global mix database.dat")); + var db = new XccGlobalDatabase(context.Open("global mix database.dat")); foreach (var e in db.Entries) { var hash = PackageEntry.HashFilename(e, type); @@ -249,7 +252,7 @@ namespace OpenRA.FileSystem { // Cannot modify existing mixfile - rename existing file and // create a new one with original content plus modifications - GlobalFileSystem.Unmount(this); + context.Unmount(this); // TODO: Add existing data to the contents list if (index.Count > 0) diff --git a/OpenRA.Game/FileSystem/Pak.cs b/OpenRA.Game/FileSystem/Pak.cs index eb15e1dab0..51f69113f8 100644 --- a/OpenRA.Game/FileSystem/Pak.cs +++ b/OpenRA.Game/FileSystem/Pak.cs @@ -28,13 +28,13 @@ namespace OpenRA.FileSystem readonly Dictionary index; readonly Stream stream; - public PakFile(string filename, int priority) + public PakFile(FileSystem context, string filename, int priority) { this.filename = filename; this.priority = priority; index = new Dictionary(); - stream = GlobalFileSystem.Open(filename); + stream = context.Open(filename); try { index = new Dictionary(); diff --git a/OpenRA.Game/FileSystem/ZipFile.cs b/OpenRA.Game/FileSystem/ZipFile.cs index 92cfbf6caf..cbf9b720bf 100644 --- a/OpenRA.Game/FileSystem/ZipFile.cs +++ b/OpenRA.Game/FileSystem/ZipFile.cs @@ -28,10 +28,11 @@ namespace OpenRA.FileSystem ZipConstants.DefaultCodePage = Encoding.Default.CodePage; } - public ZipFile(string filename, int priority) + public ZipFile(FileSystem context, string filename, int priority) { this.filename = filename; this.priority = priority; + try { // Pull the file into memory, don't keep it open. @@ -44,7 +45,7 @@ namespace OpenRA.FileSystem } // Create a new zip with the specified contents. - public ZipFile(string filename, int priority, Dictionary contents) + public ZipFile(FileSystem context, string filename, int priority, Dictionary contents) { this.priority = priority; this.filename = filename; diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 76eee3235b..9d17c53d1a 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -17,7 +17,6 @@ using System.Linq; using System.Net; using System.Threading; using OpenRA.Chat; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Network; using OpenRA.Primitives; @@ -196,7 +195,7 @@ namespace OpenRA { Console.WriteLine("Platform is {0}", Platform.CurrentPlatform); - AppDomain.CurrentDomain.AssemblyResolve += GlobalFileSystem.ResolveAssembly; + AppDomain.CurrentDomain.AssemblyResolve += FileSystem.FileSystem.ResolveAssembly; InitializeSettings(args); @@ -219,7 +218,6 @@ namespace OpenRA GeoIP.Initialize(); - GlobalFileSystem.Mount(Platform.GameDir); // Needed to access shaders var renderers = new[] { Settings.Graphics.Renderer, "Default", null }; foreach (var r in renderers) { @@ -280,7 +278,11 @@ namespace OpenRA OrderManager.Dispose(); if (ModData != null) + { + ModData.ModFiles.UnmountAll(); ModData.Dispose(); + } + ModData = null; // Fall back to default if the mod doesn't exist or has missing prerequisites. diff --git a/OpenRA.Game/GameRules/MusicInfo.cs b/OpenRA.Game/GameRules/MusicInfo.cs index dd91bed550..3cce2d9804 100644 --- a/OpenRA.Game/GameRules/MusicInfo.cs +++ b/OpenRA.Game/GameRules/MusicInfo.cs @@ -9,7 +9,6 @@ #endregion using OpenRA.FileFormats; -using OpenRA.FileSystem; namespace OpenRA.GameRules { @@ -36,11 +35,11 @@ namespace OpenRA.GameRules public void Load() { - if (!GlobalFileSystem.Exists(Filename)) + if (!Game.ModData.ModFiles.Exists(Filename)) return; Exists = true; - using (var s = GlobalFileSystem.Open(Filename)) + using (var s = Game.ModData.ModFiles.Open(Filename)) { if (Filename.ToLowerInvariant().EndsWith("wav")) Length = (int)WavLoader.WaveLength(s); diff --git a/OpenRA.Game/Graphics/ChromeProvider.cs b/OpenRA.Game/Graphics/ChromeProvider.cs index 89148a3b28..7a4490a24c 100644 --- a/OpenRA.Game/Graphics/ChromeProvider.cs +++ b/OpenRA.Game/Graphics/ChromeProvider.cs @@ -9,6 +9,7 @@ #endregion using System.Collections.Generic; +using System.IO; using System.Linq; namespace OpenRA.Graphics @@ -110,7 +111,9 @@ namespace OpenRA.Graphics sheet = cachedSheets[mi.Src]; else { - sheet = new Sheet(SheetType.BGRA, mi.Src); + using (var stream = Game.ModData.ModFiles.Open(mi.Src)) + sheet = new Sheet(SheetType.BGRA, stream); + cachedSheets.Add(mi.Src, sheet); } diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs index 2267d70170..5352054ec3 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -10,10 +10,7 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; -using OpenRA.FileSystem; -using OpenRA.Primitives; namespace OpenRA.Graphics { @@ -42,7 +39,7 @@ namespace OpenRA.Graphics var palettes = new Dictionary(); foreach (var p in nodesDict["Palettes"].Nodes) - palettes.Add(p.Key, new ImmutablePalette(GlobalFileSystem.Open(p.Value.Value), shadowIndex)); + palettes.Add(p.Key, new ImmutablePalette(modData.ModFiles.Open(p.Value.Value), shadowIndex)); Palettes = palettes.AsReadOnly(); diff --git a/OpenRA.Game/Graphics/Sheet.cs b/OpenRA.Game/Graphics/Sheet.cs index aaee749448..73f9a2b89a 100644 --- a/OpenRA.Game/Graphics/Sheet.cs +++ b/OpenRA.Game/Graphics/Sheet.cs @@ -11,8 +11,9 @@ using System; using System.Drawing; using System.Drawing.Imaging; +using System.IO; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using OpenRA.FileSystem; namespace OpenRA.Graphics { @@ -47,9 +48,8 @@ namespace OpenRA.Graphics Size = texture.Size; } - public Sheet(SheetType type, string filename) + public Sheet(SheetType type, Stream stream) { - using (var stream = GlobalFileSystem.Open(filename)) using (var bitmap = (Bitmap)Image.FromStream(stream)) { Size = bitmap.Size; diff --git a/OpenRA.Game/Graphics/SpriteLoader.cs b/OpenRA.Game/Graphics/SpriteLoader.cs index 220844ef8f..57abfdc7de 100644 --- a/OpenRA.Game/Graphics/SpriteLoader.cs +++ b/OpenRA.Game/Graphics/SpriteLoader.cs @@ -11,7 +11,6 @@ using System.Drawing; using System.IO; using System.Linq; -using OpenRA.FileSystem; using OpenRA.Primitives; namespace OpenRA.Graphics @@ -66,7 +65,7 @@ namespace OpenRA.Graphics public static ISpriteFrame[] GetFrames(string filename, ISpriteLoader[] loaders) { - using (var stream = GlobalFileSystem.Open(filename)) + using (var stream = Game.ModData.ModFiles.Open(filename)) { ISpriteFrame[] frames; foreach (var loader in loaders) diff --git a/OpenRA.Game/Graphics/VoxelLoader.cs b/OpenRA.Game/Graphics/VoxelLoader.cs index afac3ab8e3..64630e54a2 100644 --- a/OpenRA.Game/Graphics/VoxelLoader.cs +++ b/OpenRA.Game/Graphics/VoxelLoader.cs @@ -13,7 +13,6 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using OpenRA.FileFormats; -using OpenRA.FileSystem; using OpenRA.Primitives; namespace OpenRA.Graphics @@ -217,9 +216,9 @@ namespace OpenRA.Graphics { VxlReader vxl; HvaReader hva; - using (var s = GlobalFileSystem.Open(files.First + ".vxl")) + using (var s = Game.ModData.ModFiles.Open(files.First + ".vxl")) vxl = new VxlReader(s); - using (var s = GlobalFileSystem.Open(files.Second + ".hva")) + using (var s = Game.ModData.ModFiles.Open(files.Second + ".hva")) hva = new HvaReader(s, files.Second + ".hva"); return new Voxel(this, vxl, hva); } diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 19bdf5e802..f190c5b3f8 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -317,7 +317,7 @@ namespace OpenRA public Map(string path) { Path = path; - Container = GlobalFileSystem.OpenPackage(path, null, int.MaxValue); + Container = Game.ModData.ModFiles.OpenPackage(path, null, int.MaxValue); AssertExists("map.yaml"); AssertExists("map.bin"); @@ -650,7 +650,7 @@ namespace OpenRA Path = toPath; // Create a new map package - Container = GlobalFileSystem.CreatePackage(Path, int.MaxValue, entries); + Container = Game.ModData.ModFiles.CreatePackage(Path, int.MaxValue, entries); } // Update existing package diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index 4fbaf94feb..ed7034ed53 100644 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -12,7 +12,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using OpenRA.FileSystem; namespace OpenRA { @@ -230,12 +229,6 @@ namespace OpenRA return ret; } - public static List FromFileInPackage(string path) - { - using (var stream = GlobalFileSystem.Open(path)) - return FromLines(stream.ReadAllLines(), path); - } - public static Dictionary DictFromFile(string path) { return FromFile(path).ToDictionary(x => x.Key, x => x.Value); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index bfd345619e..60ea3d44c0 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -13,9 +13,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Widgets; +using FS = OpenRA.FileSystem.FileSystem; namespace OpenRA { @@ -31,8 +31,9 @@ namespace OpenRA public ILoadScreen LoadScreen { get; private set; } public VoxelLoader VoxelLoader { get; private set; } public CursorProvider CursorProvider { get; private set; } + public FS ModFiles = new FS(); - Lazy defaultRules; + readonly Lazy defaultRules; public Ruleset DefaultRules { get { return defaultRules.Value; } } public ModData(string mod, bool useLoadScreen = false) @@ -95,7 +96,7 @@ namespace OpenRA public void MountFiles() { - GlobalFileSystem.LoadFromManifest(Manifest); + ModFiles.LoadFromManifest(Manifest); } public void InitializeLoaders() @@ -166,10 +167,10 @@ namespace OpenRA // Reinitialize all our assets InitializeLoaders(); - GlobalFileSystem.LoadFromManifest(Manifest); + ModFiles.LoadFromManifest(Manifest); // Mount map package so custom assets can be used. TODO: check priority. - GlobalFileSystem.Mount(GlobalFileSystem.OpenPackage(map.Path, null, int.MaxValue)); + ModFiles.Mount(ModFiles.OpenPackage(map.Path, null, int.MaxValue)); using (new Support.PerfTimer("Map.PreloadRules")) map.PreloadRules(); diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 4c9bf7f17b..8188c4cfa7 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -95,6 +95,7 @@ + @@ -321,7 +322,7 @@ - + diff --git a/OpenRA.Game/Scripting/ScriptContext.cs b/OpenRA.Game/Scripting/ScriptContext.cs index f869fb2820..9e274d5423 100644 --- a/OpenRA.Game/Scripting/ScriptContext.cs +++ b/OpenRA.Game/Scripting/ScriptContext.cs @@ -11,12 +11,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Drawing; -using System.IO; using System.Linq; using System.Reflection; using Eluant; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Primitives; using OpenRA.Support; @@ -133,7 +130,7 @@ namespace OpenRA.Scripting .ToArray(); runtime.Globals["GameDir"] = Platform.GameDir; - runtime.DoBuffer(GlobalFileSystem.Open(Platform.ResolvePath(".", "lua", "scriptwrapper.lua")).ReadAllText(), "scriptwrapper.lua").Dispose(); + runtime.DoBuffer(Game.ModData.ModFiles.Open(Platform.ResolvePath(".", "lua", "scriptwrapper.lua")).ReadAllText(), "scriptwrapper.lua").Dispose(); tick = (LuaFunction)runtime.Globals["Tick"]; // Register globals @@ -172,7 +169,7 @@ namespace OpenRA.Scripting using (var loadScript = (LuaFunction)runtime.Globals["ExecuteSandboxedScript"]) { foreach (var s in scripts) - loadScript.Call(s, GlobalFileSystem.Open(s).ReadAllText()).Dispose(); + loadScript.Call(s, Game.ModData.ModFiles.Open(s).ReadAllText()).Dispose(); } } diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index 2127cc1046..b6beb531bd 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -9,14 +9,11 @@ #endregion using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; using OpenRA.FileFormats; -using OpenRA.FileSystem; using OpenRA.GameRules; using OpenRA.Primitives; -using OpenRA.Traits; namespace OpenRA { @@ -48,17 +45,17 @@ namespace OpenRA ISoundSource LoadSound(string filename) { - if (!GlobalFileSystem.Exists(filename)) + if (!Game.ModData.ModFiles.Exists(filename)) { Log.Write("sound", "LoadSound, file does not exist: {0}", filename); return null; } if (filename.ToLowerInvariant().EndsWith("wav")) - using (var s = GlobalFileSystem.Open(filename)) + using (var s = Game.ModData.ModFiles.Open(filename)) return LoadWave(new WavLoader(s)); - using (var s = GlobalFileSystem.Open(filename)) + using (var s = Game.ModData.ModFiles.Open(filename)) return LoadSoundRaw(AudLoader.LoadSound(s), 1, 16, 22050); } diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index 2d75becf2e..aedc046d1f 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; +using System.IO; using OpenRA.Graphics; using OpenRA.Mods.Common.LoadScreens; using OpenRA.Widgets; @@ -41,7 +42,9 @@ namespace OpenRA.Mods.Cnc r = Game.Renderer; if (r == null) return; - sheet = new Sheet(SheetType.BGRA, Platform.ResolvePath(loadInfo["Image"])); + using (var stream = File.OpenRead(Platform.ResolvePath(loadInfo["Image"]))) + sheet = new Sheet(SheetType.BGRA, stream); + var res = r.Resolution; bounds = new Rectangle(0, 0, res.Width, res.Height); diff --git a/OpenRA.Mods.Common/InstallUtils.cs b/OpenRA.Mods.Common/InstallUtils.cs index 98e471ff0c..4489c41500 100644 --- a/OpenRA.Mods.Common/InstallUtils.cs +++ b/OpenRA.Mods.Common/InstallUtils.cs @@ -14,7 +14,6 @@ using System.IO; using System.Linq; using ICSharpCode.SharpZipLib; using ICSharpCode.SharpZipLib.Zip; -using OpenRA.FileSystem; namespace OpenRA.Mods.Common { @@ -46,9 +45,9 @@ namespace OpenRA.Mods.Common Directory.CreateDirectory(destPath); Log.Write("debug", "Mounting {0}".F(srcPath)); - GlobalFileSystem.Mount(srcPath); + Game.ModData.ModFiles.Mount(srcPath); Log.Write("debug", "Mounting {0}".F(package)); - GlobalFileSystem.Mount(package, annotation); + Game.ModData.ModFiles.Mount(package, annotation); foreach (var directory in filesByDirectory) { @@ -71,7 +70,7 @@ namespace OpenRA.Mods.Common Directory.CreateDirectory(containingDir); - using (var sourceStream = GlobalFileSystem.Open(file)) + using (var sourceStream = Game.ModData.ModFiles.Open(file)) using (var destStream = File.Create(dest)) { Log.Write("debug", "Extracting {0} to {1}".F(file, dest)); diff --git a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs index 2ffed1422e..1408a50686 100644 --- a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs @@ -8,12 +8,10 @@ */ #endregion -using System; using System.Collections.Generic; using System.IO; using System.Linq; using OpenRA.FileFormats; -using OpenRA.FileSystem; using OpenRA.Mods.Common.Widgets.Logic; using OpenRA.Widgets; diff --git a/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs index ebfc11a7a2..150f9b65b2 100644 --- a/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; +using System.IO; using OpenRA.Graphics; using OpenRA.Widgets; @@ -40,7 +41,9 @@ namespace OpenRA.Mods.Common.LoadScreens if (info.ContainsKey("Image")) { - sheet = new Sheet(SheetType.BGRA, Platform.ResolvePath(info["Image"])); + using (var stream = File.OpenRead(Platform.ResolvePath(info["Image"]))) + sheet = new Sheet(SheetType.BGRA, stream); + logo = new Sprite(sheet, new Rectangle(0, 0, 256, 256), TextureChannel.Alpha); stripe = new Sprite(sheet, new Rectangle(256, 0, 256, 256), TextureChannel.Alpha); stripeRect = new Rectangle(0, r.Resolution.Height / 2 - 128, r.Resolution.Width, 256); diff --git a/OpenRA.Mods.Common/LoadScreens/ModChooserLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/ModChooserLoadScreen.cs index 13f5f24d7d..ae2287651a 100644 --- a/OpenRA.Mods.Common/LoadScreens/ModChooserLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/ModChooserLoadScreen.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Drawing; +using System.IO; using OpenRA.Graphics; using OpenRA.Widgets; @@ -22,10 +23,14 @@ namespace OpenRA.Mods.Common.LoadScreens public void Init(Manifest m, Dictionary info) { - var sheet = new Sheet(SheetType.BGRA, info["Image"]); var res = Game.Renderer.Resolution; bounds = new Rectangle(0, 0, res.Width, res.Height); - sprite = new Sprite(sheet, new Rectangle(0, 0, 1024, 480), TextureChannel.Alpha); + + using (var stream = File.OpenRead(info["Image"])) + { + var sheet = new Sheet(SheetType.BGRA, stream); + sprite = new Sprite(sheet, new Rectangle(0, 0, 1024, 480), TextureChannel.Alpha); + } } public void Display() diff --git a/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs index b147a48987..f680774eea 100644 --- a/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs @@ -14,7 +14,6 @@ using System.IO; using Eluant; using OpenRA.Effects; using OpenRA.FileFormats; -using OpenRA.FileSystem; using OpenRA.GameRules; using OpenRA.Graphics; using OpenRA.Mods.Common.Effects; @@ -165,10 +164,10 @@ namespace OpenRA.Mods.Common.Scripting else onCompleteRadar = () => { }; - Stream s = null; + Stream s; try { - s = GlobalFileSystem.Open(movie); + s = Game.ModData.ModFiles.Open(movie); } catch (FileNotFoundException e) { diff --git a/OpenRA.Mods.Common/Traits/World/PaletteFromCurrentTileset.cs b/OpenRA.Mods.Common/Traits/World/PaletteFromCurrentTileset.cs index c0997e4ed3..ede922fefe 100644 --- a/OpenRA.Mods.Common/Traits/World/PaletteFromCurrentTileset.cs +++ b/OpenRA.Mods.Common/Traits/World/PaletteFromCurrentTileset.cs @@ -9,7 +9,6 @@ #endregion using System.Collections.Generic; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Traits; @@ -43,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits public void LoadPalettes(WorldRenderer wr) { - wr.AddPalette(info.Name, new ImmutablePalette(GlobalFileSystem.Open(world.TileSet.Palette), info.ShadowIndex), info.AllowModifiers); + wr.AddPalette(info.Name, new ImmutablePalette(Game.ModData.ModFiles.Open(world.TileSet.Palette), info.ShadowIndex), info.AllowModifiers); } public IEnumerable PaletteNames { get { yield return info.Name; } } diff --git a/OpenRA.Mods.Common/Traits/World/PaletteFromFile.cs b/OpenRA.Mods.Common/Traits/World/PaletteFromFile.cs index 1cb85da799..152f029a37 100644 --- a/OpenRA.Mods.Common/Traits/World/PaletteFromFile.cs +++ b/OpenRA.Mods.Common/Traits/World/PaletteFromFile.cs @@ -9,7 +9,6 @@ #endregion using System.Collections.Generic; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Traits; @@ -49,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits public void LoadPalettes(WorldRenderer wr) { if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant()) - wr.AddPalette(info.Name, new ImmutablePalette(GlobalFileSystem.Open(info.Filename), info.ShadowIndex), info.AllowModifiers); + wr.AddPalette(info.Name, new ImmutablePalette(Game.ModData.ModFiles.Open(info.Filename), info.ShadowIndex), info.AllowModifiers); } public IEnumerable PaletteNames diff --git a/OpenRA.Mods.Common/Traits/World/PlayerPaletteFromCurrentTileset.cs b/OpenRA.Mods.Common/Traits/World/PlayerPaletteFromCurrentTileset.cs index 9ec1253ff3..4e3dbdc6d9 100644 --- a/OpenRA.Mods.Common/Traits/World/PlayerPaletteFromCurrentTileset.cs +++ b/OpenRA.Mods.Common/Traits/World/PlayerPaletteFromCurrentTileset.cs @@ -8,7 +8,6 @@ */ #endregion -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Traits; @@ -41,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits public void LoadPalettes(WorldRenderer wr) { var filename = world.TileSet.PlayerPalette ?? world.TileSet.Palette; - wr.AddPalette(info.Name, new ImmutablePalette(GlobalFileSystem.Open(filename), info.ShadowIndex), info.AllowModifiers); + wr.AddPalette(info.Name, new ImmutablePalette(Game.ModData.ModFiles.Open(filename), info.ShadowIndex), info.AllowModifiers); } } } diff --git a/OpenRA.Mods.Common/UtilityCommands/CheckCodeStyle.cs b/OpenRA.Mods.Common/UtilityCommands/CheckCodeStyle.cs index 3fc54bf4ad..38be383b50 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CheckCodeStyle.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CheckCodeStyle.cs @@ -30,6 +30,9 @@ namespace OpenRA.Mods.Common.UtilityCommands var relativePath = args[1]; var projectPath = Path.GetFullPath(relativePath); + // HACK: The engine code assumes that Game.modData is set. + Game.ModData = modData; + var console = new StyleCopConsole(null, false, null, null, true); var project = new CodeProject(0, projectPath, new Configuration(null)); foreach (var filePath in Directory.GetFiles(projectPath, "*.cs", SearchOption.AllDirectories)) diff --git a/OpenRA.Mods.Common/UtilityCommands/CheckSequenceSprites.cs b/OpenRA.Mods.Common/UtilityCommands/CheckSequenceSprites.cs index 11671cd10f..9968528f99 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CheckSequenceSprites.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CheckSequenceSprites.cs @@ -10,7 +10,6 @@ using System; using System.Linq; -using OpenRA.FileSystem; using OpenRA.Graphics; namespace OpenRA.Mods.Common.UtilityCommands @@ -29,7 +28,7 @@ namespace OpenRA.Mods.Common.UtilityCommands { // HACK: The engine code assumes that Game.modData is set. Game.ModData = modData; - GlobalFileSystem.LoadFromManifest(Game.ModData.Manifest); + Game.ModData.ModFiles.LoadFromManifest(Game.ModData.Manifest); Game.ModData.SpriteSequenceLoader.OnMissingSpriteError = s => Console.WriteLine("\t" + s); foreach (var t in Game.ModData.Manifest.TileSets) diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractFilesCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractFilesCommand.cs index cffb2b02e8..6445c202fb 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ExtractFilesCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractFilesCommand.cs @@ -28,11 +28,11 @@ namespace OpenRA.Mods.Common.UtilityCommands public void Run(ModData modData, string[] args) { var files = args.Skip(1); - GlobalFileSystem.LoadFromManifest(modData.Manifest); + modData.ModFiles.LoadFromManifest(modData.Manifest); foreach (var f in files) { - var src = GlobalFileSystem.Open(f); + var src = modData.ModFiles.Open(f); if (src == null) throw new InvalidOperationException("File not found: {0}".F(f)); var data = src.ReadAllBytes(); diff --git a/OpenRA.Mods.Common/UtilityCommands/FixClassicTilesets.cs b/OpenRA.Mods.Common/UtilityCommands/FixClassicTilesets.cs index e5357839c0..44b8066c3d 100644 --- a/OpenRA.Mods.Common/UtilityCommands/FixClassicTilesets.cs +++ b/OpenRA.Mods.Common/UtilityCommands/FixClassicTilesets.cs @@ -13,7 +13,6 @@ using System.Drawing; using System.IO; using System.Linq; using System.Reflection; -using OpenRA.FileSystem; using OpenRA.Graphics; namespace OpenRA.Mods.Common.UtilityCommands @@ -32,7 +31,7 @@ namespace OpenRA.Mods.Common.UtilityCommands { // HACK: The engine code assumes that Game.modData is set. Game.ModData = modData; - GlobalFileSystem.LoadFromManifest(Game.ModData.Manifest); + modData.ModFiles.LoadFromManifest(Game.ModData.Manifest); var imageField = typeof(TerrainTemplateInfo).GetField("Image"); var pickAnyField = typeof(TerrainTemplateInfo).GetField("PickAny"); @@ -56,7 +55,7 @@ namespace OpenRA.Mods.Common.UtilityCommands foreach (var ext in exts) { Stream s; - if (GlobalFileSystem.TryOpen(template.Images[0] + ext, out s)) + if (modData.ModFiles.TryOpen(template.Images[0] + ext, out s)) s.Dispose(); else continue; diff --git a/OpenRA.Mods.Common/UtilityCommands/GenerateMinimapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/GenerateMinimapCommand.cs index 344b329bd2..181fe1523d 100644 --- a/OpenRA.Mods.Common/UtilityCommands/GenerateMinimapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/GenerateMinimapCommand.cs @@ -10,7 +10,6 @@ using System; using System.IO; -using OpenRA.FileSystem; using OpenRA.Graphics; namespace OpenRA.Mods.Common.UtilityCommands @@ -30,9 +29,9 @@ namespace OpenRA.Mods.Common.UtilityCommands Game.ModData = modData; var map = new Map(args[1]); - GlobalFileSystem.UnmountAll(); + modData.ModFiles.UnmountAll(); foreach (var dir in Game.ModData.Manifest.Folders) - GlobalFileSystem.Mount(dir); + modData.ModFiles.Mount(dir); var minimap = Minimap.RenderMapPreview(map.Rules.TileSets[map.Tileset], map, true); diff --git a/OpenRA.Mods.Common/UtilityCommands/LegacyMapImporter.cs b/OpenRA.Mods.Common/UtilityCommands/LegacyMapImporter.cs index 96c878e68c..4fd92de815 100644 --- a/OpenRA.Mods.Common/UtilityCommands/LegacyMapImporter.cs +++ b/OpenRA.Mods.Common/UtilityCommands/LegacyMapImporter.cs @@ -14,7 +14,6 @@ using System.IO; using System.Linq; using System.Text; using OpenRA.FileFormats; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Primitives; @@ -130,7 +129,7 @@ namespace OpenRA.Mods.Common.UtilityCommands public void ConvertIniMap(string iniFile) { - using (var stream = GlobalFileSystem.Open(iniFile)) + using (var stream = Game.ModData.ModFiles.Open(iniFile)) { var file = new IniFile(stream); var basic = file.GetSection("Basic"); @@ -162,7 +161,7 @@ namespace OpenRA.Mods.Common.UtilityCommands else { // CnC - using (var s = GlobalFileSystem.Open(iniFile.Substring(0, iniFile.Length - 4) + ".bin")) + using (var s = Game.ModData.ModFiles.Open(iniFile.Substring(0, iniFile.Length - 4) + ".bin")) UnpackCncTileData(s); ReadCncOverlay(file); ReadCncTrees(file); diff --git a/OpenRA.Mods.Common/UtilityCommands/RemapShpCommand.cs b/OpenRA.Mods.Common/UtilityCommands/RemapShpCommand.cs index e4fb9f6b2a..a12860e199 100644 --- a/OpenRA.Mods.Common/UtilityCommands/RemapShpCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/RemapShpCommand.cs @@ -13,7 +13,6 @@ using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Mods.Common.SpriteLoaders; using OpenRA.Traits; @@ -41,14 +40,14 @@ namespace OpenRA.Mods.Common.UtilityCommands var srcMod = args[1].Split(':')[0]; Game.ModData = new ModData(srcMod); - GlobalFileSystem.LoadFromManifest(Game.ModData.Manifest); + Game.ModData.ModFiles.LoadFromManifest(Game.ModData.Manifest); var srcRules = Game.ModData.RulesetCache.Load(); var srcPaletteInfo = srcRules.Actors["player"].TraitInfo(); var srcRemapIndex = srcPaletteInfo.RemapIndex; var destMod = args[2].Split(':')[0]; Game.ModData = new ModData(destMod); - GlobalFileSystem.LoadFromManifest(Game.ModData.Manifest); + Game.ModData.ModFiles.LoadFromManifest(Game.ModData.Manifest); var destRules = Game.ModData.RulesetCache.Load(); var destPaletteInfo = destRules.Actors["player"].TraitInfo(); var destRemapIndex = destPaletteInfo.RemapIndex; diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index 8b27509659..95653fc16c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic this.world = world; panel = widget; - assetSource = GlobalFileSystem.MountedFolders.First(); + assetSource = Game.ModData.ModFiles.MountedFolders.First(); var ticker = panel.GetOrNull("ANIMATION_TICKER"); if (ticker != null) @@ -306,7 +306,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (string.IsNullOrEmpty(filename)) return false; - if (!GlobalFileSystem.Exists(filename)) + if (!Game.ModData.ModFiles.Exists(filename)) return false; if (Path.GetExtension(filename.ToLowerInvariant()) == ".vqa") @@ -345,7 +345,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic // TODO: Re-enable "All Packages" once list generation is done in a background thread // var sources = new[] { (IFolder)null }.Concat(GlobalFileSystem.MountedFolders); - var sources = GlobalFileSystem.MountedFolders; + var sources = Game.ModData.ModFiles.MountedFolders; dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 280, sources, setupItem); return true; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs index a4054334e8..a65305d7e2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs @@ -10,7 +10,6 @@ #endregion using System; -using OpenRA.FileSystem; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic @@ -32,7 +31,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var template = scrollPanel.Get("CREDITS_TEMPLATE"); scrollPanel.RemoveChildren(); - var lines = GlobalFileSystem.Open("AUTHORS").ReadAllLines(); + var lines = Game.ModData.ModFiles.Open("AUTHORS").ReadAllLines(); foreach (var l in lines) { // Improve the formatting diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromCDLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromCDLogic.cs index 89a096cf73..1d5b2be5cf 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromCDLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromCDLogic.cs @@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic new Thread(() => { - using (var cabExtractor = new InstallShieldCABExtractor(source)) + using (var cabExtractor = new InstallShieldCABExtractor(Game.ModData.ModFiles, source)) { var denom = installData.InstallShieldCABFileIds.Count; var extractFiles = installData.ExtractFilesFromCD; diff --git a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs index ec1fba73ee..329eeaaa88 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs @@ -14,7 +14,6 @@ using System.IO; using System.Linq; using System.Net; using System.Threading; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Network; using OpenRA.Widgets; @@ -171,11 +170,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic var briefingVideo = selectedMapPreview.Map.Videos.Briefing; var briefingVideoVisible = briefingVideo != null; - var briefingVideoDisabled = !(briefingVideoVisible && GlobalFileSystem.Exists(briefingVideo)); + var briefingVideoDisabled = !(briefingVideoVisible && Game.ModData.ModFiles.Exists(briefingVideo)); var infoVideo = selectedMapPreview.Map.Videos.BackgroundInfo; var infoVideoVisible = infoVideo != null; - var infoVideoDisabled = !(infoVideoVisible && GlobalFileSystem.Exists(infoVideo)); + var infoVideoDisabled = !(infoVideoVisible && Game.ModData.ModFiles.Exists(infoVideo)); startBriefingVideoButton.IsVisible = () => briefingVideoVisible && playingVideo != PlayingVideo.Briefing; startBriefingVideoButton.IsDisabled = () => briefingVideoDisabled || playingVideo != PlayingVideo.None; @@ -295,7 +294,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return; var gameStartVideo = selectedMapPreview.Map.Videos.GameStart; - if (gameStartVideo != null && GlobalFileSystem.Exists(gameStartVideo)) + if (gameStartVideo != null && Game.ModData.ModFiles.Exists(gameStartVideo)) { var fsPlayer = fullscreenVideoPlayer.Get("PLAYER"); fullscreenVideoPlayer.Visible = true; diff --git a/OpenRA.Mods.Common/Widgets/VqaPlayerWidget.cs b/OpenRA.Mods.Common/Widgets/VqaPlayerWidget.cs index c54fc289ee..ecb51c118e 100644 --- a/OpenRA.Mods.Common/Widgets/VqaPlayerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/VqaPlayerWidget.cs @@ -11,7 +11,6 @@ using System; using System.Drawing; using OpenRA.FileFormats; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Widgets; @@ -50,7 +49,7 @@ namespace OpenRA.Mods.Common.Widgets { if (filename == cachedVideo) return; - var video = new VqaReader(GlobalFileSystem.Open(filename)); + var video = new VqaReader(Game.ModData.ModFiles.Open(filename)); cachedVideo = filename; Open(video); diff --git a/OpenRA.Mods.D2k/Traits/World/FogPaletteFromR8.cs b/OpenRA.Mods.D2k/Traits/World/FogPaletteFromR8.cs index 91d7e19c2a..e5c3ddae44 100644 --- a/OpenRA.Mods.D2k/Traits/World/FogPaletteFromR8.cs +++ b/OpenRA.Mods.D2k/Traits/World/FogPaletteFromR8.cs @@ -10,7 +10,6 @@ using System.Collections.Generic; using System.IO; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; @@ -44,7 +43,7 @@ namespace OpenRA.Mods.D2k.Traits public void LoadPalettes(WorldRenderer wr) { var colors = new uint[Palette.Size]; - using (var s = GlobalFileSystem.Open(info.Filename)) + using (var s = Game.ModData.ModFiles.Open(info.Filename)) { s.Seek(info.Offset, SeekOrigin.Begin); diff --git a/OpenRA.Mods.D2k/Traits/World/PaletteFromR8.cs b/OpenRA.Mods.D2k/Traits/World/PaletteFromR8.cs index bb757ee323..4eb8488168 100644 --- a/OpenRA.Mods.D2k/Traits/World/PaletteFromR8.cs +++ b/OpenRA.Mods.D2k/Traits/World/PaletteFromR8.cs @@ -10,7 +10,6 @@ using System.Collections.Generic; using System.IO; -using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; @@ -44,7 +43,7 @@ namespace OpenRA.Mods.D2k.Traits public void LoadPalettes(WorldRenderer wr) { var colors = new uint[Palette.Size]; - using (var s = GlobalFileSystem.Open(info.Filename)) + using (var s = Game.ModData.ModFiles.Open(info.Filename)) { s.Seek(info.Offset, SeekOrigin.Begin); diff --git a/OpenRA.Mods.TS/UtilityCommands/LegacyTilesetImporter.cs b/OpenRA.Mods.TS/UtilityCommands/LegacyTilesetImporter.cs index 33c816a532..de4722fc82 100644 --- a/OpenRA.Mods.TS/UtilityCommands/LegacyTilesetImporter.cs +++ b/OpenRA.Mods.TS/UtilityCommands/LegacyTilesetImporter.cs @@ -12,7 +12,6 @@ using System; using System.Collections.Generic; using System.IO; using OpenRA.FileFormats; -using OpenRA.FileSystem; namespace OpenRA.Mods.TS.UtilityCommands { @@ -31,7 +30,7 @@ namespace OpenRA.Mods.TS.UtilityCommands // HACK: The engine code assumes that Game.modData is set. Game.ModData = modData; - GlobalFileSystem.LoadFromManifest(Game.ModData.Manifest); + Game.ModData.ModFiles.LoadFromManifest(Game.ModData.Manifest); var file = new IniFile(File.Open(args[1], FileMode.Open)); var extension = args[2]; @@ -73,10 +72,10 @@ namespace OpenRA.Mods.TS.UtilityCommands for (var i = 1; i <= sectionCount; i++, templateIndex++) { var templateFilename = "{0}{1:D2}.{2}".F(sectionFilename, i, extension); - if (!GlobalFileSystem.Exists(templateFilename)) + if (!Game.ModData.ModFiles.Exists(templateFilename)) continue; - using (var s = GlobalFileSystem.Open(templateFilename)) + using (var s = Game.ModData.ModFiles.Open(templateFilename)) { Console.WriteLine("\tTemplate@{0}:", templateIndex); Console.WriteLine("\t\tCategory: {0}", sectionCategory); @@ -88,7 +87,7 @@ namespace OpenRA.Mods.TS.UtilityCommands for (var v = 'a'; v <= 'z'; v++) { var variant = "{0}{1:D2}{2}.{3}".F(sectionFilename, i, v, extension); - if (GlobalFileSystem.Exists(variant)) + if (Game.ModData.ModFiles.Exists(variant)) images.Add(variant); } diff --git a/OpenRA.Platforms.Default/Shader.cs b/OpenRA.Platforms.Default/Shader.cs index 06e15247fb..840a5d2b8d 100644 --- a/OpenRA.Platforms.Default/Shader.cs +++ b/OpenRA.Platforms.Default/Shader.cs @@ -12,7 +12,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Text; -using OpenRA.FileSystem; using OpenTK.Graphics.OpenGL; namespace OpenRA.Platforms.Default @@ -25,11 +24,9 @@ namespace OpenRA.Platforms.Default protected int CompileShaderObject(ShaderType type, string name) { - string ext = type == ShaderType.VertexShader ? "vert" : "frag"; - string filename = "glsl{0}{1}.{2}".F(Path.DirectorySeparatorChar, name, ext); - string code; - using (var file = new StreamReader(GlobalFileSystem.Open(filename))) - code = file.ReadToEnd(); + var ext = type == ShaderType.VertexShader ? "vert" : "frag"; + var filename = "glsl{0}{1}.{2}".F(Path.DirectorySeparatorChar, name, ext); + var code = File.ReadAllText(filename); var shader = GL.CreateShader(type); ErrorHandler.CheckGlError(); diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index c32662ab75..9c9cf976ab 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -11,7 +11,6 @@ using System; using System.Collections.Generic; using System.Linq; -using OpenRA.FileSystem; namespace OpenRA.Utility { @@ -35,7 +34,7 @@ namespace OpenRA.Utility return; } - AppDomain.CurrentDomain.AssemblyResolve += GlobalFileSystem.ResolveAssembly; + AppDomain.CurrentDomain.AssemblyResolve += FileSystem.FileSystem.ResolveAssembly; Log.AddChannel("perf", null); Log.AddChannel("debug", null);