Skip to content

Commit

Permalink
use the defined title, eventually append the number too
Browse files Browse the repository at this point in the history
  • Loading branch information
GrayHatter committed Mar 20, 2015
1 parent 82b670a commit ea8218d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
22 changes: 13 additions & 9 deletions file_transfers.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void incoming_file_callback_request(Tox *tox, uint32_t friend_number, uin
memcmp(filename, "utox-inline.png", filename_length) == 0) {
file_handle->in_memory = 1;
file_handle->status = FILE_TRANSFER_STATUS_ACTIVE;
file_handle->data = malloc(file_size);
file_handle->memory = malloc(file_size);
tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error);
postmessage(FRIEND_FILE_IN_NEW_INLINE, friend_number, file_number, NULL);
} else {
Expand All @@ -110,16 +110,15 @@ static void incoming_file_callback_chunk(Tox *tox, uint32_t friend_number, uint3

TOX_ERR_FILE_SEND_CHUNK error;
FILE_TRANSFER *file_handle = &active_transfer[friend_number][file_number];
FILE *file = file_handle->data;
uint64_t last_bit = position + length;
// time_t time = time(NULL);
file_handle->last_chunk_time = time(NULL);

if(file_handle->in_memory) {
memcpy(file_handle->data + file_handle->size_received, data, length);
memcpy(file_handle->memory + file_handle->size_received, data, length);
} else {
fseeko(file, 0, position);
size_t write_size = fwrite(data, 1, length, file);
fseeko(file_handle->file, 0, position);
size_t write_size = fwrite(data, 1, length, file_handle->file);
if(write_size != length){
debug("\n\nFileTransfer:\tERROR WRITING DATA TO FILE! (%u & %u)\n\n", friend_number, file_number);
tox_postmessage(TOX_FILE_INCOMING_CANCEL, friend_number, file_number, NULL);
Expand Down Expand Up @@ -160,12 +159,14 @@ void outgoing_file_send_new(Tox *tox, uint32_t friend_number, uint8_t *path, con


TOX_ERR_FILE_SEND error;
const uint8_t *file_id;

uint64_t file_size = 0;
fseeko(file, 0, SEEK_END);
file_size = ftello(file);
fseeko(file, 0, SEEK_SET);

int file_number = tox_file_send(tox, friend_number, TOX_FILE_KIND_DATA, file_size, filename, filename_length, &error);
int file_number = tox_file_send(tox, friend_number, TOX_FILE_KIND_DATA, file_size, file_id, filename, filename_length, &error);

if(file_number != -1) {
FILE_TRANSFER *file_handle = &active_transfer[friend_number][file_number];
Expand All @@ -177,6 +178,8 @@ void outgoing_file_send_new(Tox *tox, uint32_t friend_number, uint8_t *path, con
file_handle->status = FILE_TRANSFER_STATUS_PAUSED_THEM;
//TODO file_handle->sendsize = tox_file_data_size(tox, fid);

file_handle->file = file;

file_handle->name = (uint8_t*)strdup((char*)filename);
file_handle->path = (uint8_t*)strdup((char*)path);
file_handle->name_length = filename_length;
Expand All @@ -203,7 +206,7 @@ static void outgoing_file_callback_chunk(Tox *tox, uint32_t friend_number, uint3
buffer = malloc(length);

FILE_TRANSFER *file_handle = &active_transfer[friend_number][file_number];
FILE *file = file_handle->data;
FILE *file = file_handle->file;
uint64_t last_bit = position + length;

fseeko(file, 0, position);
Expand All @@ -221,12 +224,13 @@ static void outgoing_file_callback_chunk(Tox *tox, uint32_t friend_number, uint3
if(last_bit == file_handle->size){
debug("FileTransfer:\tOutgoing transfer is done (%u & %u)\n", friend_number, file_number);
}
free(buffer);
}

void utox_file_start_write(uint32_t friend_number, uint32_t file_number, void *filepath){
FILE_TRANSFER *file_handle = &active_transfer[friend_number][file_number];
file_handle->data = fopen(filepath, "wb");
if(!file_handle->data) {
file_handle->file = fopen(filepath, "wb");
if(!file_handle->file) {
free(filepath);
file_handle->status = FILE_TRANSFER_STATUS_BROKEN;
return;
Expand Down
5 changes: 3 additions & 2 deletions file_transfers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ enum UTOX_FILE_TRANSFER_STATUS{

typedef struct FILE_TRANSFER {
uint32_t friend_number, file_number;
uint8_t status;
uint8_t status, file_id[TOX_FILE_ID_LENGTH];
_Bool in_memory, incoming;
uint8_t *path, *name;
size_t path_length, name_length, size, size_received;
void *data;
uint8_t *memory;
FILE *file;
time_t request_time, start_time, last_chunk_time, finish_time, pause_time;
} FILE_TRANSFER;

Expand Down
2 changes: 1 addition & 1 deletion friend.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void friend_free(FRIEND *f)
MSG_FILE *file = (void*)msg;
free(file->path);
FILE_TRANSFER *ft = &f->active_transfer[file->filenumber];
if(ft->data) {
if(ft->file) {
if(ft->in_memory) {
// free(ft->data);
} else {
Expand Down
2 changes: 1 addition & 1 deletion messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ MSG_FILE* message_add_type_file(FILE_TRANSFER *file){
msg->status = file->status;
// msg->name_length is the max enforce that
msg->name_length = (file->name_length > sizeof(msg->name)) ? sizeof(msg->name) : file->name_length;
memcpy(msg->name, file->name, msg->name_length);
msg->size = file->size;
msg->progress = file->size_received;
msg->speed = 0;
msg->inline_png = file->in_memory;
msg->path = NULL;
memcpy(msg->name, file->name, msg->name_length);

FRIEND *f = &friend[file->friend_number];
// *str = file_translate_status(*file->status);
Expand Down
2 changes: 1 addition & 1 deletion tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ static void tox_thread_message(Tox *tox, ToxAv *av, uint64_t time, uint8_t msg,
_Bool multifile = (name[param2 - 1] == 0);
if(!multifile) {
/* tox, Friend, path, filename, filename_length */
outgoing_file_send_new(tox, param1, data, data + param2, strlen(data) - param2);
outgoing_file_send_new(tox, param1, name, name + param2, strlen(name - param2));
} else {
// TODO : multi file support
debug("multifile not supported yet!\n");
Expand Down
4 changes: 2 additions & 2 deletions win32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1226,9 +1226,9 @@ void config_osdefaults(UTOX_SAVE *r)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmd, int nCmdShow){

/* if opened with argument, check if uTox is already open and pass the argument to the existing process */
CreateMutex(NULL, 0, "uTox");
CreateMutex(NULL, 0, TITLE);
if(GetLastError() == ERROR_ALREADY_EXISTS) {
HWND window = FindWindow("uTox", NULL);
HWND window = FindWindow(TITLE, NULL);
SetForegroundWindow(window);
if (*cmd) {
COPYDATASTRUCT data = {
Expand Down

0 comments on commit ea8218d

Please sign in to comment.