<commit_before>var exec = require('child_process').exec;
var fs = require('fs');
var path = require('path');

var packages;
var currentPackageIndex = 0;
var original_cwd = process.cwd();
var outDir = path.join(original_cwd, 'captures', 'apks');

if(!fs.existsSync(outDir)) {
    fs.mkdirSync(outDir);
}

process.chdir(outDir);

exec('adb shell pm list packages', function(error, stdout, stderr) {
    
    packages = stdout.split('\r\n');

    processNext();

});

function processNext() {
    var pk = packages[currentPackageIndex];

    console.log('this', pk);

    var f = pk.replace('package:', '');
    f = f + '-1.apk';

    console.log('pull', f);

    exec('adb pull /data/app/' + f, function(er, sout, serr) {

        currentPackageIndex++;

        if(currentPackageIndex < packages.length) {
            process.nextTick(processNext);
        } else {
            finish();
        }
    });
}

function finish() {
    console.log('done');
    exec('cd ' + original_cwd);
}

<commit_msg>make apk-bck use the settings too<commit_after>var exec = require('child_process').exec;
var fs = require('fs');
var path = require('path');
var settings = require('./settings');

var packages;
var currentPackageIndex = 0;
var original_cwd = process.cwd();
var outDir = path.join(original_cwd, settings.get('outputDir'), settings.get('apksDir'));

console.log('apk-bck out dir=' + outDir);

if(!fs.existsSync(outDir)) {
    fs.mkdirSync(outDir);
}

process.chdir(outDir);

exec('adb shell pm list packages', function(error, stdout, stderr) {
    

    if(error) {
        var errorMsg = error.toString();
        console.error(errorMsg);
        if(errorMsg.search('device not found')) {
            console.log('>>> hint hint: IS THE DEVICE CONNECTED TO THE COMPUTER?');
        }
    } else {

        packages = stdout.split('\r\n');
        processNext();

    }

});

function processNext() {
    var pk = packages[currentPackageIndex];
    currentPackageIndex++;

    var f = pk.replace('package:', '');
    f = f + '-1.apk';

    console.log(f);

    if(fs.existsSync(f)) {

        console.log('\t=> already exists');
        nextStep();

    } else {

        exec('adb pull /data/app/' + f, function(er, sout, serr) {
            nextStep();
        });

    }
}

function nextStep() {
    if(currentPackageIndex < packages.length) {
        process.nextTick(processNext);
    } else {
        finish();
    }
}

function finish() {
    console.log('done');
    exec('cd ' + original_cwd);
}


{'fraction_non_alphanumeric': 0.1673991210547343, 'fraction_numerical': 0.0015980823012385138, 'mean_word_length': 2.906396255850234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5025300', 'n_tokens_mistral': 838, 'n_tokens_neox': 813, 'n_words': 175}