本文整理汇总了C#中FileSystem.Open方法的典型用法代码示例。如果您正苦于以下问题:C# FileSystem.Open方法的具体用法?C# FileSystem.Open怎么用?C# FileSystem.Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem
的用法示例。
在下文中一共展示了FileSystem.Open方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObjectCreator
public ObjectCreator(Manifest manifest, FileSystem.FileSystem modFiles)
{
typeCache = new Cache<string, Type>(FindType);
ctorCache = new Cache<Type, ConstructorInfo>(GetCtor);
// Allow mods to load types from the core Game assembly, and any additional assemblies they specify.
var assemblyList = new List<Assembly>() { typeof(Game).Assembly };
foreach (var path in manifest.Assemblies)
{
var data = modFiles.Open(path).ReadAllBytes();
// .NET doesn't provide any way of querying the metadata of an assembly without either:
// (a) loading duplicate data into the application domain, breaking the world.
// (b) crashing if the assembly has already been loaded.
// We can't check the internal name of the assembly, so we'll work off the data instead
var hash = CryptoUtil.SHA1Hash(data);
Assembly assembly;
if (!ResolvedAssemblies.TryGetValue(hash, out assembly))
{
assembly = Assembly.Load(data);
ResolvedAssemblies.Add(hash, assembly);
}
assemblyList.Add(assembly);
}
AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;
assemblies = assemblyList.SelectMany(asm => asm.GetNamespaces().Select(ns => Pair.New(asm, ns))).ToArray();
AppDomain.CurrentDomain.AssemblyResolve -= ResolveAssembly;
}
示例2: BigFile
public BigFile(FileSystem context, string filename)
{
Name = filename;
s = context.Open(filename);
try
{
if (s.ReadASCII(4) != "BIGF")
throw new InvalidDataException("Header is not BIGF");
// Total archive size.
s.ReadUInt32();
var entryCount = s.ReadUInt32();
if (BitConverter.IsLittleEndian)
entryCount = int2.Swap(entryCount);
// First entry offset? This is apparently bogus for EA's .big files
// and we don't have to try seeking there since the entries typically start next in EA's .big files.
s.ReadUInt32();
for (var i = 0; i < entryCount; i++)
{
var entry = new Entry(s);
index.Add(entry.Path, entry);
}
}
catch
{
Dispose();
throw;
}
}
示例3: MixFile
public MixFile(FileSystem context, string filename)
{
Name = filename;
this.context = context;
s = context.Open(filename);
try
{
// Detect format type
var isCncMix = s.ReadUInt16() != 0;
// The C&C mix format doesn't contain any flags or encryption
var isEncrypted = false;
if (!isCncMix)
isEncrypted = (s.ReadUInt16() & 0x2) != 0;
List<PackageEntry> entries;
if (isEncrypted)
{
long unused;
entries = ParseHeader(DecryptHeader(s, 4, out dataStart), 0, out unused);
}
else
entries = ParseHeader(s, isCncMix ? 0 : 4, out dataStart);
index = ParseIndex(entries.ToDictionaryWithConflictLog(x => x.Hash,
"{0} ({1} format, Encrypted: {2}, DataStart: {3})".F(filename, isCncMix ? "C&C" : "RA/TS/RA2", isEncrypted, dataStart),
null, x => "(offs={0}, len={1})".F(x.Offset, x.Length)));
}
catch (Exception)
{
Dispose();
throw;
}
}
示例4: PakFile
public PakFile(FileSystem context, string filename)
{
Name = filename;
index = new Dictionary<string, Entry>();
stream = context.Open(filename);
try
{
index = new Dictionary<string, Entry>();
var offset = stream.ReadUInt32();
while (offset != 0)
{
var file = stream.ReadASCIIZ();
var next = stream.ReadUInt32();
var length = (next == 0 ? (uint)stream.Length : next) - offset;
// Ignore duplicate files
if (index.ContainsKey(file))
continue;
index.Add(file, new Entry { Offset = offset, Length = length, Filename = file });
offset = next;
}
}
catch
{
Dispose();
throw;
}
}
示例5: BagFile
public BagFile(FileSystem context, string filename)
{
Name = filename;
// A bag file is always accompanied with an .idx counterpart
// For example: audio.bag requires the audio.idx file
var indexFilename = Path.ChangeExtension(filename, ".idx");
// Build the index and dispose the stream, it is no longer needed after this
List<IdxEntry> entries;
using (var indexStream = context.Open(indexFilename))
entries = new IdxReader(indexStream).Entries;
index = entries.ToDictionaryWithConflictLog(x => x.Filename,
"{0} (bag format)".F(filename),
null, x => "(offs={0}, len={1})".F(x.Offset, x.Length));
s = context.Open(filename);
}
示例6: InstallShieldCABExtractor
public InstallShieldCABExtractor(FileSystem context, string hdrFilename)
{
var fileGroups = new List<FileGroup>();
var fileGroupOffsets = new List<uint>();
hdrFile = context.Open(hdrFilename);
this.context = context;
// Strips archive number AND file extension
Name = Regex.Replace(hdrFilename, @"\d*\.[^\.]*$", "");
var signature = hdrFile.ReadUInt32();
if (signature != 0x28635349)
throw new InvalidDataException("Not an Installshield CAB package");
commonHeader = new CommonHeader(hdrFile);
cabDescriptor = new CabDescriptor(hdrFile, commonHeader);
/* unknown */ hdrFile.ReadBytes(14);
for (var i = 0U; i < MaxFileGroupCount; ++i)
fileGroupOffsets.Add(hdrFile.ReadUInt32());
hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset, SeekOrigin.Begin);
directoryTable = new List<uint>();
for (var i = 0U; i < cabDescriptor.DirectoryCount; ++i)
directoryTable.Add(hdrFile.ReadUInt32());
foreach (var offset in fileGroupOffsets)
{
var nextOffset = offset;
while (nextOffset != 0)
{
hdrFile.Seek((long)nextOffset + 4 + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);
var descriptorOffset = hdrFile.ReadUInt32();
nextOffset = hdrFile.ReadUInt32();
hdrFile.Seek(descriptorOffset + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);
fileGroups.Add(new FileGroup(hdrFile, commonHeader.CabDescriptorOffset));
}
}
hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2, SeekOrigin.Begin);
foreach (var fileGroup in fileGroups)
{
for (var i = fileGroup.FirstFile; i <= fileGroup.LastFile; ++i)
{
AddFileDescriptorToList(i);
var fileDescriptor = fileDescriptors[i];
var fullFilePath = "{0}\\{1}\\{2}".F(fileGroup.Name, DirectoryName(fileDescriptor.DirectoryIndex), fileDescriptor.Filename);
index.Add(fullFilePath, i);
}
}
}
示例7: InstallShieldPackage
public InstallShieldPackage(FileSystem context, string filename)
{
Name = filename;
s = context.Open(filename);
try
{
// Parse package header
var signature = s.ReadUInt32();
if (signature != 0x8C655D13)
throw new InvalidDataException("Not an Installshield package");
s.Position += 8;
/*var FileCount = */s.ReadUInt16();
s.Position += 4;
/*var ArchiveSize = */s.ReadUInt32();
s.Position += 19;
var tocAddress = s.ReadInt32();
s.Position += 4;
var dirCount = s.ReadUInt16();
// Parse the directory list
s.Position = tocAddress;
// Parse directories
var directories = new Dictionary<string, uint>();
for (var i = 0; i < dirCount; i++)
{
// Parse directory header
var fileCount = s.ReadUInt16();
var chunkSize = s.ReadUInt16();
var nameLength = s.ReadUInt16();
var dirName = s.ReadASCII(nameLength);
// Skip to the end of the chunk
s.ReadBytes(chunkSize - nameLength - 6);
directories.Add(dirName, fileCount);
}
// Parse files
foreach (var dir in directories)
for (var i = 0; i < dir.Value; i++)
ParseFile(s, dir.Key);
}
catch
{
Dispose();
throw;
}
}
示例8: D2kSoundResources
public D2kSoundResources(FileSystem context, string filename)
{
Name = filename;
s = context.Open(filename);
try
{
var headerLength = s.ReadUInt32();
while (s.Position < headerLength + 4)
{
var name = s.ReadASCIIZ();
var offset = s.ReadUInt32();
var length = s.ReadUInt32();
index.Add(name, new Entry(offset, length));
}
}
catch
{
Dispose();
throw;
}
}
示例9: NextFile
void NextFile(FileSystem context)
{
if (cabFile != null)
cabFile.Dispose();
++volumeNumber;
cabFile = context.Open("{0}{1}.cab".F(commonName, volumeNumber));
if (cabFile.ReadUInt32() != 0x28635349)
throw new InvalidDataException("Not an Installshield CAB package");
uint fileOffset;
if ((fileDes.Flags & FileSplit) != 0)
{
cabFile.Seek(CommonHeader.Size, SeekOrigin.Current);
var head = new VolumeHeader(cabFile);
if (index == head.LastFileIndex)
{
if ((fileDes.Flags & FileCompressed) != 0)
RemainingArchiveStream = head.LastFileSizeCompressed;
else
RemainingArchiveStream = head.LastFileSizeExpanded;
fileOffset = head.LastFileOffset;
}
else if (index == head.FirstFileIndex)
{
if ((fileDes.Flags & FileCompressed) != 0)
RemainingArchiveStream = head.FirstFileSizeCompressed;
else
RemainingArchiveStream = head.FirstFileSizeExpanded;
fileOffset = head.FirstFileOffset;
}
else
throw new Exception("Cannot Resolve Remaining Stream");
}
else
{
if ((fileDes.Flags & FileCompressed) != 0)
RemainingArchiveStream = fileDes.CompressedSize;
else
RemainingArchiveStream = fileDes.ExpandedSize;
fileOffset = fileDes.DataOffset;
}
cabFile.Seek(fileOffset, SeekOrigin.Begin);
}
示例10: ExtractFromPackage
// TODO: The package should be mounted into its own context to avoid name collisions with installed files
public static bool ExtractFromPackage(FileSystem.FileSystem fileSystem, string srcPath, string package, Dictionary<string, string[]> filesByDirectory,
string destPath, bool overwrite, ContentInstaller.FilenameCase caseModifier, Action<string> onProgress, Action<string> onError)
{
Directory.CreateDirectory(destPath);
Log.Write("debug", "Mounting {0}".F(srcPath));
fileSystem.Mount(srcPath);
Log.Write("debug", "Mounting {0}".F(package));
fileSystem.Mount(package);
foreach (var directory in filesByDirectory)
{
var targetDir = directory.Key;
foreach (var file in directory.Value)
{
var containingDir = Path.Combine(destPath, targetDir);
var dest = Path.Combine(containingDir, GetFileName(file, caseModifier));
if (File.Exists(dest))
{
if (overwrite)
File.Delete(dest);
else
{
Log.Write("debug", "Skipping {0}".F(dest));
continue;
}
}
Directory.CreateDirectory(containingDir);
using (var sourceStream = fileSystem.Open(file))
using (var destStream = File.Create(dest))
{
Log.Write("debug", "Extracting {0} to {1}".F(file, dest));
onProgress("Extracting " + file);
destStream.Write(sourceStream.ReadAllBytes());
}
}
}
return true;
}