//////////////////////////////////////////////////////////////////// // ScriptId "AbiWord" "{36DFD440-2256-11d8-81A8-00409545058B}" // Language "JScript" // // ActiveDisk purpose: // This ActiveDisk launches an instance of AbiWord from the disk. // The OpenOffice application will be closed upon ejecting disk. // // Script version: // 28. 11. 2003 v. 1.0, Tomas Frydrych (based on Open Office Script) // // Requirements/Notes: //////////////////////////////////////////////////////////////////// // Common AD Globals var g_Path = ":\\AbiSuite\\AbiWord"; var g_LicPath = ":\\AbiSuite"; var g_LicName = "readme"; var g_LicExt = ".txt"; var g_Exe = "\\AbiWord.exe"; var g_Product = "AbiWord"; var g_Bin = "\\bin"; var g_Lib = "\\lib"; var g_ProfName = "AbiWord.profile"; // these will be initialised later var g_LibPath; var g_ExePath; var g_License; var g_ProfParam; // arrays to hold version information for us var g_ADVer; var g_WSHVer; // Global ActiveX Objects var FileSysObj; var WshShellObj; var WshShell; var customObj; // global custom application // Other Globals var AppIndex; var WindowsFolder; // the windows folder object var gbDrvLetter; // the initial drive letter var IsNT; // Flag Set so we know if its NT or 9X var SplashIndex; // splash message app index var DeskTop; // used to store the path of the desktop var StartMenu; // used to store the path of the startmenu function OnInsert(drvLetter) { // Initialize globals gbDrvLetter= drvLetter; // retain drive letter // Create a Shell Object try { WshShellObj = new ActiveXObject( "WScript.Shell"); } catch(err) { MsgString = "shell object is null"; window.alert(MsgString); return false; } //WshShellObj.PopUp("Success initiating shell object"); // Instantiate the file system object try { FileSysObj = new ActiveXObject( "Scripting.FileSystemObject" ); } catch(err) { WshShellObj.PopUp("Unable to create filesystem object"); return false; } //WshShellObj.PopUp("Success initiating file system object"); // Get the Windows Directory IsNT = false; var reg95 = "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\SystemRoot"; var regNT = "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SystemRoot"; if(!IsRegThere(reg95)) { if(!IsRegThere(regNT)) { WshShellObj.PopUp("Unable to detect operating system version"); } WindowsFolder= WshShellObj.RegRead(regNT); IsNT = true; } else { WindowsFolder= WshShellObj.RegRead(reg95); } WindowsFolder += "\\"; // Instantiate a drive letter of the active disk try { customObj = new ActiveXObject("AutoLib.AutoCust"); customObj.InitDriveLetter(drvLetter); } catch(err) { WshShellObj.PopUp("Unable to create Autolib object"); return false; } //WshShellObj.PopUp("Success initiating autolib object"); // retrieve version info var VerStr = customObj.GetAutoDiskVersionStr(); g_ADVer = new Array(0,0,0,0); ParseVersionString(VerStr, g_ADVer); //WshShellObj.PopUp("AD version: " + g_ADVer); VerStr = customObj.GetWSHEngineVersionStr(); g_WSHVer = new Array(0,0,0,0); ParseVersionString(VerStr, g_WSHVer); //WshShellObj.PopUp("WHS version: " + g_WSHVer); // init various paths var WshSpec = WshShellObj.SpecialFolders; DeskTop = WshSpec("DeskTop"); DeskTop += "\\"; StartMenu = WshSpec("StartMenu"); StartMenu += "\\"; g_ExePath = drvLetter + g_Path + g_Bin + g_Exe; g_LibPath = drvLetter + g_Path + g_Lib; g_License = drvLetter + g_LicPath + "\\" + g_LicName + g_LicExt; g_ProfParam = "-u " + drvLetter + g_Path + "\\" + g_ProfName; //WshShellObj.PopUp("g_ExePath: " + g_ExePath); //WshShellObj.PopUp("g_LibPath: " + g_LibPath); //WshShellObj.PopUp("g_License: " + g_License); // Show license aggreement if(FileSysObj.FileExists(g_License)) { //WshShellObj.PopUp("Found licence file"); var bAgree = false; try { bAgree = customObj.DisplayLicenseAgreement(g_License); } catch(err) { WshShellObj.PopUp("Problem displaying licence file"); return false; } if(bAgree) { // move the file to the root of the drive; this will stop // the licence reappearing in the future, and yet will // leave it at the users disposal var moveMe = drvLetter + ":\\" + g_LicName + g_LicExt; try { FileSysObj.MoveFile(g_License, moveMe); } catch(err) { WshShellObj.PopUp("Problem moving licence (from " + g_Licence + " to " + moveMe); } } else { // quit WshShellObj.PopUp("Since you did not agree to the conditions of AbiWord License, Active Disk cannot proceed."); return false; } } else { } // Initialize and execute Active Disk if(RunAppFromDisk(drvLetter) == false) return false; customObj.CloseSplash(SplashIndex); return true; } // end of OnInsert function ParseVersionString(str, v) { var nextStart = 0; var dotIndx; for(i=0; i < 4; ++i) { dotIndx = str.indexOf(".", nextStart); if(dotIndx < 0) { if(i < 3) break; else dotIndx = str.length; } v[i] = str.substr(nextStart, dotIndx - nextStart); nextStart = dotIndx + 1; } } function OnEject() { customObj.ShutdownApplication(AppIndex,true,true,1); } function RunAppFromDisk(drvLetter) { //WshShellObj.PopUp("Running application ..."); // Display splash screen var pSplash= "Loading " + g_Product + ", Please wait..."; SplashIndex = customObj.DisplaySplash(true,pSplash); CreateShortcuts(); RegisterFileTypes(); try { AppIndex = customObj.StartApp(g_ExePath, g_ProfParam, g_LibPath, 2, false, 0, true, true, 10); } catch(err) { WshShellObj.PopUp( "Unable to run AbiWord ("+g_ExePath+", "+g_LibPath+")"); return false; } return true; } function IsRegThere(sRegString) { var regResult var value = true; try { regResult = WshShellObj.RegRead(sRegString); } catch(err) { value = false; } return value; } function CreateShortcuts() { var Location, Param, Target, HotKey, Desc, CWD; var LinkName = "AbiWord Active Disk.lnk" Location = gbDrvLetter +":\\" + LinkName; Target = g_ExePath; Param = g_ProfParam; Desc = "AbiWord (Active Disk)"; HotKey = "CTRL+SHIFT+a"; CWD = g_LibPath; NewShortcut(Location, Target, Param, HotKey, Desc, CWD); Location = DeskTop + LinkName; NewShortcut(Location, Target, Param, HotKey, Desc, CWD); // On // DeskTop Location = StartMenu + LinkName; NewShortcut(Location, Target, Param, HotKey, Desc, CWD); // In StartMenu } function NewShortcut(Location, Target,Param, HotKey, Desc, CWD) { var ShortCut; try { ShortCut = WshShellObj.CreateShortcut(Location); ShortCut.TargetPath = Target; ShortCut.Arguments = Param; ShortCut.WindowStyle = 1; ShortCut.HotKey = HotKey; ShortCut.IconLocation = Target; ShortCut.Description = Desc; ShortCut.WorkingDirectory = CWD; ShortCut.Save(); } catch(err) { WshShellObj.Popup("Error: Couln't Create New ShortCut - " + Location); return false; } // log shortcut so it gets automatically removed customObj.LogTempFile(Location); } function AddRegistryEntry(registry, key, value, type, force) { try { if(IsRegThere(registry + "\\" + key)) { //WshShellObj.Popup("Key already exists, r: "+registry+", k: "+key+", v: "+value); // only change the existing entry if force == true if(force) { //WshShellObj.Popup("Attempting to change registry value"); var OldVal = WshShellObj.RegRead(registry + "\\" + key); var OldValStr = OldVal.toString(10); //WshShellObj.Popup("Old value: " + OldVal + ", OldValStr: " + OldValStr); WshShellObj.RegWrite(registry + "\\" + key, value, type); //WshShellObj.Popup("Logging old value."); // there is a bug in the logging function -- it will // strip off leading and trainling " // we will add extra " to compensate for this var logVal = new String(); if(OldValStr.substr(0,1) == "\"") logVal += "\""; logVal += OldValStr; if(OldValStr.substr(OldValStr.length - 1, 1) == "\"") logVal += "\""; //WshShellObj.Popup("Old value: " + OldVal + ", OldValStr: " + OldValStr + ", log: " + logVal); customObj.LogRegChange(registry,key,logVal,type); } else { //WshShellObj.Popup("Leaving entry untouched"); } } else { //WshShellObj.Popup("New key, r: "+registry+", k: "+key+", v: "+value); WshShellObj.RegWrite(registry + "\\" + key, value, type); //WshShellObj.Popup("Logging new value."); customObj.LogNewRegKey(registry + "\\" + key); } } catch(err) { WshShellObj.Popup("Error: Couln't add registry entry - " + registry + "\\" + key); return false; } } function RegisterFileTypes() { // the command to open an associated file var Command = g_ExePath + " " + g_ProfParam + " \"%1\""; // first register our application AddRegistryEntry("HKCR\\AbiSuite.AbiWord", "", "AbiWord Document", "REG_SZ", true); AddRegistryEntry("HKCR\\AbiSuite.AbiWord\\DefaultIcon", "", g_ExePath + ",2", "REG_SZ", true); AddRegistryEntry("HKCR\\AbiSuite.AbiWord\\shell\\open\\command", "", Command, "REG_SZ", true); // register association for AW native formats, this we will force AddRegistryEntry("HKCR\\.abw","", "AbiSuite.AbiWord", "REG_SZ", true); AddRegistryEntry("HKCR\\.abw","Content Type", "application/abiword", "REG_SZ", true); AddRegistryEntry("HKCR\\.zabw","", "AbiSuite.AbiWord", "REG_SZ", true); AddRegistryEntry("HKCR\\.zabw","Content Type", "application/abiword-compressed", "REG_SZ", true); AddRegistryEntry("HKCR\\.awt","", "AbiSuite.AbiWord", "REG_SZ", true); AddRegistryEntry("HKCR\\.awt","Content Type", "application/abiword-template", "REG_SZ", true); // now register additional document types if not present ... AddRegistryEntry("HKCR\\.rtf","", "AbiSuite.AbiWord", "REG_SZ", false); AddRegistryEntry("HKCR\\.rtf","Content Type", "application/abiword", "REG_SZ", false); AddRegistryEntry("HKCR\\.doc","", "AbiSuite.AbiWord", "REG_SZ", false); AddRegistryEntry("HKCR\\.doc","Content Type", "application/abiword", "REG_SZ", false); }