Exemplo n.º 1
0
        public static string ExtractArchiveFile(string psarcPath, string entryNamePath, string outputDir)
        {
            if (!File.Exists(psarcPath))
            {
                return("");
            }

            using (PSARC archive = new PSARC(true))
                using (var psarcStream = File.OpenRead(psarcPath))
                {
                    archive.Read(psarcStream, true);
                    var tocEntry = archive.TOC.Where(entry => entry.Name.Contains(entryNamePath)).FirstOrDefault();

                    if (tocEntry != null)
                    {
                        if (!Directory.Exists(outputDir))
                        {
                            Directory.CreateDirectory(outputDir);
                        }

                        archive.InflateEntry(tocEntry, Path.Combine(outputDir, Path.GetFileName(tocEntry.ToString())));

                        return(Path.Combine(outputDir, tocEntry.ToString()));
                    }

                    return("");
                }
        }
 // Loads song archive file to memory.
 public PsarcLoader(string fileName, bool useMemory = true)
 {
     _filePath   = fileName;
     _archive    = new PSARC(useMemory);
     _fileStream = File.OpenRead(_filePath);
     _archive.Read(_fileStream);
 }
Exemplo n.º 3
0
        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);
                }
        }
Exemplo n.º 4
0
        public static bool InjectArchiveEntry(string psarcPath, string entryName, string sourcePath, bool useMemory = true)
        {
            if (!File.Exists(psarcPath))
            {
                return(false);
            }

            using (PSARC archive = new PSARC(useMemory))
                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.º 5
0
        public static bool ReplaceData(this PSARC p, Dictionary <Func <Entry, bool>, Stream> newData)
        {
            bool result = true;

            foreach (var d in newData)
            {
                if (!p.ReplaceData(d.Key, d.Value))
                {
                    result = false;
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        public static Stream GetData(this PSARC p, Func <Entry, bool> dataEntry)
        {
            var de = p.TOC.Where(dataEntry).FirstOrDefault();

            if (de != null)
            {
                if (de.Data == null)
                {
                    p.InflateEntry(de);
                }

                return(de.Data);
            }
            return(null);
        }
        public void Dispose()
        {
            if (_fileStream != null)
            {
                _fileStream.Close();
                _fileStream.Dispose();
                _fileStream = null;
            }
            if (_archive != null)
            {
                _archive.Dispose();
                _archive = null;
            }

            GC.SuppressFinalize(this);
        }
Exemplo n.º 8
0
        public static NoCloseStream ReplaceData(this PSARC p, Func <Entry, bool> dataEntry, String newData)
        {
            NoCloseStream s = new NoCloseStream();

            using (var sr = new StreamWriter(s))
                sr.Write(newData);

            s.Position = 0;

            if (!ReplaceData(p, dataEntry, s))
            {
                s.canClose = true;
                s.Dispose();
                return(null);
            }
            return(s);
        }
Exemplo n.º 9
0
        public static bool ReplaceData(this PSARC p, Func <Entry, bool> dataEntry, Stream newData)
        {
            var de = p.TOC.Where(dataEntry).FirstOrDefault();

            if (de != null)
            {
                if (de.Data != null)
                {
                    de.Data.Dispose();
                    de.Data = null;
                }
                else
                {
                    p.InflateEntry(de);
                }

                de.Data = newData;
                return(true);
            }
            return(false);
        }
Exemplo n.º 10
0
        public static Stream ExtractArchiveFile(string psarcPath, string entryNamePath)
        {
            if (!File.Exists(psarcPath))
            {
                return(null);
            }

            using (PSARC archive = new PSARC(true))
                using (var psarcStream = File.OpenRead(psarcPath))
                {
                    archive.Read(psarcStream, true);
                    var tocEntry = archive.TOC.FirstOrDefault(x => (x.Name.Equals(entryNamePath)));

                    if (tocEntry != null)
                    {
                        archive.InflateEntry(tocEntry);
                        return(tocEntry.Data);
                    }
                }

            return(null);
        }
Exemplo n.º 11
0
        public static Stream ExtractPSARCData(this Stream stream, Func <Entry, bool> dataEntry)
        {
            using (PSARC p = new PSARC(true))
            {
                p.Read(stream, true);

                var de = p.TOC.Where(dataEntry).FirstOrDefault();
                if (de != null)
                {
                    MemoryStream ms = new MemoryStream();
                    p.InflateEntry(de);
                    if (de.Data == null)
                    {
                        return(null);
                    }
                    de.Data.Position = 0;
                    de.Data.CopyTo(ms);
                    ms.Position = 0;
                    return(ms);
                }

                return(null);
            }
        }
 public static Entry getEntry(this GraphItem gi, PSARC.PSARC archive)
 {
     return archive.Entries.Single(e => e.Name.Equals(gi.RelPath));
 }
Exemplo n.º 13
-2
 public ArcFileWrapper(string archiveFile)
 {
     _psarc = new PSARC();
     _archiveFile = archiveFile;
     using (var inputStream = System.IO.File.OpenRead(archiveFile))
     {
         _psarc.Read(inputStream);
     }
 }
 public static Attributes2014 getManifest(this GraphItem jsonItem, PSARC.PSARC archive)
 {
     return Manifest2014<Attributes2014>.LoadFromFile(jsonItem.getEntry(archive).Data).Entries.ToArray()[0].Value.ToArray()[0].Value;
 }