My programs are usually distributed as a zip file containing the exe as well as a folder structure with DLLs, etc. Sometimes new users will download it and try and run the exe from within the zip file.
At present I raise an error about the DLLs not found and call Application.Terminate but it seems to keep running due to MadExcept and they will see more errors if they choose to continue.
Is there a way to detect if the exe is withing a zip file and terminate more cleanly after that first fatal error?
I just tried this on W10 and found that Params(0) contained āAppData\Local\Tempā but not anything with āzipā. This is possibly because I have 7Zip installed?
Either way, checking for āAppData\Local\Tempā should cover it no matter what tool Windows uses.
I still have the problem that calling Application.Terminate still lets the user progress further by clicking Continue to the MadExcept prompts.
I would run SameText( ExtractPath(Applilication.ExeName), IncludeTrailingPathDelimiter(GetEnvironmentVariable(āTEMPā))) is true and if true then terminate the application.
Because thereās a random folder added to the temp folder for the unzipping, I ended up with this:
AppFolder := LowerCase(ExtractFilePath(Application.ExeName));
TempFolder := LowerCase(IncludeTrailingPathDelimiter(GetEnvironmentVariable('TEMP')));
if Pos(TempFolder,AppFolder) > 0 then
begin
ShowMessage('Application needs to be unzipped first. Terminating now.');
ForcedHalt := True;
Halt;
end;
The ForcedHalt is used in the finalization section to bypass the unloading of the DLLs that were never loaded due to the error in the initialization.