Selaa lähdekoodia

Bug 1993: When installing an extension from a file, it is always saved in UTF-8 with BOM, disregarding the original encoding

https://winscp.net/tracker/1993

+ When installing from a URL, not saving the extension with BOM (to allow downloading extensions in languages that do not support it, like batch files)

Source commit: f5efcf827a1045340da7c57ae08a9237686dc05f
Martin Prikryl 4 vuotta sitten
vanhempi
sitoutus
fb7bad0af2
1 muutettua tiedostoa jossa 13 lisäystä ja 1 poistoa
  1. 13 1
      source/forms/Preferences.cpp

+ 13 - 1
source/forms/Preferences.cpp

@@ -3,6 +3,7 @@
 #pragma hdrstop
 
 #include <StrUtils.hpp>
+#include <System.IOUtils.hpp>
 #include <Common.h>
 #include <math.h>
 
@@ -2647,6 +2648,7 @@ void __fastcall TPreferencesDialog::AddExtension()
     bool Latest;
     UnicodeString FileName;
     UnicodeString ExtensionPath;
+    UnicodeString LinesSourcePath;
     std::unique_ptr<TStringList> Lines(new TStringList());
     std::unique_ptr<TCustomCommandType> CustomCommand;
 
@@ -2716,6 +2718,7 @@ void __fastcall TPreferencesDialog::AddExtension()
           ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
         }
 
+        LinesSourcePath = Path;
         LoadScriptFromFile(Path, Lines.get());
       }
 
@@ -2787,7 +2790,16 @@ void __fastcall TPreferencesDialog::AddExtension()
           ExtensionPath = WinConfiguration->UniqueExtensionName(LeftStr(OriginalExtensionPath, P - 1), Counter) + RightStr(OriginalExtensionPath, OriginalExtensionPath.Length() - P + 1);
         }
 
-        Lines->SaveToFile(ApiPath(ExtensionPath));
+        if (!LinesSourcePath.IsEmpty())
+        {
+          // Copy as is, exactly preserving the file encoding
+          TFile::Copy(ApiPath(LinesSourcePath), ApiPath(ExtensionPath));
+        }
+        else
+        {
+          Lines->WriteBOM = false;
+          Lines->SaveToFile(ApiPath(ExtensionPath));
+        }
 
         FAddedExtensions->Add(ExtensionPath);
       }