From 5cb5981c341c21432059e6814dcb7079a9aa19e0 Mon Sep 17 00:00:00 2001 From: Homes32 Date: Sun, 29 Dec 2024 13:05:37 -0600 Subject: [PATCH] Enhance Edit PhoenixPE.au3 to open with the PEBakery custom editor or notepad.exe if the .au3 file extension is not registered. (Issue #119) --- Projects/PhoenixPE/Shell/000-PreShell.script | 35 ++++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Projects/PhoenixPE/Shell/000-PreShell.script b/Projects/PhoenixPE/Shell/000-PreShell.script index 7b02560..dc2648f 100644 --- a/Projects/PhoenixPE/Shell/000-PreShell.script +++ b/Projects/PhoenixPE/Shell/000-PreShell.script @@ -35,8 +35,8 @@ Author=Homes32 Level=3 Selected=True Mandatory=True -Version=1.1.4.0 -Date=2024-09-22 +Version=1.1.5.0 +Date=2024-12-29 [Variables] @@ -93,7 +93,7 @@ If,%cb_RegisterWCS%,Equal,True,Begin End // Ventoy compatibility -// See https://www.ventoy.net/en/compatible.html & https://www.ventoy.net/en/doc_compatible_mark.html +// See https://www.ventoy.net/en/compatible.html & https://www.ventoy.net/en/doc_compatible_mark.html & https://github.com/PhoenixPE/PhoenixPE/issues/86#issuecomment-2143944944 If,%cb_VentoyCompatible%,Equal,True,Begin FileCreateBlank,"%OutputDir%\ventoy.dat" TXTAddLine,"%OutputDir%\Ventoy.dat","This file is used to mark this image as #$qVentoy Compatible#$q#$xand prevent Ventoy from trying to hook the setup CmdLine during boot.#$x#$xMore info: https://www.ventoy.net/en/doc_compatible_mark.html",Append @@ -123,7 +123,7 @@ FileCreateBlank,"%TargetSystem32%\winpeshl.ini" TXTAddLine,"%TargetSystem32%\winpeshl.ini","[LaunchApps]",Append TXTAddLine,"%TargetSystem32%\winpeshl.ini","wpeinit.exe",Append -// Register Pecmd as our pre-shell +// Register our pre-shell RegWrite,HKLM,0x1,"Tmp_System\Setup","CmdLine","AutoIt3.exe PhoenixPE.au3",NOWARN // Add the PEPrograms directory to system ENV so we can Pin shortcuts from removable media in the event the user renamed the directory in Config Source. @@ -173,13 +173,34 @@ End // Return values..: // Author.........: Homes32 // Remarks........: INTENDED FOR PROJECT DEVELOPERS ONLY! +// Note: If you have the AutoIt environment installed on the host computer the default action at install time +// is to Run/Execute .au3 files. This means we can't just go ShellExecute,Open and assume the .au3 file will +// open in ScITE or another editor because there is a good chance that the user did not change the defaults +// during the install which would result in the PhoenixPE loader trying to run on the host computer, +// which is **not** what we want here. AutoIt developers usually want to use the SciTE IDE that was installed +// with AutoIt so they have access to documentation, syntax checker, autocomplete, function reference, etc. +// To get around this issue we attempt to resolve the editor in the following order: +// 1. Check to see if the .au3 file extension is registered on the host computer. +// If so launch ShellExecute with the 'Edit' verb to open the default editor associated with .au3 files. +// 2. If the .au3 file extension is not registered, read the default custom editor from PEBakery's settings. +// If a custom editor is defined, then launch ShellExecute with the 'Open' using the custom editor. +// 3. If the .au3 file extension is not registered and no custom editor is defined in the settings, then +// edit with notepad.exe. // Related........: btn_EditProjectConfig // =============================================================================================================================== [EditProjectConfig] Echo,"Opening PhoenixPE.au3 in your default editor.#$x#$xPlease close the editor to continue..." ExtractAllFiles,%ScriptFile%,config,%ProjectTemp% Hash,SHA256,"%ProjectTemp%\PhoenixPE.au3",%PreEditHash% -ShellExecute,Edit,"%ProjectTemp%\PhoenixPE.au3" + +If,ExistRegSubKey,HKCR,".au3",ShellExecute,Edit,"%ProjectTemp%\PhoenixPE.au3" +Else,Begin + // The .au3 file extension is not associated with anything; fallback to the PEBakery custom editor. + IniRead,"%BaseDir%\PEBakery.ini","Interface","CustomEditorPath",%CustomEditorPath%,"Default=notepad.exe" + If,%CustomEditorPath%,Equal,"",Set,%CustomEditorPath%,"notepad.exe" + ShellExecute,Open,%CustomEditorPath%,"%ProjectTemp%\PhoenixPE.au3" +End + Hash,SHA256,"%ProjectTemp%\PhoenixPE.au3",%PostEditHash% If,Not,%PreEditHash%,Equal,%PostEditHash%,Begin If,QUESTION,"PhoenixPE.au3 has been modified.#$x#$xWould you like to save your changes?",Begin @@ -279,11 +300,11 @@ cb_RegisterWCS="Associate .wcs scripts with PECMD",1,3,10,70,200,18,True,"__Exec cb_VentoyCompatible="Ventoy Compatible",0,3,260,50,200,18,True,"__Mark the ISO as Ventoy Compatible, scan for Ventoy during startup and mount the source ISO if needed." bvl_Options="Additional Configuration",1,12,5,110,625,168,8,Bold cb_UserConfigFile="Include additional configuration file",1,3,15,225,200,18,False -fb_UserConfigFile=,1,13,15,245,517,20,file,"Title=Select your config file","Filter=AutoIt3 Scripts|*.au3;*.a3x|PECMD Scripts|*.ini;*.wcs;*.wcz|All Files|*.*" +fb_UserConfigFile=,1,13,15,245,517,20,file,"Title=Select your config file","Filter=Script Files|*.au3;*.a3x;*.ini;*.wcs;*.wcz|AutoIt3 Scripts|*.au3;*.a3x|PECMD Scripts|*.ini;*.wcs;*.wcz|All Files|*.*" lbl_AdditionalConfig="You may choose to include an additional AutoIt3 or PECMD configuration script in your project.#$x#$xThis script will be executed after the initial project configuration has been completed, but before the shell (explorer, etc.) is started.#$x#$xThe script will be placed on the root of the boot media as [PhoenixPE-UserConfig]. This allows the configuration to be manually edited on-the-fly (if the media is Read/Write) without rebuilding the project.",1,1,17,130,602,92,8,Normal btn_GenerateSampleConfig="Sample Config",1,8,539,245,80,20,GenerateSampleConfig,0,True,"__Generate a sample configuration file." bvl_AdvancedOptions="Advanced Options",0,12,5,290,625,71,8,Bold -cb_CustomConfigFile="Override the project config and use a custom PhoenixPE.au3 file",0,3,15,308,508,18,False,"__If enabled this PhoenixPE.au3 file will be used instead of the project's configuration.#$x#$xWARNING: This option is absolutely unsupported and, unless you are a developer,#$xthere is a good probability that you will break things. Use at your own risk." +cb_CustomConfigFile="Override the project config and use a custom PhoenixPE.au3 file. (DANGER!)",0,3,15,308,508,18,False,"__If enabled this PhoenixPE.au3 file will be used instead of the project's configuration.#$x#$xWARNING: This option is absolutely unsupported and, unless you are a developer,#$xthere is a good probability that you will break things. Use at your own risk." fb_CustomConfigFile=,0,13,15,328,602,20,file,"Title=Select your custom PhoenixPE.au3 file","Filter=AutoIt3 Scripts|*.au3|All Files|*.*" [InterfaceEncoded]