Browse Source

Fix/finish wizard error handling.

Martijn Laan 1 năm trước cách đây
mục cha
commit
37ce94a0db

+ 1 - 1
Projects/Src/CompRegistryDesigner.pas

@@ -82,7 +82,7 @@ end;
 function TRegistryDesignerForm.GetText: String;
 begin
   Result := '';
-  FRegistryHelper.AddScript(Result);
+  FRegistryHelper.AddScript(Result, True);
 end;
 
 procedure TRegistryDesignerForm.InsertButtonClick(Sender: TObject);

+ 1 - 1
Projects/Src/CompWizard.pas

@@ -978,7 +978,7 @@ begin
       Setup := Setup + 'PrivilegesRequiredOverridesAllowed=commandline' + SNewLine;
       
     { AppRegistry }
-    FRegistryHelper.AddScript(Registry);
+    FRegistryHelper.AddScript(Registry, False);
 
     { Languages }
     if FLanguages.Count > 1 then begin

+ 19 - 4
Projects/Src/CompWizardRegistryHelper.pas

@@ -34,7 +34,7 @@ type
         const FileButton: TButton; const UninsDeleteKeyCheck,
         UninsDeleteKeyIfEmptyCheck, UninsDeleteValueCheck, MinVerCheck: TCheckBox;
         const MinVerEdit: TEdit);
-      procedure AddScript(var Registry: String);
+      procedure AddScript(var Registry: String; const AllowException: Boolean);
       property PrivilegesRequired: TPrivilegesRequired write SetPrivilegesRequired;
     end;
 
@@ -93,7 +93,8 @@ begin
     FForm.ActiveControl := FMinVerEdit;
 end;
 
-procedure TWizardFormRegistryHelper.AddScript(var Registry: String);
+procedure TWizardFormRegistryHelper.AddScript(var Registry: String;
+  const AllowException: Boolean);
 
   function NextLine(const Lines: TStrings; var LineIndex: Integer): String;
   begin
@@ -262,6 +263,11 @@ procedure TWizardFormRegistryHelper.AddScript(var Registry: String);
     Result := ';Registry data from file ' + ExtractFileName(FFileEdit.Text);
   end;
 
+  function TextBadHeader: String;
+  begin
+    Result := ';COULD NOT IMPORT ' + ExtractFileName(FFileEdit.Text);
+  end;
+
   function TextFooter(const HadFilteredKeys, HadUnsupportedValueTypes: Boolean): String;
   begin
     Result := ';End of registry data from file ' + ExtractFileName(FFileEdit.Text);
@@ -272,6 +278,9 @@ procedure TWizardFormRegistryHelper.AddScript(var Registry: String);
   end;
 
 begin
+  if FFileEdit.Text = '' then
+    Exit;
+
   var Lines := TStringList.Create;
   var OutLines := TStringList.Create;
   try
@@ -280,8 +289,14 @@ begin
     { Official .reg files must have blank lines as second and last lines but we
       don't require that so we just check for the header on the first line }
     const Header = 'Windows Registry Editor Version 5.00'; { don't localize }
-    if (Lines.Count = 0) or (Lines[0] <> Header) then
-      raise Exception.Create('Invalid file format.');
+    if (Lines.Count = 0) or (Lines[0] <> Header) then begin
+      if AllowException then
+        raise Exception.Create('Invalid file format.')
+      else begin
+        Registry := Registry + TextBadHeader + SNewLine;
+        Exit;
+      end;
+    end;
 
     var LineIndex := 1;
     var HadFilteredKeys := False;