// ----------------------------------------------------------------------
// Copyright © 1994, National Education Training Group, Inc.		-
// All rights reserved.							-
//									-
// Skill Builder 3.01 Course Removal                     by Jerry Malik -
//                                                                      -
// $Log$                                                                -
//-----------------------------------------------------------------------

//-----------------------------------------------------------------------
// 	Set predefined constants.					-
//-----------------------------------------------------------------------

#define MAX_SIZE         255

declare // Must use declare keyword to start variable declaration

string	szText[256], szDisk[20], DelCourse[10], szBitmapPath[50],
	szResultPath[MAX_SIZE], szTitle[50], svCmdLine[MAX_SIZE], 
	szItemName[50], szErrFile[MAX_SIZE], szWinDirectory[144], 
	szTotal[20], szDefPath[50], szRemove[25], szResult[10], 
	szDelDir[MAX_SIZE], NameNum[10], szCount[3], OldCourse[10],
	szCommandLine[MAX_SIZE], svDisk[5], svWrkDir[MAX_SIZE], 
	svIconPath[MAX_SIZE], svShortCutKey[50], szSBDir[25], szWinINI[144],
	szUserPath[80];

number 	nTotal, nnew, nvIconIndex, nCount, nvMinimizeFlag;
LONG	lResult;
LIST	listID;

program /* Must use program keyword to start the statements */


Start:
	GetDisk ( SRCDIR, svDisk );
	szBitmapPath = svDisk ^ "INSTALL";
	szBitmapPath = szBitmapPath ^ "NETGLOG8.BMP";
	PlaceBitmap( szBitmapPath, 101, 20, 20, UPPER_RIGHT );


	// Set the color of the background to be BLUE
	SetColor( BACKGROUND, RGB( 0,0,255 ) );
	SetColor( STATUSBAR, RED );
	SetFont( FONT_TITLE, STYLE_NORMAL, "Helv" );
	Enable( BACKGROUND );
	Enable( STATUS );
       
	szTitle = "Skill Builder ® Removal";
	SetTitle( szTitle, 18, WHITE );
	SetStatusWindow( 1, szTitle );
       
	// In Info Window to display the file1.lis
	SetInfoWindow( "Information ", "file1.lis" );

	// Enable various objects.
	Disable( HELP );        //
	Enable( EXIT );         // Exit Button
	Disable( PAUSE );       // Pause Button
	Enable( TEXT );         // Info Windows


//---------------------------------------------------------------------
//         This procedure accepts the Course Number from user         -
//---------------------------------------------------------------------
COURSENUM:

	TARGETDIR = szResultPath;

	SetDialogTitle( DLG_ASK_TEXT,  "Enter course number" );
	szText = "Please enter the course number \nyou wish to remove. ";
	DelCourse = "";
	AskText( szText, DelCourse, DelCourse );
	if LAST_RESULT = FALSE
	then
	  goto ConfirmCancel;
	endif;

//---------------------------------------------------------------------
//           This procedure gets the Disk letter from NETG.INI and    -
//             defines the course and SB sub-directories.             -
//---------------------------------------------------------------------
TARGETLOC:


	FindFile( WINDIR, "NETG.INI", szResult );
	if LAST_RESULT != 0
	then
	  call MISSING_INI;
	endif;

	//-----------------------------------------------------------------
	//     Defines a path to the NETG.INI file using a variable       -
	//-----------------------------------------------------------------
	szWinDirectory = WINDIR;
	szWinDirectory = szWinDirectory ^ "NETG.INI";
       

	GetProfString( szWinDirectory, DelCourse, "Path", szDefPath );
	szDefPath = szDefPath ^ "\\";


	GetDisk( szDefPath, szDisk );
	szDefPath = szDefPath ^ "SKILLB";
	szSBDir = szDefPath;
	szDefPath = szDefPath ^ DelCourse;
       
	ExistsDir( szDefPath );
	if LAST_RESULT = EXISTS
	then
	   goto REMOVECOURSE;
	endif;

	szText = "Course, ";
	szText = szText + DelCourse;
	szText = szText + ", does not exist on this system.\nPress OK to return to the course selection.";
	MessageBox( szText, WARNING );
	szDefPath = "";  // Reset Default path
	goto COURSENUM;

//---------------------------------------------------------------------
//     This procedure removes all course files & sub-directories      -
//---------------------------------------------------------------------

REMOVECOURSE:
	GetProfString( szWinDirectory, DelCourse, "UserPath", szUserPath );

	if (szUserPath = szDefPath ^ "PRESENT" | szUserPath = szDefPath ^ "ICONWARE"
	| szUserPath = szDefPath | szUserPath = szDefPath ^ "PICS_ENU" 
	| szUserPath = szDefPath ^ "INPUT" | szUserPath = szDefPath ^ "INPUT"
	| szUserPath = szDefPath ^ "VAR_ENU" | szUserPath = szDefPath ^ "TEXT_ENU" )
	then
	  SetInfoWindow( "Information ", "file2.lis" );
	  SetDialogTitle( DLG_ASK_YESNO, "Delete Learner Management Files" );
	  AskYesNo ("Learner Management files have been installed in the coures subdirectory.  Are you sure that you want to remove the course with these files?", NO );
	  if ( LAST_RESULT = NO )
	  then
	    szText = "To save Learner Management files, move these files to a non-course directory.  The files are currently in the ";
	    szText = szText + szUserPath;
	    szText = szText + "\ directory.";
	    MessageBox (szText, INFORMATION);
	    exit; 
	  endif;
	endif;

	SetInfoWindow( "Information ", "file1.lis" );
	ChangeDirectory( szDisk ^ "\\" ); // Allows removal if user is in
					  // course directory.

	szDelDir = szDefPath;
	szDefPath = szDefPath ^ "PRESENT"; 
	SetStatusWindow( 15, "Removing PRESENT" );
	DeleteDir( szDefPath, ALLCONTENTS );
	ExistsDir( szDefPath );
	if LAST_RESULT = EXISTS
	then
	  goto BAD_REMOVE;
	endif;

	szDefPath = szDelDir;
	szDefPath = szDefPath ^ "ICONWARE";
	SetStatusWindow( 30, "Removing ICONWARE" );
	DeleteDir( szDefPath, ALLCONTENTS );
	ExistsDir( szDefPath );
	if LAST_RESULT = EXISTS
	then
	  goto BAD_REMOVE;
	endif;

	szDefPath = szDelDir;
	szDefPath = szDefPath ^ "PICS_ENU";
	SetStatusWindow( 45, "Removing GRAPHICS" );
	DeleteDir( szDefPath, ALLCONTENTS );
	ExistsDir( szDefPath );
	if LAST_RESULT = EXISTS
	then
	  goto BAD_REMOVE;
	endif;

	szDefPath = szDelDir;
	szDefPath = szDefPath ^ "INPUT";
	SetStatusWindow( 60, "Removing INPUT" );
	DeleteDir( szDefPath, ALLCONTENTS );
	ExistsDir( szDefPath );
	if LAST_RESULT = EXISTS
	then
	  goto BAD_REMOVE;
	endif;

	szDefPath = szDelDir;
	szDefPath = szDefPath ^ "VAR_ENU";
	SetStatusWindow( 65, "Removing VAR_ENU" );
	DeleteDir( szDefPath, ALLCONTENTS );
	ExistsDir( szDefPath );
	if LAST_RESULT = EXISTS
	then
	  goto BAD_REMOVE;
	endif;

	szDefPath = szDelDir;
	szDefPath = szDefPath ^ "TEXT_ENU";
	SetStatusWindow( 70, "Removing TEXT_ENU" );
	DeleteDir( szDefPath, ALLCONTENTS );
	ExistsDir( szDefPath );
	if LAST_RESULT = EXISTS
	then
	  goto BAD_REMOVE;
	endif;

	szDefPath = szDelDir;
	szText = "Removing course sub-directory ";
	szText = szText + DelCourse;
	SetStatusWindow( 95, szText );
	DeleteDir( szDefPath, ALLCONTENTS );
	ExistsDir( szDefPath );
	if LAST_RESULT = EXISTS
	then
	  goto BAD_REMOVE;
	endif;

//----------------------------------------------------------------------
//	Updates NETG.INI file - if this is the last course on the      -
//	system, NETG.INI and the SB movie are deleted.		       -
//----------------------------------------------------------------------

	SetStatusWindow( 98, "Updating NETG.INI" );

	GetProfInt( szWinDirectory, "Course", "Total", nTotal );

	if nTotal = 1
	then
	//delete NETG.INI, Skill Builder Movie, and the Icon Sounds
	  TARGETDIR = WINDIR;
	  DeleteFile( "NETG.INI" );
	  TARGETDIR = szSBDir;
	  DeleteFile ( "SBMOVIE1.FLI" );
	  DeleteFile ( "*.WAV" );
	//delete NETG sounds from WIN.INI
	  szWinINI = WINDIR ^ "WIN.INI";
	  WriteProfString (szWinINI, "Sounds", "NETGRewind", "" );
	  WriteProfString (szWinINI, "Sounds", "NETGForward", "" );
	  WriteProfString (szWinINI, "Sounds", "NETGFForward", "" );
	  WriteProfString (szWinINI, "Sounds", "NETGMap", "" );
	  WriteProfString (szWinINI, "Sounds", "NETGExit", "" );

	  call Delete_SB_Directory;
	else
	  nnew = 1;
	  for nCount = 1 to nTotal
	     NameNum = "Name";
	     NumToStr( szCount, nCount );       // Build NAMEn Keyname
	     NameNum = NameNum + szCount;
	     GetProfString( szWinDirectory, "Course", NameNum, OldCourse );

	     StrCompare( OldCourse, DelCourse );  // Course to Delete ?
	     if LAST_RESULT = 0
	     then
		// Delete course entry from Course App. Section NETG.INI
		WriteProfString( szWinDirectory, "Course", NameNum, "" );
		else
		NameNum = "Name";
		NumToStr( szCount, nnew );       // Build new NAMEn Keyname
		NameNum = NameNum + szCount;
		WriteProfString( szWinDirectory, "Course", NameNum, OldCourse );
		nnew = nnew + 1;
	     endif;
	  endfor;

	  NameNum = "Name";
	  NumToStr( szCount, nTotal );           // Delete Extra NAMEn Keyname
	  NameNum = NameNum + szCount;
	  WriteProfString( szWinDirectory, "Course", NameNum, "" );

	  // Delete Course Specific area from NETG.INI
	  WriteProfString( szWinDirectory, DelCourse, "", "");
	  WriteProfString( szWinDirectory, "Course", "Total", "" );

	  nTotal = nTotal - 1;
	  NumToStr( szTotal, nTotal );
	  if LAST_RESULT = 0
	  then
	     WriteProfString( szWinDirectory, "Course", "Total", szTotal );
	  else
	     MessageBox("Missing or corrupted NETG.INI,\n You must reinstall all skill builder courseware for proper execution", INFORMATION);
	  endif;
	endif;

//---------------------------------------------------------------------
//            Check for removal of course
//---------------------------------------------------------------------

	GetDisk( szDefPath, szDisk );
        
	ExistsDir( szDelDir );
	if LAST_RESULT = EXISTS
	then
 	  goto BAD_REMOVE;
	endif;

//---------------------------------------------------------------------
//            Remove course icon from NETG SB Courseware group
//---------------------------------------------------------------------

	szCommandLine = szDelDir ^ "PRESENT\\PRESENT";
	szCommandLine = szCommandLine + " ";
	szCommandLine = szCommandLine + szDelDir;
	szCommandLine = szCommandLine ^ "ICONWARE";
	szCommandLine = szCommandLine ^ DelCourse;
	szCommandLine = szCommandLine + ".IW";

	listID = ListCreate( STRINGLIST );
	
	GetItemNameList ("NETG SB Courseware", listID );
	if (ListGetFirstString( listID,szItemName ) != END_OF_LIST)
	then
	  QueryProgItem( "NETG SB Courseware", szItemName, svCmdLine, svWrkDir, svIconPath, nvIconIndex, svShortCutKey, nvMinimizeFlag );
	  if szCommandLine = svCmdLine
	  then
	    call DeleteIcon;
	  endif;
	  while (lResult != END_OF_LIST )
	    lResult = ListGetNextString( listID, szItemName );
	    QueryProgItem( "NETG SB Courseware", szItemName, svCmdLine, svWrkDir, svIconPath, nvIconIndex, svShortCutKey, nvMinimizeFlag );
	      if szCommandLine = svCmdLine
	      then
//	MessageBox (szItemName, INFORMATION);
	        call DeleteIcon;
	      endif;
	  endwhile;
	endif;



	Delay( 3 ); //Artificial Delay
	MessageBox( "Removal complete.\nPress OK to exit.", INFORMATION );
	goto EXIT_IT;

BAD_REMOVE:

	MessageBox( "Removal did not complete correctly.\n Please Check for courseware files.", SEVERE );
	goto EXIT_IT;

MISSING_INI:

	MessageBox( "Missing NETG.INI,\n You must reinstall all Skill Builder courseware for proper execution", INFORMATION);
	goto EXIT_IT;

EXIT_IT:                               

	exit;  //Exit removal program.

//---------------------------------------------------------------------
//        This procedure will confirm with the users if they          -
//           want to terminate the removal of the course.             -
//---------------------------------------------------------------------
ConfirmCancel:

	AskYesNo( "Are you sure you want to CANCEL Remove?", FALSE );

	if LAST_RESULT = FALSE
	then
	  goto COURSENUM;
	endif;
	exit;

DeleteIcon:

	ShowGroup( "NETG SB Courseware", SW_SHOWMINNOACTIVE );
	ShowGroup( "NETG SB Courseware", SW_NORMAL );
	DeleteProgItem ( "NETG SB Courseware", szItemName, ""); 
	return;

Delete_SB_Directory:


	szText = "This is the last Skill Builder course on your system.  Do you want to delete all the files in the Skill Builder directory and the program group from Windows?";
 
	if ( AskYesNo( szText, YES) = NO )
	then
	  return;
	else
	  DeleteGroup ("NETG SB Courseware");

	  if (FindFile( szSBDir, "NE_USERS.FMT", szText ) = 0)
	  then
	    szText = "Learner Management files were found in the Skill Builder directory.  Do you wish to leave the directory with these files?";

	    if ( AskYesNo( szText, YES) = YES )
	    then
	      return;
	    endif;
	  endif;  

	  DeleteDir (szSBDir, ALLCONTENTS );
	endif;
	return;

// ----------------------------------------------------------------------
//      Copyright 1994 - National Education Training Group		-
//      Skill Builder Course Removal                                    -                                                                    
//-----------------------------------------------------------------------
