[OnOpenOPK]
dll -a OPack OPack; // temporary code

Opack.Unpack.Uninstall$=""; // SY 04-05-2004, reset "Uninstall" property before unpack an OPK file to avoid write junk into opkmlist.ini 
OPack.FileName$=%1;

OPack.TargetFolder$="*"; // unpack into temp folder
i = OPack.Unpack();
if( i != 0 ) // if unpack error
{
	Run.Section(,OnOPKError);
	return 1;
}
///i = OPack.FindFile(OPKSetup.ogs,Z);
i = OPack.FindSetup(Z);
if( i > 0 ) // if an OPKSetup.ogs was unpacked
{
	%a=OPack.TargetFolder$;
	i = Run.Section(%A%Z,OnBeforeSetup);
}
else
{
	i = 0; // continue setup
}

OPack.Undo(); // always remove temp folder

if( i == 1 ) // if installation should NOT continue
{
	return 1;
}

//OPack.TargetFolder$=""; // unpack into Origin folder - OnAfterSetup not running

OPack.TargetFolder$=%Y; // GJL & SDB 7/30/03: unpack into user folder - allows OnAfterSetup to run
i = OPack.Unpack();
if( i != 0 ) // if unpack error
{
	Run.Section(dofile,OnOPKError);
	return 1;
}
else
{
	type -b $OPK.UnpackSuccess;
}
//i = OPack.FindFile(OPKSetup.ogs,Z);
i = OPack.FindSetup(Z);
if( i > 0 ) // if an OPKSetup.ogs was unpacked
{
	%W=OPack.TargetFolder$;
	i = Run.Section(%W%Z);
	i = Run.Section(%W%Z,OnAfterSetup);
}

OPack.Reset();
File.Delete(%Y%Z); // Delete the OPKSetup file.

return 0; // success


[OnOPKError]
switch(i)
{
case 1:
	%a = OPack.FileName$;
	%z = $OPK.ErrUserAccess;
	break;
case 2:
	%a = OPack.FileName$;
	%z = $OPK.ErrFileIO;
	break;
case 3:
	%a = OPack.FileName$;
	%z = $OPK.ErrHeaderFile;
	break;
case 4:
	%a = OPack.ErrorFileName$;
	%z = $OPK.ErrExpandFile;
	break;
case 5:
	%a = OPack.FileName$;
	%z = $OPK.ErrInvalidFile;
	break;
case 6:
	%a = OPack.ErrorFileName$;
	%z = $OPK.ErrCreateFile;
	break;
default:
	%a = OPack.FileName$;
	%z = $OPK.ErrFileIO;
	break;
}

// The following 2 lines make a multi-line message.
%z=%z
%a;

type.msgBox(%z,OPack);
return 0;


[OnOpenOGS]
// ed is mapped to OLbTEdit in Origin.ini by default
	ed.open(%1);
	return 0;

[OnOpenCPP]
	ed.open(%1);
	return 0;

[OnOpenC]
	ed.open(%1);
	return 0;
	
[OnOpenH]
	ed.open(%1);
	return 0;

[OnOpenSPC]
	%W=doc.DropWinName$;
	i = exist(%W);
	switch(i)
	{
	case 2:// wks
		// we will always activate the window
		win -o %W {
			open -s %1;
		}
		break;
	case 3: // graph
		win -t Data Create;// create.otw is hidden
		open -sn %1;
		// select all
		%A=%H;
		// next we will plot all into layer, we need to make it active as well.
		win -a %W;
		if(doc.DropLayer>0)	// drop into particular layer
		{
			layer -o doc.DropLayer {
				layer -w %A;
			}
		}
		else
			layer -w %A;	
		break;
	case 5: // matrix
		if(doc.DropIndex > 1)
			win -T Matrix;
		else
			win -a %W;
		open -s %1;
		break;
	default:
		win -t Data;
		open -sn %1;
	}

[OnOpenBMP]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
	
[OnOpenGIF]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
	
[OnOpenJPG]
	Image.FileName$="%1";
	run.section(,IMGOpen);
	
[OnOpenPCX]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
	
[OnOpenPNG]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
	
[OnOpenPSD]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
	
[OnOpenTGA]
	Image.FileName$="%1";
	run.section(,IMGOpen);
	
[OnOpenTIF]
	Image.FileName$="%1";
	run.section(,IMGOpen);
	
[OnOpenWMF]
	Image.FileName$="%1";
	run.section(,IMGOpen);	

[OnOpenXPM]
	Image.FileName$="%1";
	run.section(,IMGOpen);	

[OnOpenXWD]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
					
[ObsoleteOnOpenMPJ]
	%A = "%1";
	run.section(ORDMNTB,OnDrop);

[ObsoleteOnOpenMTW]
	%A = "%1";
	run.section(ORDMNTB,OnDrop);
					
[ObsoleteOnOpenJNB]
	%A = "%1";
	run.section(ORDJNB,OnDrop);

[OnOpenFDF]
	%A="%1";
	dialog.start(Otools,SelectCat);
	return 0;

[IMGOpen]
	//ty "Openning %1...";
	%W=doc.DropWinName$;
	i = exist(%W);
	if(doc.DropIndex > 1)
		i = 0;// cannot drop more than 1 into a matix, treat as drop into open space
	switch(i)
	{
	case 5:// matrix
		// we will activate the window if point to existing matrix
		win -a %W;
		run.section(ImgFile,LoadImageIntoMatrix);
		break;
	case 3: // graph
	case 11: // layout
		win -a %W;
		run.section(ImgFile,LoadImageIntoGrObject);
		break;
	default: // new matrix
		%A = System.Matrix.DefTemplate$;
		win -T Matrix "%A";
		run.section(ImgFile,LoadImageIntoMatrix);
	}

[FileTypeRegistration]
; set OGS = 1 to tell Origin to register this extension for LabTalk editor
; to open ogs script file
; set to 0 will tell Origin not to register it

;OGS=1
	 
SPC=1
