<commit_before>#include <sys/syslimits.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <3ds.h>

#include "../../list.h"
#include "../../error.h"
#include "../../../util.h"
#include "../../../screen.h"
#include "task.h"

typedef struct {
    list_item* items;
    u32* count;
    u32 max;

    Handle cancelEvent;
} populate_titles_data;

static Result task_populate_titles_from(populate_titles_data* data, FS_MediaType mediaType) {
    FS_CardType type;
    if(mediaType == MEDIATYPE_GAME_CARD && (R_FAILED(FSUSER_GetCardType(&type)) || type != CARD_CTR)) {
        return 0;
    }

    Result res = 0;

    u32 titleCount = 0;
    if(R_SUCCEEDED(res = AM_GetTitleCount(mediaType, &titleCount))) {
        u64* titleIds = (u64*) calloc(titleCount, sizeof(u64));
        if(titleIds != NULL) {
            if(R_SUCCEEDED(res = AM_GetTitleList(&titleCount, mediaType, titleCount, titleIds))) {
                qsort(titleIds, titleCount, sizeof(u64), util_compare_u64);

                AM_TitleEntry* titleInfos = (AM_TitleEntry*) calloc(titleCount, sizeof(AM_TitleEntry));
                if(titleInfos != NULL) {
                    if(R_SUCCEEDED(res = AM_GetTitleInfo(mediaType, titleCount, titleIds, titleInfos))) {
                        SMDH smdh;
                        for(u32 i = 0; i < titleCount && i < data->max; i++) {
                            if(task_is_quit_all() || svcWaitSynchronization(data->cancelEvent, 0) == 0) {
                                break;
                            }

                            title_info* titleInfo = (title_info*) calloc(1, sizeof(title_info));
                            if(titleInfo != NULL) {
                                titleInfo->mediaType = mediaType;
                                titleInfo->titleId = titleIds[i];
                                AM_GetTitleProductCode(mediaType, titleIds[i], titleInfo->productCode);
                                titleInfo->version = titleInfos[i].version;
                                titleInfo->installedSize = titleInfos[i].size;<commit_msg>Add card inserted check for extra certainty.<commit_after>#include <sys/syslimits.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <3ds.h>

#include "../../list.h"
#include "../../error.h"
#include "../../../util.h"
#include "../../../screen.h"
#include "task.h"

typedef struct {
    list_item* items;
    u32* count;
    u32 max;

    Handle cancelEvent;
} populate_titles_data;

static Result task_populate_titles_from(populate_titles_data* data, FS_MediaType mediaType) {
    bool inserted;
    FS_CardType type;
    if(mediaType == MEDIATYPE_GAME_CARD && ((R_FAILED(FSUSER_CardSlotIsInserted(&inserted)) || !inserted) || (R_FAILED(FSUSER_GetCardType(&type)) || type != CARD_CTR))) {
        return 0;
    }

    Result res = 0;

    u32 titleCount = 0;
    if(R_SUCCEEDED(res = AM_GetTitleCount(mediaType, &titleCount))) {
        u64* titleIds = (u64*) calloc(titleCount, sizeof(u64));
        if(titleIds != NULL) {
            if(R_SUCCEEDED(res = AM_GetTitleList(&titleCount, mediaType, titleCount, titleIds))) {
                qsort(titleIds, titleCount, sizeof(u64), util_compare_u64);

                AM_TitleEntry* titleInfos = (AM_TitleEntry*) calloc(titleCount, sizeof(AM_TitleEntry));
                if(titleInfos != NULL) {
                    if(R_SUCCEEDED(res = AM_GetTitleInfo(mediaType, titleCount, titleIds, titleInfos))) {
                        SMDH smdh;
                        for(u32 i = 0; i < titleCount && i < data->max; i++) {
                            if(task_is_quit_all() || svcWaitSynchronization(data->cancelEvent, 0) == 0) {
                                break;
                            }

                            title_info* titleInfo = (title_info*) calloc(1, sizeof(title_info));
                            if(titleInfo != NULL) {
                                titleInfo->mediaType = mediaType;
                                titleInfo->titleId = titleIds[i];
                                AM_GetTitleProductCode(mediaType, titleIds[i], titleInfo->productCode);
                                titleInfo->version = titleInfos[i].version;
                                titleInfo->installedSize = titleInfos[i].size;
{'fraction_non_alphanumeric': 0.12849549341345043, 'fraction_numerical': 0.012017564132193206, 'mean_word_length': 2.001386962552011, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5090416', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1312, 'n_words': 245}