#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
//put additional include files here
#include <okocUtils.h>

//put your own support static functions here
///Cheney 2007-7-2 UPDATE_XF_ERR_THROW
//enum {
	//ERR_FAIL_INSTALL_OPX = XF_LOCAL_ERR_BEGIN,
//};
///end UPDATE_XF_ERR_THROW



void instOPX(const string& fname, const int& verbose)
{
	/// EJP 2007-08-08 v8.0676 CLEAN_XMLPKG_RETURN_VALUES
	///	/// EJP 2007-07-16 v8.0661 QA70-9103 INSTALL_PKG_FILE_EXIST_ALERT
	///	///if( okutil_install_package_file(fname) )
	///	if( okutil_install_package_file(fname, TRUE) ) // TRUE for pkg already installed alert
	///	/// end INSTALL_PKG_FILE_EXIST_ALERT
	int nRet = okutil_install_package_file(fname, TRUE); // TRUE for pkg already installed alert
	if( nRet > 0 ) // if error is returned
	/// end CLEAN_XMLPKG_RETURN_VALUES
	{
		///printf(_L("The following Package failed to install:\n%s\n"), fname);
		
		///-----Kit 10/22/2010 CLEANUP_XFS_ERROR_CODE
		/////Cheney 2007-7-2 UPDATE_XF_ERR_THROW
		////XF_THROW(ERR_FAIL_INSTALL_OPX);
		//warning_msg_box(XFERR_INST_OPX_FAILED, fname, false, 'E');
		/////UPDATE_XF_ERR_THROW
		bool bRubbish;	// no used, but we can't move it, it's a bug.
		XF_THROW_EX(XFERR_INST_OPX_FAILED, fname);
		///-----End CLEANUP_XFS_ERROR_CODE
		
		
		/// YuI 12/06/07 QA70-10786 IMPROVING_ERROR_HANDLING_ON_PACKAGE_DEPLOYMENT
		StringArray arrErrorStack;
		okutil_get_package_installation_error_stack(&arrErrorStack);
		for( int ii = 0; ii < arrErrorStack.GetSize(); ii++ )
		{
			///-----Kit 10/22/2010 CLEANUP_XFS_ERROR_CODE
			//okoc_out_msg(arrErrorStack[ii], 'E');
			okoc_out_msg(arrErrorStack[ii], 'W');
			///-----End CLEANUP_XFS_ERROR_CODE
		}
		/// end IMPROVING_ERROR_HANDLING_ON_PACKAGE_DEPLOYMENT
	}
	/// EJP 2007-06-21 v8.0647 QA70-9103 DRAG_DROP_OPX_NEED_NOTIFY_SUCCESS
	/// EJP 2007-08-08 v8.0676 CLEAN_XMLPKG_RETURN_VALUES
	///if( verbose )
	if( 0 == nRet && verbose ) // if success and verbose
	/// end CLEAN_XMLPKG_RETURN_VALUES
	{
		string strMsg;
		///Cheney 2007-7-2 UPDATE_XF_ERR_THROW
		//strMsg.Format(_L("The package \"%s\" has been installed."), GetFileName(fname, TRUE));
		ocu_load_msg_str(XF_INST_OPX_DONE, &strMsg, GetFileName(fname, TRUE) ); 
		///end UPDATE_XF_ERR_THROW
		MessageBox(GetWindow(), strMsg, _L("Install OPX"), MB_OK);
	}
	/// end DRAG_DROP_OPX_NEED_NOTIFY_SUCCESS
}

//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int instOPX_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return instOPX_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	return false;

}

int instOPX_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	return false;
}
//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void instOPX_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{

}
//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int instOPX_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
