// File: pelrun[P]aft/aft.cpp
// Function: main
int main(int argc, char *argv[])
{
	try
	{
		COptionParser optParser(appliOption, appliName, appliUsageShort, appliUsageLong, authorName, authorMail);
		
		optParser.PrintHeader(std::cout);

		if (!optParser.ParseCommandLine(&argc, &argv, 0, false))
		{
			optParser.PrintError(std::cout);
			optParser.PrintUsage(std::cout);
			return -1;
		}

		bool noLoop = false;
		std::string COMport = defaultComPort();
		std::string filename = "";
		std::string dir = "";

		
		int i=0;
		while (optParser.GetOptionI(i) != 0)
		{
			switch(optParser.GetOptionI(i))
			{
			case 'p':
				{
					COMport = optParser.GetStringOptionI(i);
					break;
				}
			case 'f':
				{
					filename = optParser.GetStringOptionI(i);
					noLoop = true;
					break;
				}
			case 'd':
				{
					dir = optParser.GetStringOptionI(i);
					break;
				}
			case 'n':
				{
					noLoop = true;
					break;
				}
			default:
				{
					break;
				}
			}

			i++;
		}

		CAksFileTransfert transfert(COMport);

		if (!transfert.IsOpen())
		{
			std::cout << "Unable to open comport " << COMport << std::endl;
			return -1;
		} else {
			std::cout << "AFT now listening on " << COMport << std::endl;
		}

		if (filename.size() != 0)
		{
			transfert.SetForceFilename(filename);
		}
		if (dir.size() != 0)
		{
			transfert.SetFilepath(dir);
		}

		while (!noLoop || (noLoop && (transfert.GetNbTransfertDone() != 1)))
		{
			transfert.Run();
		}
	}
	catch(tools::CException &e)
	{
		std::cerr << e << std::endl;
		return -1;
	}

	return 0;
}

// Assembly:
subq $0x308, %rsp            # imm = 0x308
movl $0x0, 0x304(%rsp)
movl %edi, 0x300(%rsp)
movq %rsi, 0x2f8(%rsp)
leaq 0x16918(%rip), %rcx     # 0x1b590
movq %rsp, %rax
movq %rcx, (%rax)
leaq 0x166db(%rip), %rsi     # 0x1b360
leaq 0x16924(%rip), %rdx     # 0x1b5b0
leaq 0x1693d(%rip), %rcx     # 0x1b5d0
leaq 0x16956(%rip), %r8      # 0x1b5f0
leaq 0x168cf(%rip), %r9      # 0x1b570
leaq 0x248(%rsp), %rdi
callq 0xc270
jmp 0x4cb0
movq 0x16311(%rip), %rsi     # 0x1afc8
leaq 0x248(%rsp), %rdi
callq 0xcb70
jmp 0x4cc6
leaq 0x248(%rsp), %rdi
leaq 0x300(%rsp), %rsi
leaq 0x2f8(%rsp), %rdx
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0xc430
movb %al, 0x7f(%rsp)
jmp 0x4cef
movb 0x7f(%rsp), %al
testb $0x1, %al
jne 0x4d72
jmp 0x4cf9
movq 0x162c8(%rip), %rsi     # 0x1afc8
leaq 0x248(%rsp), %rdi
callq 0xcc10
jmp 0x4d0f
movq 0x162b2(%rip), %rsi     # 0x1afc8
leaq 0x248(%rsp), %rdi
callq 0xcc50
jmp 0x4d25
movl $0xffffffff, 0x304(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x238(%rsp)
jmp 0x5287
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
jmp 0x52df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
jmp 0x52d2
movb $0x0, 0x237(%rsp)
callq 0x53a0
movq %rax, 0x70(%rsp)
jmp 0x4d86
leaq 0x20f(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x4610
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
leaq 0x210(%rsp), %rdi
callq 0x53b0
jmp 0x4db1
leaq 0x20f(%rsp), %rdi
callq 0x4380
leaq 0x1e7(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x4610
movq 0x60(%rsp), %rdx
leaq 0x10bd3(%rip), %rsi     # 0x159af
leaq 0x1e8(%rsp), %rdi
callq 0x53b0
jmp 0x4deb
leaq 0x1e7(%rsp), %rdi
callq 0x4380
leaq 0x1bf(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x4610
movq 0x58(%rsp), %rdx
leaq 0x10b99(%rip), %rsi     # 0x159af
leaq 0x1c0(%rsp), %rdi
callq 0x53b0
jmp 0x4e25
leaq 0x1bf(%rsp), %rdi
callq 0x4380
movl $0x0, 0x1b8(%rsp)
movl 0x1b8(%rsp), %esi
leaq 0x248(%rsp), %rdi
callq 0xc860
movb %al, 0x57(%rsp)
jmp 0x4e57
movb 0x57(%rsp), %al
movsbl %al, %eax
cmpl $0x0, %eax
je 0x5034
movl 0x1b8(%rsp), %esi
leaq 0x248(%rsp), %rdi
callq 0xc860
movb %al, 0x56(%rsp)
jmp 0x4e81
movb 0x56(%rsp), %al
movsbl %al, %eax
addl $-0x64, %eax
movl %eax, %ecx
movq %rcx, 0x48(%rsp)
subl $0xc, %eax
ja 0x501c
movq 0x48(%rsp), %rax
leaq 0x1015d(%rip), %rcx     # 0x15004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0x20f(%rsp), %rdi
callq 0x4380
jmp 0x52d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0x1e7(%rsp), %rdi
callq 0x4380
jmp 0x52c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0x1bf(%rsp), %rdi
callq 0x4380
jmp 0x52b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
jmp 0x52ab
movl 0x1b8(%rsp), %edx
leaq 0x198(%rsp), %rdi
leaq 0x248(%rsp), %rsi
xorl %ecx, %ecx
callq 0xcac0
jmp 0x4f5b
leaq 0x210(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x4440
leaq 0x198(%rsp), %rdi
callq 0x46a8
jmp 0x501e
movl 0x1b8(%rsp), %edx
leaq 0x178(%rsp), %rdi
leaq 0x248(%rsp), %rsi
xorl %ecx, %ecx
callq 0xcac0
jmp 0x4fa2
leaq 0x1e8(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x4440
leaq 0x178(%rsp), %rdi
callq 0x46a8
movb $0x1, 0x237(%rsp)
jmp 0x501e
movl 0x1b8(%rsp), %edx
leaq 0x158(%rsp), %rdi
leaq 0x248(%rsp), %rsi
xorl %ecx, %ecx
callq 0xcac0
jmp 0x4fee
leaq 0x1c0(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x4440
leaq 0x158(%rsp), %rdi
callq 0x46a8
jmp 0x501e
movb $0x1, 0x237(%rsp)
jmp 0x501e
jmp 0x501e
movl 0x1b8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1b8(%rsp)
jmp 0x4e3d
leaq 0x88(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x4150
jmp 0x504b
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x5760
jmp 0x5062
leaq 0x88(%rsp), %rdi
callq 0x46a8
leaq 0xa8(%rsp), %rdi
callq 0x75c0
movb %al, 0x47(%rsp)
jmp 0x5082
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x513d
jmp 0x5090
movq 0x15f31(%rip), %rdi     # 0x1afc8
leaq 0x1008f(%rip), %rsi     # 0x1512d
callq 0x42f0
movq %rax, 0x38(%rsp)
jmp 0x50aa
movq 0x38(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x42b0
movq %rax, 0x30(%rsp)
jmp 0x50c3
movq 0x30(%rsp), %rdi
movq 0x15ed9(%rip), %rsi     # 0x1afa8
callq 0x4360
jmp 0x50d6
movl $0xffffffff, 0x304(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x238(%rsp)
jmp 0x5253
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x46a8
jmp 0x52ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x58a0
jmp 0x52ab
movq 0x15e84(%rip), %rdi     # 0x1afc8
leaq 0xfffa(%rip), %rsi      # 0x15145
callq 0x42f0
movq %rax, 0x28(%rsp)
jmp 0x5157
movq 0x28(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x42b0
movq %rax, 0x20(%rsp)
jmp 0x5170
movq 0x20(%rsp), %rdi
movq 0x15e2c(%rip), %rsi     # 0x1afa8
callq 0x4360
jmp 0x5183
jmp 0x5185
leaq 0x1e8(%rsp), %rdi
callq 0x41f0
cmpq $0x0, %rax
je 0x51b1
leaq 0xa8(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x59b0
jmp 0x51af
jmp 0x51b1
leaq 0x1c0(%rsp), %rdi
callq 0x41f0
cmpq $0x0, %rax
je 0x51dd
leaq 0xa8(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x59e0
jmp 0x51db
jmp 0x51dd
jmp 0x51df
movb $0x1, %al
testb $0x1, 0x237(%rsp)
movb %al, 0x1f(%rsp)
je 0x5228
xorl %eax, %eax
testb $0x1, 0x237(%rsp)
movb %al, 0x1e(%rsp)
je 0x5220
leaq 0xa8(%rsp), %rdi
callq 0x5b40
movl %eax, 0x18(%rsp)
jmp 0x5212
movl 0x18(%rsp), %eax
cmpl $0x1, %eax
setne %al
movb %al, 0x1e(%rsp)
movb 0x1e(%rsp), %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x5232
jmp 0x5248
leaq 0xa8(%rsp), %rdi
movl $0x1, %esi
callq 0x5b60
jmp 0x5246
jmp 0x51df
movl $0x0, 0x238(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x58a0
leaq 0x1c0(%rsp), %rdi
callq 0x46a8
leaq 0x1e8(%rsp), %rdi
callq 0x46a8
leaq 0x210(%rsp), %rdi
callq 0x46a8
leaq 0x248(%rsp), %rdi
callq 0xc3a0
movl 0x238(%rsp), %eax
testl %eax, %eax
je 0x52a6
jmp 0x52a1
jmp 0x537b
jmp 0x5370
leaq 0x1c0(%rsp), %rdi
callq 0x46a8
leaq 0x1e8(%rsp), %rdi
callq 0x46a8
leaq 0x210(%rsp), %rdi
callq 0x46a8
leaq 0x248(%rsp), %rdi
callq 0xc3a0
movl 0x23c(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x538a
movq 0x240(%rsp), %rdi
callq 0x4130
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rsi
movq 0x15cd9(%rip), %rdi     # 0x1aff0
callq 0x5470
movq %rax, 0x10(%rsp)
jmp 0x5323
movq 0x10(%rsp), %rdi
movq 0x15c79(%rip), %rsi     # 0x1afa8
callq 0x4360
jmp 0x5336
movl $0xffffffff, 0x304(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x238(%rsp)
callq 0x45b0
jmp 0x537b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
callq 0x45b0
jmp 0x536e
jmp 0x538a
movl $0x0, 0x304(%rsp)
movl 0x304(%rsp), %eax
addq $0x308, %rsp            # imm = 0x308
retq
movq 0x240(%rsp), %rdi
callq 0x11ab0
movq %rax, %rdi
callq 0x54c0
nop