Dispose() public method

public Dispose ( ) : void
return void
        public static bool RemoveArchiveEntry(string psarcPath, string entryName)
        {
            if (!File.Exists(psarcPath))
            {
                return(false);
            }

            using (PSARC archive = new PSARC(true))
                using (var psarcStream = File.OpenRead(psarcPath))
                {
                    archive.Read(psarcStream);
                    psarcStream.Dispose(); // CRITICAL

                    var tocEntry = archive.TOC.FirstOrDefault(entry => entry.Name == entryName);

                    if (tocEntry == null)
                    {
                        archive.Dispose(); // CRITICAL
                        return(true);
                    }

                    archive.TOC.Remove(tocEntry);
                    archive.TOC.Insert(0, new Entry()
                    {
                        Name = "NamesBlock.bin"
                    });

                    using (var fs = File.Create(psarcPath))
                        archive.Write(fs, true);

                    archive.Dispose(); // CRITICAL
                    return(true);
                }
        }
        public static bool InjectArchiveEntry(string psarcPath, string entryName, string sourcePath)
        {
            if (!File.Exists(psarcPath))
            {
                return(false);
            }

            using (PSARC archive = new PSARC(true))
                using (var psarcStream = File.OpenRead(psarcPath))
                {
                    try
                    {
                        archive.Read(psarcStream);
                        psarcStream.Dispose(); // CRITICAL

                        var entryStream = new MemoryStream();

                        using (var sourceStream = File.OpenRead(sourcePath))
                            sourceStream.CopyTo(entryStream);

                        entryStream.Position = 0;
                        Entry tocEntry = archive.TOC.FirstOrDefault(x => x.Name == entryName);

                        if (tocEntry != null)
                        {
                            tocEntry.Data.Dispose(); // CRITICAL
                            tocEntry.Data = entryStream;
                        }
                        else
                        {
                            archive.AddEntry(entryName, entryStream);

                            // evil genius ... ;) => forces archive update
                            archive.TOC.Insert(0, new Entry()
                            {
                                Name = "NamesBlock.bin"
                            });
                        }
                    }
                    catch
                    {
                        archive.Dispose(); // CRITICAL
                        return(false);
                    }

                    using (var fs = File.Create(psarcPath))
                        archive.Write(fs, true);

                    archive.Dispose(); // CRITICAL
                    return(true);
                }
        }
Exemplo n.º 3
0
        public void Dispose()
        {
            if (_fileStream != null)
            {
                _fileStream.Dispose();
                _fileStream = null;
            }
            if (_archive != null)
            {
                _archive.Dispose();
                _archive = null;
            }

            GC.SuppressFinalize(this);
        }