Fix invalid characters in QR codes
This commit is contained in:
262
source/camera.c
262
source/camera.c
@@ -33,45 +33,45 @@
|
|||||||
|
|
||||||
void init_qr(void)
|
void init_qr(void)
|
||||||
{
|
{
|
||||||
camInit();
|
camInit();
|
||||||
CAMU_SetSize(SELECT_OUT1_OUT2, SIZE_CTR_TOP_LCD, CONTEXT_A);
|
CAMU_SetSize(SELECT_OUT1_OUT2, SIZE_CTR_TOP_LCD, CONTEXT_A);
|
||||||
CAMU_SetOutputFormat(SELECT_OUT1_OUT2, OUTPUT_RGB_565, CONTEXT_A);
|
CAMU_SetOutputFormat(SELECT_OUT1_OUT2, OUTPUT_RGB_565, CONTEXT_A);
|
||||||
|
|
||||||
CAMU_SetNoiseFilter(SELECT_OUT1_OUT2, true);
|
CAMU_SetNoiseFilter(SELECT_OUT1_OUT2, true);
|
||||||
CAMU_SetAutoExposure(SELECT_OUT1_OUT2, true);
|
CAMU_SetAutoExposure(SELECT_OUT1_OUT2, true);
|
||||||
CAMU_SetAutoWhiteBalance(SELECT_OUT1_OUT2, true);
|
CAMU_SetAutoWhiteBalance(SELECT_OUT1_OUT2, true);
|
||||||
|
|
||||||
CAMU_SetTrimming(PORT_CAM1, false);
|
CAMU_SetTrimming(PORT_CAM1, false);
|
||||||
|
|
||||||
buf = malloc(sizeof(u16) * 400 * 240 * 2);
|
buf = malloc(sizeof(u16) * 400 * 240 * 2);
|
||||||
|
|
||||||
context = quirc_new();
|
context = quirc_new();
|
||||||
quirc_resize(context, 400, 240);
|
quirc_resize(context, 400, 240);
|
||||||
}
|
}
|
||||||
|
|
||||||
void exit_qr(void)
|
void exit_qr(void)
|
||||||
{
|
{
|
||||||
CAMU_Activate(SELECT_NONE);
|
CAMU_Activate(SELECT_NONE);
|
||||||
camExit();
|
camExit();
|
||||||
quirc_destroy(context);
|
quirc_destroy(context);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void take_picture(void)
|
void take_picture(void)
|
||||||
{
|
{
|
||||||
u32 transfer_size;
|
u32 transfer_size;
|
||||||
Handle cam_handle = 0;
|
Handle cam_handle = 0;
|
||||||
CAMU_GetMaxBytes(&transfer_size, 400, 240);
|
CAMU_GetMaxBytes(&transfer_size, 400, 240);
|
||||||
CAMU_SetTransferBytes(PORT_BOTH, transfer_size, 400, 240);
|
CAMU_SetTransferBytes(PORT_BOTH, transfer_size, 400, 240);
|
||||||
CAMU_Activate(SELECT_OUT1_OUT2);
|
CAMU_Activate(SELECT_OUT1_OUT2);
|
||||||
CAMU_ClearBuffer(PORT_BOTH);
|
CAMU_ClearBuffer(PORT_BOTH);
|
||||||
CAMU_SynchronizeVsyncTiming(SELECT_OUT1, SELECT_OUT2);
|
CAMU_SynchronizeVsyncTiming(SELECT_OUT1, SELECT_OUT2);
|
||||||
CAMU_StartCapture(PORT_BOTH);
|
CAMU_StartCapture(PORT_BOTH);
|
||||||
CAMU_SetReceiving(&cam_handle, buf, PORT_CAM1, 400 * 240 * 2, transfer_size);
|
CAMU_SetReceiving(&cam_handle, buf, PORT_CAM1, 400 * 240 * 2, transfer_size);
|
||||||
svcWaitSynchronization(cam_handle, U64_MAX);
|
svcWaitSynchronization(cam_handle, U64_MAX);
|
||||||
CAMU_StopCapture(PORT_BOTH);
|
CAMU_StopCapture(PORT_BOTH);
|
||||||
svcCloseHandle(cam_handle);
|
svcCloseHandle(cam_handle);
|
||||||
CAMU_Activate(PORT_NONE);
|
CAMU_Activate(PORT_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -80,118 +80,130 @@ This'll probably get refactored later
|
|||||||
*/
|
*/
|
||||||
Result http_get(char *url, char *path)
|
Result http_get(char *url, char *path)
|
||||||
{
|
{
|
||||||
Result ret;
|
Result ret;
|
||||||
httpcContext context;
|
httpcContext context;
|
||||||
char *new_url = NULL;
|
char *new_url = NULL;
|
||||||
u32 status_code;
|
u32 status_code;
|
||||||
u32 content_size = 0;
|
u32 content_size = 0;
|
||||||
u32 read_size = 0;
|
u32 read_size = 0;
|
||||||
u32 size = 0;
|
u32 size = 0;
|
||||||
u8 *buf;
|
u8 *buf;
|
||||||
u8 *last_buf;
|
u8 *last_buf;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ret = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1);
|
ret = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1);
|
||||||
ret = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify); // should let us do https
|
ret = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify); // should let us do https
|
||||||
ret = httpcSetKeepAlive(&context, HTTPC_KEEPALIVE_ENABLED);
|
ret = httpcSetKeepAlive(&context, HTTPC_KEEPALIVE_ENABLED);
|
||||||
ret = httpcAddRequestHeaderField(&context, "User-Agent", "Anemone3DS/1.1.0");
|
ret = httpcAddRequestHeaderField(&context, "User-Agent", "Anemone3DS/1.1.0");
|
||||||
ret = httpcAddRequestHeaderField(&context, "Connection", "Keep-Alive");
|
ret = httpcAddRequestHeaderField(&context, "Connection", "Keep-Alive");
|
||||||
|
|
||||||
ret = httpcBeginRequest(&context);
|
ret = httpcBeginRequest(&context);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
httpcCloseContext(&context);
|
httpcCloseContext(&context);
|
||||||
if (new_url != NULL) free(new_url);
|
if (new_url != NULL) free(new_url);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = httpcGetResponseStatusCode(&context, &status_code);
|
ret = httpcGetResponseStatusCode(&context, &status_code);
|
||||||
if(ret!=0){
|
if(ret!=0){
|
||||||
httpcCloseContext(&context);
|
httpcCloseContext(&context);
|
||||||
if(new_url!=NULL) free(new_url);
|
if(new_url!=NULL) free(new_url);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308))
|
if ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308))
|
||||||
{
|
{
|
||||||
if (new_url == NULL) new_url = malloc(0x1000);
|
if (new_url == NULL) new_url = malloc(0x1000);
|
||||||
ret = httpcGetResponseHeader(&context, "Location", new_url, 0x1000);
|
ret = httpcGetResponseHeader(&context, "Location", new_url, 0x1000);
|
||||||
url = new_url;
|
url = new_url;
|
||||||
httpcCloseContext(&context);
|
httpcCloseContext(&context);
|
||||||
}
|
}
|
||||||
} while ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308));
|
} while ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308));
|
||||||
|
|
||||||
if (status_code != 200)
|
if (status_code != 200)
|
||||||
{
|
{
|
||||||
httpcCloseContext(&context);
|
httpcCloseContext(&context);
|
||||||
if (new_url != NULL) free(new_url);
|
if (new_url != NULL) free(new_url);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = httpcGetDownloadSizeState(&context, NULL, &content_size);
|
ret = httpcGetDownloadSizeState(&context, NULL, &content_size);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
httpcCloseContext(&context);
|
httpcCloseContext(&context);
|
||||||
if (new_url != NULL) free(new_url);
|
if (new_url != NULL) free(new_url);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = malloc(0x1000);
|
buf = malloc(0x1000);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
{
|
{
|
||||||
httpcCloseContext(&context);
|
httpcCloseContext(&context);
|
||||||
free(new_url);
|
free(new_url);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *content_disposition = malloc(1024);
|
char *content_disposition = malloc(1024);
|
||||||
ret = httpcGetResponseHeader(&context, "Content-Disposition", content_disposition, 1024);
|
ret = httpcGetResponseHeader(&context, "Content-Disposition", content_disposition, 1024);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
free(content_disposition);
|
free(content_disposition);
|
||||||
free(new_url);
|
free(new_url);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *filename;
|
char *filename;
|
||||||
filename = strtok(content_disposition, "\"");
|
filename = strtok(content_disposition, "\"");
|
||||||
filename = strtok(NULL, "\"");
|
filename = strtok(NULL, "\"");
|
||||||
|
|
||||||
do {
|
char *illegal_characters = "\"?;:/\\+";
|
||||||
ret = httpcDownloadData(&context, buf + size, 0x1000, &read_size);
|
for (ssize_t i = 0; i < strlen(filename); i++)
|
||||||
size += read_size;
|
{
|
||||||
|
for (ssize_t n = 0; n < strlen(illegal_characters); n++)
|
||||||
|
{
|
||||||
|
if (filename[i] == illegal_characters[n])
|
||||||
|
{
|
||||||
|
filename[i] = '-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING)
|
do {
|
||||||
{
|
ret = httpcDownloadData(&context, buf + size, 0x1000, &read_size);
|
||||||
last_buf = buf;
|
size += read_size;
|
||||||
buf = realloc(buf, size + 0x1000);
|
|
||||||
if (buf == NULL)
|
|
||||||
{
|
|
||||||
httpcCloseContext(&context);
|
|
||||||
free(last_buf);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING);
|
|
||||||
|
|
||||||
last_buf = buf;
|
if (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING)
|
||||||
buf = realloc(buf, size);
|
{
|
||||||
if (buf == NULL)
|
last_buf = buf;
|
||||||
{
|
buf = realloc(buf, size + 0x1000);
|
||||||
httpcCloseContext(&context);
|
if (buf == NULL)
|
||||||
free(last_buf);
|
{
|
||||||
return -1;
|
httpcCloseContext(&context);
|
||||||
}
|
free(last_buf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING);
|
||||||
|
|
||||||
char path_to_file[0x106] = {0};
|
last_buf = buf;
|
||||||
strcpy(path_to_file, path);
|
buf = realloc(buf, size);
|
||||||
strcat(path_to_file, filename);
|
if (buf == NULL)
|
||||||
remake_file(path_to_file, ArchiveSD, size);
|
{
|
||||||
buf_to_file(size, path_to_file, ArchiveSD, (char*)buf);
|
httpcCloseContext(&context);
|
||||||
|
free(last_buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
add_theme(&themes_list, &theme_count, path_to_file, filename);
|
char path_to_file[0x106] = {0};
|
||||||
|
strcpy(path_to_file, path);
|
||||||
|
strcat(path_to_file, filename);
|
||||||
|
remake_file(path_to_file, ArchiveSD, size);
|
||||||
|
buf_to_file(size, path_to_file, ArchiveSD, (char*)buf);
|
||||||
|
|
||||||
exit_qr();
|
add_theme(&themes_list, &theme_count, path_to_file, filename);
|
||||||
|
|
||||||
return 0;
|
exit_qr();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user