Show a more helpful error when missing default.zip

also don't allocate so much on stack for zip reader
This commit is contained in:
UnknownShadow200 2018-05-14 12:30:39 +10:00
parent ad6ab7fb2a
commit 16b056e78e
3 changed files with 16 additions and 1 deletions

View File

@ -43,6 +43,16 @@ int main(void) {
ErrorHandler_CheckOrFail(result, "Program - creating texturecache directory");
}
UInt8 defPathBuffer[String_BufferSize(STRING_SIZE)];
String defPath = String_InitAndClearArray(defPathBuffer);
String_Format1(&defPath, "texpacks%rdefault.zip", &Platform_DirectorySeparator);
if (!Platform_FileExists(&defPath)) {
ErrorHandler_ShowDialog("Missing file", "default.zip missing, try running launcher first");
Platform_Exit(1);
return 1;
}
Platform_LogConst("Starting " PROGRAM_APP_NAME " ..");
Options_Init();
Options_Load();

View File

@ -17,7 +17,9 @@
/*########################################################################################################################*
*--------------------------------------------------------ZipEntry---------------------------------------------------------*
*#########################################################################################################################*/
#define ZIP_MAXNAMELEN 512
String Zip_ReadFixedString(Stream* stream, UInt8* buffer, UInt16 length) {
if (length > ZIP_MAXNAMELEN) ErrorHandler_Fail("Zip string too long");
String fileName = String_Init(buffer, length, length);
Stream_Read(stream, buffer, length);
buffer[length] = NULL; /* Ensure null terminated */
@ -39,7 +41,7 @@ void Zip_ReadLocalFileHeader(ZipState* state, ZipEntry* entry) {
UInt16 fileNameLen = Stream_ReadU16_LE(stream);
UInt16 extraFieldLen = Stream_ReadU16_LE(stream);
UInt8 filenameBuffer[String_BufferSize(UInt16_MaxValue)];
UInt8 filenameBuffer[String_BufferSize(ZIP_MAXNAMELEN)];
String filename = Zip_ReadFixedString(stream, filenameBuffer, fileNameLen);
if (!state->SelectEntry(&filename)) return;

View File

@ -665,6 +665,9 @@ ReturnCode Platform_HttpGetRequestData(AsyncRequest* request, void* handle, void
UInt32 left = size, read, totalRead = 0;
while (left > 0) {
//UInt32 toRead = min(4096, left);
//UInt32 avail = 0;
//InternetQueryDataAvailable(handle, &avail, 0, NULL);
bool success = InternetReadFile(handle, buffer, left, &read);
if (!success) { Platform_MemFree(data); return GetLastError(); }