// File: vianna274[P]dropbox/src/Client.cpp
// Function: Dropbox::Client::get_sync_dir()
void Client::get_sync_dir(){

	this->createSyncDir();
	
	DIR * dir;
    struct dirent *ent;
    if ((dir = opendir (this->getSyncDirPath().c_str())) != NULL) {
        while ((ent = readdir (dir)) != NULL) {
            if(ent->d_type == 0x8) {
                deleteFile(this->getSyncDirPath()+string(ent->d_name));
            }
        }
        closedir(dir);
    } 
	cout << "Deleted all files." << endl;
	MessageData packet = make_packet(TYPE_LIST_SERVER, 1, 1, -1, "list_server");
	socket->send(&packet);
	this->fileRecords = this->receiveFileList(this->getSocket());
	for(FileRecord record : this->fileRecords){
		MessageData request = make_packet(TYPE_REQUEST_DOWNLOAD, 1 , 1, -1, record.filename);
		this->socket->send(&request);
		MessageData *data = this->socket->receive(TIMEOUT_OFF);
		if(data->type == TYPE_SEND_FILE) {
			this->receiveFile(this->socket, record.filename, this->getSyncDirPath());
		}
	}
	this->printFileList(this->fileRecords);
	cout << "Received all files." << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2220, %rsp           # imm = 0x2220
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x21f0(%rbp)
callq 0x5d10
movq -0x21f0(%rbp), %rsi
leaq -0x38(%rbp), %rdi
movq %rdi, -0x21e8(%rbp)
callq 0x6d80
movq -0x21e8(%rbp), %rdi
callq 0x3180
movq %rax, %rdi
callq 0x3520
movq %rax, -0x21e0(%rbp)
jmp 0x3fc3
movq -0x21e0(%rbp), %rax
movq %rax, -0x10(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3280
movq -0x21e0(%rbp), %rax
cmpq $0x0, %rax
je 0x413f
jmp 0x3fea
movq -0x10(%rbp), %rdi
callq 0x3540
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x4136
movq -0x18(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x8, %eax
jne 0x4131
movq -0x21f0(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x6d80
movq -0x18(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x2200(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x21f8(%rbp)
callq 0x3620
movq -0x2200(%rbp), %rsi
movq -0x21f8(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
callq 0x3480
jmp 0x4063
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x6cb0
jmp 0x407c
movq -0x21f0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xba10
jmp 0x408e
leaq -0x68(%rbp), %rdi
callq 0x3280
leaq -0xa8(%rbp), %rdi
callq 0x3280
leaq -0xa9(%rbp), %rdi
callq 0x33e0
leaq -0x88(%rbp), %rdi
callq 0x3280
jmp 0x4131
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3280
jmp 0x4448
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4114
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4108
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3280
leaq -0xa8(%rbp), %rdi
callq 0x3280
leaq -0xa9(%rbp), %rdi
callq 0x33e0
leaq -0x88(%rbp), %rdi
callq 0x3280
jmp 0x4448
jmp 0x3fea
movq -0x10(%rbp), %rdi
callq 0x3580
movq 0x1ee82(%rip), %rdi     # 0x22fc8
leaq 0x14fc4(%rip), %rsi     # 0x19111
callq 0x33a0
movq %rax, %rdi
movq 0x1ee54(%rip), %rsi     # 0x22fb0
callq 0x33d0
leaq -0x1080(%rbp), %rdi
movl $0x6, %esi
movl $0x1, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
leaq 0x14fa5(%rip), %r9      # 0x19124
movl %ecx, %edx
callq 0x97a0
movq -0x21f0(%rbp), %rax
movq 0x40(%rax), %rdi
leaq -0x1080(%rbp), %rsi
callq 0x17d90
movq -0x21f0(%rbp), %rdi
callq 0x7290
movq -0x21f0(%rbp), %rsi
movq %rax, %rdx
leaq -0x1098(%rbp), %rdi
callq 0xb200
movq -0x21f0(%rbp), %rdi
addq $0xc0, %rdi
leaq -0x1098(%rbp), %rsi
callq 0x72b0
leaq -0x1098(%rbp), %rdi
callq 0x6a00
movq -0x21f0(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x10a0(%rbp)
movq -0x10a0(%rbp), %rdi
callq 0x6f40
movq %rax, -0x10a8(%rbp)
movq -0x10a0(%rbp), %rdi
callq 0x6fb0
movq %rax, -0x10b0(%rbp)
leaq -0x10a8(%rbp), %rdi
leaq -0x10b0(%rbp), %rsi
callq 0x6f70
testb $0x1, %al
jne 0x423b
jmp 0x43c3
leaq -0x10a8(%rbp), %rdi
callq 0x7180
movq %rax, %rsi
leaq -0x1198(%rbp), %rdi
movl $0xe8, %edx
callq 0x3300
leaq -0x1198(%rbp), %r9
leaq -0x216c(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl %ecx, %edx
callq 0x97a0
movq -0x21f0(%rbp), %rax
movq 0x40(%rax), %rdi
leaq -0x216c(%rbp), %rsi
callq 0x17d90
movq -0x21f0(%rbp), %rax
movq 0x40(%rax), %rdi
xorl %esi, %esi
callq 0x18090
movq %rax, -0x2178(%rbp)
movq -0x2178(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x43b0
movq -0x21f0(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x2210(%rbp)
leaq -0x2199(%rbp), %rdi
movq %rdi, -0x2208(%rbp)
callq 0x3620
movq -0x2208(%rbp), %rdx
leaq -0x2198(%rbp), %rdi
leaq -0x1198(%rbp), %rsi
callq 0x3480
jmp 0x4301
movq -0x21f0(%rbp), %rsi
leaq -0x21c0(%rbp), %rdi
callq 0x6d80
jmp 0x4316
movq -0x2210(%rbp), %rsi
movq -0x21f0(%rbp), %rdi
leaq -0x2198(%rbp), %rdx
leaq -0x21c0(%rbp), %rcx
callq 0x9c30
jmp 0x4339
leaq -0x21c0(%rbp), %rdi
callq 0x3280
leaq -0x2198(%rbp), %rdi
callq 0x3280
leaq -0x2199(%rbp), %rdi
callq 0x33e0
jmp 0x43b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x439f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4393
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x21c0(%rbp), %rdi
callq 0x3280
leaq -0x2198(%rbp), %rdi
callq 0x3280
leaq -0x2199(%rbp), %rdi
callq 0x33e0
jmp 0x4448
jmp 0x43b2
leaq -0x10a8(%rbp), %rdi
callq 0x72e0
jmp 0x421f
movq -0x21f0(%rbp), %rsi
addq $0xc0, %rsi
leaq -0x21d8(%rbp), %rdi
movq %rdi, -0x2218(%rbp)
callq 0x6bc0
movq -0x21f0(%rbp), %rdi
movq -0x2218(%rbp), %rsi
callq 0xb310
jmp 0x43f9
leaq -0x21d8(%rbp), %rdi
callq 0x6a00
movq 0x1ebbc(%rip), %rdi     # 0x22fc8
leaq 0x14d1d(%rip), %rsi     # 0x19130
callq 0x33a0
movq %rax, %rdi
movq 0x1eb8e(%rip), %rsi     # 0x22fb0
callq 0x33d0
addq $0x2220, %rsp           # imm = 0x2220
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x21d8(%rbp), %rdi
callq 0x6a00
movq -0x40(%rbp), %rdi
callq 0x3610
nopw %cs:(%rax,%rax)