⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pak.c

📁 连连看
💻 C
📖 第 1 页 / 共 2 页
字号:
    }    /* Close both the file streams */    fclose( InputStream );    fclose( PAKStream );    /* Advance to the next file to be written according to the FT */    Current = Current->Next;  }  return TRUE;}gboolean ClearPAKClass(){	guint32 i;	/* Default the path variables */	memset(m_szFolderPath,0,sizeof(m_szFolderPath));	memset(m_szPakName,0,sizeof(m_szPakName));	/* Check if there is data in the FT */	if( m_FileTable != NULL )	{        /* Loop through each file table entry and delete it */		for( i = 0; i < m_Header.dwNumFTEntries; i++ )		{			/* Create a temporary FT node */			struct sFileTableEntry* Temp = m_FileTable;			/* Make head node point to it's child */			m_FileTable = Temp->Next;			/* Free the temp pointer */			free( Temp );		}	}	/* Clear the PAK header */	memset( &m_Header,0,sizeof(struct sPakHeader) );	return TRUE;}gboolean LoadPAKHFT( gchar* PakFile ){  /* Declare local variables */  FILE* InputStream;  struct sFileTableEntry* NewEntry;  guint32 i,z;  /* Clear previous data if there is any */  ClearPAKClass();  /* Error check */  if( strlen(PakFile) == 0 ){ return FALSE; }  /* Store the PAK name in the class */  memcpy( m_szPakName, PakFile, 300 );  /* Open the specified file */  InputStream = fopen( PakFile, "rb" );  if( !InputStream ){ return FALSE; }  /* Read in the file header */  fread( &m_Header, sizeof(struct sPakHeader), 1, InputStream );  /* Read in the file table */  for( i = 0; i < m_Header.dwNumFTEntries; i++ )  {    /* Create a BYTE array the size of a file table entry */    guint8* Ptr = NULL;    Ptr = (guint8 *)g_malloc( sizeof(struct sFileTableEntry) );    /* Read in the entry a BYTE at a time */    for( z = 0; z < sizeof(struct sFileTableEntry); z++ )    {      /* Read a BYTE at a time */      Ptr[z] = fgetc( InputStream );      /* Perform decryption using the caesar cypher (reversed to decrypt) */      if( m_Header.bCypherAddition == TRUE )        Ptr[z] -= m_Header.iCypherValue;      else        Ptr[z] += m_Header.iCypherValue;    }    /* Create the file entry to add to the list */    NewEntry = (struct sFileTableEntry *)g_malloc(sizeof(struct sFileTableEntry));    /* Copy the contents of the BYTE array to the entry */    memcpy( NewEntry, Ptr, sizeof(struct sFileTableEntry) );    /* Add this to the linked list, file table member variable */    NewEntry->Next = m_FileTable;    m_FileTable = NewEntry;    /* Free the BYTE array */    g_free(Ptr);    Ptr = NULL;  }  /* Close the file stream */  fclose( InputStream );	  return TRUE;}gboolean ExtractPAK(gchar *Path){  /* Declare local variables */  FILE*  ReadStream;   /* A read data stream */  FILE*  WriteStream;  /* A write data stream */  fpos_t Pos;      /* Offset in to file */  struct sFileTableEntry* Current;  gchar extract_to_name[330];  /* Error check the PAK name that is acquired in LoadPAKHFT() */  if( strlen(m_szPakName) == 0 ){ return FALSE; }  /* Make it the head of the file table */  Current = m_FileTable;  while( Current != NULL )  {    /* Declare local variables */    guchar Buffer=0;    guint32 Count;    /* Open PAK file stream (to read from) */    ReadStream = fopen( m_szPakName, "rb" );    if( !ReadStream )      return FALSE;    /* Attempt to open the write stream for creating the file */    sprintf(extract_to_name,"%s/%s",Path,Current->szFileName);    WriteStream = fopen( extract_to_name, "wb" );    if( !WriteStream )    {      fclose( ReadStream );      return FALSE;    }    /* Set the offset in PAK to the beginning of this particular file       to be extracted */	/* If not GNU system,this should be Pos = Current->dwOffset */#ifdef WIN32	Pos = Current->dwOffset;#else    Pos.__pos = Current->dwOffset; #endif    fsetpos( ReadStream, &Pos );    /* Loop through the file by it's size and read from the PAK       followed by write to file */    for( Count = 0; Count < Current->dwFileSize; Count++ )    {      /* Read in the char */      Buffer = fgetc(ReadStream);      /* Perform decryption using the caesar cypher (reversed to decrypt) */      if( m_Header.bCypherAddition == TRUE )        Buffer -= m_Header.iCypherValue;      else        Buffer += m_Header.iCypherValue;      /* Write to the file */      fwrite( &Buffer, sizeof(guchar), 1, WriteStream );    }    /* Close the file streams */    fclose(WriteStream);    fclose(ReadStream);    /* Move on the the next file to extract */    Current = Current->Next;  }  return TRUE;}gboolean ExtractSingleFile( gchar* Filename){  /* Declare local variables */  FILE*  ReadStream=NULL;    /* A read data stream */  FILE*  WriteStream=NULL;   /* A write data stream */  fpos_t Pos;       /* Offset in to file */  guchar  Buffer = 0;    /* A read buffer */  guint32 Count;  /* Declare a temporary file table node to work from */  struct sFileTableEntry* Current;  /* Error check the method parameters and PAK file acquired from LoadPAKHFT() */  if( strlen(m_szPakName) == 0 ){ return FALSE; }  if( strlen(Filename) == 0 ){ return FALSE; }  /* Make it the top of the file table */  Current = m_FileTable;  /* Iterate through Current until it is the entry specified in the method parameters */  while(Current != NULL && strcmp(Current->szFileName, Filename) != 0 )  {    /* Advance Current to the next entry */    Current = Current->Next;  }  if(Current == NULL)return FALSE;  /* No such file name in these entries */  /* Open PAK file stream (to read from) */  ReadStream = fopen( m_szPakName, "rb" );  if( !ReadStream )    return FALSE;  /* Attempt to open the write stream for creating the file */  gchar tmpstr[40];  sprintf(tmpstr,"/tmp/llk_%s",Current->szFileName);  WriteStream = fopen( tmpstr, "wb" );  if( !WriteStream )  {    fclose( ReadStream );    return FALSE;  }  /* Set the offset in PAK to the beginning of this particular file     to be extracted */	/* If not GNU system,this should be Pos = Current->dwOffset */#ifdef WIN32	Pos = Current->dwOffset;#else    Pos.__pos = Current->dwOffset; #endif  fsetpos( ReadStream, &Pos );  /* Loop through the file by it's size and read from the PAK     followed by write to file */  for( Count = 0; Count < Current->dwFileSize; Count++ )  {    /* Read in the char */    Buffer = fgetc(ReadStream);    /* Perform decryption using the caesar cypher (reversed to decrypt) */    if( m_Header.bCypherAddition == TRUE )      Buffer -= m_Header.iCypherValue;    else      Buffer += m_Header.iCypherValue;    /* Write to the file */    fwrite( &Buffer, sizeof(guchar), 1, WriteStream );  }  /* Close the file streams */  fclose(ReadStream);  fclose(WriteStream);  return TRUE;}gboolean FindFile(gchar *filename){  struct sFileTableEntry* Current;  Current = m_FileTable;  while(Current != NULL )  {    if(!strcasecmp( Current->szFileName, filename))return TRUE;    Current = Current->Next;  }  return FALSE;}gint GetFileNum(gchar *Firstname,gchar *Lastname){  gint Count = 0;  gchar str[30];  while(TRUE)  {    sprintf(str,"%s%d.%s",Firstname,Count,Lastname);    if( FindFile(str) )Count++;    else return Count;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -