Encapsulates interactions with BSA files.
예제 #1
0
파일: Program.cs 프로젝트: figment/bsaunpak
 static void Main(string[] args)
 {
     if (args.Length == 0 || args.Length > 2)
     {
         Usage();
         System.Environment.Exit(1);
     }
     string infile = args[0];
     if (!File.Exists(infile))
     {
         Console.WriteLine("Unable to locate file '{0}'",infile);
         System.Environment.Exit(1);
     }
     string outdir = args.Length > 1 ? args[1] : Path.Combine(System.Environment.CurrentDirectory, Path.GetFileNameWithoutExtension(infile)) ;
     BSAArchive archive = new BSAArchive(infile);
     foreach (var name in archive.FileNames)
     {
         byte[] data = archive.GetFile(name);
         string fileName = Path.Combine(outdir, name);
         string pathName = Path.GetDirectoryName(fileName);
         try
         {
             Console.WriteLine(fileName);
             Directory.CreateDirectory(pathName);
             using (var file = File.Create(fileName, 4096))
             {
                 file.Write(data, 0, data.Length);
             }
         }
         catch (System.Exception ex)
         {
             Console.WriteLine("Unhandled exception while writing '{0}'", name);
         }
     }
 }
예제 #2
0
		/// <summary>
		/// Retrieves the list of files in the specified BSA.
		/// </summary>
		/// <param name="p_strBsa">The BSA whose file listing is requested.</param>
		/// <returns>The list of files contained in the specified BSA.</returns>
		/// <exception cref="IllegalFilePathException">Thrown if <paramref name="p_strBsa"/>
		/// contains illegal characters or refers to a file outside of the Data directory.</exception>
		/// <exception cref="BSAArchive.BSALoadException">Thrown if the specified BSA cannot be loaded.</exception>
		public string[] GetBSAFileList(string p_strBsa)
		{
			if (Path.GetDirectoryName(p_strBsa).Length > 0)
				throw new IllegalFilePathException(p_strBsa);
			if (!m_dicBSAs.ContainsKey(p_strBsa))
				m_dicBSAs[p_strBsa] = new BSAArchive(Path.Combine(GameMode.PluginDirectory, p_strBsa));
			return (string[])m_dicBSAs[p_strBsa].FileNames.Clone();
		}
예제 #3
0
		/// <summary>
		/// Gets the specified file from the specified BSA.
		/// </summary>
		/// <param name="p_strBsa">The BSA from which to extract the specified file.</param>
		/// <param name="p_strFile">The files to extract form the specified BSA.</param>
		/// <returns>The data of the specified file.</returns>
		/// <exception cref="IllegalFilePathException">Thrown if <paramref name="p_strBsa"/>
		/// contains illegal characters or refers to a file outside of the Data directory, or
		/// if <paramref name="p_strFile"/> refers to an unsafe location.</exception>
		/// <exception cref="BSAArchive.BSALoadException">Thrown if the specified BSA cannot be loaded.</exception>
		public byte[] GetDataFileFromBSA(string p_strBsa, string p_strFile)
		{
			if (Path.GetDirectoryName(p_strBsa).Length > 0)
				throw new IllegalFilePathException(p_strBsa);
			string strLoweredBsa = p_strBsa.ToLowerInvariant();
			if (!m_dicBSAs.ContainsKey(strLoweredBsa))
				m_dicBSAs[strLoweredBsa] = new BSAArchive(Path.Combine(GameMode.PluginDirectory, strLoweredBsa));
			return m_dicBSAs[strLoweredBsa].GetFile(p_strFile);
		}
예제 #4
0
			internal BSAFileInfo(BSAArchive _bsa, int _offset, int _size)
			{
				bsa = _bsa;
				offset = _offset;
				size = _size;

				if ((size & (1 << 30)) != 0)
				{
					size ^= 1 << 30;
					compressed = !bsa.defaultCompressed;
				}
				else compressed = bsa.defaultCompressed;

			}
예제 #5
0
            internal BSAFileInfo(BSAArchive _bsa, int _offset, int _size)
            {
                bsa    = _bsa;
                offset = _offset;
                size   = _size;

                if ((size & (1 << 30)) != 0)
                {
                    size      ^= 1 << 30;
                    compressed = !bsa.defaultCompressed;
                }
                else
                {
                    compressed = bsa.defaultCompressed;
                }
            }