// Controller.cpp : Implementation of CController

#include "stdafx.h"

#include "LKFStatic.h"
#include "Controller.h"

extern "C" { 
#include "../../c/lkf5defs.h"
}

// CController

CController::CController ()
{
	pLKFStatic = GetStaticObject ();
}

CController::~CController ()
{
}

STDMETHODIMP CController::get_RootPath(BSTR* pVal)
{
	char Path[MAX_PATH];
	ULONG PathLen = MAX_PATH;
	if (pLKFStatic->GetRootPath (Path, &PathLen)) {
		*pVal = createBSTR (Path);
	}
	else {
		*pVal = createBSTR ("");
	}
	return S_OK;
}

STDMETHODIMP CController::put_RootPath(BSTR newVal)
{
	char *d = createChar (newVal);
	pLKFStatic->SetRootPath (d);
	delete d;
	return S_OK;
}

STDMETHODIMP CController::get_CurrentRootPath(BSTR* pVal)
{
	const char *CurrentRootPath = pLKFStatic->GetCurrentRootPath();
	*pVal = createBSTR (CurrentRootPath);;
	return S_OK;
}

STDMETHODIMP CController::get_ExportSeparator(BSTR* pVal)
{
	char exportseparator[MAX_LINESEP];
	pLKFStatic->GetLineSeparators (exportseparator, 0);
	*pVal = createBSTR (exportseparator);
	return S_OK;
}

STDMETHODIMP CController::put_ExportSeparator(BSTR newVal)
{
	char *d = createChar (newVal);
	pLKFStatic->SetLineSeparators (0, d);
	delete d;
	return S_OK;
}

STDMETHODIMP CController::get_ImportSeparator(BSTR* pVal)
{
	char importseparator[MAX_LINESEP];
	pLKFStatic->GetLineSeparators (importseparator, 0);
	*pVal = createBSTR (importseparator);
	return S_OK;
}

STDMETHODIMP CController::put_ImportSeparator(BSTR newVal)
{
	char *d = createChar (newVal);
	pLKFStatic->SetLineSeparators (d, 0);
	delete d;
	return S_OK;
}

STDMETHODIMP CController::get_CurrentImportSeperator(BSTR* pVal)
{
	const char *importseparator;
	pLKFStatic->GetCurrentLineSeparators (0, &importseparator);
	*pVal = createBSTR (importseparator);
	return S_OK;
}

STDMETHODIMP CController::get_CurrentExportSeparator(BSTR* pVal)
{
	const char *exportseparator;
	pLKFStatic->GetCurrentLineSeparators (0, &exportseparator);
	*pVal = createBSTR (exportseparator);
	return S_OK;
}

STDMETHODIMP CController::get_Version(BSTR* pVal)
{
	*pVal = createBSTR(lkf_GetVersion());
	return S_OK;
}

STDMETHODIMP CController::get_FirstYear(LONG* pVal)
{
	*pVal = lkf_GetYearFirst();
	return S_OK;
}

STDMETHODIMP CController::get_YearLatest(LONG* pVal)
{
	*pVal = lkf_GetYearLatest();
	return S_OK;
}
