// InstallNNAWiz.js
//
// Installs the NNA plug-in wizard.
// If Visual Studio .NET is not installed, the script will do nothing.


var fso = new ActiveXObject("Scripting.FileSystemObject");
var WSHShell = WScript.CreateObject("WScript.Shell");
var strDotNetPath;


try {
    var oFSO = new ActiveXObject("Scripting.FileSystemObject");

    if (oFSO.FolderExists("C:\\Program Files\\Microsoft Visual Studio 8")) {
	    strDotNetPath = "C:\\Program Files\\Microsoft Visual Studio 8";
    }
    else
    {
	    var promptStr;
	    promptStr = "Visual Studio .NET must be installed before this script can be run.";
	    promptStr += "\nLooking in paths:\n";
	    promptStr += "  C:\\Program Files\\Microsoft Visual Studio 8";
	    WScript.Echo(promptStr);
	    WScript.Quit(1);
    }


    var strVCProjects = strDotNetPath + "\\Vc\\vcprojects";
    var strVCWizards = strDotNetPath + "\\Vc\\VCWizards";
    var strWizFolderName = "VWPluginWiz";
    var strWizardPath = strVCWizards + "\\" + strWizFolderName;
    var strScriptPath;				// Path to the install script (this file)


    // Make directories if necessary
    if (oFSO.FolderExists(strVCWizards)) {
	    if ( oFSO.FolderExists(strWizardPath))
		    oFSO.DeleteFolder(strWizardPath, true);
    }
    else {
	    WScript.Echo(strVCWizards + " does not exist.  Aborting...");
	    WScript.Quit(1);
    }

    if (! oFSO.FolderExists(strVCProjects)) {
	    WScript.Echo(strVCProjects + " does not exist.  Aborting...");
	    WScript.Quit(1);
    }


    // Determine path to the script (this file)
    var scrPath = WScript.ScriptFullName;
    var scrName = WScript.ScriptName;

    strScriptPath = scrPath.substr(0, scrPath.length - scrName.length);


    // Copy stuff
    if ( oFSO.FolderExists(strVCProjects + "\\VectorWorks SDK\\") )
	    oFSO.DeleteFolder(strVCProjects + "\\VectorWorks SDK", true);

    if ( oFSO.FileExists(strVCProjects + "\\VWPluginWiz.ico") )
	    oFSO.DeleteFile(strVCProjects + "\\VWPluginWiz.ico", true);
    if ( oFSO.FileExists(strVCProjects + "\\VWPluginWiz.vsz") )
	    oFSO.DeleteFile(strVCProjects + "\\VWPluginWiz.vsz", true);


    WScript.Echo("VW Plug-in Wizard Uninstalled.");
}
catch(err)
{
    var txt;
    txt="There was an error during uninstall.\n\n";
    txt+="Error description: " + err.description + "\n\n";
    txt+="Possible solution:\n"
    txt+="  Run 'UninstallVWPluginWiz.bat' as administrator!\n";
    txt+="  Note: You will have to put the full path to the script\n";
    txt+="        inside the batch file in order to run it as administrator!";
	WScript.Echo( txt );
	WScript.Quit(1);
}


