#ifdef __STRICT_ANSI__
#undef __STRICT_ANSI__
#endif

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <strings.h>
#include <iostream>
#include <conio.h>

#include "symbols.h"
#include "config.h"
#include "vplayer.h"
#include "exception.h"

//@@@ TODO: Decent commenting

int main(int argc, char *argv[])
{
	DIR *dir;
	bool delete_files = false;
	const char *dir_ptr = "C:\\pammmedia\\";

	for ( int ii=0 ; ii<argc ; ii++ ){
		char single_code = 0;
		char *term_ptr;
		if ( strncmp(argv[ii], "--", 2)==0 ){
			term_ptr = &argv[ii][2];
			if ( stricmp(term_ptr, "root") == 0) single_code = 'r';
			else if ( stricmp(term_ptr, "delete")==0 ) single_code = 'd';
			else {
				std::cout << "Unknown command string: " << term_ptr << "\n";
				exit(-1);
				}
			}

		if ( single_code==0 && argv[ii][0]=='-' && argv[ii][1]!=0 )
			single_code = argv[ii][1];

		switch ( single_code ){
			case 'r':
				if ( argv[ii+1][0]=='-' )
					throw new PammmException("Missing root path.");
				if ( !(dir=opendir(argv[ii+1])) )
					throw new PammmException("Non-existent root path.");

				// @@@ TOFO: Make sure file structure exists.

				closedir(dir);
				dir_ptr = argv[ii+1];
				break;
			case 'd':
				delete_files = true;
				break;
			}
		}


    printf("Hello world!\n");

    const char *cmd_line_parms[] = {
		"C:\\Development\\Pammm\\CM3\\bin\\Debug",			//@@@ TODO: Change for Linux
		"--extraintf=logger",
		"--verbose=2",
		"--logfile=C:\\temp\\vlc.log",
		"--no-directx-overlay"
//		"--logmode=text",
//		"--file-logging"
		};
	const int cmd_count = sizeof(cmd_line_parms)/sizeof(const char *);
	try {
		char ch;
		bool exit_flag = false;
		VPlayer *player = new VPlayer(cmd_count, (const char **)cmd_line_parms, dir_ptr);

		player->Start();			// @@@ Will be in media processor switch below

		while ( !exit_flag ){
			ch = _getch();
			printf("%x\n", ch);
			if ( ch==0x1b) break;
			continue;		//@@@ Temporary

			/*  Node processor */

			//@@@ TODO: Write all this.

			/* Media processor */
	/*
			switch ( ch ){
				case KEY_START:
					player->Start();
					break;
				case KEY_UP:
					player->GoUp();
					break;
				case KEY_DOWN:
					player->GoDown();
					break;
				case KEY_NEXT:
					player->GoNext();
					break;
				case KEY_PREV:
					player->GoPrev();
					break;
				case KEY_BRAKE:
					//???  @@@ TODO: Figure out what to do here.
					break;
				case KEY_FAST:
					player->GoFast();
					break;
				case KEY_SLOW:
					player->GoSlow();
					break;
					}
					*/
			}
		}

	catch ( PammmException *p ){
		p->Show();
		}

    return 0;
}
