//
// Copyright 2010 Jacob Gladish. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY Jacob Gladish ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of <copyright holder>.
//
#using <mscorlib.dll>
#include "StdAfx.h"
#include "clientuser_m.h"
#include "stdhdrs.h"
using namespace System;
using namespace System::Collections::Specialized;
using namespace System::Runtime::InteropServices;
System::String* ToDotNetString( const StrPtr& p )
{
System::String* s = p.Text();
return s;
}
/*
static ::StrBuf* _fromDotNetStringToStrBuf( System::String* s )
{
System::IntPtr ptr = Marshal::StringToHGlobalAnsi( s );
const char* str = static_cast< const char * >( ptr.ToPointer() );
::StrBuf* sb = new ::StrBuf();
sb->Set( str );
Marshal::FreeHGlobal( ptr );
return sb;
}
*/
p4dn::ClientUser::ClientUser()
{
GCHandle h = GCHandle::Alloc( this );
IntPtr ptr = GCHandle::op_Explicit( h );
_clientUserDelegate = new ClientUserDelegate( ptr.ToInt32() );
}
p4dn::ClientUser::~ClientUser()
{
delete _clientUserDelegate;
}
void p4dn::ClientUser::InputData( String* s, p4dn::Error* err )
{
}
void p4dn::ClientUser::HandleError( p4dn::Error* err )
{
}
void p4dn::ClientUser::Message( p4dn::Error* err )
{
}
void p4dn::ClientUser::OutputError( String* s )
{
}
void p4dn::ClientUser::OutputInfo( Char level, String* s )
{
}
//void p4dn::ClientUser::OutputBinary( unsigned char data[] )
//{
//
//}
void p4dn::ClientUser::OutputText( String* s )
{
}
void p4dn::ClientUser::OutputStat( StringDictionary* varList )
{
}
void p4dn::ClientUser::Prompt( const String* msg,
String*& rsp,
bool noEcho,
p4dn::Error* err )
{
}
void p4dn::ClientUser::ErrorPause( System::String* errBuf, p4dn::Error* err )
{
}
void p4dn::ClientUser::Edit( System::IO::FileInfo* info, p4dn::Error *err )
{
}
void p4dn::ClientUser::Diff( System::IO::FileInfo* f1,
System::IO::FileInfo* f2,
int doPage,
System::String* diffFlags,
p4dn::Error *err )
{
}
void p4dn::ClientUser::Merge( System::IO::FileInfo* base,
System::IO::FileInfo* leg1,
System::IO::FileInfo* leg2,
System::IO::FileInfo* result,
p4dn::Error* err )
{
}
void p4dn::ClientUser::Help( System::String* help )
{
}
void p4dn::ClientUser::RunCmd( System::String* command,
System::String* arg1,
System::String* arg2,
System::String* arg3,
System::String* arg4,
System::String* pager,
Error* err )
{
char* cmd = (char *)(void *) Marshal::StringToHGlobalAnsi( command );
char* a1 = (char *)(void *) Marshal::StringToHGlobalAnsi( arg1 );
char* a2 = (char *)(void *) Marshal::StringToHGlobalAnsi( arg2 );
char* a3 = (char *)(void *) Marshal::StringToHGlobalAnsi( arg3 );
char* a4 = (char *)(void *) Marshal::StringToHGlobalAnsi( arg4 );
char* pgr = (char *)(void *) Marshal::StringToHGlobalAnsi( pager );
::ClientUser::RunCmd( cmd, a1, a2, a3, a4, pgr, err->get_InternalError() );
Marshal::FreeHGlobal( cmd );
Marshal::FreeHGlobal( a1 );
Marshal::FreeHGlobal( a2 );
Marshal::FreeHGlobal( a3 );
Marshal::FreeHGlobal( a4 );
Marshal::FreeHGlobal( pgr );
}
//========================================================================
// Internal Object
//
p4dn::ClientUser* p4dn::ClientUser::ClientUserDelegate::_getClientUser() {
GCHandle h = GCHandle::op_Explicit( IntPtr(_clientUserHandle) );
return static_cast< p4dn::ClientUser* >( h.Target );
}
p4dn::ClientUser::ClientUserDelegate::~ClientUserDelegate()
{
GCHandle h = GCHandle::op_Explicit( IntPtr(_clientUserHandle) );
h.Free();
}
void p4dn::ClientUser::ClientUserDelegate::InputData( StrBuf *strbuf, ::Error* err )
{
System::String* s = strbuf->Text();
p4dn::Error* e = new p4dn::Error( err );
p4dn::ClientUser* cu = _getClientUser();
cu->InputData( s, e );
}
void p4dn::ClientUser::ClientUserDelegate::HandleError( ::Error *err )
{
p4dn::Error* e = new p4dn::Error( err);
p4dn::ClientUser* cu = _getClientUser();
cu->HandleError( e );
}
void p4dn::ClientUser::ClientUserDelegate::Message( ::Error *err )
{
p4dn::Error* e = new p4dn::Error( err );
p4dn::ClientUser* cu = _getClientUser();
cu->Message( e );
// TODO: DO I need to delete the error???
}
void p4dn::ClientUser::ClientUserDelegate::OutputError( const_char *errBuf )
{
System::String* s = errBuf;
p4dn::ClientUser* cu = _getClientUser();
cu->OutputError( s );
}
void p4dn::ClientUser::ClientUserDelegate::OutputInfo( char level, const_char *data )
{
System::String* s = data;
p4dn::ClientUser* cu = _getClientUser();
cu->OutputInfo( level, s );
}
// virtual void p4dn::ClientUser::ClientUserDelegate::OutputBinary( const_char *data, int length ){}
void p4dn::ClientUser::ClientUserDelegate::OutputText( const_char *data, int length )
{
System::String* s = data;
p4dn::ClientUser* cu = _getClientUser();
cu->OutputText( s );
}
void p4dn::ClientUser::ClientUserDelegate::OutputStat( StrDict *varList )
{
System::Collections::Specialized::StringDictionary* dict =
new System::Collections::Specialized::StringDictionary();
int i = 0;
::StrRef var, val;
while (varList->GetVar(i,var,val) != -0) {
System::String* key = var.Text();
System::String* value = val.Text();
if (!dict->ContainsKey(key)) {
dict->Add( key, value );
}
i++;
}
p4dn::ClientUser* cu = _getClientUser();
cu->OutputStat( dict );
}
void p4dn::ClientUser::ClientUserDelegate::Prompt( const StrPtr& msg,
StrBuf& rsp,
int noEcho,
::Error *err )
{
String* response;
String* message = ToDotNetString( msg );
bool bEcho = ( noEcho != 0 );
p4dn::Error* e = new p4dn::Error( err );
p4dn::ClientUser* cu = _getClientUser();
cu->Prompt( message, response, bEcho, e );
char* str = (char *)(void *) Marshal::StringToHGlobalAnsi( response );
rsp.Set( str );
Marshal::FreeHGlobal( str );
}
void p4dn::ClientUser::ClientUserDelegate::ErrorPause( char *errBuf, ::Error *err )
{
System::String* s = errBuf;
p4dn::Error* e = new p4dn::Error( err );
p4dn::ClientUser* cu = _getClientUser();
cu->ErrorPause( s, e );
}
void p4dn::ClientUser::ClientUserDelegate::Edit( FileSys *f1, ::Error *err )
{
p4dn::Error* e = new p4dn::Error( err );
System::String* name = f1->Name();
System::IO::FileInfo* info = new System::IO::FileInfo( name );
p4dn::ClientUser* cu = _getClientUser();
cu->Edit( info, e );
}
void p4dn::ClientUser::ClientUserDelegate::Diff( FileSys *f1,
FileSys *f2,
int doPage,
char *diffFlags,
::Error *e )
{
// TODO:
System::Console::WriteLine( "10" );
}
void p4dn::ClientUser::ClientUserDelegate::Merge( FileSys *base,
FileSys *leg1,
FileSys *leg2,
FileSys *result,
::Error *e )
{
// TODO:
}
// virtual int p4dn::ClientUser::ClientUserDelegate::Resolve( ClientMerge *m, Error *e ){}
void p4dn::ClientUser::ClientUserDelegate::Help( const_char *const *help )
{
System::String* s = *help;
p4dn::ClientUser* cu = _getClientUser();
cu->Help( s );
}
FileSys* p4dn::ClientUser::ClientUserDelegate::File( FileSysType type )
{
// TODO: does this need to be expose? I'm pretty sure it doesn't
return FileSys::Create( type );
}
void p4dn::ClientUser::ClientUserDelegate::Finished()
{
p4dn::ClientUser* cu = _getClientUser();
cu->Finished();
}