<commit_before>var fs = require("fs");
var path = require("path");
var userpath = path.join(require("os").homedir(), ".efront");
var userdatafile = path.join(userpath, 'profile');
var JSAM = require("../basic/JSAM");
var lazy = require("../basic/lazy");
var encode62 = require('../crypt/encode62');
var profile = {
    code: encode62.geta(Math.random().toString(36).slice(2)),
};
function save(pathname, data) {
    var fullpath = path.join(userpath, pathname);
    var folderpath = path.dirname(fullpath)
    if (!fs.existsSync(folderpath)) fs.mkdirSync(folderpath, { recursive: true });
    fs.writeFileSync(fullpath, JSAM.stringify(data));
}
function load(pathname) {
    var fullpath = path.join(userpath, pathname);
    if (!fs.existsSync(fullpath)) return;
    var data = fs.readFileSync(fullpath);
    return JSAM.parse(data);
}
var profile_promise = null;
var loadProfileAsync = function () {
    if (profile_promise || !fs.existsSync(userdatafile)) return profile_promise;
    return profile_promise = new Promise(function (ok, oh) {
        fs.readFile(userdatafile, function (error, buff) {
            if (error) return oh(error);
            ok(buff);
        });
    }).then(function (data) {
        data = String(data);
        data = JSAM.parse(data);
        Object.assign(profile, data);
    }, console.error);
};
var saveProfileAsync = lazy(async function () {
    var folderpath = path.dirname(userdatafile);
    try {
        if (!fs.existsSync(folderpath)) {
            await new Promise((ok, oh) => {
                fs.mkdir(folderpath, { recursive: true }, function (error) {
                    if (error) return oh(error);
                    ok();
                });
            });
        }
        await new Promise((ok, oh) => {
            var data = JSAM.stringify(profile);
            fs.writeFile(userdatafile, data, function (error) {
                if (error) return oh(error);
                ok();
            });
        });
    } catch (e) {
        console.error("写入文件失败！");
        return;
    }
    if (!fs.existsSync(userdatafile)) { }
}, 60);
async function setItem(k, v) {
    await loadProfileAsync();
    var k0 = encode62.geta(k + profile.code);
    profile[k0] = String(encode62.encode(v, k0));
    saveProfileAsync();
}
async function getItem(k) {
    await loadProfileAsync();
    var k0 = encode62.geta(k + profile.code);
    return String(encode62.decode(profile[k0], k0));
}

async function checkPassword(p) {
    var a = encode62.geta(p);
    var c = await getItem('password-c');
    var d = await getItem('password-d');
    var b = encode62.da2b(d, a);
    var c0 = encode62.ab2c(a, b);
    return c0 === c;
}

async function checkPasswordA(a) {
    var c = await getItem('password-c');
    var d = await getItem('password-d');
    var b = encode62.da2b(d, a);
    var c0 = encode62.ab2c(a, b);
    if (c0 === c) return b;
    return null;<commit_msg>解决无配置文件时报错的问题<commit_after>var fs = require("fs");
var path = require("path");
var userpath = path.join(require("os").homedir(), ".efront");
var userdatafile = path.join(userpath, 'profile');
var JSAM = require("../basic/JSAM");
var lazy = require("../basic/lazy");
var encode62 = require('../crypt/encode62');
var profile = {
    code: encode62.geta(Math.random().toString(36).slice(2)),
};
function save(pathname, data) {
    var fullpath = path.join(userpath, pathname);
    var folderpath = path.dirname(fullpath)
    if (!fs.existsSync(folderpath)) fs.mkdirSync(folderpath, { recursive: true });
    fs.writeFileSync(fullpath, JSAM.stringify(data));
}
function load(pathname) {
    var fullpath = path.join(userpath, pathname);
    if (!fs.existsSync(fullpath)) return;
    var data = fs.readFileSync(fullpath);
    return JSAM.parse(data);
}
var profile_promise = null;
var loadProfileAsync = function () {
    if (profile_promise || !fs.existsSync(userdatafile)) return profile_promise;
    return profile_promise = new Promise(function (ok, oh) {
        fs.readFile(userdatafile, function (error, buff) {
            if (error) return oh(error);
            ok(buff);
        });
    }).then(function (data) {
        data = String(data);
        data = JSAM.parse(data);
        Object.assign(profile, data);
    }, console.error);
};
var saveProfileAsync = lazy(async function () {
    var folderpath = path.dirname(userdatafile);
    try {
        if (!fs.existsSync(folderpath)) {
            await new Promise((ok, oh) => {
                fs.mkdir(folderpath, { recursive: true }, function (error) {
                    if (error) return oh(error);
                    ok();
                });
            });
        }
        await new Promise((ok, oh) => {
            var data = JSAM.stringify(profile);
            fs.writeFile(userdatafile, data, function (error) {
                if (error) return oh(error);
                ok();
            });
        });
    } catch (e) {
        console.error("写入文件失败！");
        return;
    }
    if (!fs.existsSync(userdatafile)) { }
}, 60);
async function setItem(k, v) {
    await loadProfileAsync();
    var k0 = encode62.geta(k + profile.code);
    profile[k0] = String(encode62.encode(v, k0));
    saveProfileAsync();
}
async function getItem(k) {
    await loadProfileAsync();
    var k0 = encode62.geta(k + profile.code);
    var v = profile[k0];
    if (!v) return;
    return String(encode62.decode(v, k0));
}

async function checkPassword(p) {
    var a = encode62.geta(p);
    var c = await getItem('password-c');
    var d = await getItem('password-d');
    var b = encode62.da2b(d, a);
    var c0 = encode62.ab2c(a, b);
    return c0 === c;
}

async function checkPasswordA(a) {
    var c = await getItem('password-c');
    var d = await getItem('password-d');
    var b = encode62.da2b(d, a);
    var c0 = encode62.ab2c(a, b);
    if (c0 === c) return b;
    return null;
{'fraction_non_alphanumeric': 0.15481670929241262, 'fraction_numerical': 0.014663256606990622, 'mean_word_length': 2.7079646017699117, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7284082', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1897, 'n_words': 439}