Ejemplo n.º 1
0
        void table_doubleClick(Object sender, EventArgs e)
        {
            if (tableView.SelectedRow >= 0)
            {
                Dictionary <string, Object> row = tds.GetData()[tableView.SelectedRow];
                if ((bool)row["_directory"])
                {
                    if (row.ContainsKey("_up"))
                    {
                        path.RemoveAt(path.Count - 1);
                    }
                    else
                    {
                        path.Add((string)row["Name"]);
                    }
                    refreshView();
                }
                else
                {
                    IArchiveEntry fileEntry  = archive.GetFile(String.Join("/", path) + "/" + (string)row["Name"]);
                    string        folderPath = Path.Combine(Path.GetTempPath(), new NSUuid().ToString());
                    DirectoryInfo folder     = Directory.CreateDirectory(folderPath);
                    string        filePath   = Path.Combine(folderPath, fileEntry.FilePath.Split('/').Last());
                    FileStream    fs         = new FileStream(filePath, FileMode.Create);
                    fileEntry.WriteTo(fs);
                    fs.Close();

                    new NSWorkspace().OpenFile(filePath);
                }
            }
        }
Ejemplo n.º 2
0
        private static void ProcessArchiveVolume(IArchiveEntry volume, IList <string> assets)
        {
            Func <IArchiveEntry, string> getFirstLine = (entry) =>
            {
                var path = string.Empty;
                using (var sr = new StreamReader(entry.OpenEntryStream()))
                {
                    path = sr.ReadLine();
                }
                return(path);
            };

            var volumeStreamFilePath = Path.GetTempFileName();

            try
            {
                using (var tempStream = File.Open(volumeStreamFilePath, FileMode.Open))
                {
                    volume.WriteTo(tempStream);
                    tempStream.Flush();

                    using (var tempArchive = ArchiveFactory.Open(tempStream))
                    {
                        var pathEntries = from entry in tempArchive.Entries.ToArray()
                                          where Path.GetFileName(entry.Key).Contains("pathname") &&
                                          !entry.IsDirectory
                                          select entry;

                        var toExtract = pathEntries.ToDictionary(
                            pathEntry => Path.GetDirectoryName(pathEntry.Key),
                            pathEntry => getFirstLine(pathEntry));

                        var assetEntries = from entry in tempArchive.Entries.ToArray()
                                           where Path.GetFileName(entry.Key).Contains("asset") &&
                                           !entry.IsDirectory
                                           select new
                        {
                            entry = entry,
                            path  = toExtract[Path.GetDirectoryName(entry.Key)]
                        };


                        foreach (var asset in assetEntries)
                        {
                            assets.Add(asset.path);
                        }
                    }
                }
            }
            finally
            {
                if (volumeStreamFilePath != null && File.Exists(volumeStreamFilePath))
                {
                    File.Delete(volumeStreamFilePath);
                }
            }
        }
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
                                       ExtractOptions options = ExtractOptions.Overwrite)
        {
            if (entry.IsDirectory)
            {
                return;
            }
            FileMode fm = FileMode.Create;

            if (!FlagUtility.HasFlag(options, ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                entry.WriteTo(fs);
            }

            bool PreserveFileTime   = FlagUtility.HasFlag <ExtractOptions>(options, ExtractOptions.PreserveFileTime);
            bool PreserveAttributes = FlagUtility.HasFlag <ExtractOptions>(options, ExtractOptions.PreserveAttributes);

            if (PreserveFileTime || PreserveAttributes)
            {
                // update file time to original packed time
                FileInfo nf = new FileInfo(destinationFileName);
                if (nf.Exists)
                {
                    if (PreserveFileTime)
                    {
                        if (entry.CreatedTime.HasValue)
                        {
                            nf.CreationTime = entry.CreatedTime.Value;
                        }

                        if (entry.LastModifiedTime.HasValue)
                        {
                            nf.LastWriteTime = entry.LastModifiedTime.Value;
                        }

                        if (entry.LastAccessedTime.HasValue)
                        {
                            nf.LastAccessTime = entry.CreatedTime.Value;
                        }
                    }

                    if (PreserveAttributes)
                    {
                        if (entry.Attrib.HasValue)
                        {
                            nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Extract to specific file
 /// </summary>
 public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
                                ExtractionOptions options = null)
 {
     ExtractionMethods.WriteEntryToFile(entry, destinationFileName, options,
                                        (x, fm) =>
     {
         using (FileStream fs = File.Open(destinationFileName, fm))
         {
             entry.WriteTo(fs);
         }
     });
 }
Ejemplo n.º 5
0
        public BaseGame ExtractGameDataFromArchive(string archivePath, IArchive archive)
        {
            var archiveFileInfo = new FileInfo(archivePath);
            var game            = new BaseGame
            {
                FullPath      = archivePath,
                Path          = archivePath.Split(Path.DirectorySeparatorChar).Last(),
                Size          = archiveFileInfo.Length,
                FormattedSize = FileManager.FormatSize(archiveFileInfo.Length)
            };

            IArchiveEntry gdiEntry = ArchiveManager.RetreiveUniqueFileFromArchiveEndingWith(archive, ".gdi");

            if (gdiEntry != null)
            {
                string gdiContentInSingleLine;
                using (var ms = new MemoryStream())
                {
                    gdiEntry.WriteTo(ms);
                    gdiContentInSingleLine = Encoding.UTF8.GetString(ms.ToArray());
                }

                var gdiContent = new List <string>(
                    gdiContentInSingleLine.Split(new string[] { "\r\n", "\n" },
                                                 StringSplitOptions.RemoveEmptyEntries));

                game.GdiInfo = GetGdiFromStringContent(gdiContent);
                game.IsGdi   = true;
                var track3 = game.GdiInfo.Tracks.Single(t => t.TrackNumber == 3);
                if (track3.Lba != 45000)
                {
                    throw new Exception("Bad track03.bin LBA");
                }

                bool isRawMode = track3.SectorSize == 2352; // 2352/RAW mode or 2048

                var track3Entry = ArchiveManager.RetreiveUniqueFileFromArchiveEndingWith(archive, track3.FileName);
                using (var track3Stream = track3Entry.OpenEntryStream())
                {
                    if (isRawMode)
                    {
                        // We ignore the first line
                        byte[] dummyBuffer = new byte[16];
                        track3Stream.Read(dummyBuffer, 0, 16);
                    }

                    ReadGameInfoFromBinaryData(game, track3Stream);
                }
            }

            return(game);
        }
Ejemplo n.º 6
0
 public static void WriteToFile(this IArchiveEntry entry, string destinationFileName, ExtractOptions options = 1)
 {
     if (!entry.IsDirectory)
     {
         FileMode create = FileMode.Create;
         if (!options.HasFlag(ExtractOptions.Overwrite))
         {
             create = FileMode.CreateNew;
         }
         using (FileStream stream = File.Open(destinationFileName, create))
         {
             entry.WriteTo(stream);
         }
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
                                       IExtractionListener listener,
                                       ExtractOptions options = ExtractOptions.Overwrite)
        {
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                entry.WriteTo(fs, listener);
            }
        }
        private static CkanModInfo CreateModInfos(IArchiveEntry archiveEntry, CkanMod ckanMod)
        {
            var ms = new MemoryStream();

            archiveEntry.WriteTo(ms);
            ms.Position = 0;
            using (var sr = new StreamReader(ms))
            {
                var content  = sr.ReadToEnd();
                var modInfos = JsonConvert.DeserializeObject <CkanModInfo>(content);
                Messenger.AddInfo($"ModInfos \"{modInfos.name}\"-\"{modInfos.version}\" created from \"{archiveEntry.FilePath}\"");
                modInfos.Mod     = ckanMod;
                modInfos.version = NormalizeVersion(modInfos.version);
                return(modInfos);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
                                       ExtractOptions options = ExtractOptions.Overwrite)
        {
            if (entry.IsDirectory)
            {
                return;
            }
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                entry.WriteTo(fs);
            }
        }
Ejemplo n.º 10
0
        void outline_doubleClick(NSObject sender)
        {
            if (outlineView.SelectedRow >= 0 && outlineView.SelectedRowCount == 1 && outlineView.LevelForRow(outlineView.SelectedRow) > 0)
            {
                FileListOutlineItem item = (FileListOutlineItem)outlineView.ItemAtRow(outlineView.SelectedRow);
                if (!item.IsDirectory)
                {
                    IArchiveEntry fileEntry  = item.GetEntry();
                    string        folderPath = Path.Combine(Path.GetTempPath(), new NSUuid().ToString());
                    DirectoryInfo folder     = Directory.CreateDirectory(folderPath);
                    string        filePath   = Path.Combine(folderPath, fileEntry.FilePath.Split('/').Last());
                    FileStream    fs         = new FileStream(filePath, FileMode.Create);
                    fileEntry.WriteTo(fs);
                    fs.Close();

                    new NSWorkspace().OpenFile(filePath);
                }
            }
        }
Ejemplo n.º 11
0
        private BitmapImage GetEntryAsImage(IArchiveEntry entry)
        {
            //var s = entry.OpenEntryStream();
            Console.WriteLine(entry.Key);

            //byte[] buffer = new byte[entry.Size];
            //s.Read(buffer, 0, (int)entry.Size);

            var img = new BitmapImage();

            img.BeginInit();
            img.CacheOption  = BitmapCacheOption.OnLoad;
            img.StreamSource = new MemoryStream();
            entry.WriteTo(img.StreamSource);
            img.StreamSource.Position = 0;
            img.EndInit();
            //s.Close();
            return(img);
        }
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
                                       ExtractionOptions options = null)
        {
            FileMode fm = FileMode.Create;

            options = options ?? new ExtractionOptions()
            {
                Overwrite = true
            };


            if (!options.Overwrite)
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                entry.WriteTo(fs);
            }

            entry.PreserveExtractionOptions(destinationFileName, options);
        }
Ejemplo n.º 13
0
 public static void WriteTo(this IArchiveEntry entry, Stream stream)
 {
     entry.WriteTo(stream, new NullExtractionListener());
 }