Esempio n. 1
0
		public void LoadResourceFile( String Filename )
		{
			Int32 filecount;
			FileStream filehandle;
			BinaryReader filereader;
			List<Int32> offsetlist = new List<Int32>();
			Int32 offsetcurrent = 0;
			FileDescriptor newdescriptor;
			Int32 stringlength;
			Byte[] stringbytes;
			
			filehandle = new FileStream( Filename, FileMode.Open );
			filereader = new BinaryReader( filehandle );
	
			filecount = filereader.ReadInt32();
			for( UInt32 fileindex = 1; fileindex <= filecount; fileindex++ )
			{
				offsetcurrent = filereader.ReadInt32();
				offsetlist.Add( offsetcurrent );
			}
	
			foreach( UInt32 offsetworking in offsetlist )
			{
				if( offsetworking == 0 )
				{
					//newdescriptor = new FileDescriptor();
					//newdescriptor.Filename = "";
					//newdescriptor.Length = -1;
					newdescriptor = null;
				}
				else
				{
					filehandle.Seek( offsetworking, SeekOrigin.Begin );
					newdescriptor = new FileDescriptor();
					newdescriptor.Length = filereader.ReadInt32();
					stringlength = filereader.ReadInt32();
					stringbytes = filereader.ReadBytes( stringlength );
					newdescriptor.Filename = System.Text.ASCIIEncoding.ASCII.GetString( stringbytes );
					newdescriptor.Data = filereader.ReadBytes( newdescriptor.Length );
				}

				if (newdescriptor != null)
				{
					Files.Add(newdescriptor);
				}
			}

			Console.WriteLine("Load: " + Filename + " (Size " + filehandle.Length + ")");
			filereader.Close();
			filehandle.Close();
		}
Esempio n. 2
0
		public static void Main (string[] args)
		{
			ResourceDat datafile;

			Console.WriteLine("FTL Data Packer");
			Console.WriteLine("===============");
			Console.WriteLine();

			if (args.Length < 2)
			{
				WriteUsage();
			}
			else
			{
				switch( args[1] )
				{
					case "list":
						datafile = new ResourceDat(args[0]);
						foreach( FileDescriptor fd in datafile.Files)
						{
							Console.WriteLine(fd.Filename);
						}
						break;

					case "extract":
						if (args.Length < 3)
						{
							WriteUsage();
						}
						else
						{
							datafile = new ResourceDat(args[0]);
							foreach (FileDescriptor fd in datafile.Files)
							{
								if( fd.Length >= 0 && fd.Filename.EndsWith(args[2]))
								{
									string filename = fd.Filename.Replace('/', System.IO.Path.DirectorySeparatorChar);
									string filedir = System.IO.Path.GetDirectoryName(filename);
									if (!System.IO.Directory.Exists(filedir))
									{
										System.IO.Directory.CreateDirectory(filedir);
									}
									Console.WriteLine("Extracting " + fd.Filename + " to " + filename);
									System.IO.File.WriteAllBytes(filename, fd.Data);
								}
							}
						}
						break;

					case "extractall":
						datafile = new ResourceDat(args[0]);
						foreach( FileDescriptor fd in datafile.Files)
						{
							if (fd.Length >= 0)
							{
								Console.WriteLine(fd.Filename);
								string filename = fd.Filename.Replace('/', System.IO.Path.DirectorySeparatorChar);
								string filedir = System.IO.Path.GetDirectoryName(filename);
								if (!System.IO.Directory.Exists(filedir))
								{
									System.IO.Directory.CreateDirectory(filedir);
								}
								Console.WriteLine("Extracting " + fd.Filename + " to " + filename);
								System.IO.File.WriteAllBytes(filename, fd.Data);
							}
						}
						break;

					case "replace":
						datafile = new ResourceDat(args[0]);

						if (args.Length < 4)
						{
							WriteUsage();
						}
						else
						{
							bool foundfile = false;
							foreach (FileDescriptor fd in datafile.Files)
							{
								if (fd.Length >= 0 && fd.Filename == args[2])
								{
									foundfile = true;
									Console.WriteLine("Found file " + fd.Filename + " (Size " + fd.Length.ToString() + ")");
									fd.Data = System.IO.File.ReadAllBytes(args[3]);
									fd.Length = fd.Data.Length;
									Console.WriteLine(" New Size " + fd.Length.ToString());
									break;
								}
							}
							if( !foundfile )
							{
								Console.WriteLine("Did not find file " + args[2]);
							}
						}
						datafile.SaveResourceFile(args[0]);
						break;

					case "add":
						datafile = new ResourceDat(args[0]);
						FileDescriptor fdx = new FileDescriptor();
						fdx.Filename = args[2];
						fdx.Data = System.IO.File.ReadAllBytes(args[3]);
						datafile.Files.Add(fdx);
						datafile.SaveResourceFile(args[0]);
						break;
				}
			}


			Console.WriteLine ();
		}