mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 09:35:23 -04:00
ios: Fix download progress UI not working
This commit is contained in:
parent
b7ca3f086b
commit
ce4b6c30db
@ -811,7 +811,7 @@ static void Http_AddHeader(struct HttpRequest* req, const char* key, const cc_st
|
|||||||
CFRelease(valCF);
|
CFRelease(valCF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Http_CheckHeader(void* k, void* v, void* ctx) {
|
static void Http_CheckHeader(const void* k, const void* v, void* ctx) {
|
||||||
cc_string line; char lineBuffer[2048];
|
cc_string line; char lineBuffer[2048];
|
||||||
char keyBuf[128] = { 0 };
|
char keyBuf[128] = { 0 };
|
||||||
char valBuf[1024] = { 0 };
|
char valBuf[1024] = { 0 };
|
||||||
@ -825,12 +825,27 @@ static void Http_CheckHeader(void* k, void* v, void* ctx) {
|
|||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cc_result ParseResponseHeaders(struct HttpRequest* req, CFReadStreamRef stream) {
|
||||||
|
CFHTTPMessageRef response = CFReadStreamCopyProperty(stream, kCFStreamPropertyHTTPResponseHeader);
|
||||||
|
if (!response) return ERR_INVALID_ARGUMENT;
|
||||||
|
|
||||||
|
CFDictionaryRef headers = CFHTTPMessageCopyAllHeaderFields(response);
|
||||||
|
CFDictionaryApplyFunction(headers, Http_CheckHeader, req);
|
||||||
|
req->statusCode = CFHTTPMessageGetResponseStatusCode(response);
|
||||||
|
|
||||||
|
CFRelease(headers);
|
||||||
|
CFRelease(response);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* url) {
|
static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* url) {
|
||||||
static CFStringRef verbs[] = { CFSTR("GET"), CFSTR("HEAD"), CFSTR("POST") };
|
static CFStringRef verbs[] = { CFSTR("GET"), CFSTR("HEAD"), CFSTR("POST") };
|
||||||
CFHTTPMessageRef request, response;
|
cc_bool gotHeaders = false;
|
||||||
char tmp[NATIVE_STR_LEN];
|
char tmp[NATIVE_STR_LEN];
|
||||||
|
CFHTTPMessageRef request;
|
||||||
CFStringRef urlCF;
|
CFStringRef urlCF;
|
||||||
CFURLRef urlRef;
|
CFURLRef urlRef;
|
||||||
|
cc_result result = 0;
|
||||||
|
|
||||||
Platform_EncodeUtf8(tmp, url);
|
Platform_EncodeUtf8(tmp, url);
|
||||||
urlCF = CFStringCreateWithCString(NULL, tmp, kCFStringEncodingUTF8);
|
urlCF = CFStringCreateWithCString(NULL, tmp, kCFStringEncodingUTF8);
|
||||||
@ -839,6 +854,7 @@ static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* url) {
|
|||||||
request = CFHTTPMessageCreateRequest(NULL, verbs[req->requestType], urlRef, kCFHTTPVersion1_1);
|
request = CFHTTPMessageCreateRequest(NULL, verbs[req->requestType], urlRef, kCFHTTPVersion1_1);
|
||||||
req->meta = request;
|
req->meta = request;
|
||||||
Http_SetRequestHeaders(req);
|
Http_SetRequestHeaders(req);
|
||||||
|
CFRelease(urlRef);
|
||||||
|
|
||||||
if (req->data && req->size) {
|
if (req->data && req->size) {
|
||||||
CFDataRef body = CFDataCreate(NULL, req->data, req->size);
|
CFDataRef body = CFDataCreate(NULL, req->data, req->size);
|
||||||
@ -854,13 +870,18 @@ static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* url) {
|
|||||||
CFReadStreamSetProperty(stream, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue);
|
CFReadStreamSetProperty(stream, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue);
|
||||||
//CFHTTPReadStreamSetRedirectsAutomatically(stream, TRUE);
|
//CFHTTPReadStreamSetRedirectsAutomatically(stream, TRUE);
|
||||||
CFReadStreamOpen(stream);
|
CFReadStreamOpen(stream);
|
||||||
CFIndex read = 0;
|
UInt8 buf[1024];
|
||||||
char buf[1024];
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
CFIndex read = CFReadStreamRead(stream, buf, sizeof(buf));
|
CFIndex read = CFReadStreamRead(stream, buf, sizeof(buf));
|
||||||
if (read <= 0) break;
|
if (read <= 0) break;
|
||||||
|
|
||||||
|
// reading headers before for loop doesn't work
|
||||||
|
if (!gotHeaders) {
|
||||||
|
gotHeaders = true;
|
||||||
|
if ((result = ParseResponseHeaders(req, stream))) break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!req->_capacity) Http_BufferInit(req);
|
if (!req->_capacity) Http_BufferInit(req);
|
||||||
Http_BufferEnsure(req, read);
|
Http_BufferEnsure(req, read);
|
||||||
|
|
||||||
@ -868,17 +889,11 @@ static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* url) {
|
|||||||
Http_BufferExpanded(req, read);
|
Http_BufferExpanded(req, read);
|
||||||
}
|
}
|
||||||
|
|
||||||
response = CFReadStreamCopyProperty(stream, kCFStreamPropertyHTTPResponseHeader);
|
if (!gotHeaders)
|
||||||
if (!response) return ERR_INVALID_ARGUMENT; /* TODO mem leak? */
|
result = ParseResponseHeaders(req, stream);
|
||||||
|
|
||||||
CFDictionaryRef headers = CFHTTPMessageCopyAllHeaderFields(response);
|
|
||||||
CFDictionaryApplyFunction(headers, Http_CheckHeader, req);
|
|
||||||
req->statusCode = CFHTTPMessageGetResponseStatusCode(response);
|
|
||||||
|
|
||||||
CFRelease(headers);
|
|
||||||
CFRelease(response);
|
|
||||||
CFRelease(request);
|
CFRelease(request);
|
||||||
return 0;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -629,7 +629,7 @@ static void LBackend_HandleButton(id btn_obj) {
|
|||||||
btn->OnClick(btn);
|
btn->OnClick(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_InitButton(struct LButton* w, int width, int height) {
|
void LBackend_ButtonInit(struct LButton* w, int width, int height) {
|
||||||
UIButton* btn = [[UIButton alloc] init];
|
UIButton* btn = [[UIButton alloc] init];
|
||||||
btn.frame = CGRectMake(0, 0, width, height);
|
btn.frame = CGRectMake(0, 0, width, height);
|
||||||
// TODO should be app_handle, because win_handle can change
|
// TODO should be app_handle, because win_handle can change
|
||||||
@ -650,7 +650,7 @@ void LBackend_InitButton(struct LButton* w, int width, int height) {
|
|||||||
[btn setBackgroundImage:ToUIImage(&bmp2) forState:UIControlStateHighlighted];
|
[btn setBackgroundImage:ToUIImage(&bmp2) forState:UIControlStateHighlighted];
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_UpdateButton(struct LButton* w) {
|
void LBackend_ButtonUpdate(struct LButton* w) {
|
||||||
UIButton* btn = (__bridge UIButton*)w->meta;
|
UIButton* btn = (__bridge UIButton*)w->meta;
|
||||||
NSString* str = ToNSString(&w->text);
|
NSString* str = ToNSString(&w->text);
|
||||||
|
|
||||||
@ -659,21 +659,21 @@ void LBackend_UpdateButton(struct LButton* w) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LBackend_DrawButton(struct LButton* w) {
|
void LBackend_ButtonDraw(struct LButton* w) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------CheckboxWidget------------------------------------------------------*
|
*-----------------------------------------------------CheckboxWidget------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void LBackend_InitCheckbox(struct LCheckbox* w) {
|
void LBackend_CheckboxInit(struct LCheckbox* w) {
|
||||||
UISwitch* swt = [[UISwitch alloc] init];
|
UISwitch* swt = [[UISwitch alloc] init];
|
||||||
|
|
||||||
AssignView(w, swt);
|
AssignView(w, swt);
|
||||||
UpdateWidgetDimensions(w);
|
UpdateWidgetDimensions(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_DrawCheckbox(struct LCheckbox* w) {
|
void LBackend_CheckboxDraw(struct LCheckbox* w) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -693,7 +693,7 @@ static void LBackend_HandleInput(id ipt_obj) {
|
|||||||
if (ipt->TextChanged) ipt->TextChanged(ipt);
|
if (ipt->TextChanged) ipt->TextChanged(ipt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_InitInput(struct LInput* w, int width) {
|
void LBackend_InputInit(struct LInput* w, int width) {
|
||||||
UITextField* fld = [[UITextField alloc] init];
|
UITextField* fld = [[UITextField alloc] init];
|
||||||
fld.frame = CGRectMake(0, 0, width, 30);
|
fld.frame = CGRectMake(0, 0, width, 30);
|
||||||
fld.borderStyle = UITextBorderStyleBezel;
|
fld.borderStyle = UITextBorderStyleBezel;
|
||||||
@ -716,24 +716,24 @@ void LBackend_InitInput(struct LInput* w, int width) {
|
|||||||
UpdateWidgetDimensions(w);
|
UpdateWidgetDimensions(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_UpdateInput(struct LInput* w) {
|
void LBackend_InputUpdate(struct LInput* w) {
|
||||||
UITextField* fld = (__bridge UITextField*)w->meta;
|
UITextField* fld = (__bridge UITextField*)w->meta;
|
||||||
fld.text = ToNSString(&w->text);
|
fld.text = ToNSString(&w->text);
|
||||||
UpdateWidgetDimensions(w);
|
UpdateWidgetDimensions(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_DrawInput(struct LInput* w) {
|
void LBackend_InputDraw(struct LInput* w) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_TickInput(struct LInput* w) { }
|
void LBackend_InputTick(struct LInput* w) { }
|
||||||
void LBackend_SelectInput(struct LInput* w, int idx, cc_bool wasSelected) { }
|
void LBackend_InputSelect(struct LInput* w, int idx, cc_bool wasSelected) { }
|
||||||
void LBackend_UnselectInput(struct LInput* w) { }
|
void LBackend_InputUnselect(struct LInput* w) { }
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*------------------------------------------------------LabelWidget--------------------------------------------------------*
|
*------------------------------------------------------LabelWidget--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void LBackend_InitLabel(struct LLabel* w) {
|
void LBackend_LabelInit(struct LLabel* w) {
|
||||||
UILabel* lbl = [[UILabel alloc] init];
|
UILabel* lbl = [[UILabel alloc] init];
|
||||||
lbl.textColor = [UIColor whiteColor];
|
lbl.textColor = [UIColor whiteColor];
|
||||||
|
|
||||||
@ -741,7 +741,7 @@ void LBackend_InitLabel(struct LLabel* w) {
|
|||||||
UpdateWidgetDimensions(w);
|
UpdateWidgetDimensions(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_UpdateLabel(struct LLabel* w) {
|
void LBackend_LabelUpdate(struct LLabel* w) {
|
||||||
UILabel* lbl = (__bridge UILabel*)w->meta;
|
UILabel* lbl = (__bridge UILabel*)w->meta;
|
||||||
char raw[NATIVE_STR_LEN];
|
char raw[NATIVE_STR_LEN];
|
||||||
Platform_EncodeUtf8(raw, &w->text);
|
Platform_EncodeUtf8(raw, &w->text);
|
||||||
@ -753,14 +753,14 @@ void LBackend_UpdateLabel(struct LLabel* w) {
|
|||||||
UpdateWidgetDimensions(w);
|
UpdateWidgetDimensions(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_DrawLabel(struct LLabel* w) {
|
void LBackend_LabelDraw(struct LLabel* w) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-------------------------------------------------------LineWidget--------------------------------------------------------*
|
*-------------------------------------------------------LineWidget--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void LBackend_InitLine(struct LLine* w, int width) {
|
void LBackend_LineInit(struct LLine* w, int width) {
|
||||||
UIView* view = [[UIView alloc] init];
|
UIView* view = [[UIView alloc] init];
|
||||||
view.frame = CGRectMake(0, 0, width, 2);
|
view.frame = CGRectMake(0, 0, width, 2);
|
||||||
|
|
||||||
@ -771,14 +771,14 @@ void LBackend_InitLine(struct LLine* w, int width) {
|
|||||||
UpdateWidgetDimensions(w);
|
UpdateWidgetDimensions(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_DrawLine(struct LLine* w) {
|
void LBackend_LineDraw(struct LLine* w) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*------------------------------------------------------SliderWidget-------------------------------------------------------*
|
*------------------------------------------------------SliderWidget-------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void LBackend_InitSlider(struct LSlider* w, int width, int height) {
|
void LBackend_SliderInit(struct LSlider* w, int width, int height) {
|
||||||
UIProgressView* prg = [[UIProgressView alloc] init];
|
UIProgressView* prg = [[UIProgressView alloc] init];
|
||||||
prg.frame = CGRectMake(0, 0, width, height);
|
prg.frame = CGRectMake(0, 0, width, height);
|
||||||
|
|
||||||
@ -786,11 +786,30 @@ void LBackend_InitSlider(struct LSlider* w, int width, int height) {
|
|||||||
UpdateWidgetDimensions(w);
|
UpdateWidgetDimensions(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_UpdateSlider(struct LSlider* w) {
|
void LBackend_SliderUpdate(struct LSlider* w) {
|
||||||
UIProgressView* lbl = (__bridge UIProgressView*)w->meta;
|
UIProgressView* lbl = (__bridge UIProgressView*)w->meta;
|
||||||
|
|
||||||
lbl.progress = w->value / 100.0f;
|
lbl.progress = w->value / 100.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_DrawSlider(struct LSlider* w) {
|
void LBackend_SliderDraw(struct LSlider* w) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*------------------------------------------------------TableWidget-------------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
void LBackend_TableInit(struct LTableView* w) {
|
||||||
|
UITableView* tbl = [[UITableView alloc] init];
|
||||||
|
tbl.frame = CGRectMake(0, 0, 200, 30);
|
||||||
|
|
||||||
|
AssignView(w, tbl);
|
||||||
|
UpdateWidgetDimensions(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LBackend_TableDraw(struct LTable* w) { }
|
||||||
|
void LBackend_TableReposition(struct LTable* w) { }
|
||||||
|
|
||||||
|
void LBackend_TableMouseDown(struct LTable* w, int idx) { }
|
||||||
|
void LBackend_TableMouseUp(struct LTable* w, int idx) { }
|
||||||
|
void LBackend_TableMouseMove(struct LTable* w, int idx) { }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user