Unstatic GlobalFileSystem and rename it to FileSystem

Add a ModFiles field on ModData and move all access to the file system to go through that.
This commit is contained in:
Pavel Penev
2015-10-09 13:55:08 +03:00
parent 5684bcec1c
commit 1b88d24cfa
46 changed files with 154 additions and 172 deletions

View File

@@ -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));

View File

@@ -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;

View File

@@ -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);

View File

@@ -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<string, string> 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()

View File

@@ -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)
{

View File

@@ -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<string> PaletteNames { get { yield return info.Name; } }

View File

@@ -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<string> PaletteNames

View File

@@ -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);
}
}
}

View File

@@ -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))

View File

@@ -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)

View File

@@ -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();

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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<PlayerColorPaletteInfo>();
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<PlayerColorPaletteInfo>();
var destRemapIndex = destPaletteInfo.RemapIndex;

View File

@@ -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<LogicTickerWidget>("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;
}

View File

@@ -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<LabelWidget>("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

View File

@@ -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<VqaPlayerWidget>("PLAYER");
fullscreenVideoPlayer.Visible = true;

View File

@@ -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);