#include <windows.h>
#include <tchar.h>
#include <stdio.h>

BOOL OtevritSoubor(HWND hWnd, LPTSTR lpFile)
{
	TCHAR szSoubor[MAX_PATH] = {0};
	OPENFILENAME ofn;
	ZeroMemory(&ofn, sizeof (OPENFILENAME));
	ofn.lStructSize = sizeof (OPENFILENAME);
	ofn.lpstrFile = szSoubor;
	ofn.hwndOwner = hWnd;
	ofn.nMaxFile = sizeof (szSoubor);
	ofn.lpstrFilter = TEXT("ABC input files (*.aig; *.baf; *.bench; *.blif; *.cnf; *.dot; *.eqn; *.gml; *.pla; *.v)\0*.aig;*.baf;*.bench;*.blif;*.cnf;*.dot;*.eqn;*.gml;*.pla;*.v\0AIGER file (*.aig)\0*.aig\0BAF file (*.baf)\0*.baf\0BENCH file (*.bench)\0*.bench\0BLIF file (*.blif)\0*.blif\0CNF file (*.cnf)\0*.cnf\0DOT file (*.dot)\0*.cnf\0EQN file (*.eqn)\0*.eqn\0GML file (*.gml)\0*.gml\0PLA file (*.pla)\0*.pla\0VERILOG file (*.v)\0*.v\0All files (*.*)\0*.*\0");
	ofn.nFilterIndex = 1;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

	if (!GetOpenFileName(&ofn))
		return FALSE;

	lstrcpy(lpFile, szSoubor);
	return TRUE;
}

BOOL UlozitSoubor(HWND hWnd, LPTSTR lpFile)
{
	TCHAR szSoubor[MAX_PATH] = {0};
	OPENFILENAME ofn;
	ZeroMemory(&ofn, sizeof (OPENFILENAME));
	ofn.lStructSize = sizeof (OPENFILENAME);
	ofn.lpstrFile = szSoubor;
	ofn.hwndOwner = hWnd;
	ofn.nMaxFile = sizeof (szSoubor);
	ofn.lpstrFilter = TEXT("AIGER file (*.aig)\0*.aig\0BAF file (*.baf)\0*.baf\0BENCH file (*.bench)\0*.bench\0BLIF file (*.blif)\0*.blif\0CNF file (*.cnf)\0*.cnf\0DOT file (*.dot)\0*.cnf\0EQN file (*.eqn)\0*.eqn\0GML file (*.gml)\0*.gml\0PLA file (*.pla)\0*.pla\0VERILOG file (*.v)\0*.v\0User specified extension (*.*)\0*.*\0");
	ofn.nFilterIndex = 4;
	ofn.Flags = OFN_PATHMUSTEXIST;

	if (!GetSaveFileName(&ofn))
		return FALSE;

	switch (ofn.nFilterIndex)
	{
		case 1:
			sprintf(lpFile, "%s.aig", szSoubor);
			break;
		case 2:
			sprintf(lpFile, "%s.baf", szSoubor);
			break;
		case 3:
			sprintf(lpFile, "%s.bench", szSoubor);
			break;
		case 4:
			sprintf(lpFile, "%s.blif", szSoubor);
			break;
		case 5:
			sprintf(lpFile, "%s.cnf", szSoubor);
			break;
		case 6:
			sprintf(lpFile, "%s.dot", szSoubor);
			break;
		case 7:
			sprintf(lpFile, "%s.eqn", szSoubor);
			break;
		case 8:
			sprintf(lpFile, "%s.gml", szSoubor);
			break;
		case 9:
			sprintf(lpFile, "%s.pla", szSoubor);
			break;
		case 10:
			sprintf(lpFile, "%s.v", szSoubor);
			break;
		default:
			lstrcpy(lpFile, szSoubor);
			break;
	}
	
	return TRUE;
}
