mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-12 17:22:26 -04:00
* Rewrote all of the chunk parsers to use a bytestream reader. Most noticeably, all of the string-reading code is shared now, and all of the "Size -="s have been taken out.
* Condensed STR# reading of formats 0, -1, -2, and -4 together. * The STR# parser now supports "formatless" format 0 STR# chunks. * Made all of the command-line tools cross-platform; replaced file IO with fopen()/etc, and replaced time measurement with clock(). There is no longer a dependency on Windows.h. * Added a "Server GUI" folder to tools. Niotso Server will basically be a background daemon., and communication would "normally" be through the command line until you run a GUI.
This commit is contained in:
parent
cb40cbd867
commit
bc978bfa0b
20 changed files with 515 additions and 657 deletions
|
@ -14,9 +14,11 @@
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include "read_xa.h"
|
||||
|
||||
#ifndef write_int32
|
||||
|
@ -33,13 +35,11 @@
|
|||
int main(int argc, char *argv[]){
|
||||
int overwrite = 0;
|
||||
char *InFile, *OutFile;
|
||||
HANDLE hFile;
|
||||
HANDLE ProcessHeap = GetProcessHeap();
|
||||
unsigned FileSize;
|
||||
DWORD bytestransferred = 0;
|
||||
FILE * hFile;
|
||||
size_t FileSize;
|
||||
uint8_t * XAData;
|
||||
xaheader_t XAHeader;
|
||||
unsigned BeginningTime, EndingTime;
|
||||
clock_t BeginningTime, EndingTime;
|
||||
|
||||
if(argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
|
||||
printf("Usage: xadecode [-f] infile outfile\n"
|
||||
|
@ -66,30 +66,29 @@ int main(int argc, char *argv[]){
|
|||
** Open the file and read in entire contents to memory
|
||||
*/
|
||||
|
||||
hFile = CreateFile(InFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
if(hFile == INVALID_HANDLE_VALUE){
|
||||
if(GetLastError() == ERROR_FILE_NOT_FOUND){
|
||||
printf("%sThe specified input file does not exist.", "xadecode: error: ");
|
||||
return -1;
|
||||
}
|
||||
printf("%sThe input file could not be opened for reading.", "xadecode: error: ");
|
||||
hFile = fopen(InFile, "rb");
|
||||
if(hFile == NULL){
|
||||
printf("%sThe specified input file does not exist or could not be opened for reading.", "xadecode: error: ");
|
||||
return -1;
|
||||
}
|
||||
FileSize = GetFileSize(hFile, NULL);
|
||||
fseek(hFile, 0, SEEK_END);
|
||||
FileSize = ftell(hFile);
|
||||
if(FileSize < 24){
|
||||
printf("%sNot a valid XA file.", "xadecode: error: ");
|
||||
return -1;
|
||||
}
|
||||
XAData = HeapAlloc(ProcessHeap, HEAP_NO_SERIALIZE, FileSize);
|
||||
fseek(hFile, 0, SEEK_SET);
|
||||
|
||||
XAData = malloc(FileSize);
|
||||
if(XAData == NULL){
|
||||
printf("%sMemory for this file could not be allocated.", "xadecode: error: ");
|
||||
return -1;
|
||||
}
|
||||
if(!ReadFile(hFile, XAData, FileSize, &bytestransferred, NULL) || bytestransferred != FileSize){
|
||||
if(!fread(XAData, FileSize, 1, hFile)){
|
||||
printf("%sThe input file could not be read.", "xadecode: error: ");
|
||||
return -1;
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
fclose(hFile);
|
||||
|
||||
/****
|
||||
** Transcode the data from XA to LPCM
|
||||
|
@ -101,20 +100,20 @@ int main(int argc, char *argv[]){
|
|||
}
|
||||
|
||||
if(argc >= 3){ /* Transcode */
|
||||
uint8_t * WaveData = HeapAlloc(ProcessHeap, HEAP_NO_SERIALIZE, 44+XAHeader.dwOutSize);
|
||||
uint8_t * WaveData = malloc(44+XAHeader.dwOutSize);
|
||||
if(WaveData == NULL){
|
||||
printf("%sMemory for this file could not be allocated.", "xadecode: error: ");
|
||||
return -1;
|
||||
}
|
||||
|
||||
BeginningTime = GetTickCount();
|
||||
BeginningTime = clock();
|
||||
if(!xa_decode(XAData+24, WaveData+44, XAHeader.Frames, XAHeader.nChannels)){
|
||||
printf("%sMemory for this file could not be allocated.", "xadecode: error: ");
|
||||
return -1;
|
||||
}
|
||||
EndingTime = GetTickCount();
|
||||
EndingTime = clock();
|
||||
|
||||
HeapFree(ProcessHeap, HEAP_NO_SERIALIZE, XAData);
|
||||
free(XAData);
|
||||
|
||||
/****
|
||||
** Write the Microsoft WAV header
|
||||
|
@ -138,29 +137,29 @@ int main(int argc, char *argv[]){
|
|||
** Write the contents to the output file
|
||||
*/
|
||||
|
||||
hFile = CreateFile(OutFile, GENERIC_WRITE, 0, NULL, CREATE_NEW+overwrite,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
if(hFile == INVALID_HANDLE_VALUE){
|
||||
if(!overwrite && GetLastError() == ERROR_FILE_EXISTS){
|
||||
if(!overwrite){
|
||||
hFile = fopen(OutFile, "rb");
|
||||
if(hFile != NULL){
|
||||
/* File exists */
|
||||
char c;
|
||||
fclose(hFile);
|
||||
printf("File \"%s\" exists.\nContinue anyway? (y/n) ", OutFile);
|
||||
c = getchar();
|
||||
if(c != 'y' && c != 'Y'){
|
||||
printf("\nAborted.");
|
||||
return -1;
|
||||
}
|
||||
hFile = CreateFile(OutFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
}
|
||||
if(hFile == INVALID_HANDLE_VALUE){
|
||||
printf("%sThe output file could not be opened for writing.", "xadecode: error: ");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
hFile = fopen(OutFile, "wb");
|
||||
if(hFile == NULL){
|
||||
printf("%sThe output file could not be opened for writing.", "xadecode: error: ");
|
||||
return -1;
|
||||
}
|
||||
printf("Extracted %u bytes in %.2f seconds.\n", (unsigned) XAHeader.dwOutSize,
|
||||
((float) (EndingTime - BeginningTime))/1000);
|
||||
WriteFile(hFile, WaveData, 44+XAHeader.dwOutSize, &bytestransferred, NULL);
|
||||
CloseHandle(hFile);
|
||||
((float)(EndingTime - BeginningTime))/CLOCKS_PER_SEC);
|
||||
fwrite(WaveData, 1, 44+XAHeader.dwOutSize, hFile);
|
||||
fclose(hFile);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue