// File: /workspace/github_cpp_makefile_star2_O2/BleuLlama[P]msf-tools/msf-autosave.cpp
// Function: main
int main( int argc, char ** argv )
{
	char * pth;

	pth = getenv( "VOICERECORDER" );
	if( !pth ) {
		usage( argv[0] );
		return -1;
	}

	if( argc != 2 ) {
		usage( argv[0] );
		return -3;
	}

	std::string targetDir( argv[1] );
	if( !DiskUtils::IsValidDir( targetDir ))
	{
		DiskUtils::MakeDir( targetDir );

		if( !DiskUtils::IsValidDir( targetDir ))
		{
			std::cerr << "Unable to use target directory: " << targetDir << std::endl;
			return -4;
		}
	}

	// NOTE: on windows, put in a scan for a drive with label "IC_RECORDER"

	VoiceFile vf( pth );
	if( !vf.Valid() ) {
		std::cerr << "Directory is invalid: " << pth << std::endl;
		return -2;
	}


	for( int f=0 ; f<vf.GetFolderCount() ; f++ )
	{
		int fc = vf.GetFileCountForFolder( f );
		if( fc > 0 ) {
			std::string plural = "s";
			if( fc == 1 ) plural = "";

			std::cout << std::endl;
			std::cout << vf.GetFolderName( f ) << ": Extracting " << fc << " item" << plural << "." << std::endl;
	
			std::string folderPath = vf.GetPathForFolder( f );

			for( int i=0 ; i < fc ; i ++ ) {
				std::string sourceFile( folderPath );
				sourceFile.append( "/" );
				sourceFile.append( vf.GetFileInFolder( i, f ));

				std::string destFile( targetDir );
				destFile.append( "/" );
				destFile.append( vf.GetFolderName( f ));

				DiskUtils::MakeDir( destFile );

				destFile.append( "/" );
				destFile.append( vf.SortableDateForFileInFolder( i, f ));
				destFile.append( "__" );
				destFile.append( vf.GetFileInFolder( i, f ) );

				float fs = ((float)DiskUtils::FileSize( sourceFile )) / 1024.0/1024.0; 
				std::cout << "  Copying " << vf.GetFileInFolder( i, f )
					  << "  --  " << vf.PrintableDateForFileInFolder( i, f ) 
					  << " (" << std::setprecision( 2 ) << fs << " MB)";

				bool skipped = DiskUtils::CopyFile( sourceFile, destFile );
				if( skipped ) {
					std::cout << " (skipped)";
				}
				std::cout << std::endl;
			}
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rsi, %r14
movl %edi, %ebp
leaq 0xc10(%rip), %rdi       # 0x4311
callq 0x2150
testq %rax, %rax
je 0x3c08
cmpl $0x2, %ebp
jne 0x3c14
movq %rax, %rbx
movq 0x8(%r14), %rsi
leaq 0x28(%rsp), %r14
leaq 0x88(%rsp), %rdx
movq %r14, %rdi
callq 0x2956
leaq 0x158(%rsp), %rdi
movq %r14, %rsi
callq 0x2170
leaq 0x158(%rsp), %rdi
callq 0x2442
movl %eax, %ebp
leaq 0x158(%rsp), %rdi
callq 0x2060
testb %bpl, %bpl
jne 0x37c8
leaq 0x138(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2170
leaq 0x138(%rsp), %rdi
callq 0x23fc
leaq 0x138(%rsp), %rdi
callq 0x2060
leaq 0x118(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2170
leaq 0x118(%rsp), %rdi
callq 0x2442
movl %eax, %ebp
leaq 0x118(%rsp), %rdi
callq 0x2060
testb %bpl, %bpl
je 0x3c5d
leaq 0xf8(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movq %rbx, %rsi
callq 0x2956
leaq 0x88(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x2a60
leaq 0xf8(%rsp), %rdi
callq 0x2060
cmpb $0x1, 0x88(%rsp)
jne 0x3c21
movl $0x0, (%rsp)
leaq 0x68(%rsp), %r14
leaq 0x238(%rsp), %rbp
leaq 0x1d8(%rsp), %r13
leaq 0x88(%rsp), %rdi
callq 0x3204
movl (%rsp), %esi
cmpl %eax, %esi
jge 0x3c4c
leaq 0x88(%rsp), %rdi
callq 0x32e8
movl %eax, %ebx
testl %eax, %eax
jle 0x3c00
leaq 0x48(%rsp), %rdi
leaq 0xaf3(%rip), %rsi       # 0x4357
movq %r14, %rdx
callq 0x2956
cmpl $0x1, %ebx
jne 0x3882
leaq 0x48(%rsp), %rdi
leaq 0x92f(%rip), %rsi       # 0x41ac
callq 0x2230
movq 0x3747(%rip), %rdi      # 0x6fd0
callq 0x2080
movq %r14, %rdi
leaq 0x88(%rsp), %rsi
movl (%rsp), %edx
callq 0x3208
movq 0x3728(%rip), %rdi      # 0x6fd0
movq %r14, %rsi
callq 0x20e0
movq %rax, %rdi
leaq 0xa9f(%rip), %rsi       # 0x4359
callq 0x2100
movq %rax, %rdi
movl %ebx, %esi
callq 0x21f0
movq %rax, %rdi
leaq 0xa94(%rip), %rsi       # 0x4367
callq 0x2100
movq %rax, %rdi
leaq 0x48(%rsp), %rsi
callq 0x20e0
movq %rax, %rdi
leaq 0x72e(%rip), %rsi       # 0x401d
callq 0x2100
movq %rax, %rdi
callq 0x2080
movl %ebx, 0x4(%rsp)
movq %r14, %rdi
callq 0x2060
movq %r14, %rdi
leaq 0x88(%rsp), %rsi
movl (%rsp), %edx
callq 0x3250
xorl %r12d, %r12d
cmpl %r12d, 0x4(%rsp)
je 0x3be9
movq %rbp, %r14
movq %rbp, %rdi
leaq 0x68(%rsp), %rsi
callq 0x2170
movq %r14, %rdi
leaq 0x7d2(%rip), %rsi       # 0x4115
callq 0x2220
movq %r13, %rdi
leaq 0x88(%rsp), %rsi
movl %r12d, %edx
movl (%rsp), %ecx
callq 0x331c
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2250
movq %r13, %rdi
callq 0x2060
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0x2170
movq %r13, %rdi
leaq 0x78d(%rip), %rsi       # 0x4115
callq 0x2220
leaq 0x8(%rsp), %r14
movq %r14, %rdi
leaq 0x88(%rsp), %rsi
movl (%rsp), %edx
callq 0x3208
movq %r13, %rdi
movq %r14, %rsi
callq 0x2250
movq %r14, %rdi
callq 0x2060
leaq 0x1b8(%rsp), %rdi
movq %r13, %rsi
callq 0x2170
leaq 0x1b8(%rsp), %rbx
movq %rbx, %rdi
callq 0x23fc
movq %rbx, %rdi
callq 0x2060
movq %r13, %rdi
leaq 0x72b(%rip), %rsi       # 0x4115
callq 0x2220
leaq 0x8(%rsp), %r14
movq %r14, %rdi
leaq 0x88(%rsp), %rsi
movl %r12d, %edx
movl (%rsp), %ecx
callq 0x34c2
movq %r13, %rdi
movq %r14, %rsi
callq 0x2250
movq %r14, %rdi
callq 0x2060
movq %r13, %rdi
leaq 0x7a6(%rip), %rsi       # 0x41cd
callq 0x2220
leaq 0x8(%rsp), %r14
movq %r14, %rdi
leaq 0x88(%rsp), %rsi
movl %r12d, %edx
movl (%rsp), %ecx
callq 0x331c
movq %r13, %rdi
movq %r14, %rsi
callq 0x2250
movq %r14, %rdi
callq 0x2060
leaq 0x218(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2478
movq %rax, %r15
movq %rbx, %rdi
callq 0x2060
movq 0x3549(%rip), %rdi      # 0x6fd0
leaq 0x8df(%rip), %rsi       # 0x436d
callq 0x2100
movq %rax, %r14
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x88(%rsp), %rsi
movl %r12d, %edx
movl (%rsp), %ecx
callq 0x331c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x20e0
movq %rax, %rdi
leaq 0x8b2(%rip), %rsi       # 0x4378
callq 0x2100
movq %rax, %r14
leaq 0x198(%rsp), %rbx
movq %rbx, %rdi
leaq 0x88(%rsp), %rsi
movl %r12d, %edx
movl (%rsp), %ecx
callq 0x33e4
movq %r14, %rdi
movq %rbx, %rsi
callq 0x20e0
movq %rax, %rdi
leaq 0x87e(%rip), %rsi       # 0x437f
callq 0x2100
cvtsi2ss %r15, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x6f9(%rip), %xmm1      # 0x4210
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0x2, 0x8(%rax,%rcx)
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
leaq 0x83d(%rip), %rsi       # 0x4382
callq 0x2100
leaq 0x198(%rsp), %rdi
callq 0x2060
leaq 0x8(%rsp), %rdi
callq 0x2060
leaq 0x178(%rsp), %rdi
movq %rbp, %rsi
callq 0x2170
leaq 0x1f8(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x2170
leaq 0x178(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
pushq $0x1
popq %rdx
callq 0x27f4
movl %eax, %r14d
movq %r15, %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2060
testb %r14b, %r14b
je 0x3bc5
movq 0x3417(%rip), %rdi      # 0x6fd0
leaq 0x7c7(%rip), %rsi       # 0x4387
callq 0x2100
movq 0x3404(%rip), %rdi      # 0x6fd0
callq 0x2080
movq %r13, %rdi
callq 0x2060
movq %rbp, %rdi
callq 0x2060
incl %r12d
jmp 0x391e
leaq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x2060
leaq 0x48(%rsp), %rdi
callq 0x2060
incl (%rsp)
jmp 0x3829
movq (%r14), %rdi
callq 0x3604
pushq $-0x1
jmp 0x3c1e
movq (%r14), %rdi
callq 0x3604
pushq $-0x3
popq %rbx
jmp 0x3c92
movq 0x33c8(%rip), %rdi      # 0x6ff0
leaq 0x711(%rip), %rsi       # 0x4340
callq 0x2100
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2100
movq %rax, %rdi
callq 0x2080
pushq $-0x2
popq %rbx
jmp 0x3c4e
xorl %ebx, %ebx
leaq 0x88(%rsp), %rdi
callq 0x2d0a
jmp 0x3c88
movq 0x338c(%rip), %rdi      # 0x6ff0
leaq 0x6b4(%rip), %rsi       # 0x431f
callq 0x2100
leaq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2080
pushq $-0x4
popq %rbx
leaq 0x28(%rsp), %rdi
callq 0x2060
movl %ebx, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
jmp 0x3cda
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
jmp 0x3cda
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
jmp 0x3cda
jmp 0x3ce6
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x2060
jmp 0x3dc4
jmp 0x3cfe
movq %rax, %rbx
jmp 0x3dc4
jmp 0x3cf4
jmp 0x3cf4
jmp 0x3cfe
movq %rax, %rbx
jmp 0x3dad
jmp 0x3cfe
movq %rax, %rbx
jmp 0x3db7
jmp 0x3d51
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x2060
jmp 0x3d2c
jmp 0x3d61
movq %rax, %rbx
leaq 0x218(%rsp), %rdi
jmp 0x3d7f
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
jmp 0x3d7f
jmp 0x3d86
jmp 0x3d5a
jmp 0x3d86
jmp 0x3d86
jmp 0x3d61
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
jmp 0x3d7f
jmp 0x3d61
jmp 0x3d86
movq %rax, %rbx
jmp 0x3da3
jmp 0x3d61
jmp 0x3d5a
movq %rax, %rbx
jmp 0x3d96
jmp 0x3d86
movq %rax, %rbx
jmp 0x3d7a
jmp 0x3d86
jmp 0x3d86
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x2060
leaq 0x8(%rsp), %rdi
callq 0x2060
jmp 0x3d89
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
callq 0x2060
leaq 0x238(%rsp), %rdi
callq 0x2060
leaq 0x68(%rsp), %rdi
callq 0x2060
leaq 0x48(%rsp), %rdi
callq 0x2060
leaq 0x88(%rsp), %rdi
callq 0x2d0a
leaq 0x28(%rsp), %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2200