예제 #1
0
파일: toxic.c 프로젝트: gracchus163/toxic
static void load_data(Tox *m, char *path)
{
    if (arg_opts.ignore_data_file)
        return;

    FILE *fd;

    if ((fd = fopen(path, "rb")) != NULL) {
        fseek(fd, 0, SEEK_END);
        int len = ftell(fd);
        fseek(fd, 0, SEEK_SET);

        char *buf = malloc(len);

        if (buf == NULL) {
            fclose(fd);
            exit_toxic_err("failed in load_data", FATALERR_MEMORY);
        }

        if (fread(buf, len, 1, fd) != 1) {
            free(buf);
            fclose(fd);
            exit_toxic_err("failed in load_data", FATALERR_FREAD);
        }

        tox_load(m, (uint8_t *) buf, len);
        load_friendlist(m);

        free(buf);
        fclose(fd);
    } else {
        if (store_data(m, path) != 0)
            exit_toxic_err("failed in load_data", FATALERR_STORE_DATA);
    }
}
예제 #2
0
파일: core.cpp 프로젝트: ReDetection/qTox
void Core::loadConfiguration()
{
    QString path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME;

    QFile configurationFile(path);

    if (!configurationFile.exists()) {
        qWarning() << "The Tox configuration file was not found";
        return;
    }

    if (!configurationFile.open(QIODevice::ReadOnly)) {
        qCritical() << "File " << path << " cannot be opened";
        return;
    }

    qint64 fileSize = configurationFile.size();
    if (fileSize > 0) {
        QByteArray data = configurationFile.readAll();
        tox_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size());
    }

    configurationFile.close();

    // set GUI with user and statusmsg
    QString name = getUsername();
    if (name != "")
        emit usernameSet(name);
    
    QString msg = getStatusMessage();
    if (msg != "")
        emit statusMessageSet(msg);

    loadFriends();
}
예제 #3
0
void Core::loadConfiguration()
{
    QString path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME;

    QFile configurationFile(path);

    if (!configurationFile.exists()) {
        qWarning() << "The Tox configuration file was not found";
        return;
    }

    if (!configurationFile.open(QIODevice::ReadOnly)) {
        qCritical() << "File " << path << " cannot be opened";
        return;
    }

    qint64 fileSize = configurationFile.size();
    if (fileSize > 0) {
        QByteArray data = configurationFile.readAll();
        tox_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size());
    }

    configurationFile.close();

    loadFriends();
}
예제 #4
0
static int load_data(Tox *m)
{
    FILE *data_file = fopen(data_file_name, "r");

    if (data_file) {
        fseek(data_file, 0, SEEK_END);
        size_t size = ftell(data_file);
        rewind(data_file);

        uint8_t data[size];

        if (fread(data, sizeof(uint8_t), size, data_file) != size) {
            fputs("[!] could not read data file!\n", stderr);
            fclose(data_file);
            return 0;
        }

        tox_load(m, data, size);

        if (fclose(data_file) < 0) {
            perror("[!] fclose failed");
            /* we got it open and the expected data read... let it be ok */
            /* return 0; */
        }

        return 1;
    }

    return 0;
}
예제 #5
0
파일: main.c 프로젝트: FullName/toxic
static void load_data(Tox *m, char *path)
{
    if (f_loadfromfile == 0) /*If file loading/saving is disabled*/
        return;

    FILE *fd;
    size_t len;
    uint8_t *buf;

    if ((fd = fopen(path, "r")) != NULL) {
        fseek(fd, 0, SEEK_END);
        len = ftell(fd);
        fseek(fd, 0, SEEK_SET);

        buf = malloc(len);

        if (buf == NULL) {
            fclose(fd);
            endwin();
            fprintf(stderr, "malloc() failed. Aborting...\n");
            exit(EXIT_FAILURE);
        }

        if (fread(buf, len, 1, fd) != 1) {
            free(buf);
            fclose(fd);
            endwin();
            fprintf(stderr, "fread() failed. Aborting...\n");
            exit(EXIT_FAILURE);
        }

        tox_load(m, buf, len);

        uint32_t i = 0;

        uint8_t name[TOX_MAX_NAME_LENGTH];
        while (tox_getname(m, i, name) != -1) {
            on_friendadded(m, i);
            i++;
        }

        free(buf);
        fclose(fd);
    } else {
        int st;

        if ((st = store_data(m, path)) != 0) {
            endwin();
            fprintf(stderr, "Store messenger failed with return code: %d\n", st);
            exit(EXIT_FAILURE);
        }
    }
}
예제 #6
0
파일: core.cpp 프로젝트: tr37ion/qTox
bool Core::loadConfiguration()
{
    QString path = QDir(Settings::getSettingsDirPath()).filePath(CONFIG_FILE_NAME);

    QFile configurationFile(path);

    if (!configurationFile.exists()) {
        qWarning() << "The Tox configuration file was not found";
        return true;
    }

    if (!configurationFile.open(QIODevice::ReadOnly)) {
        qCritical() << "File " << path << " cannot be opened";
        return true;
    }

    qint64 fileSize = configurationFile.size();
    if (fileSize > 0) {
        QByteArray data = configurationFile.readAll();
        int error = tox_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size());
        if (error < 0)
        {
            qWarning() << "Core: tox_load failed with error "<<error;
        }
        else if (error == 1) // Encrypted data save
        {
            qWarning() << "Core: Can not open encrypted tox save";
            if (QMessageBox::Ok != QMessageBox::warning(nullptr, tr("Encrypted profile"),
                tr("Your tox profile seems to be encrypted, qTox can't open it\nDo you want to erase this profile ?"),
                QMessageBox::Ok | QMessageBox::Cancel))
            {
                qWarning() << "Core: Couldn't open encrypted save, giving up";
                configurationFile.close();
                return false;
            }
        }
    }

    configurationFile.close();

    // set GUI with user and statusmsg
    QString name = getUsername();
    if (name != "")
        emit usernameSet(name);
    
    QString msg = getStatusMessage();
    if (msg != "")
        emit statusMessageSet(msg);

    loadFriends();
    return true;
}
예제 #7
0
void load_key(Tox *m, char *path)
{
    FILE *data_file = fopen(path, "r");
    int size = 0;

    if (data_file) {
        //load keys
        fseek(data_file, 0, SEEK_END);
        size = ftell(data_file);
        rewind(data_file);

        uint8_t data[size];

        if (fread(data, sizeof(uint8_t), size, data_file) != size) {
            fputs("[!] could not read data file! exiting...\n", stderr);
            goto FILE_ERROR;
        }

        tox_load(m, data, size);

    } else {
        //else save new keys
        int size = tox_size(m);
        uint8_t data[size];
        tox_save(m, data);
        data_file = fopen(path, "w");

        if (!data_file) {
            perror("[!] load_key");
            exit(1);
        }

        if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
            fputs("[!] could not write data file! exiting...", stderr);
            goto FILE_ERROR;
        }
    }

    if (fclose(data_file) < 0)
        perror("[!] fclose failed");

    return;

FILE_ERROR:

    if (fclose(data_file) < 0)
        perror("[!] fclose failed");

    exit(1);
}
예제 #8
0
파일: toxic.c 프로젝트: jin-eld/toxic
static void load_data(Tox *m, char *path)
{
    if (arg_opts.ignore_data_file)
        return;

    FILE *fd;
    size_t len;
    uint8_t *buf;

    if ((fd = fopen(path, "rb")) != NULL) {
        fseek(fd, 0, SEEK_END);
        len = ftell(fd);
        fseek(fd, 0, SEEK_SET);

        buf = malloc(len);

        if (buf == NULL) {
            fclose(fd);
            endwin();
            fprintf(stderr, "malloc() failed. Aborting...\n");
            exit(EXIT_FAILURE);
        }

        if (fread(buf, len, 1, fd) != 1) {
            free(buf);
            fclose(fd);
            endwin();
            fprintf(stderr, "fread() failed. Aborting...\n");
            exit(EXIT_FAILURE);
        }

        tox_load(m, buf, len);
        load_friendlist(m);

        free(buf);
        fclose(fd);
    } else {
        int st;

        if ((st = store_data(m, path)) != 0) {
            endwin();
            fprintf(stderr, "Store messenger failed with return code: %d\n", st);
            exit(EXIT_FAILURE);
        }
    }
}
예제 #9
0
파일: mio.c 프로젝트: bapuqln/Poison
int upgrade(const char *file, const char *output) {
    FILE *f = fopen(file, "r");
    if (!f) {
        perror("mio/upgrade");
        return -1;
    }

    fseek(f, 0, SEEK_END);
    size_t bufsize = ftell(f);
    fseek(f, 0, 0);
    uint8_t *buf = malloc(bufsize);
    fread(buf, bufsize, 1, f);
    fclose(f);

    Tox *temptox = tox_new(1);
    tox_load(temptox, buf, (uint32_t)bufsize);
    free(buf);

    puts("mio/upgrade: letting Tox run for a bit");
    for (int n = 0; n < 20; ++n) {
        tox_do(temptox);
        printf(".");
        fflush(stdout);
        usleep(50000);
    }
    puts(" done");

    txd_intermediate_t txd = txd_intermediate_from_tox(temptox);
    tox_kill(temptox);

    uint8_t *clear;
    uint64_t clearlen;
    int eerr = txd_export_to_buf(txd, &clear, &clearlen);
    if (eerr != TXD_ERR_SUCCESS) {
        printf("mio/upgrade: error: txd_export_to_buf failed with code %d\n",
               eerr);
        return -1;
    }
    txd_intermediate_free(txd);

    char *template = strdup(".si-XXXXXXXX");
예제 #10
0
파일: tox.c 프로젝트: Boerde/uTox
static _Bool load_save(Tox *tox)
{
    {
        uint8_t path[512], *p;
        uint32_t size;

        p = path + datapath(path);
        strcpy((char*)p, "tox_save");

        void *data = file_raw((char*)path, &size);
        if(!data) {
            p = path + datapath_old(path);
            strcpy((char*)p, "tox_save");
            data = file_raw((char*)path, &size);
            if (!data) {
                data = file_raw("tox_save", &size);
                if(!data) {
                    return 0;
                }
            }
        }

        tox_load(tox, data, size);
        free(data);
    }

    friends = tox_count_friendlist(tox);

    uint32_t i = 0;
    while(i != friends) {
        int size;
        FRIEND *f = &friend[i];
        uint8_t name[TOX_MAX_NAME_LENGTH];

        f->msg.scroll = 1.0;

        tox_get_client_id(tox, i, f->cid);

        size = tox_get_name(tox, i, name);

        friend_setname(f, name, size);

        size = tox_get_status_message_size(tox, i);
        f->status_message = malloc(size);
        tox_get_status_message(tox, i, f->status_message, size);
        f->status_length = size;

        log_read(tox, i);

        i++;
    }

    self.name_length = tox_get_self_name(tox, self.name);
    self.statusmsg_length = tox_get_self_status_message_size(tox);
    self.statusmsg = malloc(self.statusmsg_length);
    tox_get_self_status_message(tox, self.statusmsg, self.statusmsg_length);
    self.status = tox_get_self_user_status(tox);


    return 1;
}