Properly use the virtual filesystem for map loading and saving.
This commit is contained in:
@@ -64,6 +64,32 @@ namespace OpenRA.FileSystem
|
||||
return new Folder(Platform.ResolvePath(filename));
|
||||
}
|
||||
|
||||
public IReadOnlyPackage OpenPackage(string filename, IReadOnlyPackage parent)
|
||||
{
|
||||
// HACK: limit support to zip and folder until we generalize the PackageLoader support
|
||||
if (parent is Folder)
|
||||
{
|
||||
var path = Path.Combine(parent.Name, filename);
|
||||
|
||||
// HACK: work around SharpZipLib's lack of support for writing to in-memory files
|
||||
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
||||
return new ZipFile(this, path);
|
||||
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
||||
return new ZipFile(this, path);
|
||||
|
||||
var subFolder = Platform.ResolvePath(path);
|
||||
if (Directory.Exists(subFolder))
|
||||
return new Folder(subFolder);
|
||||
}
|
||||
|
||||
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
||||
return new ZipFile(this, filename, parent.GetStream(filename));
|
||||
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
||||
return new ZipFile(this, filename, parent.GetStream(filename));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public IReadWritePackage OpenWritablePackage(string filename)
|
||||
{
|
||||
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace OpenRA.FileSystem
|
||||
{
|
||||
foreach (var filename in Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly))
|
||||
yield return Path.GetFileName(filename);
|
||||
foreach (var filename in Directory.GetDirectories(path))
|
||||
yield return Path.GetFileName(filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +61,12 @@ namespace OpenRA.FileSystem
|
||||
|
||||
public void Delete(string filename)
|
||||
{
|
||||
var filePath = Path.Combine(path, filename);
|
||||
// HACK: ZipFiles can't be loaded as read-write from a stream, so we are
|
||||
// forced to bypass the parent package and load them with their full path
|
||||
// in FileSystem.OpenPackage. Their internal name therefore contains the
|
||||
// full parent path too. We need to be careful to not add a second path
|
||||
// prefix to these hacked packages.
|
||||
var filePath = filename.StartsWith(path) ? filename : Path.Combine(path, filename);
|
||||
if (Directory.Exists(filePath))
|
||||
Directory.Delete(filePath, true);
|
||||
else if (File.Exists(filePath))
|
||||
|
||||
@@ -27,6 +27,16 @@ namespace OpenRA.FileSystem
|
||||
ZipConstants.DefaultCodePage = Encoding.UTF8.CodePage;
|
||||
}
|
||||
|
||||
public ZipFile(FileSystem context, string filename, Stream stream, bool createOrClearContents = false)
|
||||
{
|
||||
Name = filename;
|
||||
|
||||
if (createOrClearContents)
|
||||
pkg = SZipFile.Create(stream);
|
||||
else
|
||||
pkg = new SZipFile(stream);
|
||||
}
|
||||
|
||||
public ZipFile(IReadOnlyFileSystem context, string filename, bool createOrClearContents = false)
|
||||
{
|
||||
Name = filename;
|
||||
|
||||
Reference in New Issue
Block a user