From 2c982d85ecee144c1f4ff4d86d489686785dba1d Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Tue, 6 Feb 2018 12:16:24 -0800 Subject: [PATCH] Revert threading changes, disable curl code for now. --- source/core/task/capturecam.c | 2 +- source/main.c | 57 +++++---------------- source/ui/section/action/installurl.c | 4 ++ source/ui/section/task/dataop.c | 23 ++++++--- source/ui/section/task/listextsavedata.c | 2 +- source/ui/section/task/listfiles.c | 2 +- source/ui/section/task/listpendingtitles.c | 2 +- source/ui/section/task/listsystemsavedata.c | 2 +- source/ui/section/task/listtickets.c | 2 +- source/ui/section/task/listtitledb.c | 2 +- source/ui/section/task/listtitles.c | 2 +- 11 files changed, 43 insertions(+), 57 deletions(-) diff --git a/source/core/task/capturecam.c b/source/core/task/capturecam.c index a35780f..39cb108 100644 --- a/source/core/task/capturecam.c +++ b/source/core/task/capturecam.c @@ -182,7 +182,7 @@ Result task_capture_cam(capture_cam_data* data) { internalData->qrContext = quirc_new(); if(internalData->qrContext != NULL && quirc_resize(internalData->qrContext, data->width, data->height) == 0) { if(R_SUCCEEDED(res = svcCreateEvent(&data->cancelEvent, RESET_STICKY)) && R_SUCCEEDED(res = svcCreateMutex(&data->mutex, false))) { - if(threadCreate(task_capture_cam_thread, internalData, 0x10000, 0x1A, 0, true) == NULL) { + if(threadCreate(task_capture_cam_thread, internalData, 0x10000, 0x1A, 1, true) == NULL) { res = R_FBI_THREAD_CREATE_FAILED; } } diff --git a/source/main.c b/source/main.c index ad5e6b8..2b7c712 100644 --- a/source/main.c +++ b/source/main.c @@ -114,9 +114,7 @@ Result init_services() { return res; } -//static u32 old_time_limit = UINT32_MAX; - -FILE* dbg; +static u32 old_time_limit = UINT32_MAX; void init() { gfxInitDefault(); @@ -140,17 +138,17 @@ void init() { } } - /*APT_GetAppCpuTimeLimit(&old_time_limit); + osSetSpeedupEnable(true); + + APT_GetAppCpuTimeLimit(&old_time_limit); Result cpuRes = APT_SetAppCpuTimeLimit(30); if(R_FAILED(cpuRes)) { util_panic("Failed to set syscore CPU time limit: %08lX", cpuRes); return; - }*/ + } AM_InitializeExternalTitleDatabase(false); - dbg = fopen("sdmc:/debug.txt", "wb"); - curl_global_init(CURL_GLOBAL_ALL); screen_init(); @@ -160,17 +158,17 @@ void init() { } void cleanup() { - fclose(dbg); - clipboard_clear(); task_exit(); ui_exit(); screen_exit(); - /*if(old_time_limit != UINT32_MAX) { + if(old_time_limit != UINT32_MAX) { APT_SetAppCpuTimeLimit(old_time_limit); - }*/ + } + + osSetSpeedupEnable(false); cleanup_services(); @@ -179,44 +177,17 @@ void cleanup() { gfxExit(); } -static void main_thread(void* arg) { +int main(int argc, const char* argv[]) { + if(argc > 0 && envIsHomebrew()) { + util_set_3dsx_path(argv[0]); + } + init(); mainmenu_open(); while(aptMainLoop() && ui_update()); cleanup(); -} - -int main(int argc, const char* argv[]) { - if(argc > 0 && envIsHomebrew()) { - util_set_3dsx_path(argv[0]); - } - - osSetSpeedupEnable(true); - - u32 oldTimeLimit = UINT32_MAX; - APT_GetAppCpuTimeLimit(&oldTimeLimit); - - Result cpuRes = APT_SetAppCpuTimeLimit(30); - if(R_FAILED(cpuRes)) { - util_panic("Failed to set syscore CPU time limit: %08lX", cpuRes); - return 0; - } - - Thread mainThread = threadCreate(main_thread, NULL, 0x10000, 0x18, 1, true); - if(mainThread == NULL) { - util_panic("Failed to start main thread."); - return 0; - } - - threadJoin(mainThread, U64_MAX); - - if(oldTimeLimit != UINT32_MAX) { - APT_SetAppCpuTimeLimit(oldTimeLimit); - } - - osSetSpeedupEnable(false); return 0; } \ No newline at end of file diff --git a/source/ui/section/action/installurl.c b/source/ui/section/action/installurl.c index cddc126..93417c1 100644 --- a/source/ui/section/action/installurl.c +++ b/source/ui/section/action/installurl.c @@ -451,9 +451,13 @@ void action_install_url(const char* confirmMessage, const char* urls, const char data->installInfo.data = data; +#ifdef USE_CURL data->installInfo.op = DATAOP_DOWNLOAD; data->installInfo.downloadUrls = data->urls; +#else + data->installInfo.op = DATAOP_COPY; +#endif data->installInfo.bufferSize = 128 * 1024; data->installInfo.copyEmpty = false; diff --git a/source/ui/section/task/dataop.c b/source/ui/section/task/dataop.c index 8f5d3d9..c8eceb0 100644 --- a/source/ui/section/task/dataop.c +++ b/source/ui/section/task/dataop.c @@ -151,8 +151,6 @@ static Result task_data_op_copy(data_op_data* data, u32 index) { return res; } -extern FILE* dbg; - static Result task_download_execute(const char* url, void* data, size_t write_callback(char* ptr, size_t size, size_t nmemb, void* userdata), int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)) { Result res = 0; @@ -175,9 +173,6 @@ static Result task_download_execute(const char* url, void* data, size_t write_ca curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); // TODO: Certificates? - curl_easy_setopt(curl, CURLOPT_VERBOSE, true); - curl_easy_setopt(curl, CURLOPT_STDERR, dbg); - CURLcode ret = curl_easy_perform(curl); if(ret == CURLE_OK) { long responseCode; @@ -219,6 +214,7 @@ static size_t task_download_sync_write_callback(char* ptr, size_t size, size_t n } Result task_download_sync(const char* url, u32* downloadedSize, void* buf, size_t size) { +#ifdef USE_CURL if(url == NULL || buf == NULL) { return R_FBI_INVALID_ARGUMENT; } @@ -233,6 +229,21 @@ Result task_download_sync(const char* url, u32* downloadedSize, void* buf, size_ } return res; +#else + Result res = 0; + + httpcContext context; + if(R_SUCCEEDED(res = util_http_open(&context, url, true))) { + res = util_http_read(&context, downloadedSize, buf, size); + + Result closeRes = util_http_close(&context); + if(R_SUCCEEDED(res)) { + res = closeRes; + } + } + + return res; +#endif } Result task_download_json_sync(const char* url, json_t** json, size_t maxSize) { @@ -548,7 +559,7 @@ Result task_data_op(data_op_data* data) { Result res = 0; if(R_SUCCEEDED(res = svcCreateEvent(&data->cancelEvent, RESET_STICKY))) { - if(threadCreate(task_data_op_thread, data, 0x10000, 0x18, 0, true) == NULL) { + if(threadCreate(task_data_op_thread, data, 0x10000, 0x18, 1, true) == NULL) { res = R_FBI_THREAD_CREATE_FAILED; } } diff --git a/source/ui/section/task/listextsavedata.c b/source/ui/section/task/listextsavedata.c index 694eaf2..bb164f3 100644 --- a/source/ui/section/task/listextsavedata.c +++ b/source/ui/section/task/listextsavedata.c @@ -160,7 +160,7 @@ Result task_populate_ext_save_data(populate_ext_save_data_data* data) { Result res = 0; if(R_SUCCEEDED(res = svcCreateEvent(&data->cancelEvent, RESET_STICKY))) { - if(threadCreate(task_populate_ext_save_data_thread, data, 0x10000, 0x19, 0, true) == NULL) { + if(threadCreate(task_populate_ext_save_data_thread, data, 0x10000, 0x19, 1, true) == NULL) { res = R_FBI_THREAD_CREATE_FAILED; } } diff --git a/source/ui/section/task/listfiles.c b/source/ui/section/task/listfiles.c index 27cfeaa..d5d1718 100644 --- a/source/ui/section/task/listfiles.c +++ b/source/ui/section/task/listfiles.c @@ -317,7 +317,7 @@ Result task_populate_files(populate_files_data* data) { Result res = 0; if(R_SUCCEEDED(res = svcCreateEvent(&data->cancelEvent, RESET_STICKY))) { - if(threadCreate(task_populate_files_thread, data, 0x10000, 0x19, 0, true) == NULL) { + if(threadCreate(task_populate_files_thread, data, 0x10000, 0x19, 1, true) == NULL) { res = R_FBI_THREAD_CREATE_FAILED; } } diff --git a/source/ui/section/task/listpendingtitles.c b/source/ui/section/task/listpendingtitles.c index 13041ba..5617ca2 100644 --- a/source/ui/section/task/listpendingtitles.c +++ b/source/ui/section/task/listpendingtitles.c @@ -138,7 +138,7 @@ Result task_populate_pending_titles(populate_pending_titles_data* data) { Result res = 0; if(R_SUCCEEDED(res = svcCreateEvent(&data->cancelEvent, RESET_STICKY))) { - if(threadCreate(task_populate_pending_titles_thread, data, 0x10000, 0x19, 0, true) == NULL) { + if(threadCreate(task_populate_pending_titles_thread, data, 0x10000, 0x19, 1, true) == NULL) { res = R_FBI_THREAD_CREATE_FAILED; } } diff --git a/source/ui/section/task/listsystemsavedata.c b/source/ui/section/task/listsystemsavedata.c index cc95854..cfeec7f 100644 --- a/source/ui/section/task/listsystemsavedata.c +++ b/source/ui/section/task/listsystemsavedata.c @@ -106,7 +106,7 @@ Result task_populate_system_save_data(populate_system_save_data_data* data) { Result res = 0; if(R_SUCCEEDED(res = svcCreateEvent(&data->cancelEvent, RESET_STICKY))) { - if(threadCreate(task_populate_system_save_data_thread, data, 0x10000, 0x19, 0, true) == NULL) { + if(threadCreate(task_populate_system_save_data_thread, data, 0x10000, 0x19, 1, true) == NULL) { res = R_FBI_THREAD_CREATE_FAILED; } } diff --git a/source/ui/section/task/listtickets.c b/source/ui/section/task/listtickets.c index 28b4437..d1259f5 100644 --- a/source/ui/section/task/listtickets.c +++ b/source/ui/section/task/listtickets.c @@ -133,7 +133,7 @@ Result task_populate_tickets(populate_tickets_data* data) { Result res = 0; if(R_SUCCEEDED(res = svcCreateEvent(&data->cancelEvent, RESET_STICKY))) { - if(threadCreate(task_populate_tickets_thread, data, 0x10000, 0x19, 0, true) == NULL) { + if(threadCreate(task_populate_tickets_thread, data, 0x10000, 0x19, 1, true) == NULL) { res = R_FBI_THREAD_CREATE_FAILED; } } diff --git a/source/ui/section/task/listtitledb.c b/source/ui/section/task/listtitledb.c index 4335540..30156bd 100644 --- a/source/ui/section/task/listtitledb.c +++ b/source/ui/section/task/listtitledb.c @@ -275,7 +275,7 @@ Result task_populate_titledb(populate_titledb_data* data) { if(R_SUCCEEDED(res = svcCreateEvent(&data->resumeEvent, RESET_STICKY))) { svcSignalEvent(data->resumeEvent); - if(threadCreate(task_populate_titledb_thread, data, 0x10000, 0x19, 0, true) == NULL) { + if(threadCreate(task_populate_titledb_thread, data, 0x10000, 0x19, 1, true) == NULL) { res = R_FBI_THREAD_CREATE_FAILED; } } diff --git a/source/ui/section/task/listtitles.c b/source/ui/section/task/listtitles.c index e1a3023..d0f692f 100644 --- a/source/ui/section/task/listtitles.c +++ b/source/ui/section/task/listtitles.c @@ -338,7 +338,7 @@ Result task_populate_titles(populate_titles_data* data) { Result res = 0; if(R_SUCCEEDED(res = svcCreateEvent(&data->cancelEvent, RESET_STICKY))) { - if(threadCreate(task_populate_titles_thread, data, 0x10000, 0x19, 0, true) == NULL) { + if(threadCreate(task_populate_titles_thread, data, 0x10000, 0x19, 1, true) == NULL) { res = R_FBI_THREAD_CREATE_FAILED; } }